예제 #1
1
파일: ValueSubr.cs 프로젝트: takuto-h/rhea
 public void Call(IList<IValue> args, VM vm, SourceInfo info)
 {
     int argCount = args.Count;
     if (argCount < mParamCount ||
         argCount > mParamCount && !mAllowRest && !mAllowKeys)
     {
         throw new RheaException(
             this.WrongNumberOfArguments(mParamCount, argCount), info
         );
     }
     var dict = new Dictionary<IValue, IValue>();
     if (mAllowKeys)
     {
         foreach (IValue arg in args.Skip(mParamCount))
         {
             ValueArray pair = arg as ValueArray;
             if (pair == null || pair.Value.Count != 2)
             {
                 throw new RheaException(
                     "keyword arguments should occur pairwise", info
                 );
             }
             dict.Add(pair.Value[0], pair.Value[1]);
         }
     }
     var newArgs = new Arguments(args, dict);
     mSubrValue(newArgs, vm, info);
 }
예제 #2
0
 public void Call(IList<IValue> args, VM vm, SourceInfo info)
 {
     ValueCont cont = vm.GetCont();
     vm.Insns = Assign(args, info).Append(mInsns);
     vm.Stack = SList.List<IValue>(cont);
     vm.Env = new EnvLocal(mEnv);
 }
예제 #3
0
 public void Send(
     IValue receiver,
     ValueSymbol selector,
     IList<IValue> args,
     VM vm,
     SourceInfo info
 )
 {
     IValueFunc func = null;
     foreach (ValueSymbol klass in KlassList)
     {
         if (vm.Env.LookupMethod(klass, selector, out func))
         {
             break;
         }
     }
     if (func == null)
     {
         throw new RheaException(
             string.Format(
                 "invalid selector for {0}: {1}",
                 receiver,
                 selector.Name.ToIdentifier()
             ),
             info
         );
     }
     List<IValue> newArgs = new List<IValue>();
     newArgs.Add(receiver);
     newArgs.AddRange(args);
     func.Call(newArgs, vm, info);
 }
예제 #4
0
파일: ValueCont.cs 프로젝트: takuto-h/rhea
 public void Call(IList<IValue> args, VM vm, SourceInfo info)
 {
     if (args.Count != 1)
     {
         throw new RheaException(
             this.WrongNumberOfArguments(1, args.Count), info
         );
     }
     vm.SetCont(args[0], this, info);
 }
예제 #5
0
파일: ExprLambda.cs 프로젝트: takuto-h/rhea
 public ExprLambda(
     IList<ValueSymbol> paras,
     IList<IExpr> bodyExprs,
     SourceInfo info
 )
 {
     mParams = paras;
     mBodyExprs = bodyExprs;
     mInfo = info;
 }
예제 #6
0
 public InsnMakeClosure(
     IList<ValueSymbol> paras,
     ISList<IInsn> insns,
     SourceInfo info
 )
 {
     mParams = paras;
     mInsns = insns;
     mInfo = info;
 }
예제 #7
0
파일: ExprSend.cs 프로젝트: takuto-h/rhea
 public ExprSend(
     IExpr recvExpr,
     ValueSymbol selector,
     IList<IExpr> argExprs,
     SourceInfo info
 )
 {
     RecvExpr = recvExpr;
     Selector = selector;
     ArgExprs = argExprs;
     mInfo = info;
 }
예제 #8
0
 public ValueClosure(
     IList<ValueSymbol> paras,
     ISList<IInsn> insns,
     IEnv env,
     SourceInfo info
 )
 {
     mParams = paras;
     mInsns = insns;
     mEnv = env;
     mInfo = info;
 }
예제 #9
0
 public void Send(ValueSymbol selector, IList<IValue> args, VM vm, SourceInfo info)
 {
     if (smKlassHolder == null)
     {
         smKlassHolder = new KlassHolder(
             new List<ValueSymbol> {
                 Klasses.Symbol,
                 Klasses.Object
             }
         );
     }
     smKlassHolder.Send(this, selector, args, vm, info);
 }
예제 #10
0
 public void Send(ValueSymbol selector, IList<IValue> args, VM vm, SourceInfo info)
 {
     IValueFunc func;
     if (mMethods.TryGetValue(selector, out func))
     {
         List<IValue> newArgs = new List<IValue>();
         newArgs.Add(this);
         newArgs.AddRange(args);
         func.Call(newArgs, vm, info);
         return;
     }
     mKlassHolder.Send(this, selector, args, vm, info);
 }
예제 #11
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();
 }
예제 #12
0
 public void Send(ValueSymbol selector, IList<IValue> args, VM vm, SourceInfo info)
 {
     smKlassHolder.Send(this, selector, args, vm, info);
 }
예제 #13
0
파일: InsnCall.cs 프로젝트: takuto-h/rhea
 public InsnCall(int argCount, SourceInfo info)
 {
     mArgCount = argCount;
     mInfo = info;
 }
예제 #14
0
파일: ExprCall.cs 프로젝트: takuto-h/rhea
 public ExprCall(IExpr funcExpr, IList<IExpr> argExprs, SourceInfo info)
 {
     mFuncExpr = funcExpr;
     mArgExprs = argExprs;
     mInfo = info;
 }
예제 #15
0
파일: VM.cs 프로젝트: 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>();
     }
 }
예제 #16
0
파일: InsnSend.cs 프로젝트: takuto-h/rhea
 public InsnSend(ValueSymbol selector, int argCount, SourceInfo info)
 {
     mSelector = selector;
     mArgCount = argCount;
     mInfo = info;
 }
예제 #17
0
 public RheaException(SourceInfo info)
     : base()
 {
     Info = info;
 }
예제 #18
0
 public RheaException(string message, Exception innerException, SourceInfo info)
     : base(message, innerException)
 {
     Info = info;
 }
예제 #19
0
 public RheaException(string message, SourceInfo info)
     : base(message)
 {
     Info = info;
 }