From 2d0d7e0cfc58d2b963c30947607f7807f0a1d5ed Mon Sep 17 00:00:00 2001 From: otya128 Date: Thu, 22 Dec 2016 20:10:21 +0900 Subject: [PATCH] Allow empty OUT arguments --- SMILEBASIC/VM.d | 8 ++++++++ SMILEBASIC/compiler.d | 9 +++++++-- SMILEBASIC/parser.d | 26 +++++++++++++++++++------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/SMILEBASIC/VM.d b/SMILEBASIC/VM.d index 10d3d41..fd06259 100644 --- a/SMILEBASIC/VM.d +++ b/SMILEBASIC/VM.d @@ -2161,3 +2161,11 @@ class SetX : Code vm.petitcomputer.xoff(func); } } + +class Pop : Code +{ + override void execute(VM vm) + { + vm.decSP(); + } +} diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index b45b538..c9d997c 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -697,8 +697,13 @@ class Compiler genCode(new PopVarExpression(sc)); } break; - default: - throw new SyntaxError(); + case NodeType.VoidExpression: + { + genCode(new Pop()); + } + break; + default: + throw new SyntaxError(); } } diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index f2d1c82..5e3d0fa 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -970,18 +970,30 @@ class Parser while(true) { token = lex.front(); - Expression arg = expression(); - if(!isLValue(arg)) + if (token.type == TokenType.Comma) { - //to support func args... OUT (no argument) - if (!func.outVariable.length) + func.addOut(new VoidExpression(lex.location)); + } + else + { + Expression arg = expression(); + if (!arg) { + func.addOut(new VoidExpression(lex.location)); break; } - syntaxError(); - return null; + if(!isLValue(arg)) + { + //to support func args... OUT (no argument) + if (!func.outVariable.length) + { + break; + } + syntaxError(); + return null; + } + func.addOut(arg); } - func.addOut(arg); token = lex.front(); if(token.type == TokenType.Comma) {