Implement BIN$
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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();
|
||||||
while(true)
|
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());
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user