mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
new ast: regular subroutine has just 0 or 1 return type
This commit is contained in:
parent
73dbdbcbe6
commit
e227cc92ff
@ -21,7 +21,7 @@ class PtAsmSub(
|
||||
class PtSub(
|
||||
name: String,
|
||||
val parameters: List<PtSubroutineParameter>,
|
||||
val returntypes: List<DataType>,
|
||||
val returntype: DataType?,
|
||||
val inline: Boolean,
|
||||
position: Position
|
||||
) : PtNamedNode(name, position) {
|
||||
|
@ -284,7 +284,7 @@ class IntermediateAstMaker(val srcProgram: Program) {
|
||||
private fun transformSub(srcSub: Subroutine): PtSub {
|
||||
val sub = PtSub(srcSub.name,
|
||||
srcSub.parameters.map { PtSubroutineParameter(it.name, it.type, it.position) },
|
||||
srcSub.returntypes,
|
||||
srcSub.returntypes.singleOrNull(),
|
||||
srcSub.inline,
|
||||
srcSub.position)
|
||||
|
||||
|
@ -275,20 +275,15 @@ private fun Prog8ANTLRParser.LabeldefContext.toAst(): Statement =
|
||||
private fun Prog8ANTLRParser.SubroutineContext.toAst() : Subroutine {
|
||||
// non-asm subroutine
|
||||
val inline = inline()!=null
|
||||
val returntypes = sub_return_part()?.toAst() ?: emptyList()
|
||||
val returntype = sub_return_part()?.datatype()?.toAst()
|
||||
return Subroutine(identifier().text,
|
||||
sub_params()?.toAst()?.toMutableList() ?: mutableListOf(),
|
||||
returntypes,
|
||||
if(returntype==null) emptyList() else listOf(returntype),
|
||||
statement_block()?.toAst() ?: mutableListOf(),
|
||||
inline,
|
||||
toPosition())
|
||||
}
|
||||
|
||||
private fun Prog8ANTLRParser.Sub_return_partContext.toAst(): List<DataType> {
|
||||
val returns = sub_returns() ?: return emptyList()
|
||||
return returns.datatype().map { it.toAst() }
|
||||
}
|
||||
|
||||
private fun Prog8ANTLRParser.Sub_paramsContext.toAst(): List<SubroutineParameter> =
|
||||
vardecl().map {
|
||||
var datatype = it.datatype()?.toAst() ?: DataType.UNDEFINED
|
||||
|
@ -31,6 +31,9 @@ main {
|
||||
; test_stack.test()
|
||||
}
|
||||
|
||||
sub derp() -> ubyte, ubyte {
|
||||
return 0, 1
|
||||
}
|
||||
|
||||
sub find_next_prime() -> ubyte {
|
||||
|
||||
|
@ -245,7 +245,7 @@ subroutine :
|
||||
inline? 'sub' identifier '(' sub_params? ')' sub_return_part? (statement_block EOL)
|
||||
;
|
||||
|
||||
sub_return_part : '->' sub_returns ;
|
||||
sub_return_part : '->' datatype ;
|
||||
|
||||
statement_block :
|
||||
'{' EOL
|
||||
@ -256,8 +256,6 @@ statement_block :
|
||||
|
||||
sub_params : vardecl (',' EOL? vardecl)* ;
|
||||
|
||||
sub_returns : datatype (',' EOL? datatype)* ;
|
||||
|
||||
asmsubroutine :
|
||||
inline? 'asmsub' asmsub_decl statement_block
|
||||
;
|
||||
|
Loading…
x
Reference in New Issue
Block a user