internal override ElaValue Quot(ElaValue left, ElaValue right, ExecutionContext ctx) { if (right.TypeId != ElaMachine.LNG) { if (right.TypeId == ElaMachine.INT) { if (right.I4 == 0) { ctx.DivideByZero(left); return Default(); } return new ElaValue(left.Ref.AsLong() / right.I4); } else { ctx.NoOverload(left.GetTypeName() + "->" + left.GetTypeName() + "->*", left.GetTypeName() + "->" + right.GetTypeName() + "->*", "quot"); return Default(); } } var r = right.Ref.AsLong(); if (r == 0) { ctx.DivideByZero(left); return Default(); } return new ElaValue(left.Ref.AsLong() / right.Ref.AsLong()); }
internal virtual ElaValue Subtract(ElaValue left, ElaValue right, ExecutionContext ctx) { if (sub != null) { if (left.TypeId != right.TypeId) { NoOverloadBinary(left.GetTypeName(), right, "subtract", ctx); return(Default()); } ctx.SetDeffered(sub, 2); return(Default()); } ctx.NoOverload(left.GetTypeName(), "subtract"); return(Default()); }
internal virtual ElaValue Divide(ElaValue left, ElaValue right, ExecutionContext ctx) { if (div != null) { if (left.TypeId != right.TypeId) { NoOverloadBinary(left.GetTypeName(), right, "divide", ctx); return(Default()); } ctx.SetDeffered(div, 2); return(Default()); } ctx.NoOverload(left.GetTypeName(), "divide"); return(Default()); }
internal virtual ElaValue Modulus(ElaValue left, ElaValue right, ExecutionContext ctx) { if (mod != null) { if (left.TypeId != right.TypeId) { NoOverloadBinary(left.GetTypeName(), right, "modulus", ctx); return(Default()); } ctx.SetDeffered(mod, 2); return(Default()); } ctx.NoOverload(left.GetTypeName(), "modulus"); return(Default()); }
internal virtual ElaValue Power(ElaValue left, ElaValue right, ExecutionContext ctx) { if (pow != null) { if (left.TypeId != right.TypeId) { NoOverloadBinary(left.GetTypeName(), right, "power", ctx); return(Default()); } ctx.SetDeffered(pow, 2); return(Default()); } ctx.NoOverload(left.GetTypeName(), "power"); return(Default()); }
internal virtual bool Lesser(ElaValue left, ElaValue right, ExecutionContext ctx) { if (lt != null) { if (left.TypeId != right.TypeId) { NoOverloadBinary(left.GetTypeName(), right, "lesser", ctx); return(false); } ctx.SetDeffered(lt, 2); return(false); } ctx.NoOverload(left.GetTypeName(), "lesser"); return(false); }
internal virtual bool GreaterEqual(ElaValue left, ElaValue right, ExecutionContext ctx) { if (gteq != null) { if (left.TypeId != right.TypeId) { NoOverloadBinary(left.GetTypeName(), right, "greaterequal", ctx); return(false); } ctx.SetDeffered(gteq, 2); return(false); } ctx.NoOverload(left.GetTypeName(), "greaterequal"); return(false); }
internal virtual ElaValue GetLength(ElaValue value, ExecutionContext ctx) { if (len != null) { ctx.SetDeffered(len, 1); return(Default()); } ctx.NoOverload(value.GetTypeName(), "length"); return(Default()); }
internal virtual bool IsNil(ElaValue left, ExecutionContext ctx) { if (isnil != null) { ctx.SetDeffered(isnil, 1); return(false); } ctx.NoOverload(left.GetTypeName(), "isnil"); return(false); }
internal virtual ElaValue Head(ElaValue left, ExecutionContext ctx) { if (head != null) { ctx.SetDeffered(head, 1); return(Default()); } ctx.NoOverload(left.GetTypeName(), "head"); return(Default()); }
internal virtual ElaValue GetField(ElaValue obj, ElaValue field, ExecutionContext ctx) { if (getfld != null) { ctx.SetDeffered(getfld, 2); return(Default()); } ctx.NoOverload(obj.GetTypeName(), "getfield"); return(Default()); }
internal virtual bool HasField(ElaValue obj, ElaValue field, ExecutionContext ctx) { if (hasfld != null) { ctx.SetDeffered(hasfld, 2); return(false); } ctx.NoOverload(obj.GetTypeName(), "hasfield"); return(false); }
internal virtual string Show(ElaValue value, ExecutionContext ctx) { if (show != null) { ctx.SetDeffered(show, 1); return(String.Empty); } ctx.NoOverload(value.GetTypeName(), "show"); return(String.Empty); }
internal virtual ElaValue Tail(ElaValue left, ExecutionContext ctx) { if (tail != null) { ctx.SetDeffered(tail, 1); return(Default()); } ctx.NoOverload(left.GetTypeName(), "tail"); return(Default()); }
internal virtual ElaValue Concatenate(ElaValue left, ElaValue right, ExecutionContext ctx) { if (cat != null) { ctx.SetDeffered(cat, 2); return(Default()); } ctx.NoOverload(left.GetTypeName(), "concatenate"); return(Default()); }
internal virtual ElaValue ShiftLeft(ElaValue left, ElaValue right, ExecutionContext ctx) { if (shl != null) { ctx.SetDeffered(shl, 2); return(Default()); } ctx.NoOverload(left.GetTypeName(), "shiftleft"); return(Default()); }
internal virtual ElaValue BitwiseNot(ElaValue @this, ExecutionContext ctx) { if (not != null) { ctx.SetDeffered(not, 1); return(Default()); } ctx.NoOverload(@this.GetTypeName(), "bitwisenot"); return(Default()); }
internal virtual ElaValue Negate(ElaValue @this, ExecutionContext ctx) { if (neg != null) { ctx.SetDeffered(neg, 1); return(Default()); } ctx.NoOverload(@this.GetTypeName(), "negate"); return(Default()); }
internal virtual ElaValue GetValue(ElaValue value, ElaValue index, ExecutionContext ctx) { if (getval != null) { ctx.SetDeffered(getval, 2); return(Default()); } ctx.NoOverload(value.GetTypeName(), "getvalue"); return(Default()); }
private string PrintValue(ElaValue value) { try { var result = String.Empty; var hdl = new AutoResetEvent(false); var th = new Thread(() => { var obj = value.AsObject(); if (obj is ElaLazy) { result = ((ElaLazy)obj).Force().AsObject().ToString(); } else if (obj is ElaLazyList) { var lalist = (ElaLazyList)obj; result = ElaList.FromEnumerable(lalist.Take(20)).ToString() + " (lazy)"; } else { result = value.ToString(); } hdl.Set(); }); th.Start(); if (!hdl.WaitOne(500)) { th.Abort(); result = "<evaluation timeout>"; } if (result == null) { return("_|_"); } else if (result.Trim().Length == 0) { result = "[" + value.GetTypeName() + "]"; } return(result); } catch (Exception) { return("<evaluation error>"); } }
public void UnknownField(string field, ElaValue given) { Fail(ElaRuntimeError.UnknownField, field, given.ToString(), given.GetTypeName()); }
public void InvalidType(string expected, ElaValue given) { Fail(ElaRuntimeError.InvalidType, expected, given.GetTypeName()); }
protected void NoOverloadBinary(string exp, ElaValue got, string fun, ExecutionContext ctx) { ctx.NoOverload(exp + "->" + exp + "->*", exp + "->" + got.GetTypeName() + "->*", fun); }
public void NoOperator(ElaValue value, string op) { Fail(ElaRuntimeError.InvalidOp, value.GetTypeName(), op); }
public void DivideByZero(ElaValue value) { Fail(ElaRuntimeError.DivideByZero, value.ToString(), value.GetTypeName()); }
public void IndexOutOfRange(ElaValue index, ElaValue obj) { Fail(ElaRuntimeError.IndexOutOfRange, index.ToString(), index.GetTypeName(), obj.ToString(), obj.GetTypeName()); }
internal ElaFunction GetFunction(ElaValue val, ExecutionContext ctx, int contextPar) { var m = 1 << AppliedParameters; var bit = (mask & m) == m; var ct = curType; if (bit && val.TypeId == ElaMachine.LAZ) { val = val.Ref.Force(val, ctx); if (ctx.Failed) { return(null); } } if (ct == 0) { if (bit) { ct = val.TypeId; } } else { if (bit && val.TypeId != ct) { if (funs.ContainsKey(ct)) { ctx.NoOverload(ToStringWithType(ct, null, AppliedParameters), ToStringWithType(ct, val.TypeId, AppliedParameters), name); } else { ctx.NoOverload(val.GetTypeName(), name); } return(null); } } if (AppliedParameters == Parameters.Length) { var ret = default(ElaFunction); if ((mask & (1 << Parameters.Length + 1)) == (1 << Parameters.Length + 1)) { if (ct == 0) { ct = contextPar; if (ct == 0) { ctx.NoContext(name); } } else if (ct != contextPar) { var dc = contextPar; if (dc != 0) { if (funs.ContainsKey(ct)) { ctx.NoOverload(ToStringWithType(ct, null, AppliedParameters), ToStringWithType(ct, dc, AppliedParameters + 1), name); } else { ctx.NoOverload(Machine.Assembly.Types[ct].TypeName, name); } } else { ctx.NoContext(name); } } } if (!funs.TryGetValue(ct, out ret)) { if (funs.ContainsKey(ct)) { ctx.NoOverload(ToStringWithType(ct, null, AppliedParameters), ToStringWithType(ct, val.TypeId, AppliedParameters), name); } else if (ct == 0) { ctx.NoOverload(val.GetTypeName(), name); } else { ctx.NoOverload(Machine.Assembly.Types[ct].TypeName, name); } return(null); } if (ret.table) { ret = ((ElaFunTable)ret).GetFunction(val, ctx, contextPar); } ret = ret.CloneFull(); ret.Flip = Flip; ret.AppliedParameters = AppliedParameters; if (ret.Parameters.Length != Parameters.Length) { for (var i = 0; i < AppliedParameters; i++) { ret.Parameters[i] = Parameters[i]; } } else { ret.Parameters = Parameters; } return(ret); } var f = new ElaFunTable(name, mask, Parameters.Length + 1, ct, Machine); f.funs = funs; return(base.CloneFast(f)); }
public void InvalidFormat(string format, ElaValue value) { Fail(ElaRuntimeError.InvalidFormat, format, value.ToString(), value.GetTypeName()); }
public void InvalidIndexType(ElaValue index) { Fail(ElaRuntimeError.InvalidIndexType, index.GetTypeName()); }
internal override ElaValue Quot(ElaValue left, ElaValue right, ExecutionContext ctx) { if (right.TypeId != ElaMachine.INT) { if (right.TypeId == ElaMachine.LNG) { var r = right.Ref.AsLong(); if (r == 0) { ctx.DivideByZero(left); return(Default()); } return(new ElaValue(left.I4 / r)); } else { ctx.NoOverload(left.GetTypeName() + "->" + left.GetTypeName() + "->*", left.GetTypeName() + "->" + right.GetTypeName() + "->*", "quot"); return(Default()); } } if (right.I4 == 0) { ctx.DivideByZero(left); return(Default()); } return(new ElaValue(left.I4 / right.I4)); }
public void NotAlgebraicType(ElaValue val) { Fail(ElaRuntimeError.NotAlgebraicType, val.GetTypeName()); }