Implement PUSH
This commit is contained in:
@@ -2355,6 +2355,39 @@ class BuiltinFunction
|
||||
}
|
||||
return std.math.log(a) / std.math.log(b);
|
||||
}
|
||||
static void PUSH(Value ary, Value exp)
|
||||
{
|
||||
if (!ary.isArray)
|
||||
{
|
||||
throw new TypeMismatch("PUSH", 1);
|
||||
}
|
||||
if (!exp.canCast(ary.elementType))
|
||||
{
|
||||
throw new TypeMismatch("PUSH");
|
||||
}
|
||||
switch (ary.type)
|
||||
{
|
||||
case ValueType.String:
|
||||
throw new IllegalFunctionCall("NOTIMPL:PUSH string");
|
||||
case ValueType.IntegerArray:
|
||||
if (ary.integerArray.dimCount != 1)
|
||||
throw new TypeMismatch("PUSH", 1);
|
||||
ary.integerArray.push(exp.castInteger);
|
||||
break;
|
||||
case ValueType.DoubleArray:
|
||||
if (ary.doubleArray.dimCount != 1)
|
||||
throw new TypeMismatch("PUSH", 1);
|
||||
ary.doubleArray.push(exp.castDouble);
|
||||
break;
|
||||
case ValueType.StringArray:
|
||||
if (ary.stringArray.dimCount != 1)
|
||||
throw new TypeMismatch("PUSH", 1);
|
||||
ary.stringArray.push(exp.castString);
|
||||
break;
|
||||
default:
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
}
|
||||
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
||||
static BuiltinFunctions[wstring] builtinFunctions;
|
||||
static wstring getBasicName(BFD)(const wstring def)
|
||||
|
||||
@@ -235,6 +235,26 @@ struct Value
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
}
|
||||
ValueType elementType()
|
||||
{
|
||||
switch(this.type)
|
||||
{
|
||||
case ValueType.String:
|
||||
return ValueType.String;
|
||||
case ValueType.IntegerArray:
|
||||
return ValueType.Integer;
|
||||
case ValueType.DoubleArray:
|
||||
return ValueType.Double;
|
||||
case ValueType.StringArray:
|
||||
return ValueType.String;
|
||||
default:
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
}
|
||||
bool canCast(ValueType t)
|
||||
{
|
||||
return t == this.type || ((t == ValueType.Integer || t == ValueType.Double) && isNumber);
|
||||
}
|
||||
}
|
||||
//import std.experimental.ndslice;
|
||||
//ndsliceがこれに相当?
|
||||
@@ -359,5 +379,14 @@ class Array(T)
|
||||
if(i1 >= dim[0] && i2 >= dim[1] && i3 >= dim[2] && i4 >= dim[3]) throw new SubscriptOutOfRange();
|
||||
return array[i1] = v;//array[i1 * dim[0] * dim[1] * dim[2] + i2 * dim[1] + i3] = v;
|
||||
}
|
||||
void push(T v)
|
||||
{
|
||||
if (dimCount != 1)
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
array ~= v;
|
||||
dim[0]++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user