Goose  Diff

Differences From Artifact [bce6656abc]:

  • File bs/builtins/api/compiler.cpp — part of check-in [f1cab5f761] at 2019-08-24 16:54:29 on branch trunk —
    • ExecuteFile is now a regular builtin function.
    • Added #Include, which works the same as the old ExecuteFile.
    • Added a CreateConstant() builtin func.
    • Used the above to cleanup the command line parsing code in empathy.em.
    (user: achavasse size: 6305)

To Artifact [d918e677a8]:

  • File bs/builtins/api/compiler.cpp — part of check-in [fece958df9] at 2019-08-24 19:33:39 on branch trunk — More cleanup around which builtin functions should be intrinsics/eager/non eager. (user: achavasse size: 7356)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16







17
18
19
20
21
22
23
24
25
26
27
28
29







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "builtins/builtins.h"
#include "parse/parse.h"
#include "execute/execute.h"
#include "compiler.h"

using namespace empathy;

namespace empathy::builtins
{
    void SetupApiCompiler( Env& e )
    {
        weak_ptr< Env > pEnv = e.shared_from_this();

        RegisterBuiltinFunc< Eager< void > ( bool ) >( e, "#DiagnosticsEnableTraces"_sid,
            [pEnv]( bool enable )
            {







                DiagnosticsManager::GetInstance().setTraceMode( enable );
            } );

        RegisterBuiltinFunc< void ( bool ) >( e, "DiagnosticsForceColors"_sid,
            [pEnv]( bool enable )
            {
                DiagnosticsManager::GetInstance().setForceColors( enable );
            } );

        RegisterBuiltinFunc< Eager< void > ( uint32_t ) >( e, "#SetExecutionBudget"_sid,
            [pEnv]( uint32_t budget )
            {
                static bool used = false;








                if( used )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,
                        "#SetExecutionBudget can only be used once." );
                    return;
                }

                used = true;
                execute::VM::SetExecutionBudget( budget );
            } );

        RegisterBuiltinFunc< Eager< Value > ( Value, string ) >( e, "#ExternalFunction"_sid,
            [pEnv]( const Value& f, const string& symbol )
            {
                auto ft = FromValue< FuncType >( f );
                if( !ft )
                    return ToValue( "error"s ).setPoison();

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

        RegisterBuiltinFunc< void ( string, Value ) >( e, "CreateConstant"_sid,
            [pEnv]( const string& name, const Value& v )
            {













|
|

>
>
>
>
>
>
>
|








|
|


>
>
>
>
>
>
>









|


|




|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
#include "builtins/builtins.h"
#include "parse/parse.h"
#include "execute/execute.h"
#include "compiler.h"

using namespace empathy;

namespace empathy::builtins
{
    void SetupApiCompiler( Env& e )
    {
        weak_ptr< Env > pEnv = e.shared_from_this();

        RegisterBuiltinFunc< Intrinsic< void ( bool ) > >( e, "#DiagnosticsEnableTraces"_sid,
            [pEnv]( const Value& enable )
            {
                if( !enable.isConstant() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( enable.locationId(),
                        "#DiagnosticsEnableTraces: the expression doesn't evaluate to a constant." );
                    return;
                }

                DiagnosticsManager::GetInstance().setTraceMode( *FromValue< bool >( enable ) );
            } );

        RegisterBuiltinFunc< void ( bool ) >( e, "DiagnosticsForceColors"_sid,
            [pEnv]( bool enable )
            {
                DiagnosticsManager::GetInstance().setForceColors( enable );
            } );

        RegisterBuiltinFunc< Intrinsic< void ( uint32_t ) > >( e, "#SetExecutionBudget"_sid,
            [pEnv]( const Value& budget )
            {
                static bool used = false;

                if( !budget.isConstant() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( budget.locationId(),
                        "#SetExecutionBudget: the expression doesn't evaluate to a constant." );
                    return;
                }

                if( used )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( 0,
                        "#SetExecutionBudget can only be used once." );
                    return;
                }

                used = true;
                execute::VM::SetExecutionBudget( *FromValue< uint32_t >( budget ) );
            } );

        RegisterBuiltinFunc< Eager< Value > ( Value, string ) >( e, "ExternalFunction"_sid,
            [pEnv]( const Value& f, const string& symbol )
            {
                auto ft = FromValue< FuncType >( f );
                if( !ft )
                    return PoisonValue();

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

        RegisterBuiltinFunc< void ( string, Value ) >( e, "CreateConstant"_sid,
            [pEnv]( const string& name, const Value& v )
            {
87
88
89
90
91
92
93
94
95
96









97
98
99
100
101
102
103

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

                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() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( rt.locationId(),
                        "#CompileFileToFunction: type expected.", 0 );
                    return PoisonValue();
                }







|
|

>
>
>
>
>
>
>
>
>







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

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

                return *result;
            } );

        RegisterBuiltinFunc< Intrinsic< Value ( string, Value, Value ) > >( e, "#CompileFileToFunction"_sid,
            [pEnv]( 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();
                }

                auto filename = *FromValue< string >( filenameVal );

                // Validate those generic value inputs
                if( !rt.isType() )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( rt.locationId(),
                        "#CompileFileToFunction: type expected.", 0 );
                    return PoisonValue();
                }