From 768fb712004f04357668636bf7cb95a9401527a4 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 10 Mar 2023 21:55:04 +0100 Subject: [PATCH] make struct&atom useful --- app/Builtins.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Builtins.hs b/app/Builtins.hs index 60653df..4164a6c 100644 --- a/app/Builtins.hs +++ b/app/Builtins.hs @@ -167,8 +167,10 @@ struct = do heap <- use (cur . heap) scope <- use (cur . hvar) 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 + Just (BoundRef _ _) -> + backtrack _ -> structAssemble heapListLength listAtom heap ref = go 0 ref ref (id, fromJust . step) @@ -217,6 +219,7 @@ structUnify arity str = do zoom cur $ do gol %= (gcode ++) hed %= (hcode ++) + unis += 3 continue {- terms -} @@ -229,6 +232,14 @@ var = do Just (FreeRef _) -> continue _ -> 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 = do heap <- use (cur . heap) @@ -468,6 +479,7 @@ addPrelude = do {- terms -} addBi struct "struct" 3 addBi var "var" 1 + addBi atom "atom" 1 addBi number "number" 1 addBi string "string" 1 addBi sameTerm "same_term" 2