internal BlockExpression(List<Expression> body, SilverScope scope) { body.RemoveAll(e => e == null); Body = body; SetScope(scope); }
public SilverPartialFunction(SilverFunction function, List<FunctionArgument> args, SilverScope scope) : base(function.Name, new List<FunctionArgument>(), null, null) { WrappedFunction = function; PartialArguments = args; WrappedScope = scope; }
internal static dynamic CompileExpression(Expression e, SilverScope scope) { Expression newExpression = AstExpression.Convert(e, typeof (object)); newExpression.SetScope(scope); dynamic l = CreateLambdaForExpression(newExpression); return l(); }
private static dynamic ClassEval(object self, string eval, SilverScope scope) { SilverClass @class; var instance = self as SilverInstance; if (instance != null) { @class = instance.Class; } else { @class = self as SilverClass; } if (@class == null) return null; var xexpression = string.Format("{0};", eval); var lexer = new SilverLexer("source", xexpression); var stream = new CommonTokenStream(lexer.Queue); var parser = new SilverParser(stream); lexer.SetLines(parser); var res = parser.program(); return res != null ? RuntimeOperations.DefineCategory(@class, res.ToList(), scope) : null; }
public SilverFunction(string name, List<FunctionArgument> arguments, BlockExpression body, SilverScope context) { Name = name; Arguments = arguments; Body = body; Context = context; }
public SilverInstance(SilverClass @class) { _class = @class; SingletonMethods = new Dictionary<string, SilverFunction>(); UndefinedMethods = new List<string>(); RemovedMethods = new List<string>(); InstanceVariables = new SilverScope(); }
internal SilverClass() { ClassMethods = new Dictionary<string, SilverMethodTable>(); InstanceMethods = new Dictionary<string, SilverMethodTable>(); UndefinedMethods = new List<string>(); RemovedMethods = new List<string>(); Context = new SilverScope(); }
private static void SetParentScopeIfBlock(this Expression expr, SilverScope scope) { if (expr is BlockExpression) { expr.SetParentScope(scope); } else if (expr is IScopeExpression) { (expr as IScopeExpression).SetScope(scope); } }
public override void SetChildrenScopes(SilverScope scope) { LeftHandValues.ForEach(value => { if (value.Value is AstExpression) { value.Value.SetScope(scope); } }); RightHandValues.ForEach(value => { if (value.Value is AstExpression) { value.Value.SetScope(scope); } }); }
public override void SetChildrenScopes(SilverScope scope) { Test.SetScope(scope); if (DefaultBody != null) { DefaultBody.SetScope(scope); } foreach (SwitchCase @case in Cases) { foreach (Expression test in @case.TestValues) { test.SetScope(scope); } @case.Body.SetScope(scope); } }
public static SilverBoxedInstance Box(object obj, SilverScope scope = null) { if (obj == null) { return null; } if (_boxCache.ContainsKey(obj)) { _boxCache[obj].BoxedScope.MergeWithScope(scope ?? new SilverScope()); return _boxCache[obj]; } var boxed = new SilverBoxedInstance(obj, scope ?? new SilverScope()); _boxCache[obj] = boxed; if (scope != null) { string name; SilverScope _scope = scope.SearchForObject(obj, out name); if (_scope != null) { _scope[name] = boxed; } } return boxed; }
public SilverClass(string name, SilverClass parent, List<SilverFunction> classMethods, List<SilverFunction> instanceMethods) { Name = name; ClassMethods = new Dictionary<string, SilverMethodTable>(); classMethods.ForEach(func => AddMethod(ClassMethods, func)); if (!ClassMethods.ContainsKey("new")) { AddMethod(ClassMethods, new SilverFunction("new", new List<FunctionArgument>(), AstExpression.Block( AstExpression.Return(new List<FunctionArgument> { new FunctionArgument(null, AstExpression.Variable(Expression.Constant("self"))) }), Expression.Label(SilverParser.ReturnTarget, Expression.Constant(null, typeof (object)))), new SilverScope())); } InstanceMethods = new Dictionary<string, SilverMethodTable>(); instanceMethods.ForEach(func => AddMethod(InstanceMethods, func)); UndefinedMethods = new List<string>(); RemovedMethods = new List<string>(); Context = new SilverScope(); Parent = parent; }
public override void SetChildrenScopes(SilverScope scope) { Contents.ForEach(content => content.SetScope(scope)); }
internal static dynamic Invoke(Type targetType, MethodBase minfo, List<FunctionArgument> args, SilverScope scope) { bool isClassMethod = minfo.IsStatic; object target = scope.Variables.ContainsKey("self") ? scope["self"] : isClassMethod ? targetType : targetType.GetConstructor(new Type[] {}).Invoke(null); var arguments = new List<object>(); args.ForEach(arg => { dynamic _val = CompilerServices.CompileExpression(arg.Value, scope); if (_val is SilverString) { _val = (string) _val; } if (_val is SilverNumber) { _val = SilverNumber.Convert((SilverNumber) _val); } arguments.Add(_val); }); while (arguments.Count < minfo.GetParameters().Count()) { arguments.Add(null); } if (minfo.IsConstructor) { var ctor = (ConstructorInfo) minfo; return ctor.Invoke(arguments.ToArray()); } if (target is SilverInstance && !(target is SilverBoxedInstance) && ((SilverInstance) target).BackingObject != null) { target = ((SilverInstance) target).BackingObject; } dynamic val = null; if (((MethodInfo) minfo).ReturnType != typeof (void)) { val = minfo.Invoke(target, arguments.ToArray()); } else { minfo.Invoke(target, arguments.ToArray()); } return val; }
public override void SetChildrenScopes(SilverScope scope) { foreach (Expression value in Values) { value.SetScope(scope); } }
/// <summary> /// Called by SetScope to set the children scope on expressions. Should be overridden to tell the runtime which /// children should have scopes set. /// </summary> /// <param name="scope"></param> public virtual void SetChildrenScopes(SilverScope scope) { }
public override void SetChildrenScopes(SilverScope scope) { Test.SetScope(scope); IfTrue.SetScope(scope); IfFalse.SetScope(scope); }
public override void SetChildrenScopes(SilverScope scope) { foreach (FunctionArgument arg in Arguments) { arg.Value.SetScope(scope); } }
public override void SetChildrenScopes(SilverScope scope) { Key.SetScope(scope); Value.SetScope(scope); }
/// <summary> /// Sets the scope used by this expression. /// </summary> /// <param name="scope">Scope for this expression</param> public void SetScope(SilverScope scope) { _scope = scope; SetChildrenScopes(scope); }
public override void SetChildrenScopes(SilverScope scope) { Body.SetScope(scope); Init.SetScope(((AstExpression) Body).Scope); Test.SetScope(((AstExpression) Body).Scope); Step.SetScope(((AstExpression) Body).Scope); }
private static void SetParentScope(this Expression expr, SilverScope scope) { if (expr is IScopeExpression) { (expr as IScopeExpression).Scope.ParentScope = scope; } }
public override void SetChildrenScopes(SilverScope scope) { Expression.SetScope(scope); }
internal object Run(SilverScope scope) { var body = (BlockExpression) Body; body.SetScope(scope); body.SetChildrenScopes(body.Scope); dynamic block = CompilerServices.CreateLambdaForExpression(Expression.Block(body)); dynamic res = block(); if (res is Symbol) { var symval = new BlockExpression(new List<Expression> {new VariableExpression(res)}, body.Scope); res = CompilerServices.CreateLambdaForExpression(symval)(); } return res; }
public override void SetChildrenScopes(SilverScope scope) { Function.SetScope(scope); }
public override void SetChildrenScopes(SilverScope scope) { Left.SetScope(scope); Right.SetScope(scope); }
public override void SetChildrenScopes(SilverScope scope) { TargetType.SetScope(scope); Method.SetScope(scope); }
public override void SetChildrenScopes(SilverScope scope) { Enumerator.SetScope(scope); Body.SetScope(scope); }
public override void SetChildrenScopes(SilverScope scope) { Body.SetScope(scope); }
public override void SetChildrenScopes(SilverScope scope) { ExceptionObject.SetScope(scope); }