mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 03:29:22 +00:00
vm var allocator now also recognises the memory-mapped variables. no longer crashes
This commit is contained in:
parent
2ad4fdbbb9
commit
f675dbc726
@ -40,6 +40,20 @@ class SymbolTable : StNode("", StNodeType.GLOBAL, Position.DUMMY) {
|
|||||||
vars
|
vars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val allMemMappedVariables: Collection<StMemVar> by lazy {
|
||||||
|
val vars = mutableListOf<StMemVar>()
|
||||||
|
fun collect(node: StNode) {
|
||||||
|
for(child in node.children) {
|
||||||
|
if(child.value.type== StNodeType.MEMVAR)
|
||||||
|
vars.add(child.value as StMemVar)
|
||||||
|
else
|
||||||
|
collect(child.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collect(this)
|
||||||
|
vars
|
||||||
|
}
|
||||||
|
|
||||||
override fun lookup(scopedName: List<String>) = flat[scopedName]
|
override fun lookup(scopedName: List<String>) = flat[scopedName]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +200,11 @@ class StConstant(name: String, val dt: DataType, val value: Double, position: Po
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class StMemVar(name: String, val dt: DataType, val address: UInt, position: Position) :
|
class StMemVar(name: String,
|
||||||
|
val dt: DataType,
|
||||||
|
val address: UInt,
|
||||||
|
val length: Int?, // for arrays: the number of elements, for strings: number of characters *including* the terminating 0-byte
|
||||||
|
position: Position) :
|
||||||
StNode(name, StNodeType.MEMVAR, position) {
|
StNode(name, StNodeType.MEMVAR, position) {
|
||||||
override fun printProperties() {
|
override fun printProperties() {
|
||||||
print("$name dt=$dt address=${address.toHex()}")
|
print("$name dt=$dt address=${address.toHex()}")
|
||||||
|
@ -26,6 +26,18 @@ class VariableAllocator(private val st: SymbolTable, private val program: PtProg
|
|||||||
allocations[variable.scopedName] = nextLocation
|
allocations[variable.scopedName] = nextLocation
|
||||||
nextLocation += memsize
|
nextLocation += memsize
|
||||||
}
|
}
|
||||||
|
for (memvar in st.allMemMappedVariables) {
|
||||||
|
// TODO virtual machine doesn't have memory mapped variables, so treat them as regular allocated variables for now
|
||||||
|
val memsize =
|
||||||
|
when (memvar.dt) {
|
||||||
|
in NumericDatatypes -> program.memsizer.memorySize(memvar.dt)
|
||||||
|
in ArrayDatatypes -> program.memsizer.memorySize(memvar.dt, memvar.length!!)
|
||||||
|
else -> throw InternalCompilerException("weird dt")
|
||||||
|
}
|
||||||
|
|
||||||
|
allocations[memvar.scopedName] = nextLocation
|
||||||
|
nextLocation += memsize
|
||||||
|
}
|
||||||
|
|
||||||
freeMemoryStart = nextLocation
|
freeMemoryStart = nextLocation
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,13 @@ internal class SymbolTableMaker: IAstVisitor {
|
|||||||
StStaticVariable(decl.name, decl.datatype, initialNumeric, initialString, initialArray, numElements, decl.zeropage, decl.position)
|
StStaticVariable(decl.name, decl.datatype, initialNumeric, initialString, initialArray, numElements, decl.zeropage, decl.position)
|
||||||
}
|
}
|
||||||
VarDeclType.CONST -> StConstant(decl.name, decl.datatype, (decl.value as NumericLiteral).number, decl.position)
|
VarDeclType.CONST -> StConstant(decl.name, decl.datatype, (decl.value as NumericLiteral).number, decl.position)
|
||||||
VarDeclType.MEMORY -> StMemVar(decl.name, decl.datatype, (decl.value as NumericLiteral).number.toUInt(), decl.position)
|
VarDeclType.MEMORY -> {
|
||||||
|
val numElements =
|
||||||
|
if(decl.datatype in ArrayDatatypes)
|
||||||
|
decl.arraysize!!.constIndex()
|
||||||
|
else null
|
||||||
|
StMemVar(decl.name, decl.datatype, (decl.value as NumericLiteral).number.toUInt(), numElements, decl.position)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
scopestack.peek().add(node)
|
scopestack.peek().add(node)
|
||||||
// st.origAstLinks[decl] = node
|
// st.origAstLinks[decl] = node
|
||||||
|
@ -3,9 +3,9 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- assembler incorrectly assembles hello.asm now (crash when run)
|
- petaxian roller.p8 line 49 (also see test.p8) generates large code compared to 8.2
|
||||||
|
|
||||||
- why can't while and until loops use NOT condition instead of Cond==0 ? Fix this!
|
- assembler incorrectly assembles hello.asm now (crash when run)
|
||||||
|
|
||||||
- code gen for if statements has become inefficient? vm/6502?
|
- code gen for if statements has become inefficient? vm/6502?
|
||||||
if not diskio.iteration_in_progress or not num_bytes
|
if not diskio.iteration_in_progress or not num_bytes
|
||||||
|
@ -6,38 +6,38 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
|
||||||
ubyte a1 = 0
|
ubyte a1 = 0
|
||||||
ubyte a2 = 42
|
ubyte a2 = 128
|
||||||
ubyte a3 = 1
|
|
||||||
|
|
||||||
if (a1==0)==0
|
|
||||||
a3 = (a1==0)==0
|
|
||||||
|
|
||||||
if (a1!=0)==0
|
|
||||||
a3 = (a1!=0)==0
|
|
||||||
|
|
||||||
if (a1==0)!=0
|
; petaxian roller.p8 line 49
|
||||||
a3 = (a1==0)!=0
|
; super large in new version, ok in 8.2....
|
||||||
|
; TODO cx16.r0 = a2 + 25 + (a1/40)
|
||||||
|
; txt.setcc( a1, a2 + 25 + (a1/40), 11,22)
|
||||||
|
|
||||||
if (a1!=0)!=0
|
if a1 and a2 {
|
||||||
a3 = (a1!=0)!=0
|
a1++
|
||||||
|
}
|
||||||
|
|
||||||
if (a1==0) or (a2==0)
|
if a1!=99 and not a2 {
|
||||||
a3 = (a1==0) or (a2==0)
|
a1++
|
||||||
|
}
|
||||||
|
|
||||||
if (a1==0) and (a2==0)
|
; while a1 != a2 {
|
||||||
a3 = (a1==0) and (a2==0)
|
; a1++
|
||||||
|
; }
|
||||||
if not a1 or not a2 or not(not(a3))
|
;
|
||||||
a3=not a1 or not a2 or not(not(a3))
|
; while a1!='\"' {
|
||||||
|
; a1++
|
||||||
if (a1==0) or (a2==0)
|
; }
|
||||||
a3 = (a1==0) or (a2==0)
|
; do {
|
||||||
|
; a1++
|
||||||
if (a1==0) and (a2==0)
|
; } until a1==99
|
||||||
a3 = (a1==0) and (a2==0)
|
;
|
||||||
|
;close_end:
|
||||||
txt.print_ub(a3)
|
; a1++
|
||||||
|
|
||||||
|
|
||||||
; ; a "pixelshader":
|
; ; a "pixelshader":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user