diff options
Diffstat (limited to 'app/Compiler.hs')
| -rw-r--r-- | app/Compiler.hs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/app/Compiler.hs b/app/Compiler.hs index 84a63a4..6d104a9 100644 --- a/app/Compiler.hs +++ b/app/Compiler.hs @@ -10,8 +10,7 @@ desugarPrlg :: Int -> PrlgInt -> PrlgInt desugarPrlg list = go where go (CallI id ps) = CallI id $ map go ps - go (ListI (x:xs) t) = - CallI Id {str = list, arity = 2} [go x, go (ListI xs t)] + go (ListI (x:xs) t) = CallI list [go x, go (ListI xs t)] go (ListI [] Nothing) = LiteralI list go (ListI [] (Just x)) = go x go x = x @@ -29,7 +28,7 @@ varOccurs _ = M.empty variablizePrlg :: Int -> StrTable -> PrlgInt -> PrlgInt variablizePrlg void (StrTable _ _ itos) = go where - go (CallI id ps) = CallI id $ map go ps + go (CallI i ps) = CallI i $ map go ps go (LiteralI i) | i == void = VoidI | varname (itos M.! i) = VarI i i @@ -38,7 +37,7 @@ variablizePrlg void (StrTable _ _ itos) = go renumVars :: (Int -> Maybe PrlgInt) -> PrlgInt -> PrlgInt renumVars rename = go where - go (CallI id ps) = CallI id $ map go ps + go (CallI i ps) = CallI i $ map go ps go (VarI idx i) | Just new <- rename idx = new go x = x @@ -52,13 +51,13 @@ squashVars x = [(idx, VarI idx' 0) | ((idx, n), idx') <- zip occurs [1 ..], n > 1] in renumVars (m' M.!?) x -compileGoals :: Id -> Int -> PrlgInt -> [Code] +compileGoals :: Int -> Int -> PrlgInt -> [Code] compileGoals andop cut = go' where go' = go . struct2goal - go p@(CallI x args) + go p@(CallI x args@[_, _]) | x == andop = concatMap go' args - go p@(CallI (Id x 0) []) + go p@(CallI x []) | x == cut = [[Cut]] go x = [compileGoal x] @@ -66,9 +65,10 @@ compileGoal :: PrlgInt -> Code compileGoal = compileArg . struct2goal compileArg :: PrlgInt -> Code -compileArg (CallI s args) = U (Struct s) : concatMap compileArg args +compileArg (CallI i args) = + U (Struct Id {str = i, arity = length args}) : concatMap compileArg args compileArg (LiteralI s) = [U (Atom s)] -compileArg (VarI x s) = [U (LocalRef x s)] +compileArg (VarI x _) = [U (LocalRef x)] compileArg (VoidI) = [U VoidRef] seqGoals :: [Code] -> Code @@ -84,16 +84,16 @@ heapStructPrlgInt heaperr heap ref = heapStruct atom struct hrec heap ref where atom (Atom s) = pure $ LiteralI s atom VoidRef = pure $ VoidI - struct (Struct s) args = pure $ CallI s args + struct (Struct s) args = pure $ CallI (str s) args hrec (HeapRef r) ref | r == ref = pure $ VarI r 0 | otherwise = heaperr -- TODO check if this is used goal2struct :: PrlgInt -> PrlgInt -goal2struct (CallI (Id s 0) []) = LiteralI s +goal2struct (CallI s []) = LiteralI s goal2struct x = x struct2goal :: PrlgInt -> PrlgInt -struct2goal (LiteralI s) = CallI (Id s 0) [] +struct2goal (LiteralI s) = CallI s [] struct2goal x = x |
