expand like a prohuman
This commit is contained in:
parent
de4775bd77
commit
3eb6125609
|
@ -231,8 +231,8 @@ var = do
|
||||||
Just (FreeRef _) -> continue
|
Just (FreeRef _) -> continue
|
||||||
_ -> backtrack
|
_ -> backtrack
|
||||||
|
|
||||||
same_term :: InterpFn
|
sameTerm :: InterpFn
|
||||||
same_term = do
|
sameTerm = do
|
||||||
heap <- gets (heap . cur)
|
heap <- gets (heap . cur)
|
||||||
scope <- gets (hvar . cur)
|
scope <- gets (hvar . cur)
|
||||||
case map (fmap (derefHeap heap) . (scope M.!?)) [0, 1] of
|
case map (fmap (derefHeap heap) . (scope M.!?)) [0, 1] of
|
||||||
|
@ -240,6 +240,18 @@ same_term = do
|
||||||
| a == b -> continue
|
| a == b -> continue
|
||||||
_ -> backtrack
|
_ -> backtrack
|
||||||
|
|
||||||
|
currentPredicate :: InterpFn
|
||||||
|
currentPredicate =
|
||||||
|
withArgs [0] $ \[arg] -> do
|
||||||
|
heap <- gets (heap . cur)
|
||||||
|
ds <- gets defs
|
||||||
|
case derefHeap heap arg of
|
||||||
|
BoundRef _ (Struct s) ->
|
||||||
|
if s `M.member` ds
|
||||||
|
then continue
|
||||||
|
else backtrack
|
||||||
|
_ -> prlgError "not a predicate"
|
||||||
|
|
||||||
{- operator management -}
|
{- operator management -}
|
||||||
op :: InterpFn
|
op :: InterpFn
|
||||||
op =
|
op =
|
||||||
|
@ -386,7 +398,8 @@ addPrelude = do
|
||||||
{- terms -}
|
{- terms -}
|
||||||
addBi struct "struct" 3
|
addBi struct "struct" 3
|
||||||
addBi var "var" 1
|
addBi var "var" 1
|
||||||
addBi same_term "same_term" 2
|
addBi sameTerm "same_term" 2
|
||||||
|
addBi currentPredicate "current_predicate" 1
|
||||||
{- code loading -}
|
{- code loading -}
|
||||||
addBi (load False) "load" 1
|
addBi (load False) "load" 1
|
||||||
addBi (load True) "source" 1
|
addBi (load True) "source" 1
|
||||||
|
@ -398,6 +411,30 @@ addPrelude = do
|
||||||
{- macroenvironment -}
|
{- macroenvironment -}
|
||||||
addBi stashExpansions "stash_expansions" 0
|
addBi stashExpansions "stash_expansions" 0
|
||||||
addBi popExpansions "pop_expansions" 0
|
addBi popExpansions "pop_expansions" 0
|
||||||
|
let expandCode q = do
|
||||||
|
s <- findStruct (q ++ "_expansion") 2
|
||||||
|
cp <- findStruct "current_predicate" 1
|
||||||
|
addProc
|
||||||
|
[ [ U (LocalRef 0)
|
||||||
|
, U (LocalRef 1)
|
||||||
|
, Goal -- current_predicate(expand_something(_,_)),
|
||||||
|
, U (Struct cp)
|
||||||
|
, U (Struct s)
|
||||||
|
, U VoidRef
|
||||||
|
, U VoidRef
|
||||||
|
, Call -- no cut!
|
||||||
|
, Goal -- expand_something(Arg1, Arg2).
|
||||||
|
, U (Struct s)
|
||||||
|
, U (LocalRef 0)
|
||||||
|
, U (LocalRef 1)
|
||||||
|
, LastCall
|
||||||
|
]
|
||||||
|
, [U (LocalRef 0), U (LocalRef 0), NoGoal]
|
||||||
|
]
|
||||||
|
("expand_" ++ q)
|
||||||
|
2
|
||||||
|
expandCode "load"
|
||||||
|
expandCode "query"
|
||||||
{- query tools -}
|
{- query tools -}
|
||||||
addBi printLocals "print_locals" 0
|
addBi printLocals "print_locals" 0
|
||||||
addBi promptRetry' "prompt_retry" 0
|
addBi promptRetry' "prompt_retry" 0
|
||||||
|
|
|
@ -60,9 +60,9 @@ expansion noexpand expander output x = do
|
||||||
]
|
]
|
||||||
else noexpand o x
|
else noexpand o x
|
||||||
|
|
||||||
queryExpansion = expansion (\_ -> id) "query_expansion" "call"
|
queryExpansion = expansion (\_ -> id) "expand_query" "call"
|
||||||
|
|
||||||
loadExpansion = expansion (\o x -> IR.CallI o [x]) "load_expansion" "assert"
|
loadExpansion = expansion (\o x -> IR.CallI o [x]) "expand_load" "assert"
|
||||||
|
|
||||||
processInput fn queryMode input = do
|
processInput fn queryMode input = do
|
||||||
asts <- except $ tokenize fn input >>= parse fn
|
asts <- except $ tokenize fn input >>= parse fn
|
||||||
|
|
Loading…
Reference in a new issue