Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactoring, wrangling with cabal-meta

  • Loading branch information...
commit 14527be555a476c71d9c0108e7b63074504df007 1 parent b13d6d4
Patrick Thomson authored
View
5 hs-dcpu.cabal
@@ -21,7 +21,7 @@ Executable hdasm
Build-depends: array >= 0.3,
attoparsec >= 0.10.1.0,
base >= 4.2,
- bytestring >= 0.9.2,
+ bytestring >= 0.9,
Cabal >= 1.12,
checkers >= 0.2.6,
mtl >= 2,
@@ -41,7 +41,7 @@ Test-suite test-dcpu:
Build-depends: array >= 0.3,
attoparsec >= 0.10.1.0,
base >= 4.2,
- bytestring >= 0.9.2,
+ bytestring >= 0.9,
checkers >= 0.2.6,
Cabal >= 1.12,
mtl >= 2,
@@ -49,3 +49,4 @@ Test-suite test-dcpu:
QuickCheck >= 2.3,
test-framework >= 0.6,
test-framework-quickcheck2 >= 0.2.7
+
View
1  sources.txt
@@ -0,0 +1 @@
+.
View
3  src/Assembler.hs
@@ -0,0 +1,3 @@
+module Assembler where
+
+ import Core
View
22 src/Core.hs
@@ -3,11 +3,15 @@ module Core
, RAM
, Register (..)
, Slots
+ , Instruction (..)
+ , Opcode (..)
+ , Operand (..)
, module Control.Applicative
, module Control.Monad
, module Data.Array.Unboxed
, module Data.Monoid
, module Data.Word
+ , module Data.ByteString.Char8
, (++)
, bshow
)
@@ -57,10 +61,28 @@ where
show SP = "SP"
show OF = "O"
+ data Opcode
+ = SET | ADD | SUB | MUL | DIV | MOD
+ | AND | BOR | XOR | IFE | IFN | IFG | IFB
+ deriving (Show, Eq, Ord, Enum, Bounded)
+
+ -- Since all the leaves of this ADT are different, maybe this would be a
+ -- good place to try coproducts?
+ data Operand
+ = AsmLiteral Int
+ | AsmRegister Register
+ | AsmReference Operand
+ | AsmLabel ByteString
+ deriving (Show, Eq)
+
infixr 5 ++
(++) :: (Monoid a) => [a] -> a
(++) = mconcat
bshow :: (Show a) => a -> ByteString
bshow = pack <$> show
+
+ data Instruction =
+ Instruction Opcode Operand Operand
+ deriving (Show, Eq)
View
18 src/Parser.hs
@@ -7,30 +7,12 @@ module Parser
import Data.Attoparsec.ByteString.Char8
import Data.ByteString.Char8 (ByteString, pack)
- data Instruction =
- Instruction Opcode Operand Operand
- deriving (Show, Eq)
-
instruction :: Parser Instruction
instruction = Instruction <$> opcode <*> (operand <* skipSpace <* char ',') <*> (skipSpace *> operand)
- data Opcode
- = SET | ADD | SUB | MUL | DIV | MOD
- | AND | BOR | XOR | IFE | IFN | IFG | IFB
- deriving (Show, Eq, Ord, Enum, Bounded)
-
opcode :: Parser Opcode
opcode = valueParser [ SET .. IFB ]
- -- Since all the leaves of this ADT are different, maybe this would be a
- -- good place to try coproducts?
- data Operand
- = AsmLiteral Int
- | AsmRegister Register
- | AsmReference Operand
- | AsmLabel ByteString
- deriving (Show, Eq)
-
register, literal, reference, label, operand :: Parser Operand
register = AsmRegister <$> valueParser [ RA .. OF ]
literal = AsmLiteral <$> ((string "0x" *> hexadecimal) <|> decimal)
View
2  src/Pretty.hs
@@ -2,7 +2,7 @@
module Pretty where
- import Core
+ import Core hiding ((<>))
import Control.Applicative
import Text.PrettyPrint
import Text.Printf
Please sign in to comment.
Something went wrong with that request. Please try again.