WASDEV(The AI WorkShop)Docs Website Download

Chapter 1 · GAD language

Devices and firmware

What GAD does today for a program that runs on a machine, what is proved by the compiler, and what is not available yet.

What is available and what is not

  • Available: a program that declares <aparèy>, the proof that a value stays an integer, hexadecimal and binary numbers, exact 32-bit words, memory blocks and the bridge to C, C++ and Rust.
  • Available: driving hardware on a board that runs Linux, for example a Raspberry Pi.
  • Not available yet: GAD RASIN, the firmware written and flashed on a bare board (ESP32, Cortex-M). The compiler does not build it.
  • Not available yet: GAD Mobile (Android and iOS).

A program for a device

On a computer, a loop that never ends is almost always a mistake: GAD stops it. On a device it is the opposite, and <aparèy> says so.

<aparèy non="Kontwolè Limyè">

LED = 0b0001
mwatye = 2.5
k = 0
pandan k pa plis pase 3
    k ajoute 1
fini
montre k
The check warns about the decimal number on line 4
The check warns about the decimal number on line 4
  1. Create the file aparèy.gad with this code.
  2. Open the Run menu and choose GAD: Check syntax.
aparèy.gad : sentaks la kòrèk (6 deklarasyon, 1 fichye).
  avètisman :
    liy   4 : `mwatye` se yon nonb desimal. Yon aparèy pa gen FPU pou `f64` — chak kalkil ap pase nan lojisyèl.
  • A device often has no unit for decimal numbers. The check says which line uses one.
  • The warning appears only when the program declares <aparèy>.
  • 0x40021000 is hexadecimal and 0b1011 is binary. The formatter keeps the form you wrote.

Drive a pin on a Linux board

On Linux, a GPIO pin is a file. This program needs no driver and no library.

sèvi ak fichye

fichye.ekri("/sys/class/gpio/export", "17")
fichye.ekri("/sys/class/gpio/gpio17/direction", "out")

k = 0
pandan k pa plis pase 9
    fichye.ekri("/sys/class/gpio/gpio17/value", "1")
    tann(300)
    fichye.ekri("/sys/class/gpio/gpio17/value", "0")
    tann(300)
    k ajoute 1
fini
  • This example comes from the GAD reference. It was not run for this page: it needs a Linux board.
  • This is not firmware: the board runs a complete Linux.

Build a machine instruction

The family bit works on exact 32-bit words. This action builds a real RISC-V instruction, addi x1, x0, 5.

fè addi ak rd, rs1, imedya
    mo = bit.pouse-goch(bit.e(imedya, 4095), 20)
    mo = bit.osnon(mo, bit.pouse-goch(rs1, 15))
    mo = bit.osnon(mo, bit.pouse-goch(rd, 7))
    retounen bit.osnon(mo, 19)
fini

montre addi(1, 0, 5)
montre nonb.an-baz(addi(1, 0, 5), 16)
5243027
500093
  • 500093 in hexadecimal is 0x00500093, the word a RISC-V disassembler reads as this instruction.