12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
|
vt.push_back( ValueToIRExpr( param ) );
return true;
} );
return TFuncType( ValueToIRExpr( returnType ), TERM( make_shared< Vector >( vt.persistent(), false ) ) );
}
optional< Term > BuildTFuncSignature( const Context& c, const Value& returnType, const Value& params )
{
immer::vector< Term > v;
auto vt = v.transient();
bool success = true;
ForEachInTuple( params, [&]( auto&& param )
{
auto teSig = BuildTemplateSignature( c, ValueToIRExpr( param ) );
if( !teSig )
{
cout << "Invalid template parameter.\n";
success = false;
return false;
}
vt.push_back( move( *teSig ) );
return true;
} );
if( !success )
return nullopt;
auto rtSig = BuildTemplateSignature( c, ValueToIRExpr( returnType ) );
if( !rtSig )
{
cout << "Invalid template return type or texpr.\n";
return nullopt;
}
return TVEC( TERM( make_shared< Vector >( vt.persistent(), false ) ),
*rtSig );
}
optional< Value > BuildTFunc( const Context& c, const StringId& id, const Value& returnType, const Value& params, vector< Term >&& body )
{
auto sig = BuildTFuncSignature( c, returnType, params );
if( !sig )
return nullopt;
auto funcType = BuildTFuncType( returnType, params );
auto pToks = make_shared< vector< Term > >( move( body ) );
return ToValue( TFunc( move( funcType ),
*sig,
AppendToVectorTerm( c.identity(), TERM( id ) ),
move( pToks ) ) );
}
|
|
|
|
|
>
>
|
<
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
|
vt.push_back( ValueToIRExpr( param ) );
return true;
} );
return TFuncType( ValueToIRExpr( returnType ), TERM( make_shared< Vector >( vt.persistent(), false ) ) );
}
optional< Term > BuildTFuncSignature( const Context& c, const TFuncType& tft )
{
immer::vector< Term > v;
auto vt = v.transient();
bool success = true;
ForEachInVectorTerm( tft.params(), [&]( auto&& param )
{
auto teSig = BuildTemplateSignature( c, param );
if( !teSig )
{
cout << "Invalid template parameter.\n";
success = false;
return false;
}
vt.push_back( move( *teSig ) );
return true;
} );
if( !success )
return nullopt;
auto rtSig = BuildTemplateSignature( c, tft.returnType() );
if( !rtSig )
{
cout << "Invalid template return type or texpr.\n";
return nullopt;
}
return TVEC( TERM( make_shared< Vector >( vt.persistent(), false ) ),
*rtSig );
}
optional< Value > BuildTFunc( const Context& c, const StringId& id, const Value& returnType, const Value& params, vector< Term >&& body )
{
auto funcType = BuildTFuncType( returnType, params );
auto sig = BuildTFuncSignature( c, funcType );
if( !sig )
return nullopt;
auto pToks = make_shared< vector< Term > >( move( body ) );
return ToValue( TFunc( move( funcType ),
*sig,
AppendToVectorTerm( c.identity(), TERM( id ) ),
move( pToks ) ) );
}
|