Goose  Diff

Differences From Artifact [83b0d622cd]:

  • File bs/builtins/helpers.h — part of check-in [996d8d9686] at 2021-10-25 19:34:34 on branch trunk — Type predicates: store the expressions as an array of values, which avoids unecessary conversions and results in the inclusion of the CIR from the expressions in the hash (user: zlodo size: 2847)

To Artifact [b0108bc725]:

  • File bs/builtins/helpers.h — part of check-in [1ad61a2717] at 2021-11-11 20:05:58 on branch trunk — Refactored the code builder: it is now carried around as a Value, and accessed through a bunch of extension points, so we can have different builders (and even user defined ones) later to make classes etc. (user: zlodo size: 4058)

1
2
3
4




5
6
7


8
9
10
11
12
13
14
#ifndef GOOSE_BUILTINS_HELPERS_H
#define GOOSE_BUILTINS_HELPERS_H

#include "parse/parse.h"





namespace goose::builtins
{


    template< typename T >
    void DefineConstant( sema::Env& env, StringId name, T&& val )
    {
        env.storeValue( AppendToVectorTerm( RootG0Identity(), TERM( name ) ), ANYTERM( _ ), forward< T >( val ) );
    }

    extern void RegisterRule( sema::Env& env, StringId name, parse::Rule&& rule );



|
>
>
>
>



>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef GOOSE_BUILTINS_HELPERS_H
#define GOOSE_BUILTINS_HELPERS_H

namespace goose::parse
{
    class Parser;
    class Rule;
}

namespace goose::builtins
{
    extern const Term& EmptyPredicates();

    template< typename T >
    void DefineConstant( sema::Env& env, StringId name, T&& val )
    {
        env.storeValue( AppendToVectorTerm( RootG0Identity(), TERM( name ) ), ANYTERM( _ ), forward< T >( val ) );
    }

    extern void RegisterRule( sema::Env& env, StringId name, parse::Rule&& rule );
55
56
57
58
59
60
61























62
63
64
65
66
67
68
    auto MkStdRTType( I&& identity, L&& llvmType )
    {
        return VEC( forward< I >( identity ), EmptyPredicates(), forward< L >( llvmType ) );
    }

    extern bool ParseExpressionList( parse::Parser& p, uint32_t precedence, ValueVec& vec );
























    struct CTTypePattern
    {
        static const Term& GetPattern()
        {
            static auto pat = ValueToEIR( Value( TypeType(), VEC( TSID( ct_type ), REPEAT( HOLE( "_"_sid ) ) ) ) );
            return pat;
        }







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
    auto MkStdRTType( I&& identity, L&& llvmType )
    {
        return VEC( forward< I >( identity ), EmptyPredicates(), forward< L >( llvmType ) );
    }

    extern bool ParseExpressionList( parse::Parser& p, uint32_t precedence, ValueVec& vec );

    extern void PoisonBuilder( const Context& c );

    extern bool BuilderAllowsVarDecl( const Context& c );
    extern ptr< cir::CFG > GetCFG( const Context& c );

    extern uint32_t GetBreakableScopeLevels( const Context& c );
    extern uint32_t GetContinuableScopeLevels( const Context& c );

    extern void PushLifetimeScope( const Context& c );
    extern void PopLifetimeScope( const Context& c );
    extern void PushBreakableScope( const Context& c );
    extern void PopBreakableScope( const Context& c );
    extern void PushContinuableScope( const Context& c );
    extern void PopContinuableScope( const Context& c );

    extern void PushLiveValue( const Context& c, const Value& val, uint32_t index );
    extern void ExtendValueLifetime( const Context& c, uint32_t index );

    extern bool DestroyAndPopCurrentLifetimeScopeValues( const Context& c );
    extern bool DestroyAllLiveValues( const Context& c );
    extern bool DestroyAllLiveValuesFromBreakScope( const Context& c, uint32_t breakScopeLevel );
    extern bool DestroyAllLiveValuesFromContinueScope( const Context& c, uint32_t continueScopeLevel );

    struct CTTypePattern
    {
        static const Term& GetPattern()
        {
            static auto pat = ValueToEIR( Value( TypeType(), VEC( TSID( ct_type ), REPEAT( HOLE( "_"_sid ) ) ) ) );
            return pat;
        }