Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simulator prototype

  • Loading branch information...
commit afa8cc93cfb50fdfe5c24567a39d9a8dee6bcbcf 1 parent 158380b
Alexander Bernauer authored
1  examples/fail.bcs
View
@@ -0,0 +1 @@
+OP_FALSE
22 src/Language/Bitcoin/Main.hs
View
@@ -19,24 +19,24 @@ main = do
output <- exitOnError $ runAction opts input
if (optOutput opts /= optOutput defaultOptions)
then B.writeFile (optOutput opts) output
- else return ()
+ else putStrLn $ B.unpack output
runAction :: Options -> B.ByteString -> Either String B.ByteString
runAction opts input
- | optAssembler opts = assembler input
- | optDisassembler opts = disassembler input
- | optSimulator opts = simulator input
+ | optAssembler opts = Right $ assembler input
+ | optDisassembler opts = Right $ disassembler input
+ | optSimulator opts = simulator opts input
| otherwise = error "internal error"
-assembler :: B.ByteString -> Either String B.ByteString
-assembler code = Right $ run_assembler code
+assembler :: B.ByteString -> B.ByteString
+assembler = run_assembler
-disassembler :: B.ByteString -> Either String B.ByteString
-disassembler binary = Right $ run_disassembler binary
+disassembler :: B.ByteString -> B.ByteString
+disassembler = run_disassembler
-simulator :: B.ByteString -> Either String B.ByteString
-simulator code =
- case run_parser code of
+simulator :: Options -> B.ByteString -> Either String B.ByteString
+simulator opts code =
+ case run_parser (optInput opts) code of
Left parseError -> Left $ show parseError
Right script ->
case run_simulator script of
8 src/Language/Bitcoin/Parser.hs
View
@@ -10,12 +10,12 @@ import Text.ParserCombinators.Parsec
import qualified Data.ByteString.Char8 as B
-- run_parser :: Code -> Script {{{1
-run_parser :: Code -> Either ParseError Script
-run_parser code = parse script "(unknown)" (B.unpack code)
+run_parser :: String -> Code -> Either ParseError Script
+run_parser source code = parse script source (B.unpack code)
script :: Parser Script
-script = sepBy operation separator
+script = endBy operation separator
operation :: Parser Opcode
operation = opcode -- <|> paste
@@ -25,7 +25,7 @@ opcode = string "OP_FALSE" >> return OP_FALSE
--paste = string "PASTE" >> bytes >>= (\bs -> return PASTE DATA (pack bs))
separator :: Parser Char
-separator = char '\n' -- <|> char ';'
+separator = char '\n' <|> char ';'
-- run_printer :: Script -> Code {{{1
Please sign in to comment.
Something went wrong with that request. Please try again.