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

            ExecutionContext.Current = inst;
            if (enterFrame)
                Scope = new ExecutionScope();
        }
예제 #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;
            }
        }
예제 #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;
            }
        }