public void Load(IInterpreter itpr, Env env) { var code = @" empty = builtin empty fnx head x xs => x fnx tail x xs => xs fnx list x => x fn bool x => builtin bool x fn not x => builtin not x fnx is_empty x => builtin is_empty x fnx is_single x => builtin is_single x fnx is_many x => builtin is_many x fn match cond t f => builtin match cond t f fn if cond t => builtin if cond t fn exec exp => builtin exec exp fn equal x y => builtin equal x y fn not_equal x y => builtin not_equal x y fn lt x y => builtin lt x y fn gt x y => builtin gt x y fn lte x y => builtin lte x y fn gte x y => builtin gte x y fn range x y => builtin range x y "; env.LockVariable = true; foreach (var item in code.Split('\n')) { itpr.Input(item); } env.LockVariable = false; }
public void Load(IInterpreter itpr, Env env) { var code = @" E = builtin E PI = builtin PI fnx square _ => builtin square _ fnx sqrt _ => builtin sqrt _ fnx sin _ => builtin sin _ fnx sin _ => builtin sin _ fnx cos _ => builtin cos _ fnx tan _ => builtin tan _ fnx asin _ => builtin asin _ fnx acos _ => builtin acos _ fnx atan _ => builtin atan _ fnx sinh _ => builtin sinh _ fnx cosh _ => builtin cosh _ fnx tanh _ => builtin tanh _ fnx sign _ => builtin sign _ fnx abs _ => builtin abs _ fnx exp _ => builtin exp _ fnx floor _ => builtin floor _ fnx ceiling _ => builtin ceiling _ fnx log _ => builtin log _ fnx log10 _ => builtin log10 _ fnx round _ => builtin round _ fn pow _ __ => builtin pow _ __ fnx max _ => builtin max _ fnx min _ => builtin min _ fnx sum _ => builtin sum _ fnx product _ => builtin product _ "; env.LockVariable = true; foreach (var item in code.Split('\n')) { itpr.Input(item); } env.LockVariable = false; }
public void InitBuiltin(IInterpreter itpr, IStandardIo io, Env env) { _itpr = itpr; _env = env; io.Out.WriteLine("Builtin :: Loading..."); Init(); var modules = new IModule[] { new CoreModule(), new MathModule(), }; foreach (var item in modules) { io.Out.WriteLine($"Builtin :: {item.Name}"); AddModule(item); } var builtinFuncs = new Fun[] { new BuiltinFun(EvalBuiltin) { FunName = "builtin", Limit = false, Args = new List<string>() { "name", "args" } }, new BuiltinFun(EvalType) { FunName = "type", Limit = true, Args = new List<string>() { "t" } }, new BuiltinFun(EvalLoad) { FunName = "load", Limit = true, Args = new List<string>() { "name" } }, new LazyFun(EvalLazy) { FunName = "lazy" }, }; foreach (var item in builtinFuncs) { item.RegisterToEnv(env); } var code = @" load Core "; env.LockVariable = true; foreach (var item in code.Split('\n')) { itpr.Input(item); } env.LockVariable = false; io.Out.WriteLine("Builtin :: OK"); }