diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-09-14 16:55:51 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-09-15 12:50:32 +0200 |
| commit | c5f29861202836593b2d337c0bf800fe5b30c2e6 (patch) | |
| tree | bc51755c08c6826d9247e8e64b65864f0b0c765c /boot/stage10.elna | |
| parent | ee3b733a81f3136494e612a0d748f4d029064845 (diff) | |
| download | elna-c5f29861202836593b2d337c0bf800fe5b30c2e6.tar.gz | |
Do not support assembly inline statements
Diffstat (limited to 'boot/stage10.elna')
| -rw-r--r-- | boot/stage10.elna | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/boot/stage10.elna b/boot/stage10.elna index da96da7..cc99d9e 100644 --- a/boot/stage10.elna +++ b/boot/stage10.elna @@ -4,6 +4,10 @@ (* Stage 10 compiler. *) +(* - Integer division (/). *) +(* - Remainder operation (%). *) +(* - Label declaration statement. A label starts with a dot and *) +(* the statement ends with a semicolon like any other statement. *) const symbol_builtin_name_int := "Int"; symbol_builtin_name_word := "Word"; @@ -566,6 +570,24 @@ begin goto .compile_expression_end; end; + if v0 = '%' then + _advance_token(1); + _compile_binary_rhs(); + + (* Execute the operation. *) + _write_z("rem t0, t1, t0\n\0"); + + goto .compile_expression_end; + end; + if v0 = '/' then + _advance_token(1); + _compile_binary_rhs(); + + (* Execute the operation. *) + _write_z("div t0, t1, t0\n\0"); + + goto .compile_expression_end; + end; if v0 = '<' then _advance_token(1); v0 := _load_byte(source_code_position); @@ -591,7 +613,7 @@ begin _compile_binary_rhs(); (* Execute the operation. *) - _write_z("slt t0, t0, t1\n\0"); + _write_z("slt t0, t1, t0\n\0"); goto .compile_expression_end; end; @@ -599,7 +621,6 @@ begin _advance_token(1); v0 := _load_byte(source_code_position); if v0 = '=' then - li t1, '=' _advance_token(1); _compile_binary_rhs(); @@ -739,7 +760,7 @@ begin _compile_designator(); (* Save the assignee address on the stack. *) - _write_z("\tsw t0, 20(sp)\n\0"); + _write_z("\tsw t0, 60(sp)\n\0"); (* Skip the assignment sign (:=) with surrounding whitespaces. *) _advance_token(4); @@ -747,7 +768,7 @@ begin (* Compile the assignment. *) _compile_expression(); - _write_z("\tlw t1, 20(sp)\nsw t0, (t1)\n\0"); + _write_z("\tlw t1, 60(sp)\nsw t0, (t1)\n\0"); end; proc _compile_return_statement(); @@ -798,12 +819,12 @@ begin _write_label(v4); _write_z(":\n\0"); - _memcmp(source_code_position, "end", 3); - beqz a0, .compile_if_end - - _memcmp(source_code_position, "else", 3); - beqz a0, .compile_if_else - + if _memcmp(source_code_position, "end", 3) = 0 then + goto .compile_if_end; + end; + if _memcmp(source_code_position, "else", 3) = 0 then + goto .compile_if_else + end; .compile_if_else: (* Skip "else" and newline. *) _advance_token(5); @@ -817,6 +838,17 @@ begin _write_z(":\n\0"); end; +proc _compile_label_declaration(); +begin + (* Skip the dot. *) + _advance_token(1); + v0 := _read_token(); + _write_c('.'); + _write_s(source_code_position, v0); + _write_z(":\n\0"); + _advance_token(v0); +end; + proc _compile_statement(); begin _skip_spaces(); @@ -845,6 +877,11 @@ begin goto .compile_statement_end; end; + if v0 = '.' then + _compile_label_declaration(); + + goto .compile_statement_semicolon; + end; _compile_line(); goto .compile_statement_end; @@ -1047,7 +1084,6 @@ begin goto .compile_global_initializer_end; end; - unimp .compile_global_initializer_loop: _compile_global_initializer(); @@ -1206,17 +1242,13 @@ begin v4 := compiler_strings_position; .compile_loop: - lw t0, 0(sp) - lw t1, 4(sp) - bge t0, t1, .compile_end - - v8 := _load_byte(v0); - v0 := v0 + 1; - _write_c(v8); - - j .compile_loop + if v0 < v4 then + v8 := _load_byte(v0); + v0 := v0 + 1; + _write_c(v8); -.compile_end: + goto .compile_loop; + end; _write_c('"'); _write_c('\n'); end; |
