private static async Task <object> InvokeMacro(PlasticContext context, PlasticMacro macro, IExpression[] args) { var res = await macro(context, args); context.Declare("last", res); return(res); }
public static void BootstrapLib(PlasticContext context) { var lib = @" for := func (@init , @guard, @step, @body) { init() while(guard()) { body() step() } } repeat := func (times, @body) { while(times >= 0) { body() times-- } } LinkedList := class { Node := class (value) { next = null; } head := null; tail := null; add := func (value) { node := Node(value); if (head == null) { head = node; tail = node; } else { tail.next = node; tail = node; } } each := func (lambda) { current := head; while(current != null) { lambda(current.value); current = current.next; } } } Stack := class { Node := class (value,prev) { next = null; } head := null; tail := null; push := func (value) { node = Node(value,tail); if (head == null) { head = node; tail = node; } else { tail.next = node; tail = node; } } each := func (lambda) { current = tail; while(current != null) { lambda(current.value); current = current.prev; } } peek := func() { tail.value; } pop := func() { res = tail.value; tail = tail.prev; if (tail != null) { tail.next = null; } else { head = null; } res } } switch := func(exp, @body) { matched := false; case := func (value, @caseBody) { if (exp == value) { caseBody(); matched = true; } } default := func (@defaultBody) { if (matched == false) { defaultBody(); } } body(); } quote := func(@q) { q } "; var libCode = PlasticParser.Statements.Parse(lib); libCode.Eval(context); }
public static Task <object> Run(string code, PlasticContext context) { var res = PlasticParser.Statements.Parse(code); return(res.Eval(context)); }
private static async Task<object> InvokeMacro(PlasticContext context, PlasticMacro macro, IExpression[] args) { var res = await macro(context, args); context.Declare("last", res); return res; }
public PlasticContextImpl(PlasticContext parentContext) : base(parentContext) { }
public InstanceContext(object obj, PlasticContext owner):base(owner) { _obj = obj; }
public ArrayContext(object[] array, PlasticContext owner) : base(owner) { _array = array; }
public TypeContext(Type type,PlasticContext owner) : base(owner) { _type = type; }
protected PlasticContext(PlasticContext parent) { Parent = parent; }
public InstanceContext(object obj, PlasticContext owner) : base(owner) { _obj = obj; }
public TypeContext(Type type, PlasticContext owner) : base(owner) { _type = type; }
public static Task<object> Run(string code, PlasticContext context) { var res = PlasticParser.Statements.Parse(code); return res.Eval(context); }