diff options
Diffstat (limited to 'app/Compiler.hs')
| -rw-r--r-- | app/Compiler.hs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/app/Compiler.hs b/app/Compiler.hs index 6d104a9..206bc40 100644 --- a/app/Compiler.hs +++ b/app/Compiler.hs @@ -11,7 +11,7 @@ desugarPrlg list = go where go (CallI id ps) = CallI id $ map go ps go (ListI (x:xs) t) = CallI list [go x, go (ListI xs t)] - go (ListI [] Nothing) = LiteralI list + go (ListI [] Nothing) = AtomI list go (ListI [] (Just x)) = go x go x = x @@ -29,10 +29,11 @@ variablizePrlg :: Int -> StrTable -> PrlgInt -> PrlgInt variablizePrlg void (StrTable _ _ itos) = go where go (CallI i ps) = CallI i $ map go ps - go (LiteralI i) + go (AtomI i) | i == void = VoidI | varname (itos M.! i) = VarI i i - | otherwise = LiteralI i + | otherwise = AtomI i + go x = x renumVars :: (Int -> Maybe PrlgInt) -> PrlgInt -> PrlgInt renumVars rename = go @@ -67,7 +68,8 @@ compileGoal = compileArg . struct2goal compileArg :: PrlgInt -> Code compileArg (CallI i args) = U (Struct Id {str = i, arity = length args}) : concatMap compileArg args -compileArg (LiteralI s) = [U (Atom s)] +compileArg (AtomI s) = [U (Atom s)] +compileArg (NumI s) = [U (Number s)] compileArg (VarI x _) = [U (LocalRef x)] compileArg (VoidI) = [U VoidRef] @@ -82,7 +84,7 @@ seqGoals (x:xs) = [Goal] ++ x ++ [Call] ++ seqGoals xs heapStructPrlgInt :: Monad m => m PrlgInt -> Heap -> Int -> m PrlgInt heapStructPrlgInt heaperr heap ref = heapStruct atom struct hrec heap ref where - atom (Atom s) = pure $ LiteralI s + atom (Atom s) = pure $ AtomI s atom VoidRef = pure $ VoidI struct (Struct s) args = pure $ CallI (str s) args hrec (HeapRef r) ref @@ -91,9 +93,9 @@ heapStructPrlgInt heaperr heap ref = heapStruct atom struct hrec heap ref -- TODO check if this is used goal2struct :: PrlgInt -> PrlgInt -goal2struct (CallI s []) = LiteralI s +goal2struct (CallI s []) = AtomI s goal2struct x = x struct2goal :: PrlgInt -> PrlgInt -struct2goal (LiteralI s) = CallI s [] +struct2goal (AtomI s) = CallI s [] struct2goal x = x |
