Exemplo n.º 1
0
        public JST.Identifier FreshenArgument(JST.Identifier id, TypeRef type)
        {
            var newid = NameSupply.GenSym();
            var cell  = new VariableCell(newid);

            Bind(id, cell.Read());
            CompEnv.AddVariable(newid, ArgLocal.Local, true, true, type);
            return(newid);
        }
Exemplo n.º 2
0
 // Rename every non-parameter in given compilation environment and include new parameter in
 // this compilation environment
 public void FreshenLocals(CompilationEnvironment inlinedCompEnv)
 {
     foreach (var kv in inlinedCompEnv.Variables)
     {
         if (kv.Value.ArgLocal == ArgLocal.Local)
         {
             var newid = NameSupply.GenSym();
             var cell  = new VariableCell(newid);
             Bind(kv.Value.Id, cell.Read());
             CompEnv.AddVariable(newid, kv.Value.ArgLocal, kv.Value.IsInit, kv.Value.IsReadOnly, kv.Value.Type);
         }
     }
 }
Exemplo n.º 3
0
        private ExpressionStackEntry Eval(ISeq <Statement> statements, ExpressionStackEntry entry)
        {
            if (statements == null)
            {
                throw new ArgumentNullException("statements");
            }
            // Eval the expression and save it in a temporary. If result is a structure, make the implied
            // value semantics explicit by cloning the value.
            var id   = gensym();
            var cell = new VariableCell(id);

            compEnv.AddVariable(id, ArgLocal.Local, false, true, compEnv.SubstituteType(entry.Expression.Type(compEnv)));
            statements.Add(new ExpressionStatement(cell.Write(entry.Expression.CloneIfStruct(compEnv))));
            // We never re-write to temporaries, so this stack entry now has no effects, not even a 'read' effect.
            // Also, the result's Expression.IsValue will be true.
            return(new ExpressionStackEntry(cell.Read(), bottom));
        }
Exemplo n.º 4
0
 // Restore stack to match given machine state. Stack should currently be empty.
 public bool Restore(MachineState stateAfterRestore, int skip)
 {
     if (skip > stateAfterRestore.Depth)
     {
         return(Failed(false, "underflow in restore"));
     }
     if (Depth != 0)
     {
         return(Failed(false, "cannot restore into non-empty stack"));
     }
     for (var i = 0; i < stateAfterRestore.Depth - skip; i++)
     {
         var id   = stateAfterRestore.PeekId(stateAfterRestore.Depth - skip - 1 - i, gensym);
         var cell = new VariableCell(id);
         // Ok if already added as temporary
         compEnv.AddVariable
             (id, ArgLocal.Local, false, true, compEnv.SubstituteType(stateAfterRestore.PeekType(stateAfterRestore.Depth - skip - 1 - i)));
         stack.Add(new ExpressionStackEntry(cell.Read(), bottom));
     }
     return(true);
 }