Support procedure without _ in the first stage

This commit is contained in:
2025-05-13 23:14:20 +02:00
parent 1b31f532df
commit e614d43ea9
5 changed files with 104 additions and 260 deletions

View File

@@ -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)