Esempio n. 1
0
        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());
        }
Esempio n. 2
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 3
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 4
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 5
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 6
0
File: Class.cs Progetto: ngoffee/ela
        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);
        }
Esempio n. 7
0
File: Class.cs Progetto: ngoffee/ela
        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);
        }
Esempio n. 8
0
File: Class.cs Progetto: ngoffee/ela
        internal virtual ElaValue GetLength(ElaValue value, ExecutionContext ctx)
        {
            if (len != null)
            {
                ctx.SetDeffered(len, 1);
                return(Default());
            }

            ctx.NoOverload(value.GetTypeName(), "length");
            return(Default());
        }
Esempio n. 9
0
File: Class.cs Progetto: ngoffee/ela
        internal virtual bool IsNil(ElaValue left, ExecutionContext ctx)
        {
            if (isnil != null)
            {
                ctx.SetDeffered(isnil, 1);
                return(false);
            }

            ctx.NoOverload(left.GetTypeName(), "isnil");
            return(false);
        }
Esempio n. 10
0
File: Class.cs Progetto: ngoffee/ela
        internal virtual ElaValue Head(ElaValue left, ExecutionContext ctx)
        {
            if (head != null)
            {
                ctx.SetDeffered(head, 1);
                return(Default());
            }

            ctx.NoOverload(left.GetTypeName(), "head");
            return(Default());
        }
Esempio n. 11
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 12
0
File: Class.cs Progetto: ngoffee/ela
        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);
        }
Esempio n. 13
0
File: Class.cs Progetto: ngoffee/ela
        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);
        }
Esempio n. 14
0
File: Class.cs Progetto: ngoffee/ela
        internal virtual ElaValue Tail(ElaValue left, ExecutionContext ctx)
        {
            if (tail != null)
            {
                ctx.SetDeffered(tail, 1);
                return(Default());
            }

            ctx.NoOverload(left.GetTypeName(), "tail");
            return(Default());
        }
Esempio n. 15
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 16
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 17
0
File: Class.cs Progetto: ngoffee/ela
        internal virtual ElaValue BitwiseNot(ElaValue @this, ExecutionContext ctx)
        {
            if (not != null)
            {
                ctx.SetDeffered(not, 1);
                return(Default());
            }

            ctx.NoOverload(@this.GetTypeName(), "bitwisenot");
            return(Default());
        }
Esempio n. 18
0
File: Class.cs Progetto: ngoffee/ela
        internal virtual ElaValue Negate(ElaValue @this, ExecutionContext ctx)
        {
            if (neg != null)
            {
                ctx.SetDeffered(neg, 1);
                return(Default());
            }

            ctx.NoOverload(@this.GetTypeName(), "negate");
            return(Default());
        }
Esempio n. 19
0
File: Class.cs Progetto: ngoffee/ela
        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());
        }
Esempio n. 20
0
        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>");
            }
        }
Esempio n. 21
0
 public void UnknownField(string field, ElaValue given)
 {
     Fail(ElaRuntimeError.UnknownField, field, given.ToString(), given.GetTypeName());
 }
Esempio n. 22
0
 public void InvalidType(string expected, ElaValue given)
 {
     Fail(ElaRuntimeError.InvalidType, expected, given.GetTypeName());
 }
Esempio n. 23
0
File: Class.cs Progetto: ngoffee/ela
 protected void NoOverloadBinary(string exp, ElaValue got, string fun, ExecutionContext ctx)
 {
     ctx.NoOverload(exp + "->" + exp + "->*", exp + "->" + got.GetTypeName() + "->*", fun);
 }
Esempio n. 24
0
 public void NoOperator(ElaValue value, string op)
 {
     Fail(ElaRuntimeError.InvalidOp, value.GetTypeName(), op);
 }
Esempio n. 25
0
 public void DivideByZero(ElaValue value)
 {
     Fail(ElaRuntimeError.DivideByZero, value.ToString(), value.GetTypeName());
 }
Esempio n. 26
0
 public void IndexOutOfRange(ElaValue index, ElaValue obj)
 {
     Fail(ElaRuntimeError.IndexOutOfRange, index.ToString(), index.GetTypeName(),
         obj.ToString(), obj.GetTypeName());
 }
Esempio n. 27
0
        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));
        }
Esempio n. 28
0
 public void InvalidFormat(string format, ElaValue value)
 {
     Fail(ElaRuntimeError.InvalidFormat, format, value.ToString(), value.GetTypeName());
 }
Esempio n. 29
0
 public void InvalidIndexType(ElaValue index)
 {
     Fail(ElaRuntimeError.InvalidIndexType, index.GetTypeName());
 }
Esempio n. 30
0
        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));
        }
Esempio n. 31
0
 public void NotAlgebraicType(ElaValue val)
 {
     Fail(ElaRuntimeError.NotAlgebraicType, val.GetTypeName());
 }