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
|
#include "builtins/builtins.h"
#include "parse/parse.h"
#include "execute/execute.h"
using namespace empathy;
namespace empathy::builtins
{
void SetupApiCompiler( Env& e )
{
weak_ptr< Env > pEnv = e.shared_from_this();
RegisterBuiltinFunc< Value ( Value, string ) >( e, "ExternalFunction"_sid,
[pEnv]( const Value& f, const string& symbol )
{
auto ft = FromValue< FuncType >( f );
if( !ft )
return ToValue( "error"s );
return ToValue( BuildExternalFunc( *ft, symbol ) );
} );
RegisterBuiltinFunc< uint64_t ( string ) >( e, "ExecuteFile"_sid,
[pEnv]( const string& filename ) -> uint64_t
{
auto pFN = make_shared< string >( filename );
ifstream sourcefile( pFN->c_str() );
if( !sourcefile.good() )
{
|
|
|
|
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
|
#include "builtins/builtins.h"
#include "parse/parse.h"
#include "execute/execute.h"
using namespace empathy;
namespace empathy::builtins
{
void SetupApiCompiler( Env& e )
{
weak_ptr< Env > pEnv = e.shared_from_this();
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 );
return ToValue( BuildExternalFunc( *ft, symbol ) );
} );
RegisterBuiltinFunc< Eager< uint64_t > ( string ) >( e, "ExecuteFile"_sid,
[pEnv]( const string& filename ) -> uint64_t
{
auto pFN = make_shared< string >( filename );
ifstream sourcefile( pFN->c_str() );
if( !sourcefile.good() )
{
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
auto result = vm.execute( cfgBuilder->entryBB() );
if( !result )
return 1;
return *FromValue< uint64_t >( *result );
} );
RegisterBuiltinFunc< 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() )
{
// We don't have builtin optional types so return something completely unexpected instead.
// TODO: figure out something more elegant that doens't involve making the optional type builtin.
|
|
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
auto result = vm.execute( cfgBuilder->entryBB() );
if( !result )
return 1;
return *FromValue< uint64_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() )
{
// We don't have builtin optional types so return something completely unexpected instead.
// TODO: figure out something more elegant that doens't involve making the optional type builtin.
|