From e701fa5704daaad9e7f948a8f4e73c6748878928 Mon Sep 17 00:00:00 2001 From: otya128 Date: Thu, 29 Dec 2016 20:45:43 +0900 Subject: [PATCH] Implement BIN$ --- SMILEBASIC/builtinfunctions.d | 33 ++++++++++++++++++++++++++++++++- SMILEBASIC/parser.d | 20 ++++++++++++++------ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index f7acdde..acc5953 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -1350,12 +1350,18 @@ class BuiltinFunction str2[digits - str.length..digits] = str; return str2[0..digits].to!wstring; } + /+ + HEX$(1,0)=>1 + HEX$(1)=>1 + HEX$(1,)=>1(???) + HEX$(1,2)=>01 + +/ static wstring HEX(int val, DefaultValue!(int, false) digits) { import std.format; if(digits > 8 || digits < 0) { - throw new OutOfRange(); + throw new OutOfRange("HEX$", 2); } FormatSpec!char f; f.spec = 'X'; @@ -1365,6 +1371,31 @@ class BuiltinFunction formatValue(w, val, f); return cast(immutable)(w.data); } + /+ + BIN$(1,0)=>1 + BIN$(1)=>1 + BIN$(1,)=>Type mismatch(BIN$:2) + BIN$(1,2)=>01 + +/ + static wstring BIN(int val) + { + return val.to!wstring(2); + } + static wstring BIN(int val, int digits) + { + import std.format; + if(digits > 32 || digits < 0) + { + throw new OutOfRange("BIN$", 2); + } + FormatSpec!char f; + f.spec = 'b'; + f.flZero = true; + f.width = digits; + auto w = appender!wstring(); + formatValue(w, val, f); + return cast(immutable)(w.data); + } static void SPSET(PetitComputer p, int id, int defno, DefaultValue!(int, false) V, DefaultValue!(int, false) W, DefaultValue!(int, false) H, DefaultValue!(int, false) ATTR) { if(!V.isDefault && !W.isDefault) diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index 6ad85a7..4ef2759 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -1926,15 +1926,23 @@ class Parser { auto func = new CallFunction(token.value.stringValue, lex.location); node = func; - //関数呼び出しだった - while(true) + lex.popFront(); + if(lex.front().type != TokenType.RParen) { - lex.popFront(); - token = lex.front(); + //関数呼び出しだった + while(true) + { + token = lex.front(); - if(token.type == TokenType.RParen) break; func.addArg(expression()); - if(lex.front().type == TokenType.RParen) break; + if(lex.front().type == TokenType.RParen) break; + if(lex.front().type != TokenType.Comma) + { + syntaxError(); + break; + } + lex.popFront(); + } } } else