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); }
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); }
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); }
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); }
public ExprLambda( IList<ValueSymbol> paras, IList<IExpr> bodyExprs, SourceInfo info ) { mParams = paras; mBodyExprs = bodyExprs; mInfo = info; }
public InsnMakeClosure( IList<ValueSymbol> paras, ISList<IInsn> insns, SourceInfo info ) { mParams = paras; mInsns = insns; mInfo = info; }
public ExprSend( IExpr recvExpr, ValueSymbol selector, IList<IExpr> argExprs, SourceInfo info ) { RecvExpr = recvExpr; Selector = selector; ArgExprs = argExprs; mInfo = info; }
public ValueClosure( IList<ValueSymbol> paras, ISList<IInsn> insns, IEnv env, SourceInfo info ) { mParams = paras; mInsns = insns; mEnv = env; mInfo = info; }
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); }
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); }
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(); }
public void Send(ValueSymbol selector, IList<IValue> args, VM vm, SourceInfo info) { smKlassHolder.Send(this, selector, args, vm, info); }
public InsnCall(int argCount, SourceInfo info) { mArgCount = argCount; mInfo = info; }
public ExprCall(IExpr funcExpr, IList<IExpr> argExprs, SourceInfo info) { mFuncExpr = funcExpr; mArgExprs = argExprs; mInfo = info; }
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>(); } }
public InsnSend(ValueSymbol selector, int argCount, SourceInfo info) { mSelector = selector; mArgCount = argCount; mInfo = info; }
public RheaException(SourceInfo info) : base() { Info = info; }
public RheaException(string message, Exception innerException, SourceInfo info) : base(message, innerException) { Info = info; }
public RheaException(string message, SourceInfo info) : base(message) { Info = info; }