Exemplo n.º 1
1
 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 public void Execute(VM vm)
 {
     List<IValue> args = new List<IValue>();
     for (int i = 0; i < mArgCount; i++)
     {
         args.Add(vm.Pop());
     }
     args.Reverse();
     IValue receiver = vm.Pop();
     receiver.Send(mSelector, args, vm, mInfo);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
0
 public void Execute(VM vm)
 {
     List<IValue> args = new List<IValue>();
     for (int i = 0; i < mArgCount; i++)
     {
         args.Add(vm.Pop());
     }
     args.Reverse();
     IValue value = vm.Pop();
     IValueFunc func = value as IValueFunc;
     if (func == null)
     {
         throw new RheaException(
             string.Format("function required, but got {0}", value), mInfo
         );
     }
     func.Call(args, vm, mInfo);
 }
Exemplo n.º 9
0
 public void Send(ValueSymbol selector, IList<IValue> args, VM vm, SourceInfo info)
 {
     smKlassHolder.Send(this, selector, args, vm, info);
 }
Exemplo n.º 10
0
 public void Execute(VM vm)
 {
     vm.Winders = mWinders;
 }
Exemplo n.º 11
0
 private IValue Run(ISList<IInsn> insns)
 {
     VM vm = new VM(
         insns,
         SList.Nil<IValue>(),
         mEnv,
         SList.Nil<KeyValuePair<IValue, IValue>>()
     );
     while (true)
     {
         try
         {
             return vm.Run();
         }
         catch (RheaException e)
         {
             Console.WriteLine("{0}: {1}", e.Info, e.Message);
             ValueCont cont = new ValueCont(
                 SList.Nil<IInsn>(),
                 SList.Nil<IValue>(),
                 vm.Env,
                 SList.Nil<KeyValuePair<IValue, IValue>>()
             );
             vm.SetCont(null, cont, e.Info);
         }
     }
 }
Exemplo n.º 12
0
 public void Execute(VM vm)
 {
     vm.Push(new ValueClosure(mParams, mInsns, vm.Env, mInfo));
 }