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()); }
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)); }
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)); }
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); }
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); }
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)); }
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]); }
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()); }
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); }
public static void P(Arguments args, VM vm, SourceInfo info) { Console.WriteLine(args[0]); vm.Push(args[0]); }
public void Execute(VM vm) { vm.Push(mValue); }
public static void MakeHash(Arguments args, VM vm, SourceInfo info) { vm.Push(new ValueHash(args.Dict)); }
public void Execute(VM vm) { vm.Push(vm.Env.GetVariable(mSymbol, mInfo)); }