Exemplo n.º 1
0
 public Frame(List<Symbol> names)
 {
     Link = null;
     Names = names ?? new List<Symbol>();
     Values = null;
 }
Exemplo n.º 2
0
 public Frame(Frame template, List<object> args)
 {
     Link = template.Link;
     Names = template.Names;
     Values = args;
 }
Exemplo n.º 3
0
 public FrameAndScope()
 {
     Frame = new Frame();
     Scope = new AnalysisScope();
     Scope.IsFileScope = true;
     Scope.IsBlockScope = true;
 }
Exemplo n.º 4
0
 public static ThreadContextState SaveStackAndFrameWith(Frame frame, Cons form)
 {
     // used by compiler generated code
     return CurrentThreadContext.SaveStackAndFrame(frame, form);
 }
Exemplo n.º 5
0
        public static AnalysisScope ReconstructAnalysisScope(Frame context, AnalysisScope consoleScope = null)
        {
            if (consoleScope == null)
            {
                consoleScope = new AnalysisScope();
            }

            var stack = new Stack<AnalysisScope>();
            stack.Push(consoleScope);

            var scope = consoleScope;
            scope.Names = null;

            for (var frame = context; frame != null; frame = frame.Link)
            {
                if (frame.Names == null)
                {
                    continue;
                }

                if (scope == null)
                {
                    scope = new AnalysisScope();
                    stack.Push(scope);
                }

                scope.Names = new List<Symbol>();

                foreach (var key in frame.Names)
                {
                    scope.DefineFrameLocal(key, ScopeFlags.All);
                }

                scope = null;
            }

            scope = null;

            while (stack.Count > 0)
            {
                var top = stack.Pop();
                top.Parent = scope;
                scope = top;
            }

            return scope;
        }
Exemplo n.º 6
0
        public ThreadContextState SaveStackAndFrame(Frame frame = null, Cons form = null)
        {
            var saved = new ThreadContextState();

            saved.EvaluationStack = EvaluationStack;
            saved.SpecialStack = SpecialStack;
            saved.Frame = Frame;
            saved.NestingDepth = NestingDepth;

            ++NestingDepth;

            if (NestingDepth == 10000)
            {
                Debugger.Break();
            }

            if (frame != null)
            {
                Frame = new Frame(frame, null);
                Frame.Link = saved.Frame;
            }

            if (form != null)
            {
                EvaluationStack = Runtime.MakeCons(form, EvaluationStack);
            }

            return saved;
        }
Exemplo n.º 7
0
        public static Expression WrapEvaluationStack(Expression code, Frame frame = null, Cons form = null)
        {
            // For function, try and loop: anything that has a non-local exit method.
            var saved = Expression.Parameter(typeof(ThreadContextState), "saved");
            var result = Expression.Parameter(typeof(object), "result");
            var index = Expression.Parameter(typeof(int), "index");
            var exprs = new List<Expression>();

            exprs.Add(Expression.Assign(saved, CallRuntime(SaveStackAndFrameWithMethod,
                Expression.Constant(frame, typeof(Frame)),
                Expression.Constant(form, typeof(Cons)))));

            //if ( form != null )
            //{
            //    exprs.Add( Expression.Assign( index, CallRuntime( LogBeginCallMethod, Expression.Constant( form ) ) ) );
            //}

            exprs.Add(Expression.Assign(result, code));

            //if ( form != null )
            //{
            //    exprs.Add( CallRuntime( LogEndCallMethod, index ) );
            //}

            exprs.Add(CallRuntime(RestoreStackAndFrameMethod, saved));
            exprs.Add(result);

            return Expression.Block
                    (
                typeof(object),
                new[] { saved, result, index },
                exprs
            );
        }