L1VM - switch in Brackets
Switch statement in Brackets
I finally added a switch statement to my language Brackets. I created a new operator: “?” for a switch compare.
Switch in Brackets
Ich fügte ein switch Statement in Brackets ein. Ich erstellte einen neuen Operator: “?”.
prog/switch.l1com:
// Brackets - Hello world! switch // (main func) (set int64 1 zero 0) (set int64 1 x 23) (set int64 1 y 42) (set int64 1 a 0) (set string s hello "Hello world!") (set string s 23_str "= 23") (set string s 42_str "= 42") (set const-int64 1 23_const 23) (set const-int64 1 42_const 42) // print string (6 hello 0 0 intr0) (7 0 0 0 intr0) ((x y *) a =) (4 a 0 0 intr0) (7 0 0 0 intr0) (switch) (y 23_const ?) (6 23_str 0 0 intr0) (7 0 0 0 intr0) (break) (y 42_const ?) (6 42_str 0 0 intr0) (7 0 0 0 intr0) (break) (switch-end) (255 zero 0 0 intr0) (funcend)
The switch uses the iternal “if” code block, so it can be written as a “if” like statement too:
Switch verwendet intern den “if” Codeblock. Man kann es auch wie ein “if” verwenden:
prog/switch-3.l1com:
// Brackets - Hello world! if instead of switch // (main func) (set int64 1 zero 0) (set int64 1 x 23) (set int64 1 y 42) (set int64 1 a 0) (set string s hello "Hello world!") (set string s 23_str "= 23") (set string s 42_str "= 42") (set const-int64 1 23_const 23) (set const-int64 1 42_const 42) // print string (6 hello 0 0 intr0) (7 0 0 0 intr0) ((x y *) a =) (4 a 0 0 intr0) (7 0 0 0 intr0) (y 23_const ?) (6 23_str 0 0 intr0) (7 0 0 0 intr0) (endif) (y 42_const ?) (6 42_str 0 0 intr0) (7 0 0 0 intr0) (endif) (255 zero 0 0 intr0) (funcend)