mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
struct fixes
This commit is contained in:
parent
717b5f3b07
commit
7500c6efd0
@ -76,17 +76,6 @@ artifacts {
|
||||
archives shadowJar
|
||||
}
|
||||
|
||||
task p8vmScript(type: CreateStartScripts) {
|
||||
mainClassName = "prog8.vm.stackvm.MainKt"
|
||||
applicationName = "p8vm"
|
||||
outputDir = new File(project.buildDir, 'scripts')
|
||||
classpath = jar.outputs.files + project.configurations.runtime
|
||||
}
|
||||
|
||||
applicationDistribution.into("bin") {
|
||||
from(p8vmScript)
|
||||
fileMode = 0755
|
||||
}
|
||||
|
||||
// To create a fat-jar use the 'create_compiler_jar' script for now
|
||||
// @todo investigate https://imperceptiblethoughts.com/shadow/introduction/
|
||||
|
@ -62,8 +62,9 @@ internal class AstIdentifiersChecker(private val namespace: INameScope) : IAstMo
|
||||
if(decl.structHasBeenFlattened)
|
||||
return decl // don't do this multiple times
|
||||
|
||||
val decls: MutableList<IStatement> = decl.struct!!.statements.map {
|
||||
val member = it as VarDecl
|
||||
val decls: MutableList<IStatement> = decl.struct!!.statements.withIndex().map {
|
||||
val member = it.value as VarDecl
|
||||
val initvalue = if(decl.value!=null) (decl.value as LiteralValue).arrayvalue!![it.index] else null
|
||||
VarDecl(
|
||||
VarDeclType.VAR,
|
||||
member.datatype,
|
||||
@ -71,7 +72,7 @@ internal class AstIdentifiersChecker(private val namespace: INameScope) : IAstMo
|
||||
member.arraysize,
|
||||
mangledStructMemberName(decl.name, member.name),
|
||||
null,
|
||||
member.value,
|
||||
initvalue,
|
||||
member.isArray,
|
||||
true,
|
||||
member.position
|
||||
|
@ -62,22 +62,23 @@ internal class VarInitValueAndAddressOfCreator(private val namespace: INameScope
|
||||
)
|
||||
}
|
||||
|
||||
if(decl.datatype==DataType.STRUCT) {
|
||||
// a struct initialization value
|
||||
// flatten it to assignment statements
|
||||
val sourceArray = (decl.value as LiteralValue).arrayvalue!!
|
||||
val memberAssignments = decl.struct!!.statements.zip(sourceArray).map { member ->
|
||||
val memberDecl = member.first as VarDecl
|
||||
val mangled = mangledStructMemberName(decl.name, memberDecl.name)
|
||||
val idref = IdentifierReference(listOf(mangled), decl.position)
|
||||
val target = AssignTarget(null, idref, null, null, decl.position)
|
||||
val assign = VariableInitializationAssignment(target, null, member.second, member.second.position)
|
||||
assign
|
||||
}
|
||||
val scope = AnonymousScope(memberAssignments.toMutableList(), decl.position)
|
||||
scope.linkParents(decl.parent)
|
||||
return scope
|
||||
}
|
||||
// if(decl.datatype==DataType.STRUCT) {
|
||||
// println("STRUCT INIT DECL $decl")
|
||||
// // a struct initialization value perhaps
|
||||
// // flatten it to assignment statements
|
||||
// val sourceArray = (decl.value as LiteralValue).arrayvalue!!
|
||||
// val memberAssignments = decl.struct!!.statements.zip(sourceArray).map { member ->
|
||||
// val memberDecl = member.first as VarDecl
|
||||
// val mangled = mangledStructMemberName(decl.name, memberDecl.name)
|
||||
// val idref = IdentifierReference(listOf(mangled), decl.position)
|
||||
// val target = AssignTarget(null, idref, null, null, decl.position)
|
||||
// val assign = VariableInitializationAssignment(target, null, member.second, member.second.position)
|
||||
// assign
|
||||
// }
|
||||
// val scope = AnonymousScope(memberAssignments.toMutableList(), decl.position)
|
||||
// scope.linkParents(decl.parent)
|
||||
// return scope
|
||||
// }
|
||||
|
||||
return decl
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ fun compileProgram(filepath: Path,
|
||||
}
|
||||
//println(" time2: $time2")
|
||||
val time3 = measureTimeMillis {
|
||||
programAst.removeNopsFlattenAnonScopes()
|
||||
programAst.reorderStatements() // reorder statements and add type casts, to please the compiler later
|
||||
}
|
||||
//println(" time3: $time3")
|
||||
@ -88,7 +89,7 @@ fun compileProgram(filepath: Path,
|
||||
programAst.checkValid(compilerOptions) // check if final tree is valid
|
||||
programAst.checkRecursion() // check if there are recursive subroutine calls
|
||||
|
||||
printAst(programAst)
|
||||
// printAst(programAst)
|
||||
// namespace.debugPrint()
|
||||
|
||||
if(generateVmCode) {
|
||||
|
@ -54,14 +54,10 @@ The compiler will link everything together into one output program at the end.
|
||||
If you start the compiler without arguments, it will print a short usage text.
|
||||
For normal use the compiler is invoked with the command:
|
||||
|
||||
``$ java -jar prog8compiler.jar sourcefile.p8`` if you're using the packaged release version, or
|
||||
``$ java -jar prog8compiler.jar sourcefile.p8``
|
||||
|
||||
``$ ./p8compile.sh sourcefile.p8`` if you're running an unpackaged development version.
|
||||
|
||||
If you tell it to save the intermediate code for the prog8 virtual machine, you can
|
||||
actually run this code with the command:
|
||||
|
||||
``$ ./p8vm.sh sourcefile.vm.txt``
|
||||
Other options are also available, see the introduction page about how
|
||||
to build and run the compiler.
|
||||
|
||||
|
||||
By default, assembly code is generated and written to ``sourcefile.asm``.
|
||||
|
@ -3,8 +3,11 @@
|
||||
|
||||
~ main {
|
||||
|
||||
Color blocklevelcolor
|
||||
|
||||
sub start() {
|
||||
uword derp
|
||||
|
||||
uword derp =44
|
||||
ubyte[] v = [22,33,44]
|
||||
|
||||
Color foreground = [1,2,3]
|
||||
@ -16,15 +19,15 @@
|
||||
c64.CHROUT('\n')
|
||||
|
||||
|
||||
Color background = [255,255,255] ; @todo make zeros if no value is given
|
||||
Color cursor
|
||||
Color background
|
||||
Color cursor = [255,255,255]
|
||||
|
||||
foreground.red=99
|
||||
background.blue=foreground.red
|
||||
|
||||
cursor = [1,2,3] ; assign all members at once
|
||||
cursor = v
|
||||
;cursor=foreground ; @todo memberwise assignment
|
||||
cursor = foreground ; @todo memberwise assignment
|
||||
|
||||
c64scr.print_ub(foreground.red)
|
||||
c64.CHROUT(':')
|
||||
@ -45,9 +48,29 @@
|
||||
c64scr.print_ub(cursor.blue)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
foo()
|
||||
foo()
|
||||
foo()
|
||||
foo()
|
||||
foo()
|
||||
foo()
|
||||
foo()
|
||||
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
sub foo() {
|
||||
Color localcolor
|
||||
localcolor.red++
|
||||
c64scr.print_ub(localcolor.red)
|
||||
c64.CHROUT(':')
|
||||
c64scr.print_ub(localcolor.green)
|
||||
c64.CHROUT(':')
|
||||
c64scr.print_ub(localcolor.blue)
|
||||
c64.CHROUT('\n')
|
||||
}
|
||||
|
||||
struct Color {
|
||||
ubyte red
|
||||
ubyte green
|
||||
|
Loading…
Reference in New Issue
Block a user