fixed todos in Ast printer

This commit is contained in:
Irmen de Jong 2024-01-01 23:21:05 +01:00
parent 99c29343de
commit 517ea82b99
2 changed files with 18 additions and 3 deletions

View File

@ -57,9 +57,20 @@ fun printAst(root: PtNode, skipLibraries: Boolean, output: (text: String) -> Uni
"???" "???"
} }
is PtAsmSub -> { is PtAsmSub -> {
val params = if (node.parameters.isEmpty()) "" else "...TODO ${node.parameters.size} PARAMS..." val params = node.parameters.map {
val register = it.first.registerOrPair
val statusflag = it.first.statusflag
"${it.second.type} ${it.second.name} @${register ?: statusflag}"
}.joinToString(", ")
val clobbers = if (node.clobbers.isEmpty()) "" else "clobbers ${node.clobbers}" val clobbers = if (node.clobbers.isEmpty()) "" else "clobbers ${node.clobbers}"
val returns = if (node.returns.isEmpty()) "" else (if (node.returns.size == 1) "-> ${node.returns[0].second.name.lowercase()}" else "-> ${node.returns.map { it.second.name.lowercase() }}") val returns = if (node.returns.isEmpty()) "" else {
"-> ${node.returns.map {
val register = it.first.registerOrPair
val statusflag = it.first.statusflag
"${it.second} @${register ?: statusflag}"}
.joinToString(", ")
}"
}
val str = if (node.inline) "inline " else "" val str = if (node.inline) "inline " else ""
if(node.address==null) { if(node.address==null) {
str + "asmsub ${node.name}($params) $clobbers $returns" str + "asmsub ${node.name}($params) $clobbers $returns"
@ -87,7 +98,7 @@ fun printAst(root: PtNode, skipLibraries: Boolean, output: (text: String) -> Uni
} }
} }
is PtSub -> { is PtSub -> {
val params = if (node.parameters.isEmpty()) "" else "...TODO ${node.parameters.size} PARAMS..." val params = node.parameters.map { "${it.type} ${it.name}" }.joinToString(", ")
var str = "sub ${node.name}($params) " var str = "sub ${node.name}($params) "
if(node.returntype!=null) if(node.returntype!=null)
str += "-> ${node.returntype.name.lowercase()}" str += "-> ${node.returntype.name.lowercase()}"

View File

@ -79,3 +79,7 @@ Other language/syntax features to think about
- chained comparisons `10<x<20` , `x==y==z` (desugars to `10<x and x<20`, `x==y and y==z`) - chained comparisons `10<x<20` , `x==y==z` (desugars to `10<x and x<20`, `x==y and y==z`)
BUT this needs a new AST node type and rewritten parser rules, because otherwise it changes the semantics BUT this needs a new AST node type and rewritten parser rules, because otherwise it changes the semantics
of existing expressions such as if x<y==0 ... of existing expressions such as if x<y==0 ...
- Better idea perhaps is "runtime range objects" the idea would be that "a to b" generates
a new kind of "range" value rather than an array (though you can still use it to initialize an array),
so you could replace if a <= n <= b with: if n in a to b
So this means we should keep the Range Expression alive for much longer.