Ejemplo n.º 1
0
Archivo: Int.cs Proyecto: takuto-h/rhea
 public static void Eq(Arguments args, VM vm, SourceInfo info)
 {
     Check(args, 2, info);
     ValueInt integer1 = (ValueInt)args[0];
     ValueInt integer2 = (ValueInt)args[1];
     vm.Push((integer1.Value == integer2.Value).ToValueBool());
 }
Ejemplo n.º 2
0
 public static void MakeInstance(Arguments args, VM vm, SourceInfo info)
 {
     ValueArray array = args[0] as ValueArray;
     ValueHash hash = args[1] as ValueHash;
     if (array == null ||
         array.Value.Any((elem) => !(elem is ValueSymbol)))
     {
         throw new RheaException(
             string.Format("array(symbol) required, but got {0}", args[0]), info
         );
     }
     if (hash == null ||
         hash.Value.Any((kvp) => !(kvp.Key is ValueSymbol) || !(kvp.Value is IValueFunc)))
     {
         throw new RheaException(
             string.Format("hash(symbol, function) required, but got {0}", args[1]), info
         );
     }
     IList<ValueSymbol> klasses = array.Value.Select(
         (elem) => (ValueSymbol)elem
     ).ToList();
     IDictionary<ValueSymbol, IValueFunc> slots = hash.Value.ToDictionary(
         (kvp) => (ValueSymbol)kvp.Key,
         (kvp) => (IValueFunc)kvp.Value
     );
     vm.Push(new ValueInstance(klasses, slots));
 }
Ejemplo n.º 3
0
 public static void Klasses(Arguments args, VM vm, SourceInfo info)
 {
     IList<IValue> list = args[0].KlassList.Select(
         (elem) => (IValue)elem
     ).ToList();
     vm.Push(new ValueArray(list));
 }
Ejemplo n.º 4
0
 public static void SetItem(Arguments args, VM vm, SourceInfo info)
 {
     Check(args, 1, info);
     ValueHash hash = (ValueHash)args[0];
     IValue key = args[1];
     IValue value = args[2];
     vm.Push(hash.Value[key] = value);
 }
Ejemplo n.º 5
0
Archivo: Int.cs Proyecto: takuto-h/rhea
 public static void Add(Arguments args, VM vm, SourceInfo info)
 {
     Check(args, 2, info);
     ValueInt integer1 = (ValueInt)args[0];
     ValueInt integer2 = (ValueInt)args[1];
     ValueInt newInteger = new ValueInt(
         integer1.Value + integer2.Value
     );
     vm.Push(newInteger);
 }
Ejemplo n.º 6
0
 public static void MakeSymbol(Arguments args, VM vm, SourceInfo info)
 {
     ValueString str = args[0] as ValueString;
     if (str == null)
     {
         throw new RheaException(
             string.Format("string required, but got {0}", args[0]),
             info
         );
     }
     vm.Push(ValueSymbol.Generate(str.Value));
 }
Ejemplo n.º 7
0
 public static void GetItem(Arguments args, VM vm, SourceInfo info)
 {
     Check(args, 1, info);
     ValueHash hash = (ValueHash)args[0];
     IValue key = args[1];
     if (!hash.Value.ContainsKey(key))
     {
         throw new RheaException(
             string.Format("key not found for {0}: {1}", hash, key),
             info
         );
     }
     vm.Push(hash.Value[key]);
 }
Ejemplo n.º 8
0
 public static void Load(Arguments args, VM vm, SourceInfo info)
 {
     ValueString str = args[0] as ValueString;
     if (str == null)
     {
         throw new RheaException(
             string.Format("string required, but got {0}", args[0]),
             info
         );
     }
     string fileName = str.Value;
     Interpreter interp = new Interpreter(vm.Env);
     bool result = interp.InterpretFile(fileName);
     vm.Push(result.ToValueBool());
 }
Ejemplo n.º 9
0
 public void Execute(VM vm)
 {
     IValue value1 = vm.Pop();
     IValue value2 = vm.Pop();
     IValueFunc method = value1 as IValueFunc;
     ValueSymbol klass = value2 as ValueSymbol;
     if (method == null)
     {
         throw new RheaException(
             string.Format("function required, but got {0}", value1),
             mInfo
         );
     }
     if (klass == null)
     {
         throw new RheaException(
             string.Format("symbol required, but got {0}", value2),
             mInfo
         );
     }
     vm.Env.DefineMethod(klass, mSelector, method, mInfo);
     vm.Push(method);
 }
Ejemplo n.º 10
0
 public static void P(Arguments args, VM vm, SourceInfo info)
 {
     Console.WriteLine(args[0]);
     vm.Push(args[0]);
 }
Ejemplo n.º 11
0
 public void Execute(VM vm)
 {
     vm.Push(mValue);
 }
Ejemplo n.º 12
0
 public static void MakeHash(Arguments args, VM vm, SourceInfo info)
 {
     vm.Push(new ValueHash(args.Dict));
 }
Ejemplo n.º 13
0
 public void Execute(VM vm)
 {
     vm.Push(vm.Env.GetVariable(mSymbol, mInfo));
 }