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
|
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< Eager< uint32_t > ( string ) >( e, "ExecuteFile"_sid,
[pEnv]( const string& filename ) -> uint32_t
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 0;
return PoisonValue();
}
sema::Context c( pEnv.lock(), RootIdentity(), GetValueType< uint32_t >() );
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 0;
return PoisonValue();
if( !r->eos() )
{
DiagnosticsManager::GetInstance().emitSyntaxErrorMessage(
r->getCurrentLocation(), "syntax error." );
return 0;
return PoisonValue();
}
if( !cfg->entryBB()->canBeExecuted() )
{
DiagnosticsManager::GetInstance().emitErrorMessage( 0,
format( "{}: can not be executed.", filename ) );
return 0;
return PoisonValue();
}
execute::VM vm;
auto result = vm.execute( cfg->entryBB() );
if( !result )
return 1;
return ToValue< uint32_t >( 1 );
if( result->isPoison() )
return 0;
return PoisonValue();
return *FromValue< uint32_t >( *result );
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
|
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(), RootIdentity(), ftype.returnType() );
sema::Context c( pEnv.lock(), InjectDomainIntoIdentity( RootIdentity(), DomainRunTime() ), ftype.returnType() );
DiagnosticsContext dc( 0, true );
VerbosityContext vc( Verbosity::Normal, true );
auto identity = AppendToVectorTerm( InjectDomainIntoIdentity( RootIdentity(), DomainRunTime() ),
auto identity = AppendToVectorTerm( c.identity(),
TERM( StringId( pEnv.lock()->GetUniqueId() ) ) );
auto func = BuildFunc( c, ftype, identity, params, make_shared< Vector >(), c );
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,
|