Goose  Diff

Differences From Artifact [e39ec0ad6e]:

  • File bs/builtins/api/compiler.cpp — part of check-in [6a99df8278] at 2019-07-27 13:04:23 on branch trunk — Implemented external runtime functions. (user: achavasse size: 5142)

To Artifact [b7ee83987c]:

  • File bs/builtins/api/compiler.cpp — part of check-in [3c074f1b7d] at 2019-07-30 22:05:49 on branch trunk —
    • Builtin functions are now explicitely marked if they need to be evaluated eagerly.
    • Using errors out if the expression doesn't evaluate to a constant.
    (user: achavasse size: 5169)

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.