Close

Brackets - switch

A project log for L1VM

A tiny virtual machine with a 64 bit RISC CPU.

jay-tjay-t 03/29/2022 at 19:230 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

Discussions