Browse Source

Bugfix: vmcompiler: parse numeric offset in static segment

Apparently, numeric arguments to push/pop static are valid,
so I prefix them with 'STATIC_' at the parsing stage
master
Denis Tereshkin 4 years ago
parent
commit
1517d38d21
  1. 6
      src/Nand2Tetris/VM.hs

6
src/Nand2Tetris/VM.hs

@ -129,7 +129,7 @@ parseInstruction = @@ -129,7 +129,7 @@ parseInstruction =
parseSegmentInt "this" SThis,
parseSegmentInt "that" SThat,
parseSegmentInt "constant" SConstant,
(string "static" *> space1) *> (SStatic <$> parseId),
(string "static" *> space1) *> (SStatic <$> (try parseId <|> parseStaticOffset)),
parseSegmentInt "pointer" SPointer,
parseSegmentInt "temp" STemp
]
@ -141,6 +141,10 @@ parseInstruction = @@ -141,6 +141,10 @@ parseInstruction =
hs <- many (alphaNumChar <|> char '.' <|> char '_')
return $ T.pack (h : hs)
parseStaticOffset :: Parser T.Text
parseStaticOffset = do
h <- L.decimal
return $ "STATIC_" <> (T.pack . show) h
parseSegmentInt :: T.Text -> (Int -> Segment) -> Parser Segment
parseSegmentInt sname f = try $ do

Loading…
Cancel
Save