Goose  Diff

Differences From Artifact [2c1dad4735]:

  • File bs/builtins/api/compiler.cpp — part of check-in [a0ee0dfc2e] at 2020-02-17 23:15:03 on branch trunk — Register temporary values returned from function calls for destruction, so that DestroyValue() is invoked on them. (user: achavasse size: 8400)

To Artifact [9d739514d2]:

  • File bs/builtins/api/compiler.cpp — part of check-in [397f594186] at 2020-05-17 17:30:43 on branch trunk —
    • Clean up the "default return value from top level file functions" stuff.
    • Standardize to a default return value of 0 for the top level file both in execution mode and in compilation mode.
    • Implemented a combined execution/compilation test for tuples in preparation for implementing tuple compilation. (not enabled yet)
    (user: achavasse size: 8563)

121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

        RegisterBuiltinFunc< Intrinsic< uint32_t ( string ) > >( e, "#Include"_sid,
            [pEnv]( auto&& c, const Value& fnameval ) -> Value
            {
                auto filename = *FromValue< string >( fnameval );
                auto identity = InjectDomainIntoIdentity( RootIdentity(), DomainCompileTime() );

                auto result = Compiler::LoadAndExecuteFile( pEnv.lock(), filename, identity, GetValueType< uint32_t >() );


                if( !result )
                    return ToValue< uint32_t >( 1 );

                return *result;
            } );

        RegisterBuiltinFunc< uint32_t ( string ) >( e, "ExecuteFile"_sid,
            [pEnv]( const string& filename ) -> Value
            {
                auto identity = InjectDomainIntoIdentity( RootIdentity(), DomainCompileTime() );

                auto result = Compiler::LoadAndExecuteFile( pEnv.lock(), filename, identity, GetValueType< uint32_t >() );


                if( !result )
                    return ToValue< uint32_t >( 1 );

                return *result;
            } );

        RegisterBuiltinFunc< Intrinsic< Value ( string, Value, Value ) > >( e, "#CompileFileToFunction"_sid,
            [pEnv]( auto&& c, const Value& filenameVal, const Value& rt, const Value& params ) -> Value
            {
                if( !filenameVal.isConstant() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( filenameVal.locationId(),
                        "#CompileFileToFunction: the expression doesn't evaluate to a constant." );
                    return PoisonValue();
                }







|
>


|









|
>


|




|
|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

        RegisterBuiltinFunc< Intrinsic< uint32_t ( string ) > >( e, "#Include"_sid,
            [pEnv]( auto&& c, const Value& fnameval ) -> Value
            {
                auto filename = *FromValue< string >( fnameval );
                auto identity = InjectDomainIntoIdentity( RootIdentity(), DomainCompileTime() );

                auto result = Compiler::LoadAndExecuteFile( pEnv.lock(), filename, identity,
                    GetValueType< uint32_t >(), ToValue< uint32_t >( 0 ) );

                if( !result )
                    return ToValue< uint32_t >( 0 );

                return *result;
            } );

        RegisterBuiltinFunc< uint32_t ( string ) >( e, "ExecuteFile"_sid,
            [pEnv]( const string& filename ) -> Value
            {
                auto identity = InjectDomainIntoIdentity( RootIdentity(), DomainCompileTime() );

                auto result = Compiler::LoadAndExecuteFile( pEnv.lock(), filename, identity,
                    GetValueType< uint32_t >(), ToValue< uint32_t >( 0 ) );

                if( !result )
                    return ToValue< uint32_t >( 0 );

                return *result;
            } );

        RegisterBuiltinFunc< Intrinsic< Value ( string, Value, Value, Value ) > >( e, "#CompileFileToFunction"_sid,
            [pEnv]( auto&& c, const Value& filenameVal, const Value& rt, const Value& defReturnValue, const Value& params ) -> Value
            {
                if( !filenameVal.isConstant() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( filenameVal.locationId(),
                        "#CompileFileToFunction: the expression doesn't evaluate to a constant." );
                    return PoisonValue();
                }
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202
203
204
                c.env()->addVisibilityRule(
                    InjectDomainIntoIdentity( identity, ANYTERM( _ ) ),
                    InjectDomainIntoIdentity( funcIdentity, ANYTERM( _ ) ) );

                auto func = BuildFunc( localC, ftype, identity, params, nullptr, c );
                const auto& pFuncLLR = func.llr();

                auto cfg = Compiler::LoadAndParseFile( pEnv.lock(), filename,  funcIdentity, ftype.returnType() );


                if( !cfg )
                    return PoisonValue();

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

                pFuncLLR->body() = cfg;
                return ToValue( func );
            } );
    }
}







|
>












187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
                c.env()->addVisibilityRule(
                    InjectDomainIntoIdentity( identity, ANYTERM( _ ) ),
                    InjectDomainIntoIdentity( funcIdentity, ANYTERM( _ ) ) );

                auto func = BuildFunc( localC, ftype, identity, params, nullptr, c );
                const auto& pFuncLLR = func.llr();

                auto cfg = Compiler::LoadAndParseFile( pEnv.lock(), filename, funcIdentity,
                    ftype.returnType(), defReturnValue );

                if( !cfg )
                    return PoisonValue();

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

                pFuncLLR->body() = cfg;
                return ToValue( func );
            } );
    }
}