Skip to content

Commit

Permalink
now using stack install of raw cabal
Browse files Browse the repository at this point in the history
  • Loading branch information
Karocyt committed Jan 22, 2021
1 parent 861d3ae commit 39b89b2
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 87 deletions.
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
__pycache__
__pytest__
corrections
.pytest_cache
MANIFEST
.stack-work/
*~
.vscode
verif
dist
cabal.sandbox.config
.cabal-sandbox
a-machine
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog for a-machine

## Unreleased changes
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020, Kevin Azoulay and Guillaume De Rouville
Copyright Kévin Azoulay-Dessus and Guillaume de Rouville (c) 2021

All rights reserved.

Expand All @@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met:
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Kevin Azoulay and Guillaume De Rouville nor the names of other
* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# a-machine

## Requirements

### Windows
Download and install [Stack](https://get.haskellstack.org/stable/windows-x86_64-installer.exe).

### Unix systems (including MacOs)
```bash
curl -sSL https://get.haskellstack.org/ | sh
```
or
```bash
wget -qO- https://get.haskellstack.org/ | sh
```

### MacOs X Homebrew
```bash
brew install haskell-stack
```

## Build

```bash
stack build
```

## Run

```bash
stack exec a-machine-exe desc.json tape
```
where:
- `desc.json` is a json encoded file containing a valid machine description
- `tape` is a string of instructions from the machine alphabet
137 changes: 67 additions & 70 deletions a-machine.cabal
Original file line number Diff line number Diff line change
@@ -1,73 +1,70 @@
-- Initial a-machine.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/

-- The name of the package.
name: a-machine

-- The package version. See the Haskell package versioning policy (PVP)
-- for standards guiding when and how versions should be incremented.
-- https://wiki.haskell.org/Package_versioning_policy
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.0

-- A short (one-line) description of the package.
synopsis: A turing machine

-- A longer description of the package.
-- description:

-- URL for the project homepage or repository.
homepage: None

-- The license under which the package is released.
license: BSD3

-- The file containing the license text.
license-file: LICENSE

-- The package author(s).
author: Kevin Azoulay and Guillaume De Rouville

-- An email address to which users can send suggestions, bug reports, and
-- patches.
maintainer: None

-- A copyright notice.
-- copyright:

category: Math

build-type: Simple

-- Extra files to be distributed with the package, such as examples or a
-- README.
extra-source-files: CHANGELOG.md

-- Constraint on the version of Cabal needed to build this package.
cabal-version: >=1.10


executable a-machine
-- .hs or .lhs file containing the Main module.
main-is: Main.hs

-- Modules included in this executable, other than Main.
other-modules: Parser, Machine

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:

-- Other library packages from which modules are imported.
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.33.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 081d7680aa6edd0db132d6a447fed5e294f3a395863556fb44c2738aa0599292

name: a-machine
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/a-machine#readme>
homepage: https://github.com/githubuser/a-machine#readme
bug-reports: https://github.com/githubuser/a-machine/issues
author: Author name here
maintainer: [email protected]
copyright: 2021 Author name here
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md

source-repository head
type: git
location: https://github.com/githubuser/a-machine

library
exposed-modules:
Machine
Parser
Runner
other-modules:
Paths_a_machine
hs-source-dirs:
src
build-depends:
aeson
, base >=4.7 && <5
, bytestring
default-language: Haskell2010

executable a-machine-exe
main-is: Main.hs
other-modules:
Paths_a_machine
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.12 && <4.13
a-machine
, aeson
, base >=4.7 && <5
, bytestring

-- Directories containing source files.
hs-source-dirs: src

-- Base language which the package is written in.
default-language: Haskell2010

default-language: Haskell2010

test-suite a-machine-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_a_machine
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
a-machine
, aeson
, base >=4.7 && <5
, bytestring
default-language: Haskell2010
9 changes: 7 additions & 2 deletions src/Main.hs → app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import Runner

-- main :: IO ()
main = do
putStrLn "-- BEGIN ----------------------------------"
args <- processArgs =<< getArgs
putStrLn "Arguments validated"
content <- readFile $ args !! 0
putStrLn "Description read"
let tape = args !! 1
-- print content

case (parseMachine content) of
Left str -> print str
Right m -> runMachine m tape
print "Ok"
Right m -> putStrLn "Machine loaded" >> runMachine m tape

putStrLn "-- END ------------------------------------"

50 changes: 50 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: a-machine
version: 0.1.0.0
github: "githubuser/a-machine"
license: BSD3
author: "Author name here"
maintainer: "[email protected]"
copyright: "2021 Author name here"

extra-source-files:
- README.md
- ChangeLog.md

# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/a-machine#readme>

dependencies:
- base >= 4.7 && < 5
- bytestring
- aeson

library:
source-dirs: src

executables:
a-machine-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- a-machine

tests:
a-machine-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- a-machine
9 changes: 5 additions & 4 deletions src/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import Data.Aeson
import Data.ByteString.Lazy.Char8 (pack)

-- processArgs :: [String] -> IO String
processArgs xs | length xs /= 2 = putStrLn ("Usage: ./a-machine [filename]\n\twhere 'filename' is a json encoded valid machine description.") >> exitFailure
processArgs xs | length xs /= 2 = putStrLn ("Usage: ./a-machine desc.json tape\nwhere:\n\t- 'desc.json' is a json encoded file containing a valid machine description\n\t- 'tape' is a string of instructions from the machine alphabet") >> exitFailure
| otherwise = pure xs -- :: [IO String]

-- parseMachine :: String -> Either String Machine
parseMachine c = eitherDecode (pack c) :: Either String Machine
parseMachine c = lexMachine (eitherDecode (pack c) :: Either String Machine)

-- lexMachine :: Machine -> Bool
lexMachine m = True
lexMachine :: Either String Machine -> Either String Machine
lexMachine (Left str) = Left str
lexMachine (Right m) = Right m
2 changes: 1 addition & 1 deletion src/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import System.Exit (exitFailure)
import Machine

runMachine :: Machine -> String -> IO ()
runMachine m t = print "Machine running..."
runMachine m t = putStrLn "Machine running..."
67 changes: 67 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/31.yaml

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.5"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
13 changes: 13 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
size: 534126
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/31.yaml
sha256: 637fb77049b25560622a224845b7acfe81a09fdb6a96a3c75997a10b651667f6
original:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/31.yaml
2 changes: 2 additions & 0 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"

0 comments on commit 39b89b2

Please sign in to comment.