static Library() { // Make instance Nil = new SRUObject(); Proc = new SRUObject(); Klass = new SRUObject(); Object = new SRUObject(); String = new SRUObject(); Number = new SRUObject(); Array = new SRUObject(); Hash = new SRUObject(); Boolean = new SRUObject(); True = new SRUObject(); False = new SRUObject(); FieldMissing = new SRUClass.FieldMissingProc(); // Initialize each instance. SRUNil.RegesterNil(Nil); SRUProc.RegesterProc(Proc); SRUClass.RegesterClass(Klass); SRUObjectClass.RegesterObject(Object); SRUString.RegesterString(String); SRUNumber.RegesterNumber(Number); SRUArray.RegesterArray(Array); SRUHash.RegesterHash(Hash); SRUBoolean.RegesterBoolean(Boolean); SRUBoolean.RegesterTrue(True); SRUBoolean.RegesterFalse(False); FieldMissing.Initialize(); // Eval Expressions = new SRUExpressionsNamespace(); Expressions.Initialize(); Evaluator = new SRUEvaluator(); }
public static SRUObject MakeFrame(SRUObject currnet_frame) { SRUObject frame = new SRUObject(); frame["outside"] = currnet_frame; frame.RegesterMethod("field_missing", field_missing); return frame; }
public static SRUObject set(SRUObject[] arg) { if (arg.Length < 3 || !(arg[0] is SRUHash)) return Library.Nil; SRUHash self = arg[0] as SRUHash; return self.dict[arg[1]] = arg[2]; }
internal static void RegesterCallExpression(SRUObject CallExpression) { CallExpression["name"] = "CallExpression".ToSRUObject(); CallExpression["class"] = Library.Klass; CallExpression["super"] = Library.Expressions.Expression; CallExpression["field_missing"] = Library.FieldMissing; // TODO: Define method }
public static void RegesterBoolean(SRUObject Boolean) { Boolean["name"] = "Boolean".ToSRUObject(); Boolean["class"] = Library.Klass; Boolean["super"] = Library.Object; Boolean["field_missing"] = Library.FieldMissing; // TODO: Define method }
public static void RegesterArray(SRUObject Array) { Array["name"] = "Array".ToSRUObject(); Array["class"] = Library.Klass; Array["super"] = Library.Object; Array["field_missing"] = Library.FieldMissing; // TODO: Define method }
public static void RegesterString(SRUObject obj) { obj["name"] = "String".ToSRUObject(); obj["class"] = Library.Klass; obj["super"] = Library.Object; obj["field_missing"] = Library.FieldMissing; // TODO: Define method of String Class obj.RegesterInstanceMethod("equals", equals); }
public SRUObject Invoke(string name, params SRUObject[] arg) { SRUProc p = this[name] as SRUProc; // TODO: check SRUObject[] args = new SRUObject[arg.Length + 1]; args[0] = this; Array.Copy(arg, 0, args, 1, arg.Length); return p.Call(args); }
public void RegesterArrayTest() { SRUObject Array = new SRUObject(); SRUArray.RegesterArray(Array); Assert.IsTrue(Array.IsExistField("name")); Assert.IsTrue(Array.IsExistField("class")); Assert.IsTrue(Array.IsExistField("field_missing")); Assert.IsTrue(Array.IsExistField("super")); }
public static SRUObject get(SRUObject[] arg) { if (arg.Length < 2 || !(arg[0] is SRUHash)) return Library.Nil; SRUHash self = arg[0] as SRUHash; if (!self.dict.ContainsKey(arg[1])) return Library.Nil; return self.dict[arg[1]]; }
public void RegesterBooleanTest() { SRUObject Boolean = new SRUObject(); // TODO: 適切な値に初期化してください SRUBoolean.RegesterBoolean(Boolean); Assert.IsTrue(Boolean.IsExistField("name")); Assert.IsTrue(Boolean.IsExistField("class")); Assert.IsTrue(Boolean.IsExistField("field_missing")); Assert.IsTrue(Boolean.IsExistField("super")); }
public SRUObject Visit(SRUCallExpression call) { SRUObject proc = call.Method.Accept(this); SRUObject[] args = new SRUObject[call.Args.Length]; for (int i = 0; i < args.Length; i++) { args[i] = call.Args[i].Accept(this); } return proc.Call(args); }
public static void RegesterHash(SRUObject Hash) { Hash["name"] = "Hash".ToSRUObject(); Hash["class"] = Library.Klass; Hash["super"] = Library.Object; Hash["field_missing"] = Library.FieldMissing; // TODO: Define method Hash.RegesterInstanceMethod("get", get); Hash.RegesterInstanceMethod("set", set); }
public static void RegesterClass(SRUObject obj) { obj["name"] = "Class".ToSRUObject(); obj["class"] = obj; obj["super"] = Library.Object; obj["field_missing"] = Library.FieldMissing; // TODO: Define method obj.RegesterInstanceMethod("find_field", find_field); obj.RegesterMethod("find_field", find_field); obj.RegesterInstanceMethod("inspect", inspect); }
public static void RegesterNumber(SRUObject obj) { obj["name"] = "Number".ToSRUObject(); obj["class"] = Library.Klass; obj["super"] = Library.Object; obj["field_missing"] = Library.FieldMissing; // TODO: Define method of String Class obj.RegesterMethod("parse", parse); obj.RegesterInstanceMethod("inspect", inspect); obj.RegesterInstanceMethod("to_s", to_s); obj.RegesterInstanceMethod("add", add); }
public static void RegesterClass(SRUObject env) { env["Env"] = env; env["nil"] = Nil; env["Proc"] = Proc; env["Class"] = Klass; env["Object"] = Object; env["String"] = String; env["Number"] = Number; env["Array"] = Array; env["Hash"] = Hash; env["Boolean"] = Boolean; env["true"] = True; env["false"] = False; env["Expressions"] = Expressions; // TODO: this method called by initializing evaluator; //env["Evaluator"] = Evaluator; }
public static void RegesterTrue(SRUObject True) { True["class"] = Library.Boolean; True["field_missing"] = Library.FieldMissing; True.RegesterMethod("if_true", True_if_true); }
public static void RegesterExpression(SRUObject Expression) { Expression["name"] = "Expression".ToSRUObject(); Expression["class"] = Library.Klass; Expression["super"] = Library.Object; Expression["field_missing"] = Library.FieldMissing; // TODO: Define method // Make abstract and sield Expression["inheritance"] = Library.Nil; Expression["new"] = Library.Nil; }
public void Initialize() { Expression = new SRUObject(); LetExpression = new SRUObject(); RefExpression = new SRUObject(); CallExpression = new SRUObject(); ClosureExpression = new SRUObject(); StringExpression = new SRUObject(); this["expression"] = Expression; this["LetExpression"] = LetExpression; this["RefExpression"] = RefExpression; this["CallExpression"] = CallExpression; this["ClosureExpression"] = ClosureExpression; this["StringExpression"] = StringExpression; SRUExpression.RegesterExpression(Expression); SRULetExpression.RegesterLetExpression(LetExpression); SRURefExpression.RegesterRefExpression(RefExpression); SRUCallExpression.RegesterCallExpression(CallExpression); SRUClosureExpression.RegesterClosureExpression(ClosureExpression); SRUStringExpression.RegesterStringExpression(StringExpression); }
public static void RegesterStringExpression(SRUObject StringExpression) { StringExpression["name"] = "StringExpression".ToSRUObject(); StringExpression["class"] = Library.Klass; StringExpression["super"] = Library.Expressions.Expression; StringExpression["field_missing"] = Library.FieldMissing; // TODO: Define method }
public static SRUObject new_(params SRUObject[] arg) { SRUObject retval = new SRUObject(); retval["class"] = Library.Object; retval["field_missing"] = Library.FieldMissing; return retval; }
public static void RegesterProc(SRUObject obj) { obj["name"] = "Proc".ToSRUObject(); obj["class"] = Library.Klass; obj["super"] = Library.Object; obj["field_missing"] = Library.FieldMissing; // TODO: Define method of proc Class obj.RegesterInstanceMethod("inspect", inspect); }
public static void RegesterFalse(SRUObject False) { False["class"] = Library.Boolean; False["field_missing"] = Library.FieldMissing; False.RegesterMethod("if_true", False_if_true); }
public static void RegesterObject(SRUObject obj) { obj["name"] = "Object".ToSRUObject(); obj["class"] = Library.Klass; obj["supper"] = Library.Nil; obj["field_missing"] = Library.FieldMissing; // TODO: Define method obj.RegesterMethod("new", new_); obj.RegesterInstanceMethod("invoke", invoke); }
public static void RegesterClosureExpression(SRUObject ClosureExpression) { ClosureExpression["name"] = "ClosureExpression".ToSRUObject(); ClosureExpression["class"] = Library.Klass; ClosureExpression["super"] = Library.Expressions.Expression; ClosureExpression["field_missing"] = Library.FieldMissing; // TODO: Define method }