aBelle – a small language you can follow down to the machine code

Written like Python, compiled for Windows and the ESP32 board, debugged line by line in Asmonite.

aBelle has few words, three types and no hidden rules. Its compiler is written in aBelle itself. It writes the machine code and the program file itself, without an assembler and without a linker. In Asmonite you press F9: the program is compiled and runs in the debugger, with breakpoints, steps through the lines and the values of the variables.

From Asmonite 0.12.0 on aBelle is in the ZIP: the three compilers abelle.exe, abelle64.exe and abelle_esp32.exe next to Asmonite.exe, the examples in examples\abelle and the F1 help. The license of Asmonite applies: free, and what you write with it is yours.

Two first programs

On the left a program for Windows: it takes WriteFile from kernel32.dll and writes to the console. On the right one for the ESP32 board: the registers of the chip are arrays at their address, and the LED blinks.

Windows
extern "kernel32.dll":
    def GetStdHandle(n: i32) u32
    def WriteFile(h: u32, buf: pchar, n: u32,
                  written: pchar, ov: u32) i32

written: char[4]

def strlen(s: pchar) i32:
    n = 0
    while s[n] != 0: n += 1
    return n

def print(s: pchar):
    WriteFile(GetStdHandle(-11), s, u32(strlen(s)), written, 0)

def main() i32:
    print("Hello, world!\n")
    return 0
ESP32
target "esp32"

gpio:  u32[0x140] at 0x3FF44000    # the GPIO registers
iomux: u32[64]    at 0x3FF49000    # the function of each pin

LED = 2

def wait():
    for i in 0..500000: pass     # about half a second

def main():
    iomux[0x40 / 4] = 0x2800            # GPIO 2 is a GPIO
    gpio[(0x530 + 4 * LED) / 4] = 0x100
    gpio[0x24 / 4] = 1 << LED          # an output
    while True:
        gpio[0x08 / 4] = 1 << LED      # on
        wait()
        gpio[0x0C / 4] = 1 << LED      # off
        wait()

The files are called .abel. A block follows a line with : and is indented four spaces further, as in Python. A program for a board says so in its first line with target; without it, it is one for Windows.

The language at a glance

aBelle is small on purpose: just what a compiler needs to translate itself, and the registers of a board. All of it in detail is in the language description (provisional version).

WhatHow
Typesi32 (the default), u32 for addresses and bit patterns, pchar the address of a byte. Converting always explicitly: u32(x)
Variablesglobal with a type: count: i32 = 0; local at the first assignment: n = 0
Arraysfixed: names: i32[100], src: char[2000]; growing: toks: i32[] with append, len, resize; at an address: gpio: u32[0x140] at 0x3FF44000
Functionsdef add(a, b) i32:; recursion; a function may be used before its place
Control flowif / elif / else, while, for i in 0..n:, break, continue, return
Arithmeticthe operators of Python for whole numbers, and x += 1 and the others; / cuts towards 0 as the hardware does
Windowsfunctions of a DLL with extern "kernel32.dll":, also cdecl and ... for printf
Boardstarget "esp32" in the first line; registers as an array at their address, a function of the ROM with def ets_delay_us(us: u32) at 0x40008534
Several filesinclude "inc/uart.abel" puts in the text of a file, each file once

Three targets

The same language, three compilers, each from the same source but for the part that writes the code and the file.

Windows x86Windows x64ESP32
Compilerabelle.exeabelle64.exeabelle_esp32.exe
Chosen bythe defaultProject > aBelle for x64target "esp32"
Outputa console program (PE)a console program (PE32+)code for the IRAM, data for the DRAM
F9compiles and starts in the debuggerloads into the RAM over the USB cable; Shift+F9 writes it into the flash first

On the ESP32 an aBelle program can also stay on the board as a file: Debug > ESP32 Board Files uploads it to the console of examples/esp32/console.asm, which starts it, after every reset if you like.

Libraries for the ESP32: UART and WiFi

The examples for the ESP32 include files from examples\abelle\esp32\inc. They are written in aBelle themselves: you can read them, change them and follow them in the debugger.

FileWhat it brings
uart.abeltext, numbers and hex numbers over UART0, the COM port of the board
wifi.abelthe WiFi: load the service from the board, find networks, connect, send and receive frames, errors as a sentence
net.abelARP, IPv4, ICMP (ping), UDP, DHCP, DNS and mDNS
tcp.abelTCP, one connection at a time, as a client or a server
network.abelthe name and the password of your network

The WiFi itself runs on the second core of the ESP32, the aBelle program on the first. When the debugger holds the program at a breakpoint, the connection stays up, and what comes in waits in a buffer. So you go line by line through a DHCP exchange or a TCP connection. Once per board this needs Install WiFi; more on the ESP32 page.

Debugging in the source

Next to the program the compiler writes a map file: which code belongs to which line and where the variables are. With it Asmonite debugs right in the .abel file.

A compiler that translates itself

aBelle came about the way languages used to: in stages, until the language carries itself.

  1. Stage 0, written in Delphi, translates aBelle into assembler for Asmonite.
  2. The compiler in aBelle, translated by stage 0, writes the machine code and the program file itself.
  3. It translates itself into the same file, byte for byte, in about 25 milliseconds. From here on aBelle grows in aBelle.

The compiler works in one pass: read, split into tokens and write code at once, without a syntax tree. Over 350 tests and a fuzzer with random programs check that all compilers do the same.

Examples

WindowsESP32
hello.abel – Hello, world!blink.abel – the LED blinks
factorials.abel – recursionhello_uart.abel – text over the serial port
table.abel – the times tabletimer.abel – microseconds from the timer
fizzbuzz.abel – if / elif / elsetemperature.abel – the sensor in the chip
primes.abel – the sieve of Eratostheneschipinfo.abel, dice.abel, sieve.abel
strings.abel, printf.abel – textreaction.abel – a reaction game, clock.abel – the clock
WiFi: scan, dhcp, dns, ping, ntp, arpscan, wol, udpecho, httpget, webserver, telnetd

The examples for Windows are in examples\abelle, those for the ESP32 in examples\abelle\esp32. All ESP32 examples with a description →

What is not (yet) there