diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-09-04 22:07:01 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-09-04 22:07:01 +0200 |
| commit | 48882522746873d48b563ec66321ef99a51badbc (patch) | |
| tree | cd4ef5ffed9cdd9e38d674d8467c3cde95ed9126 /boot/stage5.elna | |
| parent | 4b42c59649be8f14fc81dcdc4bf0b86e576fc610 (diff) | |
| download | elna-48882522746873d48b563ec66321ef99a51badbc.tar.gz | |
Implement string literals
Diffstat (limited to 'boot/stage5.elna')
| -rw-r--r-- | boot/stage5.elna | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/boot/stage5.elna b/boot/stage5.elna index 3aed6c3..88b407f 100644 --- a/boot/stage5.elna +++ b/boot/stage5.elna @@ -2,7 +2,7 @@ # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at https://mozilla.org/MPL/2.0/. -# Stage4 compiler. +# Stage5 compiler. # # - Stack size increased to 128 bytes per procedure. # 7 words on the stack, 92 - 120, are reversed for procedure arguments (caller side). @@ -13,6 +13,7 @@ # - Binary addition "+" and multiplication "*". # - Binary logical operations: & (and), or and xor. # - Binary comparison operations: =, <, <=, >, >=, <>. +# - Return statement. .section .rodata @@ -23,7 +24,7 @@ keyword_section: .ascii ".section" keyword_type: .ascii ".type" .type keyword_ret, @object -keyword_ret: .ascii "ret" +keyword_ret: .ascii "\tret" .type keyword_global, @object keyword_global: .ascii ".globl" @@ -97,6 +98,9 @@ asm_or: .string "\tor " .type asm_xor, @object asm_xor: .string "\txor " +.type asm_xori, @object +asm_xori: .string "\txori " + .type asm_sub, @object asm_sub: .string "\tsub " @@ -109,6 +113,9 @@ asm_snez: .string "\tsnez " .type asm_slt, @object asm_slt: .string "\tslt " +.type asm_mv, @object +asm_mv: .string "\tmv " + .type asm_comma, @object asm_comma: .string ", " @@ -889,16 +896,18 @@ begin _write_z(@asm_slt); _write_register('t', 0); _write_z(@asm_comma); - _write_register('t', 1); - _write_z(@asm_comma); _write_register('t', 0); + _write_z(@asm_comma); + _write_register('t', 1); _write_c('\n'); # Execute the operation. - _write_z(@asm_not); + _write_z(@asm_xori); _write_register('t', 0); _write_z(@asm_comma); _write_register('t', 0); + _write_z(@asm_comma); + _write_i(1); _write_c('\n'); goto .compile_expression_end; @@ -933,16 +942,18 @@ begin _write_z(@asm_slt); _write_register('t', 0); _write_z(@asm_comma); - _write_register('t', 0); - _write_z(@asm_comma); _write_register('t', 1); + _write_z(@asm_comma); + _write_register('t', 0); _write_c('\n'); # Execute the operation. - _write_z(@asm_not); + _write_z(@asm_xori); _write_register('t', 0); _write_z(@asm_comma); _write_register('t', 0); + _write_z(@asm_comma); + _write_i(1); _write_c('\n'); goto .compile_expression_end; @@ -1167,6 +1178,19 @@ begin _write_c(')'); end; +proc _compile_return_statement(); +begin + # Skip "return" keyword and whitespace after it. + _advance_token(7); + _compile_expression(); + + _write_z(@asm_mv); + _write_register('a', 0); + _write_z(@asm_comma); + _write_register('t', 0); + +end; + proc _compile_statement(); begin # This is a call if the statement starts with an underscore. @@ -1185,6 +1209,10 @@ begin li t1, 'v' beq t0, t1, .compile_statement_assignment + # keyword_ret contains "\tret", so it's 4 bytes long. + _memcmp(source_code_position, @keyword_ret, 4); + beqz a0, .compile_statement_return + _compile_line(); goto .compile_statement_end; @@ -1206,9 +1234,15 @@ begin goto .compile_statement_semicolon; +.compile_statement_return: + _advance_token(1); + _compile_return_statement(); + _write_c('\n'); + + goto .compile_statement_end; + .compile_statement_semicolon: _advance_token(2); - _write_c('\n'); .compile_statement_end: |
