fixed subroutine parameter value issue

This commit is contained in:
Irmen de Jong 2020-03-22 23:50:15 +01:00
parent 8bfa2c4c02
commit 0c561d8528
21 changed files with 81 additions and 161 deletions

View File

@ -147,8 +147,7 @@ internal class AstIdentifiersChecker(private val program: Program,
subroutine.parameters
.filter { it.name !in namesInSub }
.forEach {
val vardecl = VarDecl(VarDeclType.VAR, it.type, ZeropageWish.NOT_IN_ZEROPAGE, null, it.name, null, null,
isArray = false, autogeneratedDontRemove = true, position = subroutine.position)
val vardecl = ParameterVarDecl(it.name, it.type, subroutine.position)
vardecl.linkParents(subroutine)
subroutine.statements.add(0, vardecl)
}

View File

@ -196,7 +196,8 @@ enum class ZeropageWish {
NOT_IN_ZEROPAGE
}
class VarDecl(val type: VarDeclType,
open class VarDecl(val type: VarDeclType,
private val declaredDatatype: DataType,
val zeropage: ZeropageWish,
var arraysize: ArrayIndex?,
@ -307,6 +308,11 @@ class VarDecl(val type: VarDeclType,
}
}
// a vardecl used only for subroutine parameters
class ParameterVarDecl(name: String, declaredDatatype: DataType, position: Position)
: VarDecl(VarDeclType.VAR, declaredDatatype, ZeropageWish.NOT_IN_ZEROPAGE, null, name, null, null, false, true, position)
class ArrayIndex(var index: Expression, override val position: Position) : Node {
override lateinit var parent: Node

View File

@ -604,6 +604,7 @@ internal class AsmGen(private val program: Program,
internal fun translate(stmt: Statement) {
outputSourceLine(stmt)
when(stmt) {
is ParameterVarDecl -> { /* subroutine parameter vardecls don't get any special treatment here */ }
is VarDecl -> translate(stmt)
is StructDecl, is NopStatement -> {}
is Directive -> translate(stmt)

View File

@ -2,6 +2,9 @@
TODO
====
- fix manderbrot compiler issue
- remove statements after an exit() or return
- fix warnings about that unreachable code?

View File

@ -110,12 +110,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -36,7 +36,8 @@ main {
}
sub start() {
; TODO call this too: unimplemented()
; TODO call this once implemented:
; unimplemented()
lsr(A)
lsl(A)
@ -113,12 +114,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -111,11 +111,10 @@ main {
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -110,12 +110,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -110,12 +110,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -110,12 +110,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -142,12 +142,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -93,12 +93,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -109,11 +109,10 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -93,12 +93,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -123,12 +123,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -159,12 +159,11 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -12,8 +12,8 @@ main {
}
}
uword fib_prev = 0 ; TODO fix initialization of block-global vars (outside of a subroutine)
uword fib_current = 1 ; TODO fix initialization of block-global vars (outside of a subroutine)
uword fib_prev = 0
uword fib_current = 1
sub fib_next() -> uword {
uword new = fib_current + fib_prev

View File

@ -8,14 +8,10 @@ main {
sub start() {
c64scr.print("mid-point\ncircle\n and\nbresenham\nline\nalgorithms.\n")
circle(20, 12, 6)
circle(20, 12, 6) ; TODO FIX ERROR IN LOCALS
circle(20, 12, 6) ; TODO FIX ERROR IN LOCALS
; ubyte r
; for r in 3 to 12 step 3 {
; circle(20, 12, r)
; }
ubyte r
for r in 3 to 12 step 3 {
circle(20, 12, r)
}
c64scr.print("enter for disc:")
void c64.CHRIN()
@ -112,13 +108,6 @@ main {
byte y = 0
byte decisionOver2 = 1-x
c64scr.print_b(x)
c64.CHROUT(',')
c64scr.print_b(y)
c64.CHROUT(',')
c64scr.print_b(decisionOver2)
c64.CHROUT('\n')
while x>=y {
c64scr.setcc(xcenter + x as ubyte, ycenter + y as ubyte, 81, 1)
c64scr.setcc(xcenter - x as ubyte, ycenter + y as ubyte, 81, 2)

View File

@ -19,6 +19,10 @@ main {
ubyte pixelx
ubyte pixely
; TODO fix compiler - calculation is broken now
for pixely in 0 to height-1 {
float yy = (pixely as float)/0.4/height - 1.0

View File

@ -5,11 +5,13 @@
main {
sub subje() {
ubyte yy=33 ; TODO reinitialize var here
ubyte zz ; TODO reinitialize var here
sub subje(ubyte arg1) {
ubyte yy=33
ubyte zz
ubyte[5] array1 = [1,2,3,4,5]
c64scr.print_ub(arg1)
c64.CHROUT(',')
c64scr.print_ub(yy)
c64.CHROUT(',')
c64scr.print_ub(zz)
@ -22,10 +24,10 @@ main {
sub start() {
ubyte zz2
A=zz2
subje()
subje()
subje()
subje()
subje(111)
subje(112)
subje(113)
subje(114)
return
; ubyte ub1

View File

@ -1,73 +0,0 @@
%zeropage basicsafe
main {
sub start() {
c64scr.print("print uw0:")
c64scr.print_uw0(53204)
c64.CHROUT(' ')
c64scr.print_uw0(3204)
c64.CHROUT(' ')
c64scr.print_uw0(204)
c64.CHROUT(' ')
c64scr.print_uw0(14)
c64.CHROUT(' ')
c64scr.print_uw0(4)
c64.CHROUT(' ')
c64scr.print_uw0(0)
c64.CHROUT('\n')
c64scr.print("print uw:")
c64scr.print_uw(53204)
c64.CHROUT(' ')
c64scr.print_uw(3204)
c64.CHROUT(' ')
c64scr.print_uw(204)
c64.CHROUT(' ')
c64scr.print_uw(14)
c64.CHROUT(' ')
c64scr.print_uw(4)
c64.CHROUT(' ')
c64scr.print_uw(0)
c64.CHROUT('\n')
c64scr.print("print w:")
c64scr.print_w(23204)
c64.CHROUT(' ')
c64scr.print_w(3204)
c64.CHROUT(' ')
c64scr.print_w(204)
c64.CHROUT(' ')
c64scr.print_w(14)
c64.CHROUT(' ')
c64scr.print_w(4)
c64.CHROUT(' ')
c64scr.print_w(0)
c64.CHROUT('\n')
c64scr.print_w(-23204)
c64.CHROUT(' ')
c64scr.print_w(-3204)
c64.CHROUT(' ')
c64scr.print_w(-204)
c64.CHROUT(' ')
c64scr.print_w(-14)
c64.CHROUT(' ')
c64scr.print_w(-4)
c64.CHROUT(' ')
c64scr.print_w(-0)
c64.CHROUT('\n')
check_eval_stack()
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}