Skip to content

Commit

Permalink
opt parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lisphacker committed Sep 16, 2023
1 parent 8d23482 commit c001ad2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ executables:
main: Main.hs
dependencies:
- tis100
- optparse-applicative
ghc-options:
- -rtsopts
- -threaded
Expand Down
28 changes: 28 additions & 0 deletions sim/CmdLine.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module CmdLine where

import Options.Applicative

-- import Data.String.Interpolate (i)
-- import TIS100

-- main :: IO ()
-- main = do
-- let a = 1
-- let b = 2
-- putStrLn [i| Sum of #{a} and #{b} is #{sum' a b}|]

data CmdLineOpts = CmdLineOpts
{ asmFilePath :: String
}

sample :: Parser CmdLineOpts
sample =
CmdLineOpts
<$> strArgument
( metavar "ASMFILE"
<> help "Assembly file name"
)

greet :: CmdLineOpts -> IO ()
greet (CmdLineOpts asmFilePath) = putStrLn $ "asm: " ++ asmFilePath
greet _ = return ()
18 changes: 12 additions & 6 deletions sim/Main.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{-# LANGUAGE QuasiQuotes #-}

module Main where

import Lib
import Data.String.Interpolate (i)
import CmdLine
import Options.Applicative

main :: IO ()
main = do
let a = 1
let b = 2
putStrLn [i| Sum of #{a} and #{b} is #{sum' a b}|]
main = greet =<< execParser opts
where
opts =
info
(sample <**> helper)
( fullDesc
<> progDesc "Print a greeting for TARGET"
<> header "hello - a test for optparse-applicative"
)
3 changes: 3 additions & 0 deletions src/TIS100/Simulator/CPU.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module TIS100.Simulator.CPU where

import Data.Vector.Mutable
import TIS100.Nodes.T21 (T21 (..))
import TIS100.Nodes.T30 (T30 (..))

data Node = InactiveNode | Node21 T21 | Node30 T30
deriving (Eq, Show)

type CPUState m = MVector m Node

0 comments on commit c001ad2

Please sign in to comment.