make struct&atom useful

This commit is contained in:
Mirek Kratochvil 2023-03-10 21:55:04 +01:00
parent 452cd49496
commit 768fb71200

View file

@ -167,8 +167,10 @@ struct = do
heap <- use (cur . heap) heap <- use (cur . heap)
scope <- use (cur . hvar) scope <- use (cur . hvar)
case derefHeap heap <$> scope M.!? 0 of case derefHeap heap <$> scope M.!? 0 of
Just (BoundRef addr (Struct Id {arity = arity, str = str})) -> Just (BoundRef _ (Struct Id {arity = arity, str = str})) ->
structUnify arity str structUnify arity str
Just (BoundRef _ _) ->
backtrack
_ -> structAssemble _ -> structAssemble
heapListLength listAtom heap ref = go 0 ref ref (id, fromJust . step) heapListLength listAtom heap ref = go 0 ref ref (id, fromJust . step)
@ -217,6 +219,7 @@ structUnify arity str = do
zoom cur $ do zoom cur $ do
gol %= (gcode ++) gol %= (gcode ++)
hed %= (hcode ++) hed %= (hcode ++)
unis += 3
continue continue
{- terms -} {- terms -}
@ -229,6 +232,14 @@ var = do
Just (FreeRef _) -> continue Just (FreeRef _) -> continue
_ -> backtrack _ -> backtrack
atom :: InterpFn
atom = do
heap <- use (cur . heap)
scope <- use (cur . hvar)
case derefHeap heap <$> scope M.!? 0 of
Just (BoundRef _ (C (Atom _))) -> continue
_ -> backtrack
number :: InterpFn number :: InterpFn
number = do number = do
heap <- use (cur . heap) heap <- use (cur . heap)
@ -468,6 +479,7 @@ addPrelude = do
{- terms -} {- terms -}
addBi struct "struct" 3 addBi struct "struct" 3
addBi var "var" 1 addBi var "var" 1
addBi atom "atom" 1
addBi number "number" 1 addBi number "number" 1
addBi string "string" 1 addBi string "string" 1
addBi sameTerm "same_term" 2 addBi sameTerm "same_term" 2