Goose  Diff

Differences From Artifact [fdca04b650]:

  • File bs/builtins/types/runtime/pointer.cpp — part of check-in [27fc719d74] at 2019-08-16 14:48:20 on branch trunk — Added a new type of template expression: TVec, along with a helper function to make it possible for parametric types to be constructed either normally or as a template expression when passed template parameters. Only used by LocalVar for now, parametric runtime types require some refactoring. (user: achavasse size: 1507)

To Artifact [b9b53d8d60]:

  • File bs/builtins/types/runtime/pointer.cpp — part of check-in [9a68159d52] at 2019-08-25 01:54:54 on branch trunk —
    • Got rid of the LoadConstInt instruction and directly handle integer constants in codegen. The old system didn't work for compile-time evaluated runtime integers.
    • Added missing implementations for unsigned comparison, that were somehow forgotten.
    • Implemented the nullptr constant.
    • Made a test version of the mandelbrot sample that gets both compiled and interpreted and whose results are compared with the same reference file, as a sanity test that interpreted and compiled code behave identically.
    (user: achavasse size: 2811)

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::builtins;

namespace empathy::builtins
{
    void SetupRuntimePointerType( Env& e )
    {



        RegisterBuiltinFunc< Eager< Value > ( Value ) >( e, "pointer"_sid,
            []( const Value& pointedType )
            {
                if( !GetLLVMType( pointedType ) )
                {
                    // TODO come up with some lightweight builtin option type
                    // for the builtin apis, because this is a very bullshit









>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::builtins;

namespace empathy::builtins
{
    void SetupRuntimePointerType( Env& e )
    {
        // null pointer literal
        e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( nullptr ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( NullPointer() ) ) );

        RegisterBuiltinFunc< Eager< Value > ( Value ) >( e, "pointer"_sid,
            []( const Value& pointedType )
            {
                if( !GetLLVMType( pointedType ) )
                {
                    // TODO come up with some lightweight builtin option type
                    // for the builtin apis, because this is a very bullshit
45
46
47
48
49
50
51
52














































        if( !result )
            return nullopt;

        auto&& [llvmType, pointedType] = *result;
        return PointerType( pointedType );
    }
}




















































|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

        if( !result )
            return nullopt;

        auto&& [llvmType, pointedType] = *result;
        return PointerType( pointedType );
    }

    const Value& Bridge< NullPointerType >::ToValue( const NullPointerType& np )
    {
        static auto val = Value( Type(), TSID( nullptr ) );
        return val;
    }

    optional< NullPointerType > Bridge< NullPointerType >::FromValue( const Value& v )
    {
        auto result = Decompose( v.val(),
            Lit( "nullptr"_sid )
        );

        if( !result )
            return nullopt;

        return NullPointerType();
    }

    const Term& Bridge< NullPointer >::Type()
    {
        static auto type = ValueToIRExpr( ir::ToValue( NullPointerType() ) );
        return type;
    }

    const Value& Bridge< NullPointer >::ToValue( const NullPointer& np )
    {
        static auto val = Value( Type(), TSID( nullptr ) );
        return val;
    }

    optional< NullPointer > Bridge< NullPointer >::FromValue( const Value& v )
    {
        if( !FromValue< NullPointerType >( *ValueFromIRExpr( v.type() ) ) )
            return nullopt;

        auto result = Decompose( v.val(),
            Lit( "nullptr"_sid )
        );

        if( !result )
            return nullopt;

        return NullPointer();
    }
}