From 96ef7ba55d899be5b9ddcd9dc534a6a4065c2e34 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 29 Sep 2020 00:28:11 +0200 Subject: [PATCH] fixed ast to source for structs --- compiler/src/prog8/ast/AstToSourceCode.kt | 7 +++-- examples/test.p8 | 33 ++++++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/compiler/src/prog8/ast/AstToSourceCode.kt b/compiler/src/prog8/ast/AstToSourceCode.kt index 25f460c66..da6ee9031 100644 --- a/compiler/src/prog8/ast/AstToSourceCode.kt +++ b/compiler/src/prog8/ast/AstToSourceCode.kt @@ -85,7 +85,7 @@ class AstToSourceCode(val output: (text: String) -> Unit, val program: Program): DataType.ARRAY_W -> "word[" DataType.ARRAY_F -> "float[" DataType.STRUCT -> "" // the name of the struct is enough - else -> "?????2" + else -> "?????" } } @@ -113,7 +113,10 @@ class AstToSourceCode(val output: (text: String) -> Unit, val program: Program): VarDeclType.CONST -> output("const ") VarDeclType.MEMORY -> output("&") } - output(decl.struct?.name ?: "") + + if(decl.datatype==DataType.STRUCT && decl.struct!=null) + output(decl.struct!!.name) + output(datatypeString(decl.datatype)) if(decl.arraysize!=null) { decl.arraysize!!.index.accept(this) diff --git a/examples/test.p8 b/examples/test.p8 index 107ed2aa0..fe6c1b6d4 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,23 +5,36 @@ main { - str[] names = ["aap", "noot", "mies", "vuur"] - uword[] names3 = ["aap", "noot", "mies", "vuur"] - ubyte[] values = [11,22,33,44] - uword[] arrays = [names, names3, values] - struct Color { ubyte red ubyte green ubyte blue } - Color c1 = [11,22,33] ; TODO fix crash - Color c2 = [11,22,33] ; TODO fix crash - Color c3 = [11,22,33] ; TODO fix crash - ; uword[] colors = [ c1, c2, c3] +; Color c1 = [11,22,33] ; TODO fix crash +; Color c2 = [11,22,33] ; TODO fix crash +; Color c3 = [11,22,33] ; TODO fix crash +; uword[] colors = [ c1, c2, c3] ; TODO should contain pointers to (the first element) of each struct + + + str[] names = ["aap", "noot", "mies", "vuur"] + uword[] names3 = ["aap", "noot", "mies", "vuur"] + ubyte[] values = [11,22,33,44] + uword[] arrays = [names, names3, values] + sub start() { + Color c1 = [11,22,33] + Color c2 = [11,22,33] + Color c3 = [11,22,33] + uword[] colors = [ c1, c2, c3] ; TODO should contain pointers to (the first element) of each struct + + c1.red = 100 + c1.green = 100 + c1.blue = 100 + ; c1 = [11,22,33] ; TODO rewrite into individual struct member assignments + + uword s for s in names { txt.print(s) @@ -35,7 +48,7 @@ main { txt.chrout('\n') repeat { - txt.print(names3[rnd()&3]) ; TODO doesn't show correct names? only shows 'aap' and 'noot' works fine if idx in separate var + txt.print(names3[rnd()&3]) txt.chrout(' ') } }