-
Variable ranges
01/17/2023 at 16:43 • 0 commentsI did add a variable range keyword in to Brackets. If a variable is out of legal range then a runtime exception happens! This was inspired by Ada. More here on my blog: L1VM ranges.
-
Brackets - switch
03/29/2022 at 19:23 • 0 comments// switch.l1com // Brackets - Hello world! switch // #include (main func) (set int64 1 zero 0) (set int64 1 x 23) (set int64 1 y 42) (set string s 23_str "y = 23") (set string s 42_str "y = 42") (set const-int64 1 23_const 23) (set const-int64 1 42_const 42) (set string s hello_str "Hello world!") (set int64 1 a 0) // print string print_s (hello_str) print_n ((x y *) a =) print_i (a) print_n (switch) (y 23_const ?) print_s (23_str) print_n (break) (y 42_const ?) print_s (42_str) print_n (break) (switchend) exit (zero) (funcend)
This program uses the switch statement. It prints out:
$ l1vm prog/switch -q Hello world! 966 y = 42
-
Math demo program
03/29/2022 at 19:01 • 1 comment// math-lib.l1com // math library demo // #include <math-const.l1h> #include <intr.l1h> (main func) (set int64 1 zero 0) (set int64 1 randstart 2003) (set int64 1 random 0) (set int64 1 digits 3) (set int64 1 numstr_len 30) (set int64 1 not_num 0) (set int64 1 not_ret) (set string 30 numstr "") (zero :math_init call) (loadreg) (randstart :math_randinit call) (loadreg) (:math_randint call) (random stpopi) (loadreg) print_i (random) print_n print_d (m_pi@math) print_n // round pi to "digits" (3) digits and store number in string (m_pi@math digits numstraddr numstr_len :double_rounded_string call) (loadreg) print_s (numstr) print_n (not_num :math_not call) (not_ret stpopi) (loadreg) print_i (not_ret) print_n // close module free_mod (zero) exit (zero) (funcend) #include <math-lib.l1h>
This demo program prints out:
$ l1vm lib/math-lib -q 3368910609462220170 3.1415926536 3.142 1
-
MPFR floating point numbers module
10/21/2019 at 19:40 • 0 commentsI wrote a module for calculate with big floating point numbers (MPFR library module).
In the library are more than 80 math functions. The numbers are defined by setting text strings.
After a calculation the numbers can be printed on screen or saved as text strings.
I included a demo in the library code: lib/mpfr-lib-auto.l1com.
-
Build files for OSv unikernel
09/08/2019 at 14:14 • 0 commentsIn my GitHub repository of L1VM I added build directories for OSv unikernel support.
The goal is here to put the L1VM in a image together with the OSv unikernel.
You need to install the "capstan" build tool of OSv first. The build script makes an Qemu .img file which can run by Qemu or be installed on real hardware.
One demo shows how to load a module, in this case the math module. So you can load modules from your L1VM programs too!
-
Array variables access
06/01/2019 at 08:35 • 0 commentsI added array variable access in the bracket compiler:
// array demo // (main func) (set int64 1 zero 0) (set int64 1 one 1) (set int64 1 offset 8) (set int64 1 x 23) (set int64 1 y 42) (set int64 1 a 0) (set int64 1 b 0) (set int64 2 z 0 0) // assign to array (x z [ zero ] =) (y z [ offset ] =) // get array variable (z [ zero ] a =) (z [ offset ] b =) (4 a 0 0 intr0) (7 0 0 0 intr0) (4 b 0 0 intr0) (7 0 0 0 intr0) (255 zero 0 0 intr0) (funcend)
All variable types are supported! The source code is on GitHub. There are some examples in the prog/ directory.
-
Double float benchmark with close to C speed
05/18/2019 at 18:54 • 0 commentsI wrote a benchmark calculating with double float numbers.
The benchmark on my L1VM is close to a native C program doing the same math.
Here is the L1VM benchmark source code:
(main func) (set int64 1 zero 0) (set double 1 x 23.0) (set double 1 y 42.0) (set double 1 z 7.0) (set double 1 a 1.0) (set int64 1 max 80000000Q) (set int64 1 one 1) (ASM) loada zero, 0, I0 loadd x, 0, F1 loadd y, 0, F2 loadd z, 0, F3 loadd a, 0, F4 loadd a, 0, F10 loadd y, 0, F22 loadd x, 0, F20 loada one, 0, I4 loada max, 0, I5 loada one, 0, I6 loadl :jit, I40 loadl :jit_end, I41 // run jit compiler intr0 253, I40, I41, 0 :loop // call jit code intr0 254, I0, 0, 0 // jump to following non-jit code jmp :next :jit addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F22, F10 addd F10, F22, F10 addd F10, F22, F10 addd F10, F22, F10 addd F10, F22, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F20, F10 addd F10, F22, F10 addd F10, F22, F10 addd F10, F22, F10 addd F10, F22, F10 :jit_end addd F10, F22, F10 // store :next intr0 5, F10, 0, 0 intr0 7, 0, 0, 0 addi I4, I6, I4 lseqi I4, I5, I30 jmpi I30, :loop intr0 5, F10, 0, 0 intr0 7, 0, 0, 0 intr0 255, 0, 0, 0 (ASM_END) (funcend)
Here is the result of the C program:
$time ./double-test >/dev/null 2>&1 real 1m3,400s user 1m3,249s sys 0m0,148s
And my L1VM:
$time vm/l1vm prog/jit-test-double >/dev/null 2>&1 real 1m11,828s user 1m11,704s sys 0m0,120s
So my VM is close to C in that case. :)
-
Time and date functions
02/28/2019 at 14:12 • 0 commentsI added time and date functions via interrupt 0.
So programs can use this information to do something with it.
I wrote a little demo which shows "Hello world!" and the current time.
Here it is:
// bra(et - Hello world! and time!! // (main func) (set int64 1 zero 0) (set string 13 hello "Hello world!") (set string 2 colon ":") (set int64 1 hour 0) (set int64 1 min 0) (set int64 1 sec 0) (set int64 1 ten 10) (set int64 1 f 0) // print string (6 hello 0 0 intr0) // print newline (7 0 0 0 intr0) (17 hour min sec intr0) (((hour ten <) f =) f if) (4 zero 0 0 intr0) (endif) (4 hour 0 0 intr0) (6 colon 0 0 intr0) (((min ten <) f =) f if) (4 zero 0 0 intr0) (endif) (4 min 0 0 intr0) (6 colon 0 0 intr0) (((sec ten <) f =) f if) (4 zero 0 0 intr0) (endif) (4 sec 0 0 intr0) (7 0 0 0 intr0) (255 zero 0 0 intr0) (funcend)