Skip to content

Commit

Permalink
remove need for explicit length of initial words list
Browse files Browse the repository at this point in the history
  • Loading branch information
devyn committed Aug 9, 2023
1 parent 2ee2883 commit 9cb55f4
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions stage1/words.s
Original file line number Diff line number Diff line change
Expand Up @@ -224,34 +224,35 @@ INITIAL_WORDS:
.ascii "print-obj$"
.balign 8

.set INITIAL_WORDS_LEN, 32
# end
.quad 0
.quad 0

.text

# set up the initial words
.global words_init
words_init:
addi sp, sp, -0x20
addi sp, sp, -0x18
sd ra, 0x00(sp)
sd s1, 0x08(sp)
sd s2, 0x10(sp)
sd s3, 0x18(sp)
# zero the words table
la a0, WORDS
li a1, WORDS_LEN
mv a2, zero
call mem_set_d
# unpack the initial words table
la s1, INITIAL_WORDS
li s2, INITIAL_WORDS_LEN
1:
beqz s2, .Lwords_init_ret
# load the symbol into (a0, a1) and intern
# a zero length symbol ends the initial words list
lhu a1, 0x08(s1) # len
beqz a1, .Lwords_init_ret # zero-length, end
addi a0, s1, 0x0b # buf
call symbol_intern
beqz a0, .Lwords_init_ret # error
mv s3, a0 # save the symbol
mv s2, a0 # save the symbol
# create the object
lbu a0, 0x0a(s1) # type from INITIAL_WORDS
ld a1, 0x00(s1) # field0 from INITIAL_WORDS
Expand All @@ -261,11 +262,9 @@ words_init:
beqz a0, .Lwords_init_ret # error
# call define with (symbol, object)
mv a1, a0
mv a0, s3
mv a0, s2
call define
bnez a0, .Lwords_init_ret # error
# done: the word has been added
addi s2, s2, -1
# increment pointer to INITIAL_WORDS entry
lhu t1, 0x08(s1) # get length of string into t1
addi s1, s1, 11 # length of (object, len, type) = 11 bytes
Expand All @@ -281,8 +280,7 @@ words_init:
ld ra, 0x00(sp)
ld s1, 0x08(sp)
ld s2, 0x10(sp)
ld s3, 0x18(sp)
addi sp, sp, 0x20
addi sp, sp, 0x18
ret


Expand Down

0 comments on commit 9cb55f4

Please sign in to comment.