1
0

Implement BIN$

This commit is contained in:
otya128
2016-12-29 20:45:43 +09:00
parent 20889c28e1
commit e701fa5704
2 changed files with 46 additions and 7 deletions

View File

@@ -1350,12 +1350,18 @@ class BuiltinFunction
str2[digits - str.length..digits] = str; str2[digits - str.length..digits] = str;
return str2[0..digits].to!wstring; 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) static wstring HEX(int val, DefaultValue!(int, false) digits)
{ {
import std.format; import std.format;
if(digits > 8 || digits < 0) if(digits > 8 || digits < 0)
{ {
throw new OutOfRange(); throw new OutOfRange("HEX$", 2);
} }
FormatSpec!char f; FormatSpec!char f;
f.spec = 'X'; f.spec = 'X';
@@ -1365,6 +1371,31 @@ class BuiltinFunction
formatValue(w, val, f); formatValue(w, val, f);
return cast(immutable)(w.data); 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) 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) if(!V.isDefault && !W.isDefault)

View File

@@ -1926,15 +1926,23 @@ class Parser
{ {
auto func = new CallFunction(token.value.stringValue, lex.location); auto func = new CallFunction(token.value.stringValue, lex.location);
node = func; node = func;
lex.popFront();
if(lex.front().type != TokenType.RParen)
{
//関数呼び出しだった //関数呼び出しだった
while(true) while(true)
{ {
lex.popFront();
token = lex.front(); token = lex.front();
if(token.type == TokenType.RParen) break;
func.addArg(expression()); 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 else