diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index fbb9ca7..2671e06 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -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) diff --git a/SMILEBASIC/type.d b/SMILEBASIC/type.d index a865308..5bd4a59 100644 --- a/SMILEBASIC/type.d +++ b/SMILEBASIC/type.d @@ -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)