merge term stuff
This commit is contained in:
commit
d48816e226
5 changed files with 60 additions and 77 deletions
|
@ -227,6 +227,9 @@ A *term* is one of:
|
||||||
- `{variable name}` - the value of a (local or global) variable
|
- `{variable name}` - the value of a (local or global) variable
|
||||||
- `.{label name}` - the address of a label
|
- `.{label name}` - the address of a label
|
||||||
- `{number}`
|
- `{number}`
|
||||||
|
- `&{variable}` - address of variable
|
||||||
|
- `*1{variable}` / `*2{variable}` / `*4{variable}` / `*8{variable}` - dereference 1, 2, 4, or 8 bytes
|
||||||
|
- `~{term}` - bitwise not
|
||||||
|
|
||||||
An *l-value* is the left-hand side of an assignment expression,
|
An *l-value* is the left-hand side of an assignment expression,
|
||||||
and it is one of:
|
and it is one of:
|
||||||
|
@ -239,9 +242,6 @@ and it is one of:
|
||||||
An *r-value* is an expression, which can be more complicated than a term.
|
An *r-value* is an expression, which can be more complicated than a term.
|
||||||
r-values are one of:
|
r-values are one of:
|
||||||
- `{term}`
|
- `{term}`
|
||||||
- `&{variable}` - address of variable
|
|
||||||
- `*1{variable}` / `*2{variable}` / `*4{variable}` / `*8{variable}` - dereference 1, 2, 4, or 8 bytes
|
|
||||||
- `~{term}` - bitwise not
|
|
||||||
- `{function}({term}, {term}, ...)`
|
- `{function}({term}, {term}, ...)`
|
||||||
- `{term} + {term}`
|
- `{term} + {term}`
|
||||||
- `{term} - {term}`
|
- `{term} - {term}`
|
||||||
|
|
|
@ -107,12 +107,10 @@ function stoi
|
||||||
|
|
||||||
function strlen
|
function strlen
|
||||||
argument s
|
argument s
|
||||||
local c
|
|
||||||
local p
|
local p
|
||||||
p = s
|
p = s
|
||||||
:strlen_loop
|
:strlen_loop
|
||||||
c = *1p
|
if *1p == 0 goto strlen_loop_end
|
||||||
if c == 0 goto strlen_loop_end
|
|
||||||
p += 1
|
p += 1
|
||||||
goto strlen_loop
|
goto strlen_loop
|
||||||
:strlen_loop_end
|
:strlen_loop_end
|
||||||
|
|
104
04/in03
104
04/in03
|
@ -1238,6 +1238,12 @@ align
|
||||||
?C=D:term_number
|
?C=D:term_number
|
||||||
D='.
|
D='.
|
||||||
?C=D:term_label
|
?C=D:term_label
|
||||||
|
D='*
|
||||||
|
?C=D:term_dereference
|
||||||
|
D='&
|
||||||
|
?C=D:term_addressof
|
||||||
|
D='~
|
||||||
|
?C=D:term_bitwise_not
|
||||||
D=d58
|
D=d58
|
||||||
?C<D:term_number
|
?C<D:term_number
|
||||||
; (fallthrough)
|
; (fallthrough)
|
||||||
|
@ -1274,16 +1280,6 @@ align
|
||||||
C=:rvalue
|
C=:rvalue
|
||||||
8C=I
|
8C=I
|
||||||
|
|
||||||
C=1I
|
|
||||||
D='&
|
|
||||||
?C=D:rvalue_addressof
|
|
||||||
|
|
||||||
D='~
|
|
||||||
?C=D:rvalue_bitwise_not
|
|
||||||
|
|
||||||
D='*
|
|
||||||
?C=D:rvalue_dereference
|
|
||||||
|
|
||||||
J=I
|
J=I
|
||||||
:rvalue_loop
|
:rvalue_loop
|
||||||
C=1J
|
C=1J
|
||||||
|
@ -1506,50 +1502,6 @@ align
|
||||||
:rvalue_shr
|
:rvalue_shr
|
||||||
call :set_rcx_to_rsi
|
call :set_rcx_to_rsi
|
||||||
!:emit_shr_rax_cl
|
!:emit_shr_rax_cl
|
||||||
|
|
||||||
:rvalue_addressof
|
|
||||||
I+=d1
|
|
||||||
!:set_rax_to_address_of_variable
|
|
||||||
|
|
||||||
:rvalue_bitwise_not
|
|
||||||
I+=d1
|
|
||||||
call :set_rax_to_term
|
|
||||||
J=d4
|
|
||||||
I=:not_rax
|
|
||||||
D=d3
|
|
||||||
syscall x1
|
|
||||||
return
|
|
||||||
:not_rax
|
|
||||||
x48
|
|
||||||
xf7
|
|
||||||
xd0
|
|
||||||
|
|
||||||
:rvalue_dereference_size
|
|
||||||
reserve d1
|
|
||||||
|
|
||||||
:rvalue_dereference
|
|
||||||
I+=d1
|
|
||||||
D=1I
|
|
||||||
C=:rvalue_dereference_size
|
|
||||||
1C=D
|
|
||||||
I+=d1
|
|
||||||
call :set_rax_to_variable
|
|
||||||
call :set_rbx_to_rax
|
|
||||||
call :zero_rax
|
|
||||||
C=:rvalue_dereference_size
|
|
||||||
C=1C
|
|
||||||
|
|
||||||
D='1
|
|
||||||
?C=D:set_al_to_[rbx]
|
|
||||||
D='2
|
|
||||||
?C=D:set_ax_to_[rbx]
|
|
||||||
D='4
|
|
||||||
?C=D:set_eax_to_[rbx]
|
|
||||||
D='8
|
|
||||||
?C=D:set_rax_to_[rbx]
|
|
||||||
|
|
||||||
!:bad_term
|
|
||||||
|
|
||||||
|
|
||||||
; set <rax> to address of variable in rsi
|
; set <rax> to address of variable in rsi
|
||||||
:set_rax_to_address_of_variable
|
:set_rax_to_address_of_variable
|
||||||
|
@ -1600,7 +1552,51 @@ align
|
||||||
call :read_number
|
call :read_number
|
||||||
I=A
|
I=A
|
||||||
!:set_rax_to_immediate
|
!:set_rax_to_immediate
|
||||||
|
|
||||||
|
:term_bitwise_not
|
||||||
|
I+=d1
|
||||||
|
call :set_rax_to_term
|
||||||
|
J=d4
|
||||||
|
I=:not_rax
|
||||||
|
D=d3
|
||||||
|
syscall x1
|
||||||
|
return
|
||||||
|
:not_rax
|
||||||
|
x48
|
||||||
|
xf7
|
||||||
|
xd0
|
||||||
|
|
||||||
|
:term_dereference_size
|
||||||
|
reserve d1
|
||||||
|
|
||||||
|
:term_dereference
|
||||||
|
I+=d1
|
||||||
|
D=1I
|
||||||
|
C=:term_dereference_size
|
||||||
|
1C=D
|
||||||
|
I+=d1
|
||||||
|
call :set_rax_to_variable
|
||||||
|
call :set_rbx_to_rax
|
||||||
|
call :zero_rax
|
||||||
|
C=:term_dereference_size
|
||||||
|
C=1C
|
||||||
|
|
||||||
|
D='1
|
||||||
|
?C=D:set_al_to_[rbx]
|
||||||
|
D='2
|
||||||
|
?C=D:set_ax_to_[rbx]
|
||||||
|
D='4
|
||||||
|
?C=D:set_eax_to_[rbx]
|
||||||
|
D='8
|
||||||
|
?C=D:set_rax_to_[rbx]
|
||||||
|
|
||||||
|
!:bad_term
|
||||||
|
|
||||||
|
:term_addressof
|
||||||
|
I+=d1
|
||||||
|
!:set_rax_to_address_of_variable
|
||||||
|
|
||||||
|
|
||||||
; set rax to the number in the string at rsi
|
; set rax to the number in the string at rsi
|
||||||
:read_number
|
:read_number
|
||||||
C=1I
|
C=1I
|
||||||
|
|
7
04/in04
7
04/in04
|
@ -15,8 +15,7 @@ function strlen
|
||||||
local p
|
local p
|
||||||
p = s
|
p = s
|
||||||
:strlen_loop
|
:strlen_loop
|
||||||
c = *1p
|
if *1p == 0 goto strlen_loop_end
|
||||||
if c == 0 goto strlen_loop_end
|
|
||||||
p += 1
|
p += 1
|
||||||
goto strlen_loop
|
goto strlen_loop
|
||||||
:strlen_loop_end
|
:strlen_loop_end
|
||||||
|
@ -24,9 +23,7 @@ function strlen
|
||||||
|
|
||||||
function putc
|
function putc
|
||||||
argument c
|
argument c
|
||||||
local p
|
syscall(1, 1, &c, 1)
|
||||||
p = &c
|
|
||||||
syscall(1, 1, p, 1)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
function puts
|
function puts
|
||||||
|
|
16
04a/in04
16
04a/in04
|
@ -331,11 +331,9 @@ function memchr
|
||||||
argument mem
|
argument mem
|
||||||
argument c
|
argument c
|
||||||
local p
|
local p
|
||||||
local a
|
|
||||||
p = mem
|
p = mem
|
||||||
:memchr_loop
|
:memchr_loop
|
||||||
a = *1p
|
if *1p == c goto memchr_loop_end
|
||||||
if a == c goto memchr_loop_end
|
|
||||||
p += 1
|
p += 1
|
||||||
goto memchr_loop
|
goto memchr_loop
|
||||||
:memchr_loop_end
|
:memchr_loop_end
|
||||||
|
@ -343,12 +341,10 @@ function memchr
|
||||||
|
|
||||||
function strlen
|
function strlen
|
||||||
argument s
|
argument s
|
||||||
local c
|
|
||||||
local p
|
local p
|
||||||
p = s
|
p = s
|
||||||
:strlen_loop
|
:strlen_loop
|
||||||
c = *1p
|
if *1p == 0 goto strlen_loop_end
|
||||||
if c == 0 goto strlen_loop_end
|
|
||||||
p += 1
|
p += 1
|
||||||
goto strlen_loop
|
goto strlen_loop
|
||||||
:strlen_loop_end
|
:strlen_loop_end
|
||||||
|
@ -414,9 +410,7 @@ function fputn
|
||||||
function fputc
|
function fputc
|
||||||
argument fd
|
argument fd
|
||||||
argument c
|
argument c
|
||||||
local p
|
syscall(1, fd, &c, 1)
|
||||||
p = &c
|
|
||||||
syscall(1, fd, p, 1)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
function putc
|
function putc
|
||||||
|
@ -428,10 +422,8 @@ function putc
|
||||||
function fgetc
|
function fgetc
|
||||||
argument fd
|
argument fd
|
||||||
local c
|
local c
|
||||||
local p
|
|
||||||
c = 0
|
c = 0
|
||||||
p = &c
|
syscall(0, fd, &c, 1)
|
||||||
syscall(0, fd, p, 1)
|
|
||||||
return c
|
return c
|
||||||
|
|
||||||
; read a line from fd as a null-terminated string
|
; read a line from fd as a null-terminated string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue