Exemplo n.º 1
0
        public override Value VisitTopLevelExpression([NotNull] TopLevelExpressionContext context)
        {
            var function = GetOrDeclareFunction(new Prototype($"anon_expr_{AnonNameIndex++}")
                                                , isAnonymous: true
                                                );

            return(DefineFunction(function, context.expression( )));
        }
Exemplo n.º 2
0
        public override IAstNode VisitTopLevelExpression([NotNull] TopLevelExpressionContext context)
        {
            BeginFunctionDefinition( );
            var sig    = new Prototype(context.GetSourceSpan( ), RuntimeState.GenerateAnonymousName( ), true);
            var body   = ( IExpression )context.expression( ).Accept(this);
            var retVal = new FunctionDefinition(context.GetSourceSpan( ), sig, body, true);

            RuntimeState.FunctionDefinitions.AddOrReplaceItem(retVal);
            return(retVal);
        }
Exemplo n.º 3
0
        public override Value VisitTopLevelExpression([NotNull] TopLevelExpressionContext context)
        {
            var proto    = new Prototype($"anon_expr_{AnonNameIndex++}");
            var function = GetOrDeclareFunction(proto
                                                , isAnonymous: true
                                                );

            var(_, jitHandle) = DefineFunction(function, context.expression());

            var nativeFunc = JIT.GetDelegateForFunction <AnonExpressionFunc>(proto.Identifier.Name);
            var retVal     = Context.CreateConstant(nativeFunc( ));

            JIT.RemoveModule(jitHandle);
            return(retVal);
        }
Exemplo n.º 4
0
        public override IAstNode VisitTopLevelExpression(TopLevelExpressionContext context)
        {
            BeginFunctionDefinition( );
            var sig    = new Prototype(context.GetSourceSpan( ), RuntimeState.GenerateAnonymousName( ), true);
            var body   = ( IExpression )context.expression( ).Accept(this);
            var retVal = new FunctionDefinition(context.GetSourceSpan( ), sig, body, true);

            // only add valid definitions to the runtime state.
            var errors = retVal.CollectErrors( );

            if (errors.Count == 0)
            {
                RuntimeState.FunctionDefinitions.AddOrReplaceItem(retVal);
            }
            return(retVal);
        }