label definitions?

This commit is contained in:
Leo Tenenbaum 2021-11-20 11:38:34 -05:00
parent dfd0610698
commit d74db67011
2 changed files with 76 additions and 7 deletions

View file

@ -5,6 +5,11 @@ D=:global_variables
; initialize static_memory_end ; initialize static_memory_end
C=:static_memory_end C=:static_memory_end
D=x500000 D=x500000
8C=D
; initialize labels_end
C=:labels_end
D=:labels
8C=D
I=8S I=8S
A=d3 A=d3
@ -104,6 +109,9 @@ D=1C
C=xa C=xa
?C=D:read_line ?C=D:read_line
C=':
?C=D:handle_label_definition
I=:line I=:line
J=:"global" J=:"global"
C=x20 C=x20
@ -245,6 +253,49 @@ D=A
:mov_rbp_rsp :mov_rbp_rsp
R=S R=S
:handle_label_definition
; make sure label only has identifier characters
I=:line
I+=d1
:label_checking_loop
C=1I
D=xa
?C=D:label_checking_loop_end
I+=d1
B=C
call :isident
D=A
?D!0:label_checking_loop
!:bad_label
:label_checking_loop_end
; @TODO: check if already exists
J=:labels_end
J=8J
I=:line
I+=d1
call :ident_copy
R=J
J=d4
I=d0
D=d1
syscall x8
C=A
C+=x400000
J=R
4J=C
J+=d4
; update labels_end
C=:labels_end
8C=J
; read the next line
!:read_line
:handle_return :handle_return
; @TODO: handle argument ; @TODO: handle argument
@ -280,16 +331,15 @@ D=A
:ident_loop :ident_loop
C=1I C=1I
1J=C
I+=d1
J+=d1
D=xa D=xa
?C=D:ident_loop_end ?C=D:ident_loop_end
B=C B=C
call :isident call :isident
D=A D=A
?D=0:bad_identifier ?D=0:bad_identifier
C=1I
1J=C
I+=d1
J+=d1
!:ident_loop !:ident_loop
:ident_loop_end :ident_loop_end
return return
@ -397,6 +447,15 @@ D=A
str Bad identifier. str Bad identifier.
xa xa
x0 x0
:bad_label
B=:bad_label_error_message
!:program_error
:bad_label_error_message
str Bad label.
xa
x0
:bad_type :bad_type
B=:bad_type_error_message B=:bad_type_error_message
@ -577,7 +636,15 @@ D=A
J+=d1 J+=d1
D-=d1 D-=d1
!:memcpy !:memcpy
; copy from rdi to rsi, until byte cl is reached
:memccpy
D=1I
1J=D
I+=d1
J+=d1
?D!C:memccpy
return
:"char" :"char"
str char str char
@ -623,13 +690,15 @@ align
reserve d8 reserve d8
:stack_end :stack_end
reserve d8 reserve d8
:labels_end
reserve d8
:line_number :line_number
reserve d8 reserve d8
:global_variables :global_variables
reserve d50000 reserve d50000
:local_variables :local_variables
reserve d20000 reserve d20000
:label_table :labels
reserve d200000 reserve d200000
:ELF_header :ELF_header

View file

@ -73,7 +73,7 @@ function
p = &c p = &c
syscall(1, 1, p, 1, 0, 0, 0, 0) syscall(1, 1, p, 1, 0, 0, 0, 0)
return return
:puts :puts
function function
argument *char s argument *char s