diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-05-08 00:13:07 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-05-08 00:13:07 +0200 |
| commit | 3f11d63a0f86191f010bc0093ee8616c154d9a1b (patch) | |
| tree | 24b2412bab652d6580c77f518806c7bfc1172f94 /boot/symbol.s | |
| parent | 40701008f04f2242ab69bfb4bc4f376e6b75429a (diff) | |
| download | elna-3f11d63a0f86191f010bc0093ee8616c154d9a1b.tar.gz | |
Add builtin symbols
Diffstat (limited to 'boot/symbol.s')
| -rw-r--r-- | boot/symbol.s | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/boot/symbol.s b/boot/symbol.s new file mode 100644 index 0000000..66409aa --- /dev/null +++ b/boot/symbol.s @@ -0,0 +1,104 @@ +# This Source Code Form is subject to the terms of the Mozilla Public License, +# 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/. + +.global symbol_table_build + +.include "boot/definitions.inc" + +.equ SYMBOL_PRIME, 1543 + +.section .rodata + +.type symbol_builtin_name_int, @object +symbol_builtin_name_int: .ascii "Int" +.type symbol_builtin_name_word, @object +symbol_builtin_name_word: .ascii "Word" +.type symbol_builtin_name_byte, @object +symbol_builtin_name_byte: .ascii "Byte" +.type symbol_builtin_name_char, @object +symbol_builtin_name_char: .ascii "Char" + +# Every type info starts with a word describing what type it is. + +# Primitive types have only type size. +.type symbol_builtin_type_int, @object +symbol_builtin_type_int: .word TYPE_PRIMITIVE + .word 4 +.type symbol_builtin_type_word, @object +symbol_builtin_type_word: .word TYPE_PRIMITIVE + .word 4 +.type symbol_builtin_type_byte, @object +symbol_builtin_type_byte: .word TYPE_PRIMITIVE + .word 1 +.type symbol_builtin_type_char, @object +symbol_builtin_type_char: .word TYPE_PRIMITIVE + .word 1 + +.section .bss + +# The first word of the symbol table is its length. +# Then a list of type infos follows: +# +# record +# name: String +# info: ^TypeInfo +# end +.type symbol_table, @object +symbol_table: .zero SYMBOL_PRIME + +.section .text + +# Build the initial symbols. +# +# Sets a0 to the pointer to the global symbol table. +.type symbol_build, @function +symbol_table_build: + la a0, symbol_table + addi t0, a0, 4 + + li t1, 3 # Length of the word "Int". + sw t1, 0(t0) + la t1, symbol_builtin_name_int + sw t1, 4(t0) + la t1, symbol_builtin_type_int + sw t1, 8(t0) + lw t1, 0(a0) + addi t1, t1, 1 + sw t1, 0(a0) + addi t0, t0, 12 + + li t1, 4 # Length of the word "Word". + sw t1, 0(t0) + la t1, symbol_builtin_name_word + sw t1, 4(t0) + la t1, symbol_builtin_type_word + sw t1, 8(t0) + lw t1, 0(a0) + addi t1, t1, 1 + sw t1, 0(a0) + addi t0, t0, 12 + + li t1, 4 # Length of the word "Byte". + sw t1, 0(t0) + la t1, symbol_builtin_name_byte + sw t1, 4(t0) + la t1, symbol_builtin_type_byte + sw t1, 8(t0) + lw t1, 0(a0) + addi t1, t1, 1 + sw t1, 0(a0) + addi t0, t0, 12 + + li t1, 4 # Length of the word "Char". + sw t1, 0(t0) + la t1, symbol_builtin_name_char + sw t1, 4(t0) + la t1, symbol_builtin_type_char + sw t1, 8(t0) + lw t1, 0(a0) + addi t1, t1, 1 + sw t1, 0(a0) + addi t0, t0, 12 + + ret |
