Ejemplo n.º 1
0
 public static Value Eval(RuntimeInstance inst, string s)
 {
     using (new InstanceScope(inst))
     {
         return CodeUnit.GetExpression(s).Eval();
     }
 }
Ejemplo n.º 2
0
        public InstanceScope(RuntimeInstance inst, bool enterFrame)
        {
            Instance = inst;
            Other = ExecutionContext.Current;

            ExecutionContext.Current = inst;
            if (enterFrame)
                Scope = new ExecutionScope();
        }
Ejemplo n.º 3
0
 public InstanceScope(RuntimeInstance inst)
     : this(inst, true) { }
        public static IEnumerable<RuntimeInstance> WithInstance(Value v)
        {
            if (!v.IsReal)
                throw new ProgramError(Error.ExpectedObjectId);

            // Save the last instances being used
            var c = Current;
            var o = Other;
            Other = c;

            try
            {
                switch ((InstanceTarget)(int)v)
                {
                    case InstanceTarget.Self:
                        yield return c;
                        break;
                    case InstanceTarget.Other:
                        if (o != null)
                            yield return o;
                        break;
                    case InstanceTarget.All:
                        foreach (var i in ExecutionContext.Instances)
                            yield return i;
                        break;
                    case InstanceTarget.Global:
                        throw new ProgramError(Error.GlobalWith);
                    default:
                        if (ExecutionContext.Instances.Any(e => e.id == v))
                            yield return LibraryContext.Current.InstanceFactory.Instances[v] as RuntimeInstance;
                        else
                            foreach (var i in ExecutionContext.Instances.Where(ii => ii.object_index == v))
                                yield return i;
                        break;
                }
            }
            finally
            {
                // Restore current and other instances
                Current = c;
                Other = o;
            }
        }
Ejemplo n.º 5
0
        public static IEnumerable <RuntimeInstance> WithInstance(Value v)
        {
            if (!v.IsReal)
            {
                throw new ProgramError(Error.ExpectedObjectId);
            }

            // Save the last instances being used
            var c = Current;
            var o = Other;

            Other = c;

            try
            {
                switch ((InstanceTarget)(int)v)
                {
                case InstanceTarget.Self:
                    yield return(c);

                    break;

                case InstanceTarget.Other:
                    if (o != null)
                    {
                        yield return(o);
                    }
                    break;

                case InstanceTarget.All:
                    foreach (var i in ExecutionContext.Instances)
                    {
                        yield return(i);
                    }
                    break;

                case InstanceTarget.Global:
                    throw new ProgramError(Error.GlobalWith);

                default:
                    if (ExecutionContext.Instances.Any(e => e.id == v))
                    {
                        yield return(LibraryContext.Current.InstanceFactory.Instances[v] as RuntimeInstance);
                    }
                    else
                    {
                        foreach (var i in ExecutionContext.Instances.Where(ii => ii.object_index == v))
                        {
                            yield return(i);
                        }
                    }
                    break;
                }
            }
            finally
            {
                // Restore current and other instances
                Current = c;
                Other   = o;
            }
        }