Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
add work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Dec 6, 2023
1 parent b390b67 commit 32af367
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ComputeAST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

module ComputeAST
(
computeAST,
computeAllAST
) where

Expand Down Expand Up @@ -92,12 +93,14 @@ computeTree env tree = computeTree env (resolveDeepestNode env tree)
------------ COMPUTE AST ------------

-- Call appropriate function depending on the node
computeAST :: Env -> [Atom] -> Tree -> (Env, [Atom])
computeAST env atoms tree@(Node "define" _ _) = (registerDefine env tree, atoms)
computeAST env atoms tree = (env, atoms ++ [computeTree env tree])
computeAST :: Env -> Tree -> (Env, Maybe Atom)
computeAST env tree@(Node "define" _ _) = (registerDefine env tree, Nothing)
computeAST env tree = (env, Just (computeTree env tree))

-- Call computeAST on every tree in the list
computeAllAST :: Env -> [Tree] -> [Atom]
computeAllAST _ [] = []
computeAllAST env (tree:rest) = atoms ++ computeAllAST newEnv rest
where (newEnv, atoms) = computeAST env [] tree
computeAllAST env (tree:rest) = case atom of
Just atom -> atom : computeAllAST newEnv rest

Check warning on line 104 in src/ComputeAST.hs

View workflow job for this annotation

GitHub Actions / compil-macos

This binding for ‘atom’ shadows the existing binding

Check warning on line 104 in src/ComputeAST.hs

View workflow job for this annotation

GitHub Actions / compil-windows

This binding for `atom' shadows the existing binding

Check warning on line 104 in src/ComputeAST.hs

View workflow job for this annotation

GitHub Actions / compil-linux

This binding for ‘atom’ shadows the existing binding
Nothing -> computeAllAST newEnv rest
where (newEnv, atom) = computeAST env tree
4 changes: 4 additions & 0 deletions src/Defines.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ data Env = Env {
defines :: [Define]
} deriving (Show)

instance Eq Env where
(Env []) == (Env []) = True
_ == _ = True

-- Register a define in the Defines list
registerDefine :: Env -> Tree -> Env
registerDefine env
Expand Down

0 comments on commit 32af367

Please sign in to comment.