From e614d43ea9af078301d538fcddb19e83eed7e879 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 13 May 2025 23:14:20 +0200 Subject: Support procedure without _ in the first stage --- boot/symbol.s | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'boot/symbol.s') diff --git a/boot/symbol.s b/boot/symbol.s index fe88aef..fdf4ad2 100644 --- a/boot/symbol.s +++ b/boot/symbol.s @@ -3,8 +3,8 @@ # obtain one at https://mozilla.org/MPL/2.0/. .global symbol_table -.global symbol_table_build, symbol_table_find, symbol_table_insert, symbol_table_dump -.global symbol_table_make_pointer, symbol_table_make_parameter, symbol_table_make_local +.global symbol_table_build, symbol_table_lookup, symbol_table_enter, symbol_table_dump +.global symbol_table_make_pointer, symbol_table_make_parameter, symbol_table_make_local, symbol_table_make_procedure .include "boot/definitions.inc" @@ -101,8 +101,8 @@ symbol_table_dump: # a1 - Pointer to the symbol name. # # Sets a0 to the symbol info pointer or 0 if the symbol has not been found. -.type symbol_table_find, @function -symbol_table_find: +.type symbol_table_lookup, @function +symbol_table_lookup: # Prologue. addi sp, sp, -32 sw ra, 28(sp) @@ -121,8 +121,8 @@ symbol_table_find: lw s2, 0(s1) addi s1, s1, 4 # Advance to the first symbol in the table. -.Lsymbol_table_find_loop: - beqz s2, .Lsymbol_table_find_not_found +.Lsymbol_table_lookup_loop: + beqz s2, .Lsymbol_table_lookup_not_found # Compare string lengths. mv a0, s3 @@ -131,20 +131,20 @@ symbol_table_find: lw a3, 4(s1) call _string_equal - beqz a0, .Lsymbol_table_find_continue + beqz a0, .Lsymbol_table_lookup_continue lw a0, 8(s1) # Pointer to the symbol. - j .Lsymbol_table_find_end + j .Lsymbol_table_lookup_end -.Lsymbol_table_find_continue: +.Lsymbol_table_lookup_continue: addi s1, s1, 12 addi s2, s2, -1 - j .Lsymbol_table_find_loop + j .Lsymbol_table_lookup_loop -.Lsymbol_table_find_not_found: +.Lsymbol_table_lookup_not_found: li a0, 0 -.Lsymbol_table_find_end: +.Lsymbol_table_lookup_end: lw s1, 20(sp) lw s2, 16(sp) lw s3, 12(sp) @@ -208,14 +208,32 @@ symbol_table_make_local: li a0, 12 ret +# Creates a procedure type and procedure info objects refering the type. +# +# Parameters: +# a0 - Output memory. +# +# Sets a0 to the size of newly created info object in bytes. +.type symbol_table_make_procedure, @function +symbol_table_make_procedure: + li t0, TYPE_PROCEDURE + sw t0, 8(a0) + + li t0, INFO_PROCEDURE + sw t0, 0(a0) + sw a0, 4(a0) # Procedure type stored in the same memory segment. + + li a0, 12 + ret + # Inserts a symbol into the table. # # Parameters: # a0 - Symbol name length. # a1 - Symbol name pointer. # a2 - Symbol pointer. -.type symbol_table_insert, @function -symbol_table_insert: +.type symbol_table_enter, @function +symbol_table_enter: la t0, symbol_table lw t1, 0(t0) # Current table length. @@ -250,27 +268,27 @@ symbol_table_build: li a0, 3 # Length of the word "Int". la a1, symbol_builtin_name_int la a2, symbol_builtin_type_int - call symbol_table_insert + call symbol_table_enter li a0, 4 # Length of the word "Word". la a1, symbol_builtin_name_word la a2, symbol_builtin_type_word - call symbol_table_insert + call symbol_table_enter li a0, 4 # Length of the word "Byte". la a1, symbol_builtin_name_byte la a2, symbol_builtin_type_byte - call symbol_table_insert + call symbol_table_enter li a0, 4 # Length of the word "Char". la a1, symbol_builtin_name_char la a2, symbol_builtin_type_char - call symbol_table_insert + call symbol_table_enter li a0, 4 # Length of the word "Bool". la a1, symbol_builtin_name_bool la a2, symbol_builtin_type_bool - call symbol_table_insert + call symbol_table_enter # Epilogue. lw ra, 12(sp) -- cgit v1.2.3