mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
some array literals weren't put on the heap
This commit is contained in:
parent
bb7b063757
commit
fb0d7a1908
@ -81,9 +81,6 @@ artifacts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// To create a fat-jar use the 'create_compiler_jar' script for now
|
|
||||||
// @todo investigate https://imperceptiblethoughts.com/shadow/introduction/
|
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
baseName = 'prog8compiler'
|
baseName = 'prog8compiler'
|
||||||
version = prog8version
|
version = prog8version
|
||||||
|
@ -67,7 +67,7 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
|
|||||||
checkResult.add(NameError("builtin function cannot be redefined", decl.position))
|
checkResult.add(NameError("builtin function cannot be redefined", decl.position))
|
||||||
|
|
||||||
if(decl.name in AssemblyProgram.opcodeNames)
|
if(decl.name in AssemblyProgram.opcodeNames)
|
||||||
checkResult.add(NameError("can't use a cpu opcode name as a symbol", decl.position))
|
checkResult.add(NameError("can't use a cpu opcode name as a symbol: '${decl.name}'", decl.position))
|
||||||
|
|
||||||
// is it a struct variable? then define all its struct members as mangled names,
|
// is it a struct variable? then define all its struct members as mangled names,
|
||||||
// and include the original decl as well.
|
// and include the original decl as well.
|
||||||
@ -104,7 +104,7 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
|
|||||||
|
|
||||||
override fun visit(subroutine: Subroutine): Statement {
|
override fun visit(subroutine: Subroutine): Statement {
|
||||||
if(subroutine.name in AssemblyProgram.opcodeNames) {
|
if(subroutine.name in AssemblyProgram.opcodeNames) {
|
||||||
checkResult.add(NameError("can't use a cpu opcode name as a symbol", subroutine.position))
|
checkResult.add(NameError("can't use a cpu opcode name as a symbol: '${subroutine.name}'", subroutine.position))
|
||||||
} else if(subroutine.name in BuiltinFunctions) {
|
} else if(subroutine.name in BuiltinFunctions) {
|
||||||
// the builtin functions can't be redefined
|
// the builtin functions can't be redefined
|
||||||
checkResult.add(NameError("builtin function cannot be redefined", subroutine.position))
|
checkResult.add(NameError("builtin function cannot be redefined", subroutine.position))
|
||||||
@ -165,7 +165,7 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
|
|||||||
|
|
||||||
override fun visit(label: Label): Statement {
|
override fun visit(label: Label): Statement {
|
||||||
if(label.name in AssemblyProgram.opcodeNames)
|
if(label.name in AssemblyProgram.opcodeNames)
|
||||||
checkResult.add(NameError("can't use a cpu opcode name as a symbol", label.position))
|
checkResult.add(NameError("can't use a cpu opcode name as a symbol: '${label.name}'", label.position))
|
||||||
|
|
||||||
if(label.name in BuiltinFunctions) {
|
if(label.name in BuiltinFunctions) {
|
||||||
// the builtin functions can't be redefined
|
// the builtin functions can't be redefined
|
||||||
@ -429,8 +429,6 @@ internal fun fixupArrayDatatype(array: ArrayLiteralValue, vardecl: VarDecl, prog
|
|||||||
litval2.addToHeap(program.heap)
|
litval2.addToHeap(program.heap)
|
||||||
return litval2
|
return litval2
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
array.addToHeap(program.heap)
|
|
||||||
}
|
}
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ fun compileProgram(filepath: Path,
|
|||||||
programAst.checkValid(compilerOptions) // check if final tree is valid
|
programAst.checkValid(compilerOptions) // check if final tree is valid
|
||||||
programAst.checkRecursion() // check if there are recursive subroutine calls
|
programAst.checkRecursion() // check if there are recursive subroutine calls
|
||||||
|
|
||||||
printAst(programAst)
|
// printAst(programAst)
|
||||||
|
|
||||||
if(writeAssembly) {
|
if(writeAssembly) {
|
||||||
// asm generation directly from the Ast, no need for intermediate code
|
// asm generation directly from the Ast, no need for intermediate code
|
||||||
|
@ -601,6 +601,8 @@ class ConstantFolding(private val program: Program) : IAstModifyingVisitor {
|
|||||||
override fun visit(arrayLiteral: ArrayLiteralValue): Expression {
|
override fun visit(arrayLiteral: ArrayLiteralValue): Expression {
|
||||||
val array = super.visit(arrayLiteral)
|
val array = super.visit(arrayLiteral)
|
||||||
if(array is ArrayLiteralValue) {
|
if(array is ArrayLiteralValue) {
|
||||||
|
if(array.heapId==null)
|
||||||
|
array.addToHeap(program.heap)
|
||||||
val vardecl = array.parent as? VarDecl
|
val vardecl = array.parent as? VarDecl
|
||||||
return if (vardecl!=null) {
|
return if (vardecl!=null) {
|
||||||
fixupArrayDatatype(array, vardecl, program)
|
fixupArrayDatatype(array, vardecl, program)
|
||||||
|
104
examples/test.p8
104
examples/test.p8
@ -7,104 +7,18 @@ main {
|
|||||||
sub start() {
|
sub start() {
|
||||||
|
|
||||||
ubyte i
|
ubyte i
|
||||||
for i in 0 to 10 {
|
|
||||||
A=i
|
for i in [1,3,5,99] {
|
||||||
|
c64scr.print_ub(i)
|
||||||
|
c64.CHROUT(',')
|
||||||
}
|
}
|
||||||
|
c64.CHROUT('\n')
|
||||||
|
|
||||||
for i in 0 to 10 {
|
for A in [1,3,5,99] {
|
||||||
Y=i
|
c64scr.print_ub(A)
|
||||||
|
c64.CHROUT(',')
|
||||||
}
|
}
|
||||||
|
c64.CHROUT('\n')
|
||||||
; ubyte[] uba = [10,0,2,8,5,4,3,9]
|
|
||||||
; uword[] uwa = [1000,0,200,8000,50,40000,3,900]
|
|
||||||
; byte[] ba = [-10,0,-2,8,5,4,-3,9,-99]
|
|
||||||
; word[] wa = [-1000,0,-200,8000,50,31111,3,-900]
|
|
||||||
;
|
|
||||||
; for ubyte ub in uba {
|
|
||||||
; c64scr.print_ub(ub)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for uword uw in uwa {
|
|
||||||
; c64scr.print_uw(uw)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for byte bb in ba {
|
|
||||||
; c64scr.print_b(bb)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for word ww in wa {
|
|
||||||
; c64scr.print_w(ww)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; sort(uba)
|
|
||||||
; sort(uwa)
|
|
||||||
; sort(ba)
|
|
||||||
; sort(wa)
|
|
||||||
;
|
|
||||||
; for ubyte ub2 in uba {
|
|
||||||
; c64scr.print_ub(ub2)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for uword uw2 in uwa {
|
|
||||||
; c64scr.print_uw(uw2)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for byte bb2 in ba {
|
|
||||||
; c64scr.print_b(bb2)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for word ww2 in wa {
|
|
||||||
; c64scr.print_w(ww2)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; reverse(uba)
|
|
||||||
; reverse(uwa)
|
|
||||||
; reverse(ba)
|
|
||||||
; reverse(wa)
|
|
||||||
;
|
|
||||||
; for ubyte ub3 in uba {
|
|
||||||
; c64scr.print_ub(ub3)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for uword uw3 in uwa {
|
|
||||||
; c64scr.print_uw(uw3)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for byte bb3 in ba {
|
|
||||||
; c64scr.print_b(bb3)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
;
|
|
||||||
; for word ww3 in wa {
|
|
||||||
; c64scr.print_w(ww3)
|
|
||||||
; c64.CHROUT(',')
|
|
||||||
; }
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
; c64.CHROUT('\n')
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,9 @@ main {
|
|||||||
}
|
}
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
|
|
||||||
for uw in warr {
|
word ww
|
||||||
c64scr.print_w(uw)
|
for ww in warr {
|
||||||
|
c64scr.print_w(ww)
|
||||||
c64.CHROUT(',')
|
c64.CHROUT(',')
|
||||||
}
|
}
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
@ -129,7 +130,6 @@ main {
|
|||||||
}
|
}
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
|
|
||||||
word ww
|
|
||||||
for ww in 999 to -999 step -500 {
|
for ww in 999 to -999 step -500 {
|
||||||
c64scr.print_w(ww)
|
c64scr.print_w(ww)
|
||||||
c64.CHROUT(',')
|
c64.CHROUT(',')
|
||||||
|
Loading…
Reference in New Issue
Block a user