Goose  Diff

Differences From Artifact [c24970f281]:

  • File bs/builtins/api/compiler.cpp — part of check-in [bd4456308c] at 2019-08-18 20:54:03 on branch trunk —
    • Added a function to adjust the compile time execution budget.
    • lexer: Implemented escape sequences in string literals.
    (user: achavasse size: 7022)

To Artifact [d164d23b7c]:

  • File bs/builtins/api/compiler.cpp — part of check-in [baf9721752] at 2019-08-19 13:43:31 on branch trunk —
    • Fixed many issues with compile time versus run time function invocations.
    • Improved some error messages.
    (user: achavasse size: 7177)

38
39
40
41
42
43
44
45
46
47


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
                auto ft = FromValue< FuncType >( f );
                if( !ft )
                    return ToValue( "error"s ).setPoison();

                return ToValue( BuildExternalFunc( *ft, symbol ) );
            } );

        RegisterBuiltinFunc< Eager< uint32_t > ( string ) >( e, "ExecuteFile"_sid,
            [pEnv]( const string& filename ) -> uint32_t
            {


                ifstream sourcefile( filename.c_str() );
                if( !sourcefile.good() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,
                        format( "can't open '{}'.", filename ) );
                    return 0;
                }

                sema::Context c( pEnv.lock(), RootIdentity(), GetValueType< uint32_t >() );
                DiagnosticsContext dc( 0, true );
                VerbosityContext vc( Verbosity::Normal, true );

                auto r = make_shared< parse::Resolver >(
                    make_shared< lex::Lexer >( sourcefile, filename ), c );
                parse::Parser p( r );

                auto cfg = make_shared< llr::CFG >();
                p.setCFG( cfg );
                p.cfg()->setCurrentBB( cfg->entryBB() );

                p.parseSequence();

                if( cfg->isPoisoned() )
                    return 0;

                if( !r->eos() )
                {
                    DiagnosticsManager::GetInstance().emitSyntaxErrorMessage(
                        r->getCurrentLocation(), "syntax error." );
                    return 0;
                }

                if( !cfg->entryBB()->canBeExecuted() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,
                        format( "{}: can not be executed.", filename ) );
                    return 0;
                }

                execute::VM vm;
                auto result = vm.execute( cfg->entryBB() );
                if( !result )
                    return 1;

                if( result->isPoison() )
                    return 0;

                return *FromValue< uint32_t >( *result );
            } );

        RegisterBuiltinFunc< Eager< Value > ( string, Value, Value ) >( e, "CompileFileToFunction"_sid,
            [pEnv]( const string& filename, const Value& rt, const Value& params ) -> Value
            {
                // Validate those generic value inputs
                if( !rt.isType() )







|
|

>
>





|


|














|





|






|





|


|

|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
                auto ft = FromValue< FuncType >( f );
                if( !ft )
                    return ToValue( "error"s ).setPoison();

                return ToValue( BuildExternalFunc( *ft, symbol ) );
            } );

        RegisterBuiltinFunc< Intrinsic< uint32_t ( string ) > >( e, "ExecuteFile"_sid,
            [pEnv]( const Value& fnameval ) -> Value
            {
                auto filename = *FromValue< string >( fnameval );

                ifstream sourcefile( filename.c_str() );
                if( !sourcefile.good() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,
                        format( "can't open '{}'.", filename ) );
                    return PoisonValue();
                }

                sema::Context c( pEnv.lock(), InjectDomainIntoIdentity( RootIdentity(), DomainCompileTime() ), GetValueType< uint32_t >() );
                DiagnosticsContext dc( 0, true );
                VerbosityContext vc( Verbosity::Normal, true );

                auto r = make_shared< parse::Resolver >(
                    make_shared< lex::Lexer >( sourcefile, filename ), c );
                parse::Parser p( r );

                auto cfg = make_shared< llr::CFG >();
                p.setCFG( cfg );
                p.cfg()->setCurrentBB( cfg->entryBB() );

                p.parseSequence();

                if( cfg->isPoisoned() )
                    return PoisonValue();

                if( !r->eos() )
                {
                    DiagnosticsManager::GetInstance().emitSyntaxErrorMessage(
                        r->getCurrentLocation(), "syntax error." );
                    return PoisonValue();
                }

                if( !cfg->entryBB()->canBeExecuted() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,
                        format( "{}: can not be executed.", filename ) );
                    return PoisonValue();
                }

                execute::VM vm;
                auto result = vm.execute( cfg->entryBB() );
                if( !result )
                    return ToValue< uint32_t >( 1 );

                if( result->isPoison() )
                    return PoisonValue();

                return *result;
            } );

        RegisterBuiltinFunc< Eager< Value > ( string, Value, Value ) >( e, "CompileFileToFunction"_sid,
            [pEnv]( const string& filename, const Value& rt, const Value& params ) -> Value
            {
                // Validate those generic value inputs
                if( !rt.isType() )
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
                    return ToValue( "error"s ).setPoison();
                }

                auto ftype = BuildFuncType( sema::DomainAny(), rt, params );

                // TODO at some point we'll want to pass the base identity to use as a param but
                // let's wait and see how the module and namespace stuff pans out first
                sema::Context c( pEnv.lock(), RootIdentity(), ftype.returnType() );
                DiagnosticsContext dc( 0, true );
                VerbosityContext vc( Verbosity::Normal, true );

                auto identity = AppendToVectorTerm( InjectDomainIntoIdentity( RootIdentity(), DomainRunTime() ),
                    TERM( StringId( pEnv.lock()->GetUniqueId() ) ) );
                auto func = BuildFunc( c, ftype, identity, params, make_shared< Vector >(), c );
                const auto& pFuncLLR = func.llr();

                ifstream sourcefile( filename.c_str() );
                if( !sourcefile.good() )
                {
                    pFuncLLR->setInvalid();
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,







|



|

|







115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
                    return ToValue( "error"s ).setPoison();
                }

                auto ftype = BuildFuncType( sema::DomainAny(), rt, params );

                // TODO at some point we'll want to pass the base identity to use as a param but
                // let's wait and see how the module and namespace stuff pans out first
                sema::Context c( pEnv.lock(), InjectDomainIntoIdentity( RootIdentity(), DomainRunTime() ), ftype.returnType() );
                DiagnosticsContext dc( 0, true );
                VerbosityContext vc( Verbosity::Normal, true );

                auto identity = AppendToVectorTerm( c.identity(),
                    TERM( StringId( pEnv.lock()->GetUniqueId() ) ) );
                auto func = BuildFunc( c, ftype, identity, params, nullptr, c );
                const auto& pFuncLLR = func.llr();

                ifstream sourcefile( filename.c_str() );
                if( !sourcefile.good() )
                {
                    pFuncLLR->setInvalid();
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,