new language idea
This commit is contained in:
parent
ea3c931992
commit
6a31b0560a
2 changed files with 34 additions and 38 deletions
15
04b/in03
15
04b/in03
|
@ -243,7 +243,6 @@ align
|
||||||
reserve d8
|
reserve d8
|
||||||
|
|
||||||
:handle_global
|
:handle_global
|
||||||
xcc
|
|
||||||
; ignore if this is the second pass
|
; ignore if this is the second pass
|
||||||
C=:second_pass
|
C=:second_pass
|
||||||
C=1C
|
C=1C
|
||||||
|
@ -262,6 +261,7 @@ align
|
||||||
8C=I
|
8C=I
|
||||||
J=:global_variables
|
J=:global_variables
|
||||||
D=d5
|
D=d5
|
||||||
|
|
||||||
call :ident_lookup
|
call :ident_lookup
|
||||||
C=A
|
C=A
|
||||||
?C!0:global_redeclaration
|
?C!0:global_redeclaration
|
||||||
|
@ -458,17 +458,15 @@ align
|
||||||
; look up identifier rsi in list rdi with separation rdx between entries
|
; 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
|
; returns address of whatever's right after the identifier in the list, or 0 if not found
|
||||||
:ident_lookup
|
:ident_lookup
|
||||||
C=:second_pass
|
|
||||||
C=1C
|
|
||||||
; use default of 1 on first pass
|
|
||||||
?C=0:return_1
|
|
||||||
|
|
||||||
C=:ident_lookup_sep
|
C=:ident_lookup_sep
|
||||||
8C=D
|
8C=D
|
||||||
C=:ident_lookup_i
|
C=:ident_lookup_i
|
||||||
8C=I
|
8C=I
|
||||||
|
|
||||||
:ident_lookup_loop
|
:ident_lookup_loop
|
||||||
|
; check if reached the end of the table
|
||||||
|
C=1J
|
||||||
|
?C=0:return_0
|
||||||
I=:ident_lookup_i
|
I=:ident_lookup_i
|
||||||
I=8I
|
I=8I
|
||||||
call :ident=
|
call :ident=
|
||||||
|
@ -485,9 +483,6 @@ align
|
||||||
C=:ident_lookup_sep
|
C=:ident_lookup_sep
|
||||||
C=8C
|
C=8C
|
||||||
J+=C
|
J+=C
|
||||||
; check if reached the end of the table
|
|
||||||
C=1J
|
|
||||||
?C=0:return_0
|
|
||||||
!:ident_lookup_loop
|
!:ident_lookup_loop
|
||||||
|
|
||||||
; can the character in rbx appear in an identifier?
|
; can the character in rbx appear in an identifier?
|
||||||
|
@ -525,8 +520,8 @@ align
|
||||||
|
|
||||||
; variable
|
; variable
|
||||||
J=:local_variables
|
J=:local_variables
|
||||||
D=d5
|
|
||||||
xcc
|
xcc
|
||||||
|
D=d5
|
||||||
call :ident_lookup
|
call :ident_lookup
|
||||||
C=A
|
C=A
|
||||||
?C=0:rax2term_try_global
|
?C=0:rax2term_try_global
|
||||||
|
|
57
04b/in04b
57
04b/in04b
|
@ -1,4 +1,3 @@
|
||||||
; types: char, short, int, long, *type
|
|
||||||
; declaration:
|
; declaration:
|
||||||
; global <type> <name>
|
; global <type> <name>
|
||||||
; local <type> <name>
|
; local <type> <name>
|
||||||
|
@ -11,7 +10,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:
|
||||||
|
@ -29,7 +28,7 @@
|
||||||
; `<string>`
|
; `<string>`
|
||||||
; <var>
|
; <var>
|
||||||
; &<var>
|
; &<var>
|
||||||
; *<var>
|
; *1 <var> / *2 <var> / *4 <var> / *8 <var>
|
||||||
; <var>[<term>]
|
; <var>[<term>]
|
||||||
; ~<var>
|
; ~<var>
|
||||||
; <function>(<term>, <term>, ...)
|
; <function>(<term>, <term>, ...)
|
||||||
|
@ -48,18 +47,20 @@
|
||||||
|
|
||||||
main() ; hello
|
main() ; hello
|
||||||
|
|
||||||
global char x
|
global x
|
||||||
global short y ;123
|
global y ;123
|
||||||
global long z
|
global z
|
||||||
|
|
||||||
:strlen
|
:strlen
|
||||||
function
|
function
|
||||||
argument *char s
|
argument s
|
||||||
local long len
|
local len
|
||||||
local char c
|
local c
|
||||||
|
local p
|
||||||
len = 0
|
len = 0
|
||||||
:strlen_loop
|
:strlen_loop
|
||||||
c = s[len]
|
p = s + len
|
||||||
|
c = *1 p
|
||||||
if c == 0 goto strlen_loop_end
|
if c == 0 goto strlen_loop_end
|
||||||
len += 1
|
len += 1
|
||||||
goto strlen_loop
|
goto strlen_loop
|
||||||
|
@ -68,40 +69,40 @@ function
|
||||||
|
|
||||||
:putc
|
:putc
|
||||||
function
|
function
|
||||||
argument char c
|
argument c
|
||||||
local *char p
|
local 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
|
||||||
function
|
function
|
||||||
argument *char s
|
argument s
|
||||||
local long len
|
local 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
|
||||||
function
|
function
|
||||||
local *char hello
|
local hello
|
||||||
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
|
||||||
function
|
function
|
||||||
argument *long x
|
argument x
|
||||||
argument *long y
|
argument y
|
||||||
local long v
|
local v
|
||||||
local *long p
|
local p
|
||||||
v = *x
|
v = *4x
|
||||||
p = *y
|
p = *8y
|
||||||
*p = v
|
*4p = v
|
||||||
if v == 0 goto something
|
if v == 0 goto something
|
||||||
p[1] = v + 1
|
*1p = v + 1
|
||||||
return p[2]
|
return *2p
|
||||||
:something
|
:something
|
||||||
return p[1]
|
return *4p
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue