L1VM - loadl

In Brackets meiner Programmiersprache für die L1VM kann man jetzt “loadl” verwenden. Man kann mit “loadl” ein Label in einer Variablen speichern. Das braucht man z.B. für den Start eines neuen Threads. Jetzt geht das auch ohne inline Assembly!

In Brackets my programming language for the L1VM now “loadl” can be used. With “loadl” you can save a label into a variable. This is needed for example for starting a new thread. Now this works without inline assembly!

Here is a full example program: (it is included on my GitHub repo in the prog/ directory)

// hello-thread-2.l1com
// Brackets - Hello world! threads
//
// This is an exammple how to launch threads using the new compiler opcode "loadl".
//
(main func)
	(set int64 1 zero 0)
	(set int64 1 one 1)
	(set int64 1 two 2)
	(set int64 1 three 3)
	(set int64 1 four 4)
	(set int64 1 run 0)
	(set int64 1 f 0)
	(set int64 1 delay 4000)
	(set int64 1 cpu 0)
	(set string s infostr "starting threads...")
	// run the two threads
	(4 cpu 0 0 intr1)
	(((cpu zero ==) f =) f if)
		(6 infostr 0 0 intr0)
		(7 0 0 0 intr0)
		(:start_thread !)
		(8 delay 0 0 intr0)
		(one run =)
	(endif)
	(255 0 0 0 intr0)
(funcend)
(hello_a func)
	(set string s hello@hello_one "Hello world! thread 1")
	(set int64 1 delay@hello_one 2000)
	(6 hello@hello_one 0 0 intr0)
	(7 0 0 0 intr0)
	(8 delay@hello_one 0 0 intr0)
(funcend)
(hello_b func)
	(set string s hello@hello_two "Hello world! thread 2")
	(set int64 1 delay@hello_two 2000)
	(6 hello@hello_two 0 0 intr0)
	(7 0 0 0 intr0)
	(8 delay@hello_two 0 0 intr0)
(funcend)
(start_thread func)
	(set int64 1 run_th 0)
	(set int64 1 lab_hello_one 0)
	(set int64 1 lab_hello_two 0)
	(set int64 1 zero_th 0)
	(set int64 1 one_th 1)
	(set int64 1 f_th 0)
	(set int64 1 delay_th 2500)
	(reset-reg)
	(:hello_a lab_hello_one loadl)
	(:hello_b lab_hello_two loadl)
	(((run_th zero_th ==) f_th =) f_th if)
		// run threads
		(0 lab_hello_one 0 0 intr1)
		(0 lab_hello_two 0 0 intr1)
		(one_th run_th =)
	(endif)
	(8 delay_th 0 0 intr0)
	(1 0 0 0 intr1)
	(255 0 0 0 intr0)
(funcend)