mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 08:29:25 +00:00
trying to fix namespace lookup errors
This commit is contained in:
parent
f1a7fa1870
commit
56e0f4c525
@ -21,8 +21,6 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
||||
override fun process(module: Module) {
|
||||
super.process(module)
|
||||
|
||||
module.statements = sortConstantAssignments(module.statements)
|
||||
|
||||
val (blocks, other) = module.statements.partition { it is Block }
|
||||
module.statements = other.asSequence().plus(blocks.sortedBy { (it as Block).address ?: Int.MAX_VALUE }).toMutableList()
|
||||
|
||||
@ -40,17 +38,18 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
||||
module.statements.addAll(0, directives)
|
||||
|
||||
// add any new vardecls
|
||||
// @todo doing it this late causes problems with namespace lookups elsewhere in sortConstantAssignments
|
||||
for(decl in vardeclsToAdd)
|
||||
for(d in decl.value) {
|
||||
d.linkParents(decl.key as Node)
|
||||
decl.key.statements.add(0, d)
|
||||
}
|
||||
|
||||
sortConstantAssignments(module.statements)
|
||||
}
|
||||
|
||||
override fun process(block: Block): IStatement {
|
||||
|
||||
block.statements = sortConstantAssignments(block.statements)
|
||||
|
||||
val subroutines = block.statements.filterIsInstance<Subroutine>()
|
||||
var numSubroutinesAtEnd = 0
|
||||
// move all subroutines to the end of the block
|
||||
@ -93,13 +92,16 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
||||
val directives = block.statements.filter {it is Directive && it.directive in directivesToMove}
|
||||
block.statements.removeAll(directives)
|
||||
block.statements.addAll(0, directives)
|
||||
|
||||
sortConstantAssignments(block.statements)
|
||||
|
||||
return super.process(block)
|
||||
}
|
||||
|
||||
override fun process(subroutine: Subroutine): IStatement {
|
||||
super.process(subroutine)
|
||||
|
||||
subroutine.statements = sortConstantAssignments(subroutine.statements)
|
||||
sortConstantAssignments(subroutine.statements)
|
||||
|
||||
val varDecls = subroutine.statements.filterIsInstance<VarDecl>()
|
||||
subroutine.statements.removeAll(varDecls)
|
||||
@ -124,11 +126,12 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
||||
}
|
||||
|
||||
override fun process(scope: AnonymousScope): AnonymousScope {
|
||||
scope.statements = sortConstantAssignments(scope.statements)
|
||||
return super.process(scope)
|
||||
scope.statements = scope.statements.map { it.process(this)}.toMutableList()
|
||||
sortConstantAssignments(scope.statements)
|
||||
return scope
|
||||
}
|
||||
|
||||
private fun sortConstantAssignments(statements: MutableList<IStatement>): MutableList<IStatement> {
|
||||
private fun sortConstantAssignments(statements: MutableList<IStatement>) {
|
||||
// sort assignments by datatype and value, so multiple initializations with the same value can be optimized (to load the value just once)
|
||||
val result = mutableListOf<IStatement>()
|
||||
val stmtIter = statements.iterator()
|
||||
@ -147,7 +150,8 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
||||
else
|
||||
result.add(stmt)
|
||||
}
|
||||
return result
|
||||
statements.clear()
|
||||
statements.addAll(result)
|
||||
}
|
||||
|
||||
private fun sortConstantAssignmentSequence(first: Assignment, stmtIter: MutableIterator<IStatement>): Pair<List<Assignment>, IStatement?> {
|
||||
|
@ -1,14 +1,14 @@
|
||||
%import c64lib
|
||||
%import c64utils
|
||||
%import c64flt
|
||||
|
||||
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
; set screen colors and activate lowercase charset
|
||||
c64.EXTCOL = 5
|
||||
c64.BGCOL0 = 0
|
||||
c64.COLOR = 1
|
||||
; set text color and activate lowercase charset
|
||||
c64.COLOR = 13
|
||||
c64.VMCSB |= 2
|
||||
|
||||
; use optimized routine to write text
|
||||
@ -24,6 +24,23 @@
|
||||
for ubyte c in 0 to len(bye)
|
||||
c64.CHROUT(bye[c])
|
||||
|
||||
|
||||
float clock_seconds = ((c64.TIME_LO as float) + 256.0*(c64.TIME_MID as float) + 65536.0*(c64.TIME_HI as float)) / 60
|
||||
ubyte hours = clock_seconds / 3600 as ubyte
|
||||
clock_seconds -= hours * 3600
|
||||
ubyte minutes = clock_seconds / 60 as ubyte
|
||||
clock_seconds -= minutes * 60
|
||||
ubyte seconds = 0; clock_seconds as ubyte ; @todo fix crash
|
||||
|
||||
|
||||
; @todo implement strcpy/strcat/strlen?
|
||||
c64scr.print("system time is ")
|
||||
c64scr.print_ub(hours)
|
||||
c64.CHROUT(':')
|
||||
c64scr.print_ub(minutes)
|
||||
c64.CHROUT(':')
|
||||
c64scr.print_ub(seconds)
|
||||
c64.CHROUT('\n')
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,38 +1,25 @@
|
||||
%import c64lib
|
||||
%option enable_floats
|
||||
%import c64utils
|
||||
%import c64flt
|
||||
|
||||
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
sub start() {
|
||||
|
||||
ubyte ub1
|
||||
ubyte ub2
|
||||
byte b1
|
||||
byte b2
|
||||
uword uw1
|
||||
uword uw2
|
||||
word w1
|
||||
word w2
|
||||
|
||||
memory ubyte mub1 = $c000
|
||||
memory ubyte mub2 = $c001
|
||||
memory uword muw1 = $c100
|
||||
memory uword muw2 = $c102
|
||||
|
||||
ubyte[3] uba1
|
||||
byte[3] ba1
|
||||
uword[3] uwa1
|
||||
word[3] wa1
|
||||
ubyte[3] uba2
|
||||
byte[3] ba2
|
||||
uword[3] uwa2
|
||||
word[3] wa2
|
||||
str hoi = "hoi"
|
||||
str hoi2 = "hoi2"
|
||||
float clock_seconds = ((c64.TIME_LO as float) + 256.0*(c64.TIME_MID as float) + 65536.0*(c64.TIME_HI as float)) / 60
|
||||
float hours = floor(clock_seconds / 3600)
|
||||
clock_seconds -= hours * 3600
|
||||
float minutes = floor(clock_seconds / 60)
|
||||
clock_seconds -= minutes * 60.0
|
||||
|
||||
ubyte hours_b = hours as ubyte
|
||||
ubyte minutes_b = minutes as ubyte
|
||||
ubyte seconds_b = clock_seconds as ubyte
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user