internal override void Preprocess(FunctionCompiler compiler) { foreach (var statement in _statements) { statement.Preprocess(compiler); } }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { OpCode callOpCode; if (CallFunction.Type != ExpressionType.Member) { CallFunction.CompileBy(compiler, false); callOpCode = OpCode.Call; } else { var memberOperator = (MemberOperator)CallFunction; memberOperator.BaseValue.CompileBy(compiler, false); compiler.Emitter.Emit(OpCode.Dup); memberOperator.CompilePropertyBy(compiler); compiler.Emitter.Emit(OpCode.LdMember); callOpCode = OpCode.CallMember; } foreach (var argument in ArgumentList) { argument.CompileBy(compiler, false); } compiler.Emitter.Emit(OpCode.LdInteger, ArgumentList.Count); compiler.Emitter.Emit(callOpCode, !isLastOperator); }
internal override void Preprocess(FunctionCompiler compiler) { for (var current = Parent; current != null; current = current.Parent) { current.RegisterExitPoint(this); } }
internal override void CompileBy(FunctionCompiler compiler) { if (_catchBlock == null && _finallyBlock == null) { Errors.ThrowInternalError(); } if (_catchBlock != null) { if (_finallyBlock == null) { EmitTryCatch(compiler); } else { EmitTryCatchFinally(compiler); } } else { EmitTryFinally(compiler); } compiler.MarkEndOfStatement(); }
internal override void DoEmitProlog(FunctionCompiler compiler) { if (_initialization != null) { _initialization.CompileBy(compiler, true); } }
static MetaProperty ResolveMetaproperty(FunctionCompiler methodCompiler, AmbientParser.Node metaPropertyNode) { MetaProperty mp; var function = methodCompiler.Function as Method; if (function == null) { return(null); } foreach (var block in function.DrawBlocks) { mp = ResolveForEachMetaProperty(block.Members, metaPropertyNode); if (mp != null) { return(mp); } foreach (var item in block.Members) { var apply = item as Apply; if (apply != null && apply.Block != null) { mp = ResolveForEachMetaProperty(apply.Block.Members, metaPropertyNode); if (mp != null) { return(mp); } } } } return(null); }
void SuggestForBlock(FunctionCompiler methodCompiler, string memberExp) { if (memberExp == "") { var last = Enumerable.Last(_context.NodePath); SuggestKeywordsIfCan(last); SuggestKeywords(TypeAliases.AllAliases.ToArray()); var lastInlineBlock = _context.InlineBlock; var lastBlock = _context.Block; if (lastBlock != null && lastBlock.BlockBase is Block) { var b = (Block)lastBlock.BlockBase; SuggestBlockItems(b); } else if (lastInlineBlock != null && lastInlineBlock.Children != null) { SuggestForInlineBlock(methodCompiler, lastInlineBlock); } } SuggestTerminals(); SuggestKeywords("vertex_attrib", "sample", "import", "req", "tag"); SuggestTypes(memberExp, true, true); }
public FunctionMetaData(ulong id, FunctionType functionType, FunctionCompiler compiler, ParameterStorage[] parameterStorage) { Id = id; FunctionType = functionType; Compiler = compiler; ParameterStorage = parameterStorage; }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { if (Properties.Count == 0) { if (isLastOperator) { return; } compiler.Emitter.Emit(OpCode.MakeEmptyObject); } else { foreach (var property in Properties) { property.Value.CompileBy(compiler, isLastOperator); compiler.Emitter.Emit(OpCode.LdString, property.Key); } compiler.Emitter.Emit(OpCode.LdInteger, Properties.Count); compiler.Emitter.Emit(OpCode.MakeObject); if (isLastOperator) { compiler.Emitter.Emit(OpCode.Pop); } } }
static SourceObject ResolveStringWhenClassDeclaration(string memberExp, FunctionCompiler fc) { var classScope = fc.Namescope as ClassType; if (classScope == null) { return(null); } var found = classScope.Properties.FirstOrDefault(property => property.Name == memberExp) as SourceObject; if (found != null) { return(found); } found = classScope.Fields.FirstOrDefault(field => field.Name == memberExp); if (found != null) { return(found); } found = classScope.Methods.FirstOrDefault(method => method.Name == memberExp); if (found != null) { return(found); } return(null); }
public void ValueGetter_ReturnsCorrectPropertyOrField_ActualValue(string field, string expected) { var test = GetTest(); var valueGetter = FunctionCompiler.CreateValueGetter <Test>(field); Assert.Equal(expected, valueGetter(test)?.ToString()); }
internal override void Preprocess(FunctionCompiler compiler) { foreach (var caseClause in _caseClauses) { caseClause.Preprocess(compiler); } }
public async Task PerformMetricsTest(string language, string functionName, string moduleName, string functionHandler, HttpStatusCode expectedResponse) { // Arrange EnvironmentManager.SetVariables(moduleName, functionHandler, funcRuntime: "dotnetcore3.1"); FunctionCompiler.PublishTestFunction(language, functionName); HttpClient client = _factory.CreateClient(); var request = new HttpRequestMessage(new HttpMethod("GET"), "/"); var invokeResponse = await client.SendAsync(request); Assert.Equal(expectedResponse, invokeResponse.StatusCode); // Act var response = await client.GetAsync("/metrics"); // Assert response.EnsureSuccessStatusCode(); var responseBody = await response.Content.ReadAsStringAsync(); Assert.Contains("kubeless_calls_total", responseBody); Assert.Contains($"status=\"{(int) expectedResponse}\"", responseBody); Assert.Contains("function=\"handler\"", responseBody); Assert.Contains("runtime=\"dotnetcore3.1\"", responseBody); Assert.Contains("handler=\"module\"", responseBody); }
internal void EmitTryCatchFinally(FunctionCompiler compiler) { Contract.Assert(_catchBlock != null && _finallyBlock != null); var finallyLabel = compiler.Emitter.DefineLabel(); compiler.Emitter.Emit(OpCode.EnterTry, finallyLabel); var catchLabel = compiler.Emitter.DefineLabel(); compiler.Emitter.Emit(OpCode.EnterTry, catchLabel); _tryBlock.CompileBy(compiler); compiler.Emitter.Emit(OpCode.LeaveTry); compiler.Emitter.MarkLabel(catchLabel); compiler.Emitter.Emit(OpCode.EnterCatch, _catchBlockVariable); _catchBlock.CompileBy(compiler); compiler.Emitter.Emit(OpCode.LeaveCatch); compiler.Emitter.Emit(OpCode.LeaveTry); compiler.Emitter.MarkLabel(finallyLabel); _finallyBlock.CompileBy(compiler); compiler.Emitter.Emit(OpCode.Rethrow); }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { if (isLastOperator) { return; } compiler.Emitter.Emit(OpCode.LdLocalFunc, Value.Index); }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { for (var i = 0; i < Operands.Count - 1; i++) { Operands[i].CompileBy(compiler, true); } Operands[Operands.Count - 1].CompileBy(compiler, isLastOperator); }
internal override void Preprocess(FunctionCompiler compiler) { if (_catchBlock == null && _finallyBlock == null) { Errors.ThrowInternalError(); } compiler.TryStatements.Add(this); }
public BaseDataGridColumn() { // TODO: move this to cached FunctionCompiler so it doesn't get compiled every time valueTypeGetter = new Lazy <Func <Type> >(() => FunctionCompiler.CreateValueTypeGetter <TItem>(Field)); defaultValueByType = new Lazy <Func <object> >(() => FunctionCompiler.CreateDefaultValueByType <TItem>(Field)); valueGetter = new Lazy <Func <TItem, object> >(() => FunctionCompiler.CreateValueGetter <TItem>(Field)); valueSetter = new Lazy <Action <TItem, object> >(() => FunctionCompiler.CreateValueSetter <TItem>(Field)); }
internal override void CompileBy(FunctionCompiler compiler) { foreach (var statement in _statements) { statement.CompileBy(compiler); } compiler.MarkEndOfStatement(); }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { if (isLastOperator) { return; } compiler.Emitter.Emit(OpCode.LdLocal, ArgumentsLiteral); }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { if (isLastOperator) { return; } compiler.Emitter.Emit(OpCode.LdFloat, Value); }
public FunctionMetaData CreateHostMetaData(FunctionType functionType, FunctionCompiler compiler) { var id = NextFunctionId(); var metaData = new FunctionMetaData(id, functionType, compiler); AddFunctionMetaData(metaData); return(metaData); }
public DataGrid() { newItemCreator = new Lazy <Func <TItem> >(() => FunctionCompiler.CreateNewItem <TItem>()); paginationTemplates = new PaginationTemplates <TItem>(); paginationContext = new PaginationContext <TItem>(this); paginationContext.SubscribeOnPageSizeChanged(pageSize => InvokeAsync(() => StateHasChanged())); }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { Operand.CompileBy(compiler, false); compiler.Emitter.Emit(OpCode.Pop); if (!isLastOperator) { compiler.Emitter.Emit(OpCode.LdUndefined); } }
public static RendererFunction GetFunctionHandle(string formula) { CompiledFunction fn = FunctionCompiler.Compile(2, formula); return(new RendererFunction(delegate(double x, double y) { return fn(x, y); })); }
public Expression CallOperator(Source src, DataType dt, string op, params Expression[] args) { var fc = new FunctionCompiler(_compiler, dt, null); var type = Operator.Parse(args.Length, op); foreach (var m in dt.Operators) { if (m.Type == type && fc.IsArgumentListCompatible(m.Parameters, args)) { switch (args.Length) { case 1: return(new CallUnOp(src, m, args[0])); case 2: return(new CallBinOp(src, m, args[0], args[1])); } } } foreach (var m in dt.Operators) { if (m.Type == type) { if (fc.IsArgumentListCompatibleUsingImplicitCasts(m.Parameters, args)) { fc.ApplyImplicitCastsOnArgumentList(m.Parameters, args); switch (args.Length) { case 1: return(new CallUnOp(src, m, args[0])); case 2: return(new CallBinOp(src, m, args[0], args[1])); } } } } var pl = "("; var first = true; foreach (var a in args) { if (!first) { pl += ","; } pl += a.ReturnType; first = false; } pl += ")"; Log.Error(src, ErrorCode.E0000, "No matching operator overload: '" + dt + "." + op + pl + "'"); return(Expression.Invalid); }
internal void CompileIncDecBy(FunctionCompiler compiler, OpCode op, bool isPostfix, bool isLastOperator) { Contract.Requires(op == OpCode.Inc || op == OpCode.Dec); if (Operand.Type == ExpressionType.Ident) { var operand = (Identifier)Operand; compiler.Emitter.Emit(OpCode.LdLocal, operand.Value); compiler.Emitter.Emit(OpCode.CastToPrimitive); if (isPostfix) { if (!isLastOperator) { compiler.Emitter.Emit(OpCode.Dup); } compiler.Emitter.Emit(op); } else { compiler.Emitter.Emit(op); if (!isLastOperator) { compiler.Emitter.Emit(OpCode.Dup); } } compiler.Emitter.Emit(OpCode.StLocal, operand.Value); } else { Contract.Assert(Operand.Type == ExpressionType.Member); var operand = (MemberOperator)Operand; operand.BaseValue.CompileBy(compiler, false); operand.CompilePropertyBy(compiler); compiler.Emitter.Emit(OpCode.MakeRef); compiler.Emitter.Emit(OpCode.Dup); compiler.Emitter.Emit(OpCode.LdMemberByRef); compiler.Emitter.Emit(OpCode.CastToPrimitive); if (isLastOperator) { compiler.Emitter.Emit(OpCode.Inc); compiler.Emitter.Emit(OpCode.StMemberByRef); } else { if (!isPostfix) { compiler.Emitter.Emit(op); compiler.Emitter.Emit(OpCode.StMemberByRefDup); } else { compiler.Emitter.Emit(OpCode.SwapDup); compiler.Emitter.Emit(op); compiler.Emitter.Emit(OpCode.StMemberByRef); } } } }
internal override void CompileBy(FunctionCompiler compiler, bool isLastOperator) { BaseValue.CompileBy(compiler, false); CompilePropertyBy(compiler); compiler.Emitter.Emit(OpCode.LdMember); if (isLastOperator) { compiler.Emitter.Emit(OpCode.Pop); } }
static IEnumerable <string> FindLocals(FunctionCompiler fc) { foreach (var vs in fc.VariableScopeStack) { foreach (var v in vs.Variables.Keys) { yield return(v); } } }
public void TestCompile() { var f = (Func <SeriesBase, double>)FunctionCompiler.Compile("x => (double)x.Mean()", new[] { typeof(SeriesBase), typeof(double) }, true); var s = new Series(new[] { 1, 2, 3 }); var mean = f.Invoke(s); Assert.Equal(2.0, mean); }