change syntax of address-of in p8virt code to &X, instead of {X}

This commit is contained in:
Irmen de Jong 2022-09-13 23:28:52 +02:00
parent 7dd14955c1
commit e34bab9585
7 changed files with 34 additions and 35 deletions

View File

@ -48,9 +48,9 @@ class AssemblyProgram(override val name: String, private val allocations: Variab
} }
is VmCodeLabel -> write("_" + line.name.joinToString(".") + ":\n") is VmCodeLabel -> write("_" + line.name.joinToString(".") + ":\n")
is VmCodeInlineAsm -> { is VmCodeInlineAsm -> {
val asm = line.assembly.replace("""\{[a-zA-Z\d_\.]+\}""".toRegex()) { matchResult -> val asm = line.assembly.replace("""&[a-zA-Z\d_\.]+""".toRegex()) { matchResult ->
// "{ X }" -> address of X // TODO USE &X instead for address of X???? // "&X" -> address of X
val name = matchResult.value.substring(1, matchResult.value.length-1).split('.') val name = matchResult.value.substring(1, matchResult.value.length).split('.')
allocations.get(name).toString() } allocations.get(name).toString() }
write(asm+"\n") write(asm+"\n")
} }

View File

@ -196,7 +196,7 @@ sub str2uword(str string) -> uword {
; the number may NOT be preceded by a + sign and may NOT contain spaces ; the number may NOT be preceded by a + sign and may NOT contain spaces
; (any non-digit character will terminate the number string that is parsed) ; (any non-digit character will terminate the number string that is parsed)
%asm {{ %asm {{
loadm.w r0, {conv.str2uword.string} loadm.w r0,&conv.str2uword.string
syscall 11 syscall 11
return return
}} }}
@ -207,7 +207,7 @@ sub str2word(str string) -> word {
; the number may be preceded by a + or - sign but may NOT contain spaces ; the number may be preceded by a + or - sign but may NOT contain spaces
; (any non-digit character will terminate the number string that is parsed) ; (any non-digit character will terminate the number string that is parsed)
%asm {{ %asm {{
loadm.w r0, {conv.str2word.string} loadm.w r0,&conv.str2word.string
syscall 12 syscall 12
return return
}} }}

View File

@ -10,7 +10,7 @@ floats {
sub print_f(float value) { sub print_f(float value) {
; ---- prints the floating point value (without a newline). ; ---- prints the floating point value (without a newline).
%asm {{ %asm {{
loadm.f fr0,{floats.print_f.value} loadm.f fr0,&floats.print_f.value
syscall 25 syscall 25
return return
}} }}
@ -18,8 +18,8 @@ sub print_f(float value) {
sub pow(float value, float power) -> float { sub pow(float value, float power) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.pow.value} loadm.f fr0,&floats.pow.value
loadm.f fr1,{floats.pow.power} loadm.f fr1,&floats.pow.power
fpow.f fr0,fr1 fpow.f fr0,fr1
return return
}} }}
@ -27,7 +27,7 @@ sub pow(float value, float power) -> float {
sub fabs(float value) -> float { sub fabs(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.fabs.value} loadm.f fr0,&floats.fabs.value
fabs.f fr0,fr0 fabs.f fr0,fr0
return return
}} }}
@ -35,7 +35,7 @@ sub fabs(float value) -> float {
sub sin(float angle) -> float { sub sin(float angle) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.sin.angle} loadm.f fr0,&floats.sin.angle
fsin.f fr0,fr0 fsin.f fr0,fr0
return return
}} }}
@ -43,7 +43,7 @@ sub sin(float angle) -> float {
sub cos(float angle) -> float { sub cos(float angle) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.cos.angle} loadm.f fr0,&floats.cos.angle
fcos.f fr0,fr0 fcos.f fr0,fr0
return return
}} }}
@ -51,7 +51,7 @@ sub cos(float angle) -> float {
sub tan(float value) -> float { sub tan(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.tan.value} loadm.f fr0,&floats.tan.value
ftan.f fr0,fr0 ftan.f fr0,fr0
return return
}} }}
@ -59,7 +59,7 @@ sub tan(float value) -> float {
sub atan(float value) -> float { sub atan(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.atan.value} loadm.f fr0,&floats.atan.value
fatan.f fr0,fr0 fatan.f fr0,fr0
return return
}} }}
@ -67,7 +67,7 @@ sub atan(float value) -> float {
sub ln(float value) -> float { sub ln(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.ln.value} loadm.f fr0,&floats.ln.value
fln.f fr0,fr0 fln.f fr0,fr0
return return
}} }}
@ -75,7 +75,7 @@ sub ln(float value) -> float {
sub log2(float value) -> float { sub log2(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.log2.value} loadm.f fr0,&floats.log2.value
flog.f fr0,fr0 flog.f fr0,fr0
return return
}} }}
@ -83,7 +83,7 @@ sub log2(float value) -> float {
sub sqrt(float value) -> float { sub sqrt(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.sqrt.value} loadm.f fr0,&floats.sqrt.value
sqrt.f fr0,fr0 sqrt.f fr0,fr0
return return
}} }}
@ -101,7 +101,7 @@ sub deg(float angle) -> float {
sub round(float value) -> float { sub round(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.round.value} loadm.f fr0,&floats.round.value
fround.f fr0,fr0 fround.f fr0,fr0
return return
}} }}
@ -109,7 +109,7 @@ sub round(float value) -> float {
sub floor(float value) -> float { sub floor(float value) -> float {
%asm {{ %asm {{
loadm.f fr0,{floats.floor.value} loadm.f fr0,&floats.floor.value
ffloor.f fr0,fr0 ffloor.f fr0,fr0
return return
}} }}
@ -118,7 +118,7 @@ sub floor(float value) -> float {
sub ceil(float value) -> float { sub ceil(float value) -> float {
; -- ceil: tr = int(f); if tr==f -> return else return tr+1 ; -- ceil: tr = int(f); if tr==f -> return else return tr+1
%asm {{ %asm {{
loadm.f fr0,{floats.ceil.value} loadm.f fr0,&floats.ceil.value
fceil.f fr0,fr0 fceil.f fr0,fr0
return return
}} }}

View File

@ -42,8 +42,8 @@ prog8_lib {
; Note that you can also directly compare strings and string values with eachother using ; Note that you can also directly compare strings and string values with eachother using
; comparison operators ==, < etcetera (it will use strcmp for you under water automatically). ; comparison operators ==, < etcetera (it will use strcmp for you under water automatically).
%asm {{ %asm {{
loadm.w r0, {prog8_lib.string_compare.st1} loadm.w r0,&prog8_lib.string_compare.st1
loadm.w r1, {prog8_lib.string_compare.st2} loadm.w r1,&prog8_lib.string_compare.st2
syscall 29 syscall 29
return return
}} }}

View File

@ -15,7 +15,7 @@ sys {
sub wait(uword jiffies) { sub wait(uword jiffies) {
; --- wait approximately the given number of jiffies (1/60th seconds) ; --- wait approximately the given number of jiffies (1/60th seconds)
%asm {{ %asm {{
loadm.w r0, {sys.wait.jiffies} loadm.w r0,&sys.wait.jiffies
syscall 13 syscall 13
}} }}
} }
@ -62,7 +62,7 @@ sys {
sub exit(ubyte returnvalue) { sub exit(ubyte returnvalue) {
; -- immediately exit the program with a return code in the A register ; -- immediately exit the program with a return code in the A register
%asm {{ %asm {{
loadm.b r0,{sys.exit.returnvalue} loadm.b r0,&sys.exit.returnvalue
syscall 1 syscall 1
}} }}
} }
@ -82,24 +82,24 @@ sys {
sub gfx_enable(ubyte mode) { sub gfx_enable(ubyte mode) {
%asm {{ %asm {{
loadm.b r0, {sys.gfx_enable.mode} loadm.b r0,&sys.gfx_enable.mode
syscall 8 syscall 8
}} }}
} }
sub gfx_plot(uword xx, uword yy, ubyte color) { sub gfx_plot(uword xx, uword yy, ubyte color) {
%asm {{ %asm {{
loadm.w r0, {sys.gfx_plot.xx} loadm.w r0,&sys.gfx_plot.xx
loadm.w r1, {sys.gfx_plot.yy} loadm.w r1,&sys.gfx_plot.yy
loadm.b r2, {sys.gfx_plot.color} loadm.b r2,&sys.gfx_plot.color
syscall 10 syscall 10
}} }}
} }
sub gfx_getpixel(uword xx, uword yy) -> ubyte { sub gfx_getpixel(uword xx, uword yy) -> ubyte {
%asm {{ %asm {{
loadm.w r0, {sys.gfx_getpixel.xx} loadm.w r0,&sys.gfx_getpixel.xx
loadm.w r1, {sys.gfx_getpixel.yy} loadm.w r1,&sys.gfx_getpixel.yy
syscall 30 syscall 30
return return
}} }}

View File

@ -7,7 +7,7 @@ txt {
sub clear_screen() { sub clear_screen() {
str @shared sequence = "\x1b[2J\x1B[H" str @shared sequence = "\x1b[2J\x1B[H"
%asm {{ %asm {{
load.w r0, {txt.clear_screen.sequence} load.w r0,&txt.clear_screen.sequence
syscall 3 syscall 3
}} }}
} }
@ -30,14 +30,14 @@ sub uppercase() {
sub chrout(ubyte char) { sub chrout(ubyte char) {
%asm {{ %asm {{
loadm.b r0, {txt.chrout.char} loadm.b r0,&txt.chrout.char
syscall 2 syscall 2
}} }}
} }
sub print (str text) { sub print (str text) {
%asm {{ %asm {{
loadm.w r0, {txt.print.text} loadm.w r0,&txt.print.text
syscall 3 syscall 3
}} }}
} }
@ -114,7 +114,7 @@ sub input_chars (uword buffer) -> ubyte {
; ---- Input a string (max. 80 chars) from the keyboard. Returns length of input. (string is terminated with a 0 byte as well) ; ---- Input a string (max. 80 chars) from the keyboard. Returns length of input. (string is terminated with a 0 byte as well)
; It assumes the keyboard is selected as I/O channel! ; It assumes the keyboard is selected as I/O channel!
%asm {{ %asm {{
loadm.w r0,{txt.input_chars.buffer} loadm.w r0,&txt.input_chars.buffer
syscall 6 syscall 6
return return
}} }}

View File

@ -3,10 +3,9 @@ TODO
For next release For next release
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- IR/VM: add address-of support (see CodeGen.addrssOf()) use {X} syntax or change to &X? see AssemblyProgram.kt - IR/VM: add address-of support (see CodeGen.addressOf()) syntax = &X
- IR/VM: add proper memory mapped variables support - IR/VM: add proper memory mapped variables support
- IR/VM: add proper memory slabs support - IR/VM: add proper memory slabs support
- IR/VM: fix other TODO's
... ...