diff --git a/elm/Makefile b/elm/Makefile index e7ad0989..99fcffdd 100644 --- a/elm/Makefile +++ b/elm/Makefile @@ -1,7 +1,10 @@ -SOURCES = stepA_mal.elm #step0_repl.elm step1_read_print.elm step2_eval.elm \ +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_LISP = Env.elm Core.elm Eval.elm stepA_mal.elm + + BINS = $(SOURCES:%.elm=%.js) ELM = node_modules/.bin/elm @@ -38,10 +41,10 @@ stepA_mal.js: $(STEP4_SOURCES) clean: rm -f $(BINS) -# stats: $(SOURCES) -# @wc $^ -# @printf "%5s %5s %5s %s\n" `egrep "^\w*#|^\w*$$" $^ | wc` "[comments/blanks]" +stats: $(STEP4_SOURCES) stepA_mal.elm + @wc $^ + @printf "%5s %5s %5s %s\n" `egrep "^\w*(--|\{-|-\})|^\w*$$" $^ | wc` "[comments/blanks]" -# stats-lisp: $(SOURCES_LISP) -# @wc $^ -# @printf "%5s %5s %5s %s\n" `egrep "^\w*#|^\w*$$" $^ | wc` "[comments/blanks]" +stats-lisp: $(SOURCES_LISP) + @wc $^ + @printf "%5s %5s %5s %s\n" `egrep "^\w*(--|\{-|-\})|^\w*$$" $^ | wc` "[comments/blanks]" diff --git a/elm/step4_if_fn_do.elm b/elm/step4_if_fn_do.elm index c769ffaa..113e2253 100644 --- a/elm/step4_if_fn_do.elm +++ b/elm/step4_if_fn_do.elm @@ -187,7 +187,7 @@ eval ast = fn args (MalFunction (UserFunc { eagerFn })) :: args -> - eagerFn [] args + eagerFn args fn :: _ -> Eval.withEnv @@ -437,7 +437,7 @@ evalFn args = UserFunc { frameId = frameId , lazyFn = fn - , eagerFn = always fn + , eagerFn = fn , isMacro = False , meta = Nothing } diff --git a/elm/step5_tco.elm b/elm/step5_tco.elm index 96a87b46..c460102c 100644 --- a/elm/step5_tco.elm +++ b/elm/step5_tco.elm @@ -189,7 +189,7 @@ evalApply { frameId, bound, body } = Eval.modifyEnv (Env.enter frameId bound) |> Eval.andThen (\_ -> evalNoApply body) |> Eval.finally Env.leave - |> Eval.gcPass [] + |> Eval.gcPass ) @@ -475,7 +475,7 @@ evalFn args = UserFunc { frameId = frameId , lazyFn = lazyFn - , eagerFn = \_ -> lazyFn >> Eval.andThen eval + , eagerFn = lazyFn >> Eval.andThen eval , isMacro = False , meta = Nothing } diff --git a/elm/step6_file.elm b/elm/step6_file.elm index 87643819..670cdada 100644 --- a/elm/step6_file.elm +++ b/elm/step6_file.elm @@ -246,12 +246,7 @@ malEval : List MalExpr -> Eval MalExpr malEval args = case args of [ expr ] -> - Eval.withEnv - (\env -> - Eval.modifyEnv (Env.jump Env.globalFrameId) - |> Eval.andThen (\_ -> eval expr) - |> Eval.finally Env.leave - ) + Eval.inGlobal (eval expr) _ -> Eval.fail "unsupported arguments" @@ -264,7 +259,7 @@ evalApply { frameId, bound, body } = Eval.modifyEnv (Env.enter frameId bound) |> Eval.andThen (\_ -> evalNoApply body) |> Eval.finally Env.leave - |> Eval.gcPass [] + |> Eval.gcPass ) @@ -550,7 +545,7 @@ evalFn args = UserFunc { frameId = frameId , lazyFn = lazyFn - , eagerFn = \_ -> lazyFn >> Eval.andThen eval + , eagerFn = lazyFn >> Eval.andThen eval , isMacro = False , meta = Nothing } diff --git a/elm/step7_quote.elm b/elm/step7_quote.elm index 8a09aaa5..1e396dce 100644 --- a/elm/step7_quote.elm +++ b/elm/step7_quote.elm @@ -246,12 +246,7 @@ malEval : List MalExpr -> Eval MalExpr malEval args = case args of [ expr ] -> - Eval.withEnv - (\env -> - Eval.modifyEnv (Env.jump Env.globalFrameId) - |> Eval.andThen (\_ -> eval expr) - |> Eval.finally Env.leave - ) + Eval.inGlobal (eval expr) _ -> Eval.fail "unsupported arguments" @@ -264,7 +259,7 @@ evalApply { frameId, bound, body } = Eval.modifyEnv (Env.enter frameId bound) |> Eval.andThen (\_ -> evalNoApply body) |> Eval.finally Env.leave - |> Eval.gcPass [] + |> Eval.gcPass ) @@ -549,7 +544,7 @@ evalFn args = UserFunc { frameId = frameId , lazyFn = lazyFn - , eagerFn = \_ -> lazyFn >> Eval.andThen eval + , eagerFn = lazyFn >> Eval.andThen eval , isMacro = False , meta = Nothing } diff --git a/elm/step8_macros.elm b/elm/step8_macros.elm index adf9caa2..c089a90f 100644 --- a/elm/step8_macros.elm +++ b/elm/step8_macros.elm @@ -262,12 +262,7 @@ malEval : List MalExpr -> Eval MalExpr malEval args = case args of [ expr ] -> - Eval.withEnv - (\env -> - Eval.modifyEnv (Env.jump Env.globalFrameId) - |> Eval.andThen (\_ -> eval expr) - |> Eval.finally Env.leave - ) + Eval.inGlobal (eval expr) _ -> Eval.fail "unsupported arguments" @@ -280,7 +275,7 @@ evalApply { frameId, bound, body } = Eval.modifyEnv (Env.enter frameId bound) |> Eval.andThen (\_ -> evalNoApply body) |> Eval.finally Env.leave - |> Eval.gcPass [] + |> Eval.gcPass ) @@ -604,7 +599,7 @@ evalFn args = UserFunc { frameId = frameId , lazyFn = lazyFn - , eagerFn = \_ -> lazyFn >> Eval.andThen eval + , eagerFn = lazyFn >> Eval.andThen eval , isMacro = False , meta = Nothing } @@ -687,7 +682,7 @@ macroexpand expr = case Env.get name env of Ok (MalFunction (UserFunc fn)) -> if fn.isMacro then - Left <| fn.eagerFn [] args + Left <| fn.eagerFn args else Right expr diff --git a/elm/step9_try.elm b/elm/step9_try.elm index ba886aae..356584ec 100644 --- a/elm/step9_try.elm +++ b/elm/step9_try.elm @@ -262,12 +262,7 @@ malEval : List MalExpr -> Eval MalExpr malEval args = case args of [ expr ] -> - Eval.withEnv - (\env -> - Eval.modifyEnv (Env.jump Env.globalFrameId) - |> Eval.andThen (\_ -> eval expr) - |> Eval.finally Env.leave - ) + Eval.inGlobal (eval expr) _ -> Eval.fail "unsupported arguments" @@ -280,7 +275,7 @@ evalApply { frameId, bound, body } = Eval.modifyEnv (Env.enter frameId bound) |> Eval.andThen (\_ -> evalNoApply body) |> Eval.finally Env.leave - |> Eval.gcPass [] + |> Eval.gcPass ) @@ -606,7 +601,7 @@ evalFn args = UserFunc { frameId = frameId , lazyFn = lazyFn - , eagerFn = \_ -> lazyFn >> Eval.andThen eval + , eagerFn = lazyFn >> Eval.andThen eval , isMacro = False , meta = Nothing } @@ -689,7 +684,7 @@ macroexpand expr = case Env.get name env of Ok (MalFunction (UserFunc fn)) -> if fn.isMacro then - Left <| fn.eagerFn [] args + Left <| fn.eagerFn args else Right expr