11
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
|
11
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
|
-
-
+
-
-
-
+
-
-
-
-
-
+
+
+
-
-
-
+
+
+
+
-
-
+
-
-
+
+
-
-
-
-
-
-
-
+
|
{
optional< UnificationContext > bestUC;
optional< Term > bestSol;
bool ambiguous = false;
auto sig = GetFuncSig( callee );
auto callPat = VEC( c.domain(), args.val(), HOLE( "_"_sid ) );
for( auto&& [s, uc] : FullUnify( sig, callPat, c ) )
{
if( !bestSol || uc.score() > bestUC->score() )
{
bestUC = uc;
auto us = FindBestUnification( sig, callPat, c );
bestSol = s;
ambiguous = false;
continue;
}
if( holds_alternative< NoUnification >( us ) )
{
if( uc.score() < bestUC->score() )
continue;
// TODO display details
DiagnosticsManager::GetInstance().emitErrorMessage( loc,
"function arguments mismatch." );
return PoisonValue();
ambiguous = true;
}
if( ambiguous )
if( holds_alternative< AmbiguousUnification >( us ) )
{
// TODO display details
DiagnosticsManager::GetInstance().emitErrorMessage( loc,
"ambiguous function call." );
return PoisonValue();
}
if( !bestSol )
{
auto&& [s,uc] = get< UniSol >( us );
// TODO display details
DiagnosticsManager::GetInstance().emitErrorMessage( loc,
"function arguments mismatch." );
return PoisonValue();
}
return invoke( c, loc, callee, *bestSol, *bestUC );
return invoke( c, loc, callee, s, uc );
}
Value invoke( const Context& c, uint32_t loc, const Value& callee, const Term& unifiedCallPat, UnificationContext& uc ) const final
{
auto newCallee = prepareFunc( c, 0, callee, unifiedCallPat, uc );
if( newCallee.isPoison() )
return PoisonValue();
|