Ejemplo n.º 1
0
        internal ElaValue GetField(ElaValue index, ExecutionContext ctx)
        {
            if (vm != null)
            {
                if (index.TypeId != ElaMachine.STR)
                {
                    ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), index);
                    return(Default());
                }

                var      field = index.DirectGetString();
                var      frame = vm.Assembly.GetModule(Handle);
                ScopeVar sc;

                if (!frame.GlobalScope.Locals.TryGetValue(field, out sc))
                {
                    ctx.UnknownField(index.DirectGetString(), new ElaValue(this));
                    return(Default());
                }

                if ((sc.Flags & ElaVariableFlags.Private) == ElaVariableFlags.Private)
                {
                    ctx.Fail(new ElaError(ElaRuntimeError.PrivateVariable, field));
                    return(Default());
                }

                return(vm.modules[Handle][sc.Address]);
            }

            ctx.Fail(ElaRuntimeError.Unknown, "VM is non present");
            return(Default());
        }
Ejemplo n.º 2
0
        internal override ElaValue Concatenate(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            right = right.Ref.Force(right, ctx);

            if (right.TypeId != ElaMachine.STR)
            {
                if (right.TypeId == ElaMachine.CHR)
                    return new ElaValue(left.DirectGetString() + right.ToString());

                NoOverloadBinary(TCF.STRING, right, "concatenate", ctx);
                return Default();
            }

            return new ElaValue(left.DirectGetString() + right.DirectGetString());
        }
Ejemplo n.º 3
0
        internal override ElaValue Concatenate(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            right = right.Ref.Force(right, ctx);

            if (right.TypeId != ElaMachine.STR)
            {
                if (right.TypeId == ElaMachine.CHR)
                {
                    return(new ElaValue(left.DirectGetString() + right.ToString()));
                }

                NoOverloadBinary(TCF.STRING, right, "concatenate", ctx);
                return(Default());
            }

            return(new ElaValue(left.DirectGetString() + right.DirectGetString()));
        }
Ejemplo n.º 4
0
        internal ElaValue GetField(ElaValue key, ExecutionContext ctx)
        {
            if (key.TypeId != ElaMachine.STR)
            {
                ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), key);
                return(Default());
            }

            var idx = GetOrdinal(key.DirectGetString());

            if (idx == -1)
            {
                ctx.UnknownField(key.DirectGetString(), new ElaValue(this));
                return(Default());
            }

            return(values[idx]);
        }
Ejemplo n.º 5
0
        internal override bool GreaterEqual(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.STR)
            {
                NoOverloadBinary(TCF.STRING, right, "greaterequal", ctx);
                return false;
            }

            return left.DirectGetString().CompareTo(right.DirectGetString()) <= 0;
        }
Ejemplo n.º 6
0
        internal override bool Equal(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.STR)
            {
                NoOverloadBinary(TCF.STRING, right, "equal", ctx);
                return false;
            }

            return left.DirectGetString() == right.DirectGetString();
        }
Ejemplo n.º 7
0
        internal override bool LesserEqual(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.STR)
            {
                NoOverloadBinary(TCF.STRING, right, "lesserequal", ctx);
                return(false);
            }

            return(left.DirectGetString().CompareTo(right.DirectGetString()) >= 0);
        }
Ejemplo n.º 8
0
        internal override bool NotEqual(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.STR)
            {
                NoOverloadBinary(TCF.STRING, right, "notequal", ctx);
                return(false);
            }

            return(left.DirectGetString() != right.DirectGetString());
        }
Ejemplo n.º 9
0
        internal bool HasField(ElaValue key, ExecutionContext ctx)
        {
            var idx = key.I4;

            if (key.TypeId != ElaMachine.STR)
            {
                ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), key);
                return(false);
            }

            return(GetOrdinal(key.DirectGetString()) != -1);
        }
Ejemplo n.º 10
0
        internal bool HasField(ElaValue index, ExecutionContext ctx)
        {
            if (vm != null)
            {
                if (index.TypeId != ElaMachine.STR)
                {
                    ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), index);
                    return(false);
                }

                var frame = vm.Assembly.GetModule(Handle);
                return(frame.GlobalScope.Locals.ContainsKey(index.DirectGetString()));
            }

            ctx.Fail(ElaRuntimeError.Unknown, "VM is non present");
            return(false);
        }
Ejemplo n.º 11
0
 internal override bool IsNil(ElaValue left, ExecutionContext ctx)
 {
     return left.DirectGetString().Length == 0;
 }
Ejemplo n.º 12
0
 internal override ElaValue Head(ElaValue left, ExecutionContext ctx)
 {
     return new ElaValue(left.DirectGetString()[0]);
 }
Ejemplo n.º 13
0
        internal bool HasField(ElaValue index, ExecutionContext ctx)
        {
            if (vm != null)
            {
                if (index.TypeId != ElaMachine.STR)
                {
                    ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), index);
                    return false;
                }

                var frame = vm.Assembly.GetModule(Handle);
                return frame.GlobalScope.Locals.ContainsKey(index.DirectGetString());
            }

            ctx.Fail(ElaRuntimeError.Unknown, "VM is non present");
            return false;
        }
Ejemplo n.º 14
0
        internal ElaValue GetField(ElaValue index, ExecutionContext ctx)
        {
            if (vm != null)
            {
                if (index.TypeId != ElaMachine.STR)
                {
                    ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), index);
                    return Default();
                }

                var field = index.DirectGetString();
                var frame = vm.Assembly.GetModule(Handle);
                ScopeVar sc;

                if (!frame.GlobalScope.Locals.TryGetValue(field, out sc))
                {
                    ctx.UnknownField(index.DirectGetString(), new ElaValue(this));
                    return Default();
                }

                if ((sc.Flags & ElaVariableFlags.Private) == ElaVariableFlags.Private)
                {
                    ctx.Fail(new ElaError(ElaRuntimeError.PrivateVariable, field));
                    return Default();
                }

                return vm.modules[Handle][sc.Address];
            }

            ctx.Fail(ElaRuntimeError.Unknown, "VM is non present");
            return Default();
        }
Ejemplo n.º 15
0
 internal override bool IsNil(ElaValue left, ExecutionContext ctx)
 {
     return(left.DirectGetString().Length == 0);
 }
Ejemplo n.º 16
0
 internal override ElaValue Head(ElaValue left, ExecutionContext ctx)
 {
     return(new ElaValue(left.DirectGetString()[0]));
 }