Exemplo n.º 1
0
 public static void DynamicWind(Arguments args, VM vm, SourceInfo info)
 {
     ValueCont cont = vm.GetCont();
     var winder = new KeyValuePair<IValue, IValue>(args[0], args[2]);
     var winders = SList.Cons(winder, vm.Winders);
     Stack<IInsn> insnStack = new Stack<IInsn>();
     insnStack.Push(new InsnCall(0, info));
     insnStack.Push(InsnPop.Instance);
     insnStack.Push(new InsnSetWinders(winders));
     insnStack.Push(new InsnPush(args[1]));
     insnStack.Push(new InsnCall(0, info));
     insnStack.Push(new InsnCall(1, info));
     vm.Insns = insnStack.ToSList();
     vm.Stack = SList.List<IValue>(args[0], cont);
 }
Exemplo n.º 2
0
Arquivo: VM.cs Projeto: takuto-h/rhea
 public void SetCont(IValue returnValue, ValueCont cont, SourceInfo info)
 {
     var winders = cont.Winders;
     if (winders == Winders)
     {
         Insns = cont.Insns;
         Stack = cont.Stack;
         Env = cont.Env;
         Push(returnValue);
     }
     else if (winders.ContainsList(Winders))
     {
         var newWinders = winders.GetPreviousList(Winders);
         IValue before = newWinders.Head.Key;
         Stack<IInsn> insnStack = new Stack<IInsn>();
         insnStack.Push(new InsnPush(before));
         insnStack.Push(new InsnCall(0, info));
         insnStack.Push(InsnPop.Instance);
         insnStack.Push(new InsnSetWinders(newWinders));
         insnStack.Push(new InsnPush(cont));
         insnStack.Push(new InsnPush(returnValue));
         insnStack.Push(new InsnCall(1, info));
         Insns = insnStack.ToSList();
         Stack = SList.Nil<IValue>();
     }
     else
     {
         IValue after = Winders.Head.Value;
         Winders = Winders.Tail;
         Stack<IInsn> insnStack = new Stack<IInsn>();
         insnStack.Push(new InsnPush(after));
         insnStack.Push(new InsnCall(0, info));
         insnStack.Push(InsnPop.Instance);
         insnStack.Push(new InsnPush(cont));
         insnStack.Push(new InsnPush(returnValue));
         insnStack.Push(new InsnCall(1, info));
         Insns = insnStack.ToSList();
         Stack = SList.Nil<IValue>();
     }
 }
Exemplo n.º 3
0
 private ISList<IInsn> Assign(IList<IValue> args, SourceInfo info)
 {
     Stack<IInsn> insnStack = new Stack<IInsn>();
     IEnumerator<IValue> argsEtor = args.GetEnumerator();
     foreach (ValueSymbol symbol in mParams)
     {
         if (!argsEtor.MoveNext())
         {
             throw new RheaException(
                 this.WrongNumberOfArguments(mParams.Count, args.Count), info
             );
         }
         insnStack.Push(new InsnPush(argsEtor.Current));
         insnStack.Push(new InsnDefVar(symbol, mInfo));
         insnStack.Push(InsnPop.Instance);
     }
     if (argsEtor.MoveNext())
     {
         throw new RheaException(
             this.WrongNumberOfArguments(mParams.Count, args.Count), info
         );
     }
     return insnStack.ToSList();
 }