1
0

Implement POP

This commit is contained in:
otya128
2016-12-14 20:34:31 +09:00
parent 23cea555e1
commit 96ea2e84e2
2 changed files with 41 additions and 0 deletions

View File

@@ -2526,6 +2526,36 @@ class BuiltinFunction
throw new TypeMismatch();
}
}
static Value POP(Value ary)
{
if (!ary.isArray)
{
throw new TypeMismatch("POP", 1);
}
if (ary.length == 0)
{
throw new SubscriptOutOfRange("POP");
}
switch (ary.type)
{
case ValueType.String:
throw new IllegalFunctionCall("NOTIMPL:POP string");
case ValueType.IntegerArray:
if (ary.integerArray.dimCount != 1)
throw new TypeMismatch("POP", 1);
return Value(ary.integerArray.pop());
case ValueType.DoubleArray:
if (ary.doubleArray.dimCount != 1)
throw new TypeMismatch("POP", 1);
return Value(ary.doubleArray.pop());
case ValueType.StringArray:
if (ary.stringArray.dimCount != 1)
throw new TypeMismatch("POP", 1);
return Value(ary.stringArray.pop());
default:
throw new TypeMismatch();
}
}
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
static BuiltinFunctions[wstring] builtinFunctions;
static wstring getBasicName(BFD)(const wstring def)

View File

@@ -388,6 +388,17 @@ class Array(T)
array ~= v;
dim[0]++;
}
T pop()
{
if (dimCount != 1)
{
throw new TypeMismatch();
}
auto last = array[$ - 1];
array.length--;
dim[0]--;
return last;
}
@property void length(int size)
{
if (dimCount != 1)