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
|
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< Eager< void > ( bool ) >( e, "#DiagnosticsEnableTraces"_sid,
[pEnv]( bool enable )
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( enable );
DiagnosticsManager::GetInstance().setTraceMode( *FromValue< bool >( 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 )
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( budget );
execute::VM::SetExecutionBudget( *FromValue< uint32_t >( budget ) );
} );
RegisterBuiltinFunc< Eager< Value > ( Value, string ) >( e, "#ExternalFunction"_sid,
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 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
|
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< Eager< Value > ( string, Value, Value ) >( e, "#CompileFileToFunction"_sid,
[pEnv]( const string& filename, const Value& rt, const Value& params ) -> Value
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();
}
|