Skip to content

hardenedlinux/animula

Repository files navigation

Animula logo

Intro and history

Animula means "a little soul" in Latin. It is a highly optimized and functional programming flavored Virtual Machine for compact embedded system. You just need 10KB to run a functional programming language, such as Scheme.

This is the Animula VM core.

You may want to read this annoucment: LambdaChip renamed to Animula

lambdachip.com is obsoleted, we'll move all the docs here gradually.

The Compiler

The official reference compiler implementation of Animula is Laco. Laco aims to be a highly optimized compiler infrasturcture for compact embedded system.

Programming Languages

It's possible to support multiple funciontal languages on Animula. Here're the expected languages list:

  • Scheme R7RS-small
  • Python 3.10 (WIP)
  • Lua 5.2 (WIP)

Contributions are welcome!

Documentation

Please visit Animula documents for more information.

Download

Download for Linux: animula-linux

Download for ZephyrRTOS: animula-zephyr

Build and run

The code can not be built directly, you have to use building project for specific platform.

Animula VM supports LEF (lightweight executable format) which is optimized for embedded system. You need to compile your source code to LEF with Laco compiler, and run the LEF with Animula VM.

Compile the laco

Dependencies

Please make sure you've installed Guile-3.0+:

sudo apt install -y guile-3.0

Build Laco compiler

# download laco source code
./configure
make -j5 # try more cores to speedup, it's not a tiny project
sudo make install

Or you don't have to install it, and you may use it locally:

./pre-inst-env scripts/laco

Compile code with Laco

laco foo.scm -o foo.lef

Error advices from ChatGPT

If you have API token of OpenAI, you may take advantage of powerful AI to give you advices to debug the code.

sudo apt install -y curl jq
export LACO_OPENAI_KEY=your_openai_key

If Laco encounter compiling error, and you've set LACO_OPENAI_KEY, then Laco will call ChatGPT to review the code. Just try it, Enjoy!

For users behind firewall, you may need to set https_proxy with you VPN.

For more information of Laco compiler, please checkout Animula documents

For Linux

Animula-linux is used for testing on CI, however, it is possible to implemnt practical Functional Programming language on POSIX operating system. Contributions are welcome!

# In Animula repo
make # if you haven't built Animula VM
./animula-vm foo.lef

Sometimes, animula-linux is good to debug the VM, but sometimes you may have to debug on board. If you use Alonzo board, you may debug the VM via BLE.

For ZephyrRTOS

You must have a ZephyrRTOS supported board to run Animula. And Animula developers always prefer Alonzo board to test.

Write the first Scheme program

Traditionally, when you start to learn a new programming environment, the first program is always hello world which is a trivial program to print a "hello world" string. However, in embedded software programming, the "hello world" is different, we call it blink which is also a trivial program to make LED blinking.

Open your favorite editor or IDE, and create a new file named program.scm. Just copy and paste the code below:

(define (main x)
(gpio-toggle! 'dev_led0)
(usleep 200000)
(if (= x 0)
#t
(main (- x 1))))
(main 10)

The code is self-explain, you may try to modify it to verify your ideas. Don't worry, the Alonzo board will never be bricked.

NOTE: If you bricked it, congrats! You have the chance to learn how to flash the bootloader of the Alonzo board.

Compile it

Now we can compile the program with the Laco compiler:

laco program.scm

If the compilation works successfully, you may not see anything output when it is finished. Now you should find there's a new file named program.lef. That's the generated bytecode file for the Animula virtual machine.

Copy the program.lef to TF card and then insert the TF card to Alonzo board.

TF card

Animula virtual machine will scan the TF card and find the file named program.lef. When it's found then run it automatically. If you use other names then it doesn't work at all.

Blinking!

Everything is OK! Please connect the Alonzo to your PC or power bank with a USB Type-C cable, and the board will power on, then you should see the LED blinking periodically.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages