From fc59ff9e494496f9d3832afcf3ea3e8b04b4dd32 Mon Sep 17 00:00:00 2001 From: mrsekut Date: Thu, 22 Jul 2021 18:49:59 +0900 Subject: [PATCH] feat: purscript step0 --- .psc-ide-port | 1 + Makefile.impls | 3 +- impls/purs/.gitignore | 12 ++++ impls/purs/Makefile | 7 +++ impls/purs/package.json | 5 ++ impls/purs/packages.dhall | 104 +++++++++++++++++++++++++++++++++ impls/purs/run | 2 + impls/purs/spago.dhall | 17 ++++++ impls/purs/src/Readline.js | 12 ++++ impls/purs/src/Readline.purs | 9 +++ impls/purs/src/step0_repl.purs | 38 ++++++++++++ 11 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 .psc-ide-port create mode 100644 impls/purs/.gitignore create mode 100644 impls/purs/Makefile create mode 100644 impls/purs/package.json create mode 100644 impls/purs/packages.dhall create mode 100755 impls/purs/run create mode 100644 impls/purs/spago.dhall create mode 100644 impls/purs/src/Readline.js create mode 100644 impls/purs/src/Readline.purs create mode 100644 impls/purs/src/step0_repl.purs diff --git a/.psc-ide-port b/.psc-ide-port new file mode 100644 index 00000000..e31a4371 --- /dev/null +++ b/.psc-ide-port @@ -0,0 +1 @@ +15273 \ No newline at end of file diff --git a/Makefile.impls b/Makefile.impls index a4323e28..6ac35b23 100644 --- a/Makefile.impls +++ b/Makefile.impls @@ -38,7 +38,7 @@ IMPLS = ada ada.2 awk bash basic bbc-basic c c.2 chuck clojure coffee common-lis elisp elixir elm erlang es6 factor fantom fennel forth fsharp go groovy gnu-smalltalk \ guile haskell haxe hy io janet java java-truffle js jq julia kotlin livescript logo lua make mal \ matlab miniMAL nasm nim objc objpascal ocaml perl perl6 php picolisp pike plpgsql \ - plsql powershell prolog ps python python.2 r racket rexx rpython ruby ruby.2 rust scala scheme skew sml \ + plsql powershell prolog ps purs python python.2 r racket rexx rpython ruby ruby.2 rust scala scheme skew sml \ swift swift3 swift4 swift5 tcl ts vala vb vhdl vimscript wasm wren yorick xslt zig step5_EXCLUDES += bash # never completes at 10,000 @@ -168,6 +168,7 @@ plsql_STEP_TO_PROG = impls/plsql/$($(1)).sql powershell_STEP_TO_PROG = impls/powershell/$($(1)).ps1 prolog_STEP_TO_PROG = impls/prolog/$($(1)).pl ps_STEP_TO_PROG = impls/ps/$($(1)).ps +purs_STEP_TO_PROG = impls/purs/$($(1)).js python_STEP_TO_PROG = impls/python/$($(1)).py python.2_STEP_TO_PROG = impls/python.2/$($(1)).py r_STEP_TO_PROG = impls/r/$($(1)).r diff --git a/impls/purs/.gitignore b/impls/purs/.gitignore new file mode 100644 index 00000000..38ad64c2 --- /dev/null +++ b/impls/purs/.gitignore @@ -0,0 +1,12 @@ +/bower_components/ +/node_modules/ +/.pulp-cache/ +/output/ +/generated-docs/ +/.psc-package/ +/.psc* +/.purs* +/.psa* +/.spago + +/step*.js diff --git a/impls/purs/Makefile b/impls/purs/Makefile new file mode 100644 index 00000000..5772d54b --- /dev/null +++ b/impls/purs/Makefile @@ -0,0 +1,7 @@ +src/step%: + spago bundle-app --main ${${@F}} --to $(@F:%.purs=%.js) + + +##################### + +step0_repl.purs = Mal.Step0 \ No newline at end of file diff --git a/impls/purs/package.json b/impls/purs/package.json new file mode 100644 index 00000000..65adf184 --- /dev/null +++ b/impls/purs/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "readline-sync": "^1.4.10" + } +} diff --git a/impls/purs/packages.dhall b/impls/purs/packages.dhall new file mode 100644 index 00000000..7b4147e6 --- /dev/null +++ b/impls/purs/packages.dhall @@ -0,0 +1,104 @@ +{- +Welcome to your new Dhall package-set! + +Below are instructions for how to edit this file for most use +cases, so that you don't need to know Dhall to use it. + +## Use Cases + +Most will want to do one or both of these options: +1. Override/Patch a package's dependency +2. Add a package not already in the default package set + +This file will continue to work whether you use one or both options. +Instructions for each option are explained below. + +### Overriding/Patching a package + +Purpose: +- Change a package's dependency to a newer/older release than the + default package set's release +- Use your own modified version of some dependency that may + include new API, changed API, removed API by + using your custom git repo of the library rather than + the package set's repo + +Syntax: +where `entityName` is one of the following: +- dependencies +- repo +- version +------------------------------- +let upstream = -- +in upstream + with packageName.entityName = "new value" +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with halogen.version = "master" + with halogen.repo = "https://example.com/path/to/git/repo.git" + + with halogen-vdom.version = "v4.0.0" + with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies +------------------------------- + +### Additions + +Purpose: +- Add packages that aren't already included in the default package set + +Syntax: +where `` is: +- a tag (i.e. "v4.0.0") +- a branch (i.e. "master") +- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977") +------------------------------- +let upstream = -- +in upstream + with new-package-name = + { dependencies = + [ "dependency1" + , "dependency2" + ] + , repo = + "https://example.com/path/to/git/repo.git" + , version = + "" + } +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with benchotron = + { dependencies = + [ "arrays" + , "exists" + , "profunctor" + , "strings" + , "quickcheck" + , "lcg" + , "transformers" + , "foldable-traversable" + , "exceptions" + , "node-fs" + , "node-buffer" + , "node-readline" + , "datetime" + , "now" + ] + , repo = + "https://github.com/hdgarrood/purescript-benchotron.git" + , version = + "v7.0.0" + } +------------------------------- +-} +let upstream = + https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210713/packages.dhall sha256:654c3148cb995f642c73b4508d987d9896e2ad3ea1d325a1e826c034c0d3cd7b + +in upstream diff --git a/impls/purs/run b/impls/purs/run new file mode 100755 index 00000000..6a4a5dd7 --- /dev/null +++ b/impls/purs/run @@ -0,0 +1,2 @@ +#!/bin/bash +exec node $(dirname $0)/${STEP:-stepA_mal}.js "${@}" \ No newline at end of file diff --git a/impls/purs/spago.dhall b/impls/purs/spago.dhall new file mode 100644 index 00000000..8cd9d339 --- /dev/null +++ b/impls/purs/spago.dhall @@ -0,0 +1,17 @@ +{- +Welcome to a Spago project! +You can edit this file as you like. + +Need help? See the following resources: +- Spago documentation: https://github.com/purescript/spago +- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html + +When creating a new Spago project, you can use +`spago init --no-comments` or `spago init -C` +to generate this file without the comments in this block. +-} +{ name = "mal-purescript" +, dependencies = [ "console", "effect", "prelude", "psci-support" ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +} diff --git a/impls/purs/src/Readline.js b/impls/purs/src/Readline.js new file mode 100644 index 00000000..fe9a0e34 --- /dev/null +++ b/impls/purs/src/Readline.js @@ -0,0 +1,12 @@ +"use strict"; + +var readlineSync = require('readline-sync') + +exports.readLine = function (x) { + return function () { + return readlineSync.question(x) + } +} + + +exports.argv = process.argv; \ No newline at end of file diff --git a/impls/purs/src/Readline.purs b/impls/purs/src/Readline.purs new file mode 100644 index 00000000..9807127e --- /dev/null +++ b/impls/purs/src/Readline.purs @@ -0,0 +1,9 @@ +module Readline where + +import Prelude + +import Effect (Effect) + + + +foreign import readLine :: String -> Effect String \ No newline at end of file diff --git a/impls/purs/src/step0_repl.purs b/impls/purs/src/step0_repl.purs new file mode 100644 index 00000000..1f922a7f --- /dev/null +++ b/impls/purs/src/step0_repl.purs @@ -0,0 +1,38 @@ +module Mal.Step0 where + +import Prelude +import Effect (Effect) +import Effect.Console (log) +import Readline (readLine) + + + +main :: Effect Unit +main = loop + + +loop :: Effect Unit +loop = do + line <- readLine "user> " + case line of + ":q" -> pure unit + ":Q" -> pure unit + _ -> do + log line + loop + + +read :: String -> String +read s = s + + +eval :: String -> String +eval s = s + + +print :: String -> String +print s = s + + +rep :: String -> String +rep = read >>> eval >>> print \ No newline at end of file