private static void GetElement(Evaluator eval, StackFrame frame) { var args = frame.args; Atom arg0 = (Atom)args?.value; Atom arg1 = (Atom)args?.next?.value; if (arg0.type != AtomType.Number || UNumber.NumberType(arg0.value) > UNumber.SINT) { throw new ArgumentException("First argument must be integer number!"); } if (arg1.type != AtomType.Pair) { throw new ArgumentException("Second argument must be list!"); } Atom res = arg1.ListSkip((int)arg0.value); if (res == null) { throw new ArgumentException(string.Format("List too short for argument {0}!", arg0.value)); } eval.Return(res); }
private static void Tanh(Evaluator eval, StackFrame frame) { Atom atom = (Atom)frame.args?.value; if (atom.type != AtomType.Number) { throw new ArgumentException("Argument must be number!"); } eval.Return(new Atom(AtomType.Number, UNumber.Tanh(atom.value))); }
private static void Atan2(Evaluator eval, StackFrame frame) { CheckAllNumbers(frame.args); object res = ((Atom)frame.args?.value)?.value; for (Atom iter = frame.args?.next; iter != null; iter = iter.next) { res = UNumber.Atan2(res, ((Atom)iter.value).value); } eval.Return(new Atom(AtomType.Number, res)); }
private static bool CheckNumberType(Atom atom, int type) { return(atom.type == AtomType.Number && UNumber.NumberType(atom.value) == type); }
private static void Write(Evaluator eval, StackFrame frame) { var(stream, value) = StructureUtils.Split2(frame.args); if (stream.type != AtomType.Native) { throw new ArgumentException("Argument must be stream!"); } StreamWriter writer = stream?.value as StreamWriter; if (writer == null) { throw new ArgumentException("Argument must be stream!"); } if (value == null) { throw new ArgumentException("Second argument can't be null!"); } switch (value.type) { case AtomType.Number: var type = UNumber.NumberType(value?.value); switch (type) { case UNumber.UINT_8: writer.Write(Convert.ToByte(value.value)); break; case UNumber.SINT_8: writer.Write(Convert.ToSByte(value.value)); break; case UNumber.UINT16: writer.Write(Convert.ToUInt16(value.value)); break; case UNumber.SINT16: writer.Write(Convert.ToInt16(value.value)); break; case UNumber._CHAR_: writer.Write(Convert.ToChar(value.value)); break; case UNumber.UINT32: writer.Write(Convert.ToUInt32(value.value)); break; case UNumber.SINT32: writer.Write(Convert.ToInt32(value.value)); break; case UNumber.UINT64: writer.Write(Convert.ToUInt64(value.value)); break; case UNumber.SINT64: writer.Write(Convert.ToInt64(value.value)); break; case UNumber.FLO32: writer.Write(Convert.ToSingle(value.value)); break; case UNumber.FLO64: writer.Write(Convert.ToDouble(value.value)); break; default: writer.Write(value.value); break; } break; default: writer.Write(value.value); break; } eval.Return(null); }