added codengeration for assigment of array of values to a struct variable (all members at once)

This commit is contained in:
Irmen de Jong 2020-10-02 22:37:52 +02:00
parent 8647a8290e
commit 46fbe01df9
3 changed files with 24 additions and 14 deletions

View File

@ -202,7 +202,16 @@ internal class StatementReorderer(val program: Program) : AstWalker() {
}
}
sourceVar.isArray -> {
TODO("assign struct array $structAssignment")
val array = (sourceVar.value as ArrayLiteralValue).value
return struct.statements.zip(array).map {
val decl = it.first as VarDecl
val mangled = mangledStructMemberName(identifierName, decl.name)
val targetName = IdentifierReference(listOf(mangled), structAssignment.position)
val target = AssignTarget(targetName, null, null, structAssignment.position)
val assign = Assignment(target, it.second, structAssignment.position)
assign.linkParents(structAssignment)
assign
}
}
else -> {
throw FatalAstException("can only assign arrays or structs to structs")

View File

@ -3,8 +3,7 @@ TODO
====
- get rid of all other TODO's in the code ;-)
- make it possible for array literals to not only contain compile time constants
- further optimize assignment codegeneration
- make it possible for array literals to not only contain compile time constants?
- implement @stack for asmsub parameters
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_'
- option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging)
@ -17,7 +16,8 @@ More optimizations
Add more compiler optimizations to the existing ones.
- more targeted optimizations for assigment asm code, such as the following:
- further optimize assignment codegeneration, such as the following:
- binexpr splitting (beware self-referencing expressions and asm code ballooning though)
- subroutine calling convention? like: 1 byte arg -> pass in A, 2 bytes -> pass in A+Y, return value likewise.
- can such parameter passing to subroutines be optimized to avoid copying?
- more optimizations on the language AST level

View File

@ -20,21 +20,22 @@ main {
sub start() {
txt.print_uwhex(&c1, true)
txt.print_ub(c1.red)
txt.chrout('\n')
txt.print_uwhex(&c2, true)
txt.print_ub(c1.green)
txt.chrout('\n')
txt.print_uwhex(&c3, true)
txt.print_ub(c1.blue)
txt.chrout('\n')
txt.print_uwhex(colors[0], true)
txt.chrout('\n')
txt.print_uwhex(colors[1], true)
txt.chrout('\n')
txt.print_uwhex(colors[2], true)
txt.chrout('\n')
c1 = c2
c1 = [11,22,33] ; TODO implement rewrite into individual struct member assignments
c1 = [99,88,77]
txt.print_ub(c1.red)
txt.chrout('\n')
txt.print_ub(c1.green)
txt.chrout('\n')
txt.print_ub(c1.blue)
txt.chrout('\n')
testX()
}