Skip to content

Commit

Permalink
fix: if
Browse files Browse the repository at this point in the history
 - Else block had error on parse
 - Add jump to skip branch
  • Loading branch information
vorotynsky committed May 27, 2020
1 parent 4d2da25 commit f4e65cc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion HLasm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: HLasm
version: 0.1.0.0
version: 0.2.0.0
description: Please see the README on GitHub at <https://github.com/vorotynsky/HLasm#readme>
homepage: https://github.com/vorotynsky/HLasm#readme
bug-reports: https://github.com/vorotynsky/HLasm/issues
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: HLasm
version: 0.1.0.0
version: 0.2.0.0
github: "vorotynsky/HLasm"
license: GPL-3
author: "Vorotynsky Maxim"
Expand Down
2 changes: 1 addition & 1 deletion src/HLasm/Instructions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ instructions (Node ((If lbl), _, _, _) []) = Right []
instructions (Node ((If lbl), _, _, _) xs) =
do (conds, bodies') <- Right $ traverse (uncurry branch) (zip [1..] xs)
bodies <- fmap (concat) . sequence $ bodies'
Right $ conds ++ bodies ++ [Label (lbl ++ "end")]
Right $ conds ++ [Jump (lbl ++ "end") Nothing] ++ bodies ++ [Label (lbl ++ "end")]

where condition lbl pt (Condition (left, cmp, right)) =
let find = valuableTarget pt in [Compare (find left) (find right), Jump lbl (Just cmp)]
Expand Down
4 changes: 2 additions & 2 deletions src/HLasm/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ value = (IntegerValue <$> aparse nat) <|> (NameValue <$> aparse name)
assignment = leafP id (Assignment <$> name <*> (achar '=' *> value))
condition = curry3 Condition <$> value <*> cond <*> value
where p x s = const x <$> string s
cond = p Equals "==" <|> p NotEquals "!=" <|> p Greater "<" <|> p Less ">"
cond = p Equals "==" <|> p NotEquals "!=" <|> p Greater ">" <|> p Less "<"

instrSet p = ftree <$> treeParser internal (aparse . many $ aparse p)
where internal x = pure (Node InstructionSet x, [])
Expand All @@ -71,7 +71,7 @@ ifstatment p =
(condition, label) <- parens ((,) <$> condition <*> (achar ',' *> name))
block <- returnBlock $ Just condition
return $ (label, block)
elseif = do keyword "else"; keyword "if"
elseif = do try (keyword "else" *> keyword "if")
condition <- parens condition
returnBlock $ Just condition
elseblk = keyword "else" >>= const (returnBlock Nothing)
Expand Down

0 comments on commit f4e65cc

Please sign in to comment.