1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-13 01:43:50 +03:00

Elm: re-enabled steps 1-9

This commit is contained in:
Jos van Bakel 2017-07-22 21:59:59 +02:00
parent 50ed0aa9a1
commit b346116e53
7 changed files with 28 additions and 45 deletions

View File

@ -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]"

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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