L1VM - course 01
L1VM - course 01
Hello world!
Here I want to start a little course about programming in my language Brackets. Here we go: “Hello world” in Brackets:
// hello.l1com
// Brackets - Hello world!
//
#include <intr.l1h>
(main func)
(set int64 1 zero 0)
(set int64 1 x 23)
(set int64 1 y 42)
(set int64 1 a 0)
(set string 13 hello "Hello world!")
// print string
print_s (hello)
print_n
((x y *) a =)
print_i (a)
print_n
exit (zero)
(funcend)
Here is the output:
$ l1vm prog/hello -q
Hello world!
966
So the string “hello” with the value “Hello world!” gets printed out. And the result of the calculation: “((x y *) a =)” is printed by “print_i (a)”.
The variables are declared by the “set” statement above.
if if+ else endif
Here is a program which uses the if and if+ statements. If you want to use “else” then you have to use “if+”!
// if-4.l1com
//
// if+, else, endif demo
(main func)
(set int64 1 zero 0)
(set int64 1 one 1)
// change "x" and look at the output printed
(set int64 1 x 6)
//
//
(set int64 1 y 10)
(set int64 1 z 5)
(set int64 1 twen 20)
(set int64 1 f 0)
(set string s less_str "x < 10")
(set string s more_str "x => 10")
(set string s more_less_20_str " x <= 20")
(set string s five_less_str " x <= 5")
(set string s five_more_str " x > 5")
// check if x is less or more ten
// (optimize-if)
(((x y <) f =) f if+)
(6 less_str 0 0 intr0)
(((x z <=) f =) f if+)
(6 five_less_str 0 0 intr0)
(else)
(6 five_more_str 0 0 intr0)
(endif)
(else)
(6 more_str 0 0 intr0)
(((x twen <=) f =) f if)
(6 more_less_20_str 0 0 intr0)
(endif)
(endif)
(7 0 0 0 intr0)
(255 0 0 0 intr0)
(funcend)
Note here: “(6 five_less_str 0 0 intr0)” is the print string interrupt. And the “(7 0 0 0 intr0)” means print a new line. In later programs I use “print_s” and “print_n” interrupt wrapper functions.
And here is the output:
$ l1vm prog/if-4 -q
x < 10 x > 5
Here we have some nested “if+” and “if” statements. They are comparisons to the “x” variable. Feel free to set “x” to a different value. And watch the output changes! Set the value of “x” to “11”:
$ l1vm prog/if-4 -q
x => 10 x <= 20
Update:
variable ranges
variable shortname