Skip to content

Commit

Permalink
elm: merge more ideas from #450
Browse files Browse the repository at this point in the history
Various trivial changes reducing the diff to #450.

Dockerfile: npm already depends on nodejs

Core.elm: change profile of deepEquals instead of uncurrying before
each call.
  • Loading branch information
asarhaddon committed Feb 20, 2022
1 parent a643634 commit 0cc6296
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion impls/elm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WORKDIR /mal
# Specific implementation requirements
##########################################################

RUN apt-get -y install g++ libreadline-dev nodejs npm
RUN apt-get -y install g++ libreadline-dev npm

ENV HOME /mal
ENV NPM_CONFIG_CACHE /mal/.npm
20 changes: 10 additions & 10 deletions impls/elm/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
SOURCES = Step0_repl.elm Step1_read_print.elm Step2_eval.elm \
Step3_env.elm Step4_if_fn_do.elm Step5_tco.elm Step6_file.elm \
Step7_quote.elm Step8_macros.elm Step9_try.elm StepA_mal.elm
SOURCES = src/Step0_repl.elm src/Step1_read_print.elm src/Step2_eval.elm src/\
Step3_env.elm src/Step4_if_fn_do.elm src/Step5_tco.elm src/Step6_file.elm src/\
Step7_quote.elm src/Step8_macros.elm src/Step9_try.elm src/StepA_mal.elm

BINS = $(SOURCES:S%.elm=s%.js)
BINS = $(SOURCES:src/Step%.elm=step%.js)

ELM_MAKE = node_modules/.bin/elm make
ELM = node_modules/.bin/elm

all: node_modules $(BINS)

node_modules:
npm install

s%.js: S%.elm node_modules
$(ELM_MAKE) $< --output $@
step%.js: src/Step%.elm node_modules
$(ELM) make $< --output $@

STEP0_SOURCES = IO.elm
STEP1_SOURCES = $(STEP0_SOURCES) Reader.elm Printer.elm Utils.elm Types.elm Env.elm
STEP0_SOURCES = src/IO.elm
STEP1_SOURCES = $(STEP0_SOURCES) src/Reader.elm src/Printer.elm src/Utils.elm src/Types.elm src/Env.elm
STEP2_SOURCES = $(STEP1_SOURCES)
STEP3_SOURCES = $(STEP2_SOURCES)
STEP4_SOURCES = $(STEP3_SOURCES) Core.elm Eval.elm
STEP4_SOURCES = $(STEP3_SOURCES) src/Core.elm src/Eval.elm

step0_repl.js: $(STEP0_SOURCES)
step1_read_print.js: $(STEP1_SOURCES)
Expand Down
2 changes: 1 addition & 1 deletion impls/elm/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ app.ports.readLine.subscribe(function(prompt) {
});

// Read the contents of a file.
if (4 <= args[0][4] || args[0][4] == 'A') {
if ('readFile' in app.ports) {
app.ports.readFile.subscribe(function(filename) {
try {
var contents = fs.readFileSync(filename, 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion impls/elm/elm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "application",
"source-directories": [
"."
"src"
],
"elm-version": "0.19.1",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion impls/elm/run
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
#!/usr/bin/env bash
exec node $(dirname $0)/bootstrap.js ${STEP:-stepA_mal} "${@}"
12 changes: 6 additions & 6 deletions impls/elm/Core.elm → impls/elm/src/Core.elm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ns =
True

( x :: xs, y :: ys ) ->
if deepEquals x y then
if deepEquals (x, y) then
equalLists xs ys

else
Expand All @@ -99,11 +99,11 @@ ns =

else
zip (Dict.values a) (Dict.values b)
|> List.map (\(x,y) -> deepEquals x y)
|> List.map deepEquals
|> List.all identity

deepEquals a b =
case ( a, b ) of
deepEquals c =
case c of
( MalList _ list, MalList _ otherList ) ->
equalLists list otherList

Expand Down Expand Up @@ -131,14 +131,14 @@ ns =
( _, MalMap _ _ ) ->
False

_ ->
(a, b) ->
a == b

{- = -}
equals args =
case args of
[ a, b ] ->
Eval.succeed <| MalBool (deepEquals a b)
Eval.succeed <| MalBool (deepEquals (a, b))

_ ->
Eval.fail "unsupported arguments"
Expand Down
5 changes: 3 additions & 2 deletions impls/elm/Env.elm → impls/elm/src/Env.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Array
import Dict
import Set
import Types exposing (Env, Frame, MalExpr(..), MalFunction(..))
import Utils exposing (flip)


debug : Env -> String -> a -> a
Expand Down Expand Up @@ -358,7 +359,7 @@ gc expr env =
value =
getAtom atomId env
in
countExpr value acc
countExpr value acc

_ ->
acc
Expand Down Expand Up @@ -421,7 +422,7 @@ gc expr env =
in
countFrames initSet initSet
|> countExpr expr
|> (\acc -> countList acc env.stack)
|> flip countList env.stack
|> loop
|> filterFrames env.frames
|> makeNewEnv
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 10 additions & 3 deletions impls/elm/Utils.elm → impls/elm/src/Utils.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Utils exposing
( decodeString
, encodeString
, flip
, justValues
, last
, makeCall
Expand Down Expand Up @@ -39,9 +40,10 @@ decodeString =


regex : String -> Regex.Regex
regex str = case Regex.fromString str of
Nothing -> Debug.todo "invalid regex"
Just r -> r
regex str =
case Regex.fromString str of
Nothing -> Debug.todo "invalid regex"
Just r -> r


encodeString : String -> String
Expand Down Expand Up @@ -122,3 +124,8 @@ justValues list =

Nothing :: rest ->
justValues rest


flip : (a -> b -> c) -> (b -> a -> c)
flip f b a =
f a b

0 comments on commit 0cc6296

Please sign in to comment.