Use primitive constants as a last resort

This is for the situation where there's still an ambiguous overloading,
we drop to using the built in primitive as a default.
This commit is contained in:
Edwin Brady 2019-07-05 16:40:08 +01:00
parent 27672444e4
commit bdf6c03bf1
2 changed files with 19 additions and 3 deletions

View File

@ -6,6 +6,8 @@ beyond work on the language core, are (in no particular order):
* CI integration.
* Documentation string support (at the REPL and IDE mode).
* Generating HTML documentation from documentation strings (and possibly other
formations)
* A better REPL, including:
- `it` and `:let`
- readline and tab completion

View File

@ -38,15 +38,29 @@ expandAmbigName mode nest env orig args (IVar fc x) exp
else pure $ IMustUnify fc "Name applied to arguments" orig
Nothing =>
do est <- get EST
let prims = mapMaybe id
[!fromIntegerName, !fromStringName, !fromCharName]
fi <- fromIntegerName
si <- fromStringName
ci <- fromCharName
let prims = mapMaybe id [fi, si, ci]
let primApp = isPrimName prims x
case !(lookupCtxtName x (gamma defs)) of
[] => pure orig
[nalt] => pure $ mkAlt primApp est nalt
nalts => pure $ IAlternative fc Unique
nalts => pure $ IAlternative fc (uniqType fi si ci x args)
(map (mkAlt primApp est) nalts)
where
-- If there's multiple alternatives and all else fails, resort to using
-- the primitive directly
uniqType : Maybe Name -> Maybe Name -> Maybe Name -> Name ->
List (FC, Maybe (Maybe Name), RawImp) -> AltType
uniqType (Just fi) _ _ n [(_, _, IPrimVal fc (BI x))]
= UniqueDefault (IPrimVal fc (BI x))
uniqType _ (Just si) _ n [(_, _, IPrimVal fc (Str x))]
= UniqueDefault (IPrimVal fc (Str x))
uniqType _ _ (Just ci) n [(_, _, IPrimVal fc (Ch x))]
= UniqueDefault (IPrimVal fc (Ch x))
uniqType _ _ _ _ _ = Unique
buildAlt : RawImp -> List (FC, Maybe (Maybe Name), RawImp) ->
RawImp
buildAlt f [] = f