diff --git a/src/tools/assembler/assembler.c b/src/tools/assembler/assembler.c index 6b769d9..8f3b62c 100644 --- a/src/tools/assembler/assembler.c +++ b/src/tools/assembler/assembler.c @@ -216,6 +216,7 @@ bool define_global(VM *vm, SymbolTable *st) { default: return false; } + next_token_is(TOKEN_SEMICOLON); symbol_table_add(st, s); return true; @@ -297,6 +298,8 @@ void define_var(VM *vm, SymbolTable *st, Token regType) { Token reg_num = next_token_is(TOKEN_LITERAL_INT); s.ref = atoi(reg_num.start); + + next_token_is(TOKEN_SEMICOLON); symbol_table_add(st, s); } @@ -403,6 +406,8 @@ void build_symbol_table(VM *vm, char *source, SymbolTable *st) { next_token_is(TOKEN_LITERAL_NAT); vm->pc+=4; + + next_token_is(TOKEN_SEMICOLON); } else if (streq(token.start, "call")) { vm->pc++; @@ -418,7 +423,12 @@ void build_symbol_table(VM *vm, char *source, SymbolTable *st) { } /* return type */ next = next_token(); - vm->pc++; + vm->pc++; /* we emit a value regardless, a void is register 255 */ + if (next.type == TOKEN_SEMICOLON) { + continue; + } + /* if it is not void, then it was the value */ + next_token_is(TOKEN_SEMICOLON); } else if (streq(token.start, "syscall")) { } else if (streq(token.start, "load_immediate")) { } else if (streq(token.start, "load_indirect_8")) { diff --git a/test/add.ul.ir b/test/add.ul.ir index 3364204..5ed166d 100644 --- a/test/add.ul.ir +++ b/test/add.ul.ir @@ -1,35 +1,35 @@ -global str terminal_namespace = "/dev/term/0" -global str new_line = "\n" -global int x = 1 -global int y = 1 +global str terminal_namespace = "/dev/term/0"; +global str new_line = "\n"; +global int x = 1; +global int y = 1; -function main () - int ans $2 - str ans_string $3 +function main () + int ans $2; + str ans_string $3; - load_absolute_32 x -> $0 - load_absolute_32 y -> $1 - call add $0 $1 -> ans - int_to_string ans -> ans_string - call pln ans_string -> void - exit 0 + load_absolute_32 x -> $0; + load_absolute_32 y -> $1; + call add $0 $1 -> ans; + int_to_string ans -> ans_string; + call pln ans_string -> void; + exit 0; -function add (int a $0, int b $1) - int result $2 - add_int a b -> result - return result +function add (int a $0, int b $1) + int result $2; + add_int a b -> result; + return result; -function pln (str message $0) - str term $1 - int msg_length $2 - str nl $3 - int nl_length $4 - int mode $5 +function pln (str message $0) + str term $1; + int msg_length $2; + str nl $3; + int nl_length $4; + int mode $5; - load_immediate 0 -> mode - syscall OPEN terminal_namespace mode -> term - strlen message -> msg_length - syscall WRITE term message msg_length - strlen new_line -> nl_length - syscall WRITE term nl nl_length - return + load_immediate 0 -> mode; + syscall OPEN terminal_namespace mode -> term; + strlen message -> msg_length; + syscall WRITE term message msg_length; + strlen new_line -> nl_length; + syscall WRITE term nl nl_length; + return; diff --git a/test/fib.ul.ir b/test/fib.ul.ir index d823c9a..e073416 100644 --- a/test/fib.ul.ir +++ b/test/fib.ul.ir @@ -1,48 +1,49 @@ -global str terminal_namespace = "/dev/term/0" -global str new_line = "\n" +global str terminal_namespace = "/dev/term/0"; +global str new_line = "\n"; -function main () - int n $0 - int str_n $1 +function main () + int n $0; + int str_n $1; - load_immediate 35 -> n - call fib n -> n - int_to_string n -> str_n - call pln str_n -> void - exit 0 + load_immediate 35 -> n; + call fib n -> n; + int_to_string n -> str_n; + call pln str_n -> void; + exit 0; -function fib (int n $0) - load_immediate 2 -> $1 +function fib (int n $0) + load_immediate 2 -> $1; - jump_lt_int base_case n $1 + jump_lt_int base_case n $1; - load_immediate 2 -> $3 - sub_int n $3 -> $4 - call fib $4 -> $5 + load_immediate 2 -> $3; + sub_int n $3 -> $4; + call fib $4 -> $5; - load_immediate 1 -> $3 - sub_int n $3 -> $4 - call fib $4 -> $6 + load_immediate 1 -> $3; + sub_int n $3 -> $4; + call fib $4 -> $6; - add_int $6 $5 -> $7 - return $7 + add_int $6 $5 -> $7; + return $7; - else base_case - return n + else base_case; + return n; -function pln (str message $0) - str ts $1 - int mode $5 - int msg_length $2 - str nl $3 - int nl_length $4 +function pln (str message $0) + str ts $1; + int mode $5; + int msg_length $2; + str nl $3; + int nl_length $4; - load_immediate terminal_namespace -> ts - load_immediate 0 -> mode - syscall OPEN ts mode -> ts - strlen message -> msg_length - syscall WRITE ts message msg_length - load_immediate new_line -> nl - strlen nl -> nl_length - syscall WRITE ts nl nl_length - return + load_immediate terminal_namespace -> ts; + load_immediate 0 -> mode; + syscall OPEN ts mode -> ts; + strlen message -> msg_length; + syscall WRITE ts message msg_length; + load_immediate new_line -> nl; + strlen nl -> nl_length; + syscall WRITE ts nl nl_length; + return; + \ No newline at end of file diff --git a/test/hello.ul.ir b/test/hello.ul.ir index 204fab3..7373ad9 100644 --- a/test/hello.ul.ir +++ b/test/hello.ul.ir @@ -3,25 +3,25 @@ global str new_line = "\n" global str message = "nuqneH 'u'?" function main () - str hello $0 + str hello $0; - load_immediate message -> hello - call pln hello -> void - exit 0 + load_immediate message -> hello; + call pln hello -> void; + exit 0; function pln (str message $0) - str ts $1 - int mode $5 - int msg_length $2 - str nl $3 - int nl_length $4 + str ts $1; + int mode $5; + int msg_length $2; + str nl $3; + int nl_length $4; - load_immediate terminal_namespace -> ts - load_immediate 0 -> mode - syscall OPEN ts mode -> ts - strlen message -> msg_length - syscall WRITE ts message msg_length - load_immediate new_line -> nl - strlen nl -> nl_length - syscall WRITE ts nl nl_length - return + load_immediate terminal_namespace -> ts; + load_immediate 0 -> mode; + syscall OPEN ts mode -> ts; + strlen message -> msg_length; + syscall WRITE ts message msg_length; + load_immediate new_line -> nl; + strlen nl -> nl_length; + syscall WRITE ts nl nl_length; + return; diff --git a/test/loop.ul.ir b/test/loop.ul.ir index 26b2406..0cc95f3 100644 --- a/test/loop.ul.ir +++ b/test/loop.ul.ir @@ -1,58 +1,58 @@ -global str terminal_namespace = "/dev/term/0" -global str prompt = "Enter a string:" -global str new_line = "\n" +global str terminal_namespace = "/dev/term/0"; +global str prompt = "Enter a string:"; +global str new_line = "\n"; -function main () - real a $0 - int i $1 - int mode $11 - str term $10 +function main (); + real a $0; + int i $1; + int mode $11; + str term $10; - load_immediate 5.0 -> a - load_immediate 5000 -> i - load_immediate 0 -> $2 - load_immediate -1 -> $3 - load_immediate 5.0 -> $5 - loop loop_body - add_real a $5 -> a - add_int i $3 -> i - jump_ge_int loop_body i $2 - - load_immediate terminal_namespace -> term - load_immediate 0 -> mode - syscall OPEN term mode -> term // Terminal term = open("/dev/term/0", 0); + load_immediate 5.0 -> a; + load_immediate 5000 -> i; + load_immediate 0 -> $2; + load_immediate -1 -> $3; + load_immediate 5.0 -> $5; + loop loop_body; + add_real a $5 -> a; + add_int i $3 -> i; + jump_ge_int loop_body i $2; - nat b $1 - real_to_nat a -> b - load_immediate prompt -> $7 - string_length $7 -> $8 - syscall WRITE term $7 $8 // print prompt + load_immediate terminal_namespace -> term; + load_immediate 0 -> mode; + syscall OPEN term mode -> term; // Terminal term = open("/dev/term/0", 0); - str user_string $9 - load_immediate 32 -> $8 - malloc $8 -> user_string - syscall READ term user_string $8 // read in max 32 byte string + nat b $1; + real_to_nat a -> b; + load_immediate prompt -> $7; + string_length $7 -> $8; + syscall WRITE term $7 $8; // print prompt - call pln user_string -> void - nat_to_string b -> $4 - call pln $4 -> void - real_to_string a -> $3 - call pln $3 -> void - exit 0 + str user_string $9; + load_immediate 32 -> $8; + malloc $8 -> user_string; + syscall READ term user_string; $8 // read in max 32 byte string -function pln (str message $0) - str ts $1 - int mode $5 - int msg_length $2 - str nl $3 - int nl_length $4 + call pln user_string -> void; + nat_to_string b -> $4; + call pln $4 -> void; + real_to_string a -> $3; + call pln $3 -> void; + exit 0; - load_immediate terminal_namespace -> ts - load_immediate 0 -> mode - syscall OPEN ts mode -> ts - strlen message -> msg_length - syscall WRITE ts message msg_length - load_immediate new_line -> nl - strlen nl -> nl_length - syscall WRITE ts nl nl_length - return \ No newline at end of file +function pln (str message $0); + str ts $1; + int mode $5; + int msg_length $2; + str nl $3; + int nl_length $4; + + load_immediate terminal_namespace -> ts; + load_immediate 0 -> mode; + syscall OPEN ts mode -> ts; + strlen message -> msg_length; + syscall WRITE ts message msg_length ; + load_immediate new_line -> nl; + strlen nl -> nl_length; + syscall WRITE ts nl nl_length; + return; \ No newline at end of file diff --git a/test/malloc.ul.ir b/test/malloc.ul.ir index 248ca99..9cb5155 100644 --- a/test/malloc.ul.ir +++ b/test/malloc.ul.ir @@ -1,40 +1,40 @@ -global str terminal_namespace = "/dev/term/0" -global str prompt = "Enter a string:" -global str new_line = "\n" +global str terminal_namespace = "/dev/term/0"; +global str prompt = "Enter a string:"; +global str new_line = "\n"; function main () int mode $11; str term $10; - load_immediate terminal_namespace -> term - load_immediate 0 -> mode - syscall OPEN term mode -> term // Terminal term = open("/dev/term/0", 0); + load_immediate terminal_namespace -> term; + load_immediate 0 -> mode; + syscall OPEN term mode -> term; // Terminal term = open("/dev/term/0", 0); - load_immediate prompt -> $7 - string_length $7 -> $8 - syscall WRITE term $7 $8 // print prompt + load_immediate prompt -> $7; + string_length $7 -> $8; + syscall WRITE term $7 $8; // print prompt - str user_string $9 - load_immediate 32 -> $8 - malloc $8 -> user_string - syscall READ term user_string $8 // read in max 32 byte string + str user_string $9; + load_immediate 32 -> $8; + malloc $8 -> user_string; + syscall READ term user_string $8; // read in max 32 byte string - call pln user_string -> void - exit 0 + call pln user_string -> void; + exit 0; function pln (str message $0) - str ts $1 - int mode $5 - int msg_length $2 - str nl $3 - int nl_length $4 + str ts $1; + int mode $5; + int msg_length $2; + str nl $3; + int nl_length $4; - load_immediate terminal_namespace -> ts - load_immediate 0 -> mode - syscall OPEN ts mode -> ts - strlen message -> msg_length - syscall WRITE ts message msg_length - load_immediate new_line -> nl - strlen nl -> nl_length - syscall WRITE ts nl nl_length - return + load_immediate terminal_namespace -> ts; + load_immediate 0 -> mode; + syscall OPEN ts mode -> ts; + strlen message -> msg_length; + syscall WRITE ts message msg_length; + load_immediate new_line -> nl; + strlen nl -> nl_length; + syscall WRITE ts nl nl_length; + return; diff --git a/test/paint-bw.ul.ir b/test/paint-bw.ul.ir index 4c1fb02..97b8fdf 100644 --- a/test/paint-bw.ul.ir +++ b/test/paint-bw.ul.ir @@ -1,185 +1,185 @@ -global const str screen_namespace = "/dev/screen/0" -global const str mouse_namespace = "/dev/mouse/0" -global const byte BLACK = 0 -global const byte WHITE = 255 -global const byte DARK_GRAY = 73 -global const byte GRAY = 146 -global const byte LIGHT_GRAY = 182 -global byte SELECTED_COLOR = 255 +global const str screen_namespace = "/dev/screen/0"; +global const str mouse_namespace = "/dev/mouse/0"; +global const byte BLACK = 0; +global const byte WHITE = 255; +global const byte DARK_GRAY = 73; +global const byte GRAY = 146; +global const byte LIGHT_GRAY = 182; +global byte SELECTED_COLOR = 255; function main () // Open screen - plex screen $0 - str screen_name $18 - int mode $11 - nat screen_buffer $21 + plex screen $0; + str screen_name $18; + int mode $11; + nat screen_buffer $21; // use load immediate because it a pointer to a string, not a value - load_address screen_namespace -> screen_name - load_immediate 0 -> mode - syscall OPEN screen_name mode -> screen // Screen screen = open("/dev/screen/0", 0); + load_address screen_namespace -> screen_name; + load_immediate 0 -> mode; + syscall OPEN screen_name mode -> screen; // Screen screen = open("/dev/screen/0", 0); - nat width $20 - nat size $22 - load_offset_32 screen 8 -> width // load width - load_offset_32 screen 12 -> size // load size - load_immediate 16 -> $1 // offset for screen buffer - add_nat screen $1 -> screen_buffer + nat width $20; + nat size $22; + load_offset_32 screen 8 -> width; // load width + load_offset_32 screen 12 -> size; // load size + load_immediate 16 -> $1; // offset for screen buffer + add_nat screen $1 -> screen_buffer; // open mouse - plex mouse $15 - str mouse_name $16 - load_address mouse_namespace -> mouse_name - syscall OPEN mouse_name mode -> mouse // Mouse mouse = open("/dev/mouse/0", 0); + plex mouse $15; + str mouse_name $16; + load_address mouse_namespace -> mouse_name; + syscall OPEN mouse_name mode -> mouse; // Mouse mouse = open("/dev/mouse/0", 0); - byte color $1 - nat x_pos $12 - nat y_pos $13 + byte color $1; + nat x_pos $12; + nat y_pos $13; - load_absolute_32 BLACK -> color - load_immediate 1 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void + load_absolute_32 BLACK -> color; + load_immediate 1 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; - load_absolute_32 WHITE -> color - load_immediate 21 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void + load_absolute_32 WHITE -> color; + load_immediate 21 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; // screen.draw - syscall WRITE screen screen_buffer size + syscall WRITE screen screen_buffer size; - nat zero $11 + nat zero $11; loop draw_loop // load mouse click data - syscall REFRESH mouse + syscall REFRESH mouse; - byte left_down $9 - load_offset_8 mouse 16 -> left_down // load btn1 pressed + byte left_down $9; + load_offset_8 mouse 16 -> left_down; // load btn1 pressed - jump_eq_nat draw_loop left_down zero + jump_eq_nat draw_loop left_down zero; - nat mouse_x $7 - nat mouse_y $8 - load_offset_32 mouse 8 -> mouse_x // load x - load_offset_32 mouse 12 -> mouse_y // load y + nat mouse_x $7; + nat mouse_y $8; + load_offset_32 mouse 8 -> mouse_x; // load x + load_offset_32 mouse 12 -> mouse_y; // load y - nat box_size $14 - load_immediate 20 -> box_size + nat box_size $14; + load_immediate 20 -> box_size; // first row - load_absolute_32 BLACK -> color - load_immediate 1 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void - call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void + load_absolute_32 BLACK -> color; + load_immediate 1 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; + call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void; - load_absolute_32 WHITE -> color - load_immediate 21 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void - call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void + load_absolute_32 WHITE -> color; + load_immediate 21 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; + call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void; - syscall WRITE screen screen_buffer size + syscall WRITE screen screen_buffer size; - byte selected_color $25 - load_absolute_32 SELECTED_COLOR -> selected_color + byte selected_color $25; + load_absolute_32 SELECTED_COLOR -> selected_color; - nat brush_size $19 - load_immediate 5 -> brush_size + nat brush_size $19; + load_immediate 5 -> brush_size; - call draw_box screen_buffer width selected_color mouse_x mouse_y brush_size brush_size -> void + call draw_box screen_buffer width selected_color mouse_x mouse_y brush_size brush_size -> void; - jump draw_loop + jump draw_loop; // Flush and exit - exit 0 + exit 0; function set_color_if_clicked (int click_x $0, int click_y $1, int box_x $2, int box_y $3, byte color $4, int box_size $5) // Compute right - int right_edge $6 - add_int box_x box_size -> right_edge + int right_edge $6; + add_int box_x box_size -> right_edge; // Compute bottom = box_y + box_size - int bottom_edge $7 - add_int box_y box_size -> bottom_edge + int bottom_edge $7; + add_int box_y box_size -> bottom_edge; // Bounds check: x in [box_x, right] and y in [box_y, bottom] - jump_lt_int fail click_x box_x - jump_ge_int fail click_x right_edge - jump_lt_int fail click_y box_y - jump_ge_int fail click_y bottom_edge + jump_lt_int fail click_x box_x; + jump_ge_int fail click_x right_edge; + jump_lt_int fail click_y box_y; + jump_ge_int fail click_y bottom_edge; - store_absolute_8 SELECTED_COLOR color + store_absolute_8 SELECTED_COLOR color; else fail - return + return; function draw_outlined_swatch(nat base $0, byte color $1, int x $2, int y $3, int width $4) // Constants - nat background_color $5 - load_absolute_32 GRAY -> background_color + nat background_color $5; + load_absolute_32 GRAY -> background_color; - byte selected_color $10 - load_absolute_32 SELECTED_COLOR -> selected_color + byte selected_color $10; + load_absolute_32 SELECTED_COLOR -> selected_color; - jump_eq_int set_selected selected_color color - jump end_set_selected - set_selected: - load_absolute_32 DARK_GRAY -> background_color - end_set_selected: + jump_eq_int set_selected selected_color color; + jump end_set_selected; + do set_selected + load_absolute_32 DARK_GRAY -> background_color; + else end_set_selected - nat outline_size $6 - load_immediate 20 -> outline_size + nat outline_size $6; + load_immediate 20 -> outline_size; - nat fill_size $7 - load_immediate 17 -> fill_size + nat fill_size $7; + load_immediate 17 -> fill_size; - nat offset $8 - load_immediate 2 -> offset + nat offset $8; + load_immediate 2 -> offset; - call draw_box base width background_color x y outline_size outline_size -> void + call draw_box base width background_color x y outline_size outline_size -> void; - add_int x offset -> $9 // x + 2 - add_int y offset -> $10 // y + 2 + add_int x offset -> $9; // x + 2 + add_int y offset -> $10; // y + 2 - call draw_box base width color $9 $10 fill_size fill_size -> void + call draw_box base width color $9 $10 fill_size fill_size -> void; - return + return; function draw_box (nat base $0, nat screen_width $1, byte color $2, nat x_start $3, nat y_start $4, nat width $5, nat height $6) // Compute start address: base + y*640 + x - nat offset $15 - mul_int y_start screen_width -> offset - add_int offset x_start -> offset - add_nat offset base -> offset - nat fat_ptr_size $25 - load_immediate 4 -> fat_ptr_size - add_nat offset fat_ptr_size -> offset // need to add offset for fat pointer size + nat offset $15; + mul_int y_start screen_width -> offset; + add_int offset x_start -> offset; + add_nat offset base -> offset; + nat fat_ptr_size $25; + load_immediate 4 -> fat_ptr_size; + add_nat offset fat_ptr_size -> offset; // need to add offset for fat pointer size - int i $30 - load_immediate 1 -> i + int i $30; + load_immediate 1 -> i; - int zero $26 - load_immediate 0 -> zero + int zero $26; + load_immediate 0 -> zero; - int row_end $27 - nat pixel_ptr $29 + int row_end $27; + nat pixel_ptr $29; loop draw_box_outer - add_int offset width -> row_end // current + width - register_move offset -> pixel_ptr // set pixel point - memset_8 pixel_ptr color width // draw row - add_int offset screen_width -> offset // next row += 640 - sub_int height i -> height // decrement row count - jump_gt_int draw_box_outer height zero - return + add_int offset width -> row_end; // current + width + register_move offset -> pixel_ptr; // set pixel point + memset_8 pixel_ptr color width; // draw row + add_int offset screen_width -> offset; // next row += 640 + sub_int height i -> height; // decrement row count + jump_gt_int draw_box_outer height zero; + return; diff --git a/test/paint.ul.ir b/test/paint.ul.ir index 0adc914..97b8fdf 100644 --- a/test/paint.ul.ir +++ b/test/paint.ul.ir @@ -1,184 +1,185 @@ -global const str screen_namespace = "/dev/screen/0" -global const str mouse_namespace = "/dev/mouse/0" -global const byte BLACK = 0 -global const byte WHITE = 255 -global const byte DARK_GRAY = 73 -global const byte GRAY = 146 -global const byte LIGHT_GRAY = 182 -global byte SELECTED_COLOR = 255 +global const str screen_namespace = "/dev/screen/0"; +global const str mouse_namespace = "/dev/mouse/0"; +global const byte BLACK = 0; +global const byte WHITE = 255; +global const byte DARK_GRAY = 73; +global const byte GRAY = 146; +global const byte LIGHT_GRAY = 182; +global byte SELECTED_COLOR = 255; function main () // Open screen - plex screen $0 - str screen_name $18 - int mode $11 - nat screen_buffer $21 + plex screen $0; + str screen_name $18; + int mode $11; + nat screen_buffer $21; // use load immediate because it a pointer to a string, not a value - load_address screen_namespace -> screen_name - load_immediate 0 -> mode - syscall OPEN screen_name mode -> screen // Screen screen = open("/dev/screen/0", 0); + load_address screen_namespace -> screen_name; + load_immediate 0 -> mode; + syscall OPEN screen_name mode -> screen; // Screen screen = open("/dev/screen/0", 0); - nat width $20 - nat size $22 - load_offset_32 screen 8 -> width // load width - load_offset_32 screen 12 -> size // load size - load_immediate 16 -> $1 // offset for screen buffer - add_nat screen $1 -> screen_buffer + nat width $20; + nat size $22; + load_offset_32 screen 8 -> width; // load width + load_offset_32 screen 12 -> size; // load size + load_immediate 16 -> $1; // offset for screen buffer + add_nat screen $1 -> screen_buffer; // open mouse - plex mouse $15 - str mouse_name $16 - load_address mouse_namespace -> mouse_name - syscall OPEN mouse_name mode -> mouse // Mouse mouse = open("/dev/mouse/0", 0); + plex mouse $15; + str mouse_name $16; + load_address mouse_namespace -> mouse_name; + syscall OPEN mouse_name mode -> mouse; // Mouse mouse = open("/dev/mouse/0", 0); - byte color $1 - nat x_pos $12 - nat y_pos $13 + byte color $1; + nat x_pos $12; + nat y_pos $13; - load_absolute_32 BLACK -> color - load_immediate 1 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch [screen_buffer color x_pos y_pos width] -> void + load_absolute_32 BLACK -> color; + load_immediate 1 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; - load_absolute_32 WHITE -> color - load_immediate 21 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void + load_absolute_32 WHITE -> color; + load_immediate 21 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; - // screen.draw// - syscall WRITE screen screen_buffer size + // screen.draw + syscall WRITE screen screen_buffer size; - nat zero $11 + nat zero $11; loop draw_loop // load mouse click data - syscall REFRESH mouse + syscall REFRESH mouse; - byte left_down $9 - load_offset_8 mouse 16 -> left_down // load btn1 pressed + byte left_down $9; + load_offset_8 mouse 16 -> left_down; // load btn1 pressed - jump_eq_nat draw_loop left_down zero + jump_eq_nat draw_loop left_down zero; - nat mouse_x $7 - nat mouse_y $8 - load_offset_32 mouse 8 -> mouse_x // load x - load_offset_32 mouse 12 -> mouse_y // load y + nat mouse_x $7; + nat mouse_y $8; + load_offset_32 mouse 8 -> mouse_x; // load x + load_offset_32 mouse 12 -> mouse_y; // load y - nat box_size $14 - load_immediate 20 -> box_size + nat box_size $14; + load_immediate 20 -> box_size; // first row - load_absolute_32 BLACK -> color - load_immediate 1 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void - call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void + load_absolute_32 BLACK -> color; + load_immediate 1 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; + call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void; - load_absolute_32 WHITE -> color - load_immediate 21 -> x_pos - load_immediate 1 -> y_pos - call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void - call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void + load_absolute_32 WHITE -> color; + load_immediate 21 -> x_pos; + load_immediate 1 -> y_pos; + call draw_outlined_swatch screen_buffer color x_pos y_pos width -> void; + call set_color_if_clicked mouse_x mouse_y x_pos y_pos color box_size -> void; - syscall WRITE screen screen_buffer size + syscall WRITE screen screen_buffer size; - byte selected_color $25 - load_absolute_32 SELECTED_COLOR -> selected_color + byte selected_color $25; + load_absolute_32 SELECTED_COLOR -> selected_color; - nat brush_size $19 - load_immediate 5 -> brush_size + nat brush_size $19; + load_immediate 5 -> brush_size; - call draw_box screen_buffer width selected_color mouse_x mouse_y brush_size brush_size -> void + call draw_box screen_buffer width selected_color mouse_x mouse_y brush_size brush_size -> void; - jump draw_loop + jump draw_loop; // Flush and exit - exit 0 + exit 0; function set_color_if_clicked (int click_x $0, int click_y $1, int box_x $2, int box_y $3, byte color $4, int box_size $5) // Compute right - int right_edge $6 - add_int box_x box_size -> right_edge + int right_edge $6; + add_int box_x box_size -> right_edge; // Compute bottom = box_y + box_size - int bottom_edge $7 - add_int box_y box_size -> bottom_edge + int bottom_edge $7; + add_int box_y box_size -> bottom_edge; // Bounds check: x in [box_x, right] and y in [box_y, bottom] - jump_lt_int fail click_x box_x - jump_ge_int fail click_x right_edge - jump_lt_int fail click_y box_y - jump_ge_int fail click_y bottom_edge + jump_lt_int fail click_x box_x; + jump_ge_int fail click_x right_edge; + jump_lt_int fail click_y box_y; + jump_ge_int fail click_y bottom_edge; - store_absolute_8 SELECTED_COLOR color + store_absolute_8 SELECTED_COLOR color; else fail - return + return; function draw_outlined_swatch(nat base $0, byte color $1, int x $2, int y $3, int width $4) // Constants - nat background_color $5 - load_absolute_32 GRAY -> background_color + nat background_color $5; + load_absolute_32 GRAY -> background_color; - byte selected_color $10 - load_absolute_32 SELECTED_COLOR -> selected_color + byte selected_color $10; + load_absolute_32 SELECTED_COLOR -> selected_color; - jump_eq_int set_selected selected_color color - jump end_set_selected + jump_eq_int set_selected selected_color color; + jump end_set_selected; do set_selected - load_absolute_32 DARK_GRAY -> background_color + load_absolute_32 DARK_GRAY -> background_color; else end_set_selected - nat outline_size $6 - load_immediate 20 -> outline_size + nat outline_size $6; + load_immediate 20 -> outline_size; - nat fill_size $7 - load_immediate 17 -> fill_size + nat fill_size $7; + load_immediate 17 -> fill_size; - nat offset $8 - load_immediate 2 -> offset + nat offset $8; + load_immediate 2 -> offset; - call draw_box base width background_color x y outline_size outline_size -> void + call draw_box base width background_color x y outline_size outline_size -> void; - add_int x offset -> $9 // x + 2 - add_int y offset -> $10 // y + 2 + add_int x offset -> $9; // x + 2 + add_int y offset -> $10; // y + 2 - call draw_box base width color $9 $10 fill_size fill_size -> void + call draw_box base width color $9 $10 fill_size fill_size -> void; - return + return; function draw_box (nat base $0, nat screen_width $1, - byte color $2, nat x_start $3, nat y_start $4, nat width $5, nat height $6) + byte color $2, nat x_start $3, nat y_start $4, + nat width $5, nat height $6) // Compute start address: base + y*640 + x - nat offset $15 - mul_int y_start screen_width -> offset - add_int offset x_start -> offset - add_nat offset base -> offset - nat fat_ptr_size $25 - load_immediate 4 -> fat_ptr_size - add_nat offset fat_ptr_size -> offset // need to add offset for fat pointer size + nat offset $15; + mul_int y_start screen_width -> offset; + add_int offset x_start -> offset; + add_nat offset base -> offset; + nat fat_ptr_size $25; + load_immediate 4 -> fat_ptr_size; + add_nat offset fat_ptr_size -> offset; // need to add offset for fat pointer size - int i $30 - load_immediate 1 -> i + int i $30; + load_immediate 1 -> i; - int zero $26 - load_immediate 0 -> zero + int zero $26; + load_immediate 0 -> zero; - int row_end $27 - nat pixel_ptr $29 + int row_end $27; + nat pixel_ptr $29; loop draw_box_outer - add_int offset width -> row_end // current + width - register_move offset -> pixel_ptr // set pixel point - memset_8 pixel_ptr color width // draw row - add_int offset screen_width -> offset // next row += 640 - sub_int height i -> height // decrement row count - jump_gt_int draw_box_outer height zero - return + add_int offset width -> row_end; // current + width + register_move offset -> pixel_ptr; // set pixel point + memset_8 pixel_ptr color width; // draw row + add_int offset screen_width -> offset; // next row += 640 + sub_int height i -> height; // decrement row count + jump_gt_int draw_box_outer height zero; + return; diff --git a/test/simple.ul.ir b/test/simple.ul.ir index 572d680..c973ff5 100644 --- a/test/simple.ul.ir +++ b/test/simple.ul.ir @@ -1,31 +1,31 @@ -global str terminal_namespace = "/dev/term/0" -global real x = 1.0 -global real y = 1.0 +global str terminal_namespace = "/dev/term/0"; +global real x = 1.0; +global real y = 1.0; function main () - real x $0 - load_absolute_32 &x -> x - real y $1 - load_absolute_32 &y -> y - real result $2 - add_real x y -> result - str result_str $3 - real_to_string result -> result_str - call &pln result_str -> void - exit 0 + real x $0; + load_absolute_32 x -> x; + real y $1; + load_absolute_32 y -> y; + real result $2; + add_real x y -> result; + str result_str $3; + real_to_string result -> result_str; + call pln result_str -> void; + exit 0; function pln (str message $0) - str term $1 - int msg_length $2 - str nl $3 - int nl_length $4 - int mode $5 + str term $1; + int msg_length $2; + str nl $3; + int nl_length $4; + int mode $5; - load_immediate 0 -> mode - syscall OPEN &terminal_namespace mode -> term - strlen message -> msg_length - syscall WRITE term message msg_length - load_address new_line -> nl - strlen nl -> nl_length - syscall WRITE term nl nl_length - return + load_immediate 0 -> mode; + syscall OPEN terminal_namespace mode -> term; + strlen message -> msg_length; + syscall WRITE term message msg_length; + load_address new_line -> nl; + strlen nl -> nl_length; + syscall WRITE term nl nl_length; + return; diff --git a/test/window.ul.ir b/test/window.ul.ir index c860dfc..8fa51a5 100644 --- a/test/window.ul.ir +++ b/test/window.ul.ir @@ -1,89 +1,89 @@ -global str screen_namespace = "/dev/screen/0" -global str mouse_namespace = "/dev/mouse/0" -global str terminal_namespace = "/dev/term/0" -global str new_line = "\n" -global byte white = 255 +global str screen_namespace = "/dev/screen/0"; +global str mouse_namespace = "/dev/mouse/0"; +global str terminal_namespace = "/dev/term/0"; +global str new_line = "\n"; +global byte white = 255; function main () - plex screen $0 - plex mouse $1 - str tmp_str $2 - byte color $3 - bool left_down $4 - int mode $5 - nat offset_temp $6 - nat x $7 - nat y $8 - nat width $9 - nat screen_buffer $10 - nat buffer_size $11 - nat pixel_pos $12 + plex screen $0; + plex mouse $1; + str tmp_str $2; + byte color $3; + bool left_down $4; + int mode $5; + nat offset_temp $6; + nat x $7; + nat y $8; + nat width $9; + nat screen_buffer $10; + nat buffer_size $11; + nat pixel_pos $12; - load_immediate screen_namespace -> screen - load_immediate 0 -> mode - syscall OPEN screen mode -> screen + load_immediate screen_namespace -> screen; + load_immediate 0 -> mode; + syscall OPEN screen mode -> screen; - nat_to_string screen -> tmp_str - call pln tmp_str -> void + nat_to_string screen -> tmp_str; + call pln tmp_str -> void; - load_offset_32 screen 8 -> width - nat_to_string width -> tmp_str - call pln tmp_str -> void + load_offset_32 screen 8 -> width; + nat_to_string width -> tmp_str; + call pln tmp_str -> void; - load_offset_32 screen 12 -> buffer_size - nat_to_string buffer_size -> tmp_str - call pln tmp_str -> void + load_offset_32 screen 12 -> buffer_size; + nat_to_string buffer_size -> tmp_str; + call pln tmp_str -> void; - load_immediate 16 -> offset_temp - add_nat screen offset_temp -> screen_buffer + load_immediate 16 -> offset_temp; + add_nat screen offset_temp -> screen_buffer; - nat_to_string screen_buffer -> tmp_str - call pln tmp_str -> void + nat_to_string screen_buffer -> tmp_str; + call pln tmp_str -> void; // open mouse - load_immediate mouse_namespace -> mouse - syscall OPEN mouse mode -> mouse + load_immediate mouse_namespace -> mouse; + syscall OPEN mouse mode -> mouse; - syscall WRITE screen screen_buffer buffer_size // redraw + syscall WRITE screen screen_buffer buffer_size; // redraw loop draw_loop // load mouse click data - syscall STAT mouse + syscall STAT mouse; - load_offset_8 mouse 16 -> left_down + load_offset_8 mouse 16 -> left_down; - jump_eq_nat draw_loop left_down mode // mode = 0 / false + jump_eq_nat draw_loop left_down mode; // mode = 0 / false - load_offset_32 mouse 8 -> x - load_offset_32 mouse 12 -> y + load_offset_32 mouse 8 -> x; + load_offset_32 mouse 12 -> y; // Compute start address: y *width + x - mul_nat y width -> pixel_pos - add_nat x pixel_pos -> pixel_pos - add_nat screen_buffer pixel_pos -> pixel_pos - load_immediate 4 -> fat_ptr_size - add_nat pixel_pos fat_ptr_size -> pixel_pos + mul_nat y width -> pixel_pos; + add_nat x pixel_pos -> pixel_pos; + add_nat screen_buffer pixel_pos -> pixel_pos; + load_immediate 4 -> fat_ptr_size; + add_nat pixel_pos fat_ptr_size -> pixel_pos; - load_absolute_32 white -> color - store_absolute_8 pixel_pos color // draw color at screen [x,y] - syscall WRITE screen screen_buffer buffer_size // redraw + load_absolute_32 white -> color; + store_absolute_8 pixel_pos color; // draw color at screen [x,y] + syscall WRITE screen screen_buffer buffer_size; // redraw - jump draw_loop - exit 0 + jump draw_loop; + exit 0; function pln (str message $0) - str ts $1 - int mode $5 - int msg_length $2 - str nl $3 - int nl_length $4 + str ts $1; + int mode $5; + int msg_length $2; + str nl $3; + int nl_length $4; - load_immediate terminal_namespace -> ts - load_immediate 0 -> mode - syscall OPEN ts mode -> ts - strlen message -> msg_length - syscall WRITE ts message msg_length - load_immediate new_line -> nl - strlen nl -> nl_length - syscall WRITE ts nl nl_length - return + load_immediate terminal_namespace -> ts; + load_immediate 0 -> mode; + syscall OPEN ts mode -> ts; + strlen message -> msg_length; + syscall WRITE ts message msg_length ; + load_immediate new_line -> nl; + strlen nl -> nl_length; + syscall WRITE ts nl nl_length; + return;