looking up things
This commit is contained in:
parent
d74db67011
commit
4b9596e892
2 changed files with 105 additions and 9 deletions
104
04b/in03
104
04b/in03
|
@ -153,6 +153,10 @@ D=A
|
||||||
J=d0
|
J=d0
|
||||||
syscall x3c
|
syscall x3c
|
||||||
|
|
||||||
|
align
|
||||||
|
:local_start
|
||||||
|
reserve d8
|
||||||
|
|
||||||
:handle_local
|
:handle_local
|
||||||
R=I
|
R=I
|
||||||
|
|
||||||
|
@ -168,6 +172,18 @@ D=A
|
||||||
call :read_type
|
call :read_type
|
||||||
R=A
|
R=A
|
||||||
I+=d1
|
I+=d1
|
||||||
|
|
||||||
|
; check if already defined
|
||||||
|
C=:local_start
|
||||||
|
8C=I
|
||||||
|
J=:local_variables
|
||||||
|
D=d9
|
||||||
|
call :ident_lookup
|
||||||
|
C=A
|
||||||
|
?C!0:local_redeclaration
|
||||||
|
C=:local_start
|
||||||
|
I=8C
|
||||||
|
|
||||||
J=:local_variables_end
|
J=:local_variables_end
|
||||||
J=8J
|
J=8J
|
||||||
call :ident_copy
|
call :ident_copy
|
||||||
|
@ -201,8 +217,11 @@ D=A
|
||||||
x00
|
x00
|
||||||
x00
|
x00
|
||||||
|
|
||||||
|
align
|
||||||
|
:global_start
|
||||||
|
reserve d8
|
||||||
|
|
||||||
:handle_global
|
:handle_global
|
||||||
; @TODO: check if already exists
|
|
||||||
; skip ' '
|
; skip ' '
|
||||||
I+=d1
|
I+=d1
|
||||||
call :read_type
|
call :read_type
|
||||||
|
@ -210,6 +229,19 @@ D=A
|
||||||
R=A
|
R=A
|
||||||
; skip ' ' after type
|
; skip ' ' after type
|
||||||
I+=d1
|
I+=d1
|
||||||
|
|
||||||
|
; check if already defined
|
||||||
|
C=:global_start
|
||||||
|
8C=I
|
||||||
|
J=:global_variables
|
||||||
|
D=d9
|
||||||
|
call :ident_lookup
|
||||||
|
C=A
|
||||||
|
?C!0:global_redeclaration
|
||||||
|
C=:global_start
|
||||||
|
I=8C
|
||||||
|
|
||||||
|
|
||||||
J=:global_variables_end
|
J=:global_variables_end
|
||||||
J=8J
|
J=8J
|
||||||
call :ident_copy
|
call :ident_copy
|
||||||
|
@ -269,7 +301,13 @@ D=A
|
||||||
!:bad_label
|
!:bad_label
|
||||||
:label_checking_loop_end
|
:label_checking_loop_end
|
||||||
|
|
||||||
; @TODO: check if already exists
|
I=:line
|
||||||
|
I+=d1
|
||||||
|
J=:labels
|
||||||
|
D=d4
|
||||||
|
call :ident_lookup
|
||||||
|
C=A
|
||||||
|
?C!0:label_redefinition
|
||||||
|
|
||||||
J=:labels_end
|
J=:labels_end
|
||||||
J=8J
|
J=8J
|
||||||
|
@ -343,8 +381,36 @@ D=A
|
||||||
!:ident_loop
|
!:ident_loop
|
||||||
:ident_loop_end
|
:ident_loop_end
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
align
|
||||||
|
:ident_lookup_i
|
||||||
|
reserve d8
|
||||||
|
:ident_lookup_sep
|
||||||
|
reserve d8
|
||||||
|
|
||||||
|
; look up identifier rsi in list rdi with separation rdx between entries
|
||||||
|
; returns address of whatever's right after the identifier in the list, or 0 if not found
|
||||||
|
:ident_lookup
|
||||||
|
C=:ident_lookup_sep
|
||||||
|
8C=D
|
||||||
|
C=:ident_lookup_i
|
||||||
|
8C=I
|
||||||
|
|
||||||
|
:ident_lookup_loop
|
||||||
|
I=:ident_lookup_i
|
||||||
|
I=8I
|
||||||
|
call :ident=
|
||||||
|
C=A
|
||||||
|
; move past terminator
|
||||||
|
J+=d1
|
||||||
|
?C!0:return_J
|
||||||
|
C=:ident_lookup_sep
|
||||||
|
C=8C
|
||||||
|
J+=C
|
||||||
|
C=1J
|
||||||
|
?C=0:return_0
|
||||||
|
!:ident_lookup_loop
|
||||||
|
|
||||||
; can the character in rbx appear in an identifier?
|
; can the character in rbx appear in an identifier?
|
||||||
:isident
|
:isident
|
||||||
A='0
|
A='0
|
||||||
|
@ -466,6 +532,33 @@ D=A
|
||||||
xa
|
xa
|
||||||
x0
|
x0
|
||||||
|
|
||||||
|
:label_redefinition
|
||||||
|
B=:label_redefinition_error_message
|
||||||
|
!:program_error
|
||||||
|
|
||||||
|
:label_redefinition_error_message
|
||||||
|
str Label redefinition.
|
||||||
|
xa
|
||||||
|
x0
|
||||||
|
|
||||||
|
:global_redeclaration
|
||||||
|
B=:global_redeclaration_error_message
|
||||||
|
!:program_error
|
||||||
|
|
||||||
|
:global_redeclaration_error_message
|
||||||
|
str Global variable declared twice.
|
||||||
|
xa
|
||||||
|
x0
|
||||||
|
|
||||||
|
:local_redeclaration
|
||||||
|
B=:local_redeclaration_error_message
|
||||||
|
!:program_error
|
||||||
|
|
||||||
|
:local_redeclaration_error_message
|
||||||
|
str Local variable declared twice.
|
||||||
|
xa
|
||||||
|
x0
|
||||||
|
|
||||||
:general_error
|
:general_error
|
||||||
call :eputs
|
call :eputs
|
||||||
J=d1
|
J=d1
|
||||||
|
@ -580,7 +673,10 @@ D=A
|
||||||
:return_8
|
:return_8
|
||||||
A=d8
|
A=d8
|
||||||
return
|
return
|
||||||
|
:return_J
|
||||||
|
A=J
|
||||||
|
return
|
||||||
|
|
||||||
; write the character in rbx to the file in rdi.
|
; write the character in rbx to the file in rdi.
|
||||||
:fputc
|
:fputc
|
||||||
C=B
|
C=B
|
||||||
|
|
10
04b/in04b
10
04b/in04b
|
@ -11,7 +11,7 @@
|
||||||
; <lvalue> += <rvalue>
|
; <lvalue> += <rvalue>
|
||||||
; <lvalue> -= <rvalue>
|
; <lvalue> -= <rvalue>
|
||||||
; <function>(<term>, <term>, ...)
|
; <function>(<term>, <term>, ...)
|
||||||
; syscall(<term>, <term>, ...)
|
; syscall <term>, <term>, ...
|
||||||
; return <rvalue>
|
; return <rvalue>
|
||||||
; byte <number>
|
; byte <number>
|
||||||
; term:
|
; term:
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
; <var>[<term>]
|
; <var>[<term>]
|
||||||
; ~<var>
|
; ~<var>
|
||||||
; <function>(<term>, <term>, ...)
|
; <function>(<term>, <term>, ...)
|
||||||
; syscall(<term>, <term>, ...)
|
; syscall <term>, <term>, ...
|
||||||
; <term> + <term>
|
; <term> + <term>
|
||||||
; <term> - <term>
|
; <term> - <term>
|
||||||
; NOTE: *, /, % are signed (imul and idiv)
|
; NOTE: *, /, % are signed (imul and idiv)
|
||||||
|
@ -71,7 +71,7 @@ function
|
||||||
argument char c
|
argument char c
|
||||||
local *char p
|
local *char p
|
||||||
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
|
||||||
|
@ -79,7 +79,7 @@ function
|
||||||
argument *char s
|
argument *char s
|
||||||
local long len
|
local long len
|
||||||
len = strlen(s)
|
len = strlen(s)
|
||||||
syscall(1, 1, s, len, 0, 0, 0, 0)
|
syscall 1, 1, s, len, 0, 0, 0, 0
|
||||||
return
|
return
|
||||||
|
|
||||||
:main
|
:main
|
||||||
|
@ -88,7 +88,7 @@ function
|
||||||
hello = `Hello, world!
|
hello = `Hello, world!
|
||||||
`
|
`
|
||||||
puts(hello)
|
puts(hello)
|
||||||
syscall(0x3c, 0, 0, 0, 0, 0, 0, 0)
|
syscall 0x3c, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
|
||||||
|
|
||||||
:f
|
:f
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue