2022-05-15 21:59:59 +02:00
|
|
|
# Raspberry Pi Pico Machine Code Emulator with compiler for LISP
|
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
Recently I was wondering if it is possible to run a program from the pico's ram. That's my answer!
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
## Try it?
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
- Download the git repository.
|
|
|
|
- Flash pico.ino with the arduino ide.
|
|
|
|
- Write a program with my LISP Syntax
|
|
|
|
- Compile it with: sh build.sh [lisp-file-input] [assembly-file-output] [hex-file-output]
|
|
|
|
- Copy and Past the Binary in Hex in the Serial Monitor
|
|
|
|
- Type start to run your Program
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
## Syntax in LISP
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
### DataTypes
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
- uint8
|
|
|
|
- uint16
|
|
|
|
- uint32
|
|
|
|
- int8
|
|
|
|
- int16
|
|
|
|
- int32
|
|
|
|
- float
|
|
|
|
- bool
|
2022-05-15 22:34:54 +02:00
|
|
|
- (Strings or chars are currently not supported)
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:33:38 +02:00
|
|
|
### Calculations
|
2022-05-15 22:32:35 +02:00
|
|
|
```lisp
|
|
|
|
(+ a b)
|
|
|
|
(+ a b c) ;...
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
(- a b)
|
|
|
|
(- a b c) ;...
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
(* a b)
|
|
|
|
(* a b c) ;...
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
(/ a b)
|
|
|
|
(/ a b c) ;...
|
|
|
|
```
|
2022-05-15 22:33:38 +02:00
|
|
|
### print
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
```lisp
|
|
|
|
(print a)
|
|
|
|
```
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:33:38 +02:00
|
|
|
### Comparisons and Branches
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
```lisp
|
|
|
|
(< 4 5)
|
|
|
|
(> 5 4)
|
|
|
|
(= 6 6)
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
(if (< 4 5) (print 1) (print 0))
|
|
|
|
;if [condition] [then] [else]
|
|
|
|
```
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
### Variables
|
|
|
|
Define Variables:
|
|
|
|
```lisp
|
|
|
|
(defvar myvar1:uint32 4)
|
|
|
|
(defvar myvar2:float (+ 5 1.5))
|
|
|
|
```
|
|
|
|
Set Variables:
|
|
|
|
```lisp
|
|
|
|
(let myvar1 4)
|
|
|
|
(let myvar2 (+ 5 1))
|
|
|
|
```
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:33:38 +02:00
|
|
|
### Functions
|
2022-05-15 22:32:35 +02:00
|
|
|
Define and call Functions:
|
2022-05-15 21:59:59 +02:00
|
|
|
|
2022-05-15 22:32:35 +02:00
|
|
|
```lisp
|
|
|
|
(defun faculty:uint32 (input:uint32)
|
|
|
|
(print input)
|
|
|
|
(if (< in 2) 1 (* input (faculty (- input 1))))
|
|
|
|
)
|
|
|
|
(print (faculty 10))
|
|
|
|
```
|