Gracefully ignore no-op redefs
This commit is contained in:
parent
203bc1898d
commit
3b833ca75b
32
src/Eval.hs
32
src/Eval.hs
@ -10,26 +10,26 @@ import qualified Data.Set as Set
|
|||||||
|
|
||||||
evalSingle :: Env -> TricuAST -> Env
|
evalSingle :: Env -> TricuAST -> Env
|
||||||
evalSingle env term
|
evalSingle env term
|
||||||
| SDef name [] body <- term =
|
| SDef name [] body <- term
|
||||||
if
|
= case Map.lookup name env of
|
||||||
| Map.member name env ->
|
Just existingValue
|
||||||
errorWithoutStackTrace $
|
| existingValue == evalAST env body -> env
|
||||||
"Error: Identifier '" ++ name ++ "' is already defined."
|
| otherwise -> errorWithoutStackTrace $
|
||||||
| otherwise ->
|
"Unable to rebind immutable identifier: '" ++ name
|
||||||
let res = evalAST env body
|
Nothing ->
|
||||||
in Map.insert "!result" res (Map.insert name res env)
|
let res = evalAST env body
|
||||||
| SApp func arg <- term =
|
in Map.insert "!result" res (Map.insert name res env)
|
||||||
let res = apply (evalAST env func) (evalAST env arg)
|
| SApp func arg <- term
|
||||||
|
= let res = apply (evalAST env func) (evalAST env arg)
|
||||||
in Map.insert "!result" res env
|
in Map.insert "!result" res env
|
||||||
| SVar name <- term =
|
| SVar name <- term
|
||||||
case Map.lookup name env of
|
= case Map.lookup name env of
|
||||||
Just v ->
|
Just v -> Map.insert "!result" v env
|
||||||
Map.insert "!result" v env
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
errorWithoutStackTrace $ "Variable `" ++ name ++ "` not defined\n\
|
errorWithoutStackTrace $ "Variable `" ++ name ++ "` not defined\n\
|
||||||
\This error should never occur here. Please report this as an issue."
|
\This error should never occur here. Please report this as an issue."
|
||||||
| otherwise =
|
| otherwise
|
||||||
Map.insert "!result" (evalAST env term) env
|
= Map.insert "!result" (evalAST env term) env
|
||||||
|
|
||||||
evalTricu :: Env -> [TricuAST] -> Env
|
evalTricu :: Env -> [TricuAST] -> Env
|
||||||
evalTricu env x = go env (reorderDefs env x)
|
evalTricu env x = go env (reorderDefs env x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user