aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-01-17 01:34:21 -0600
committerJoel Martin <github@martintribe.org>2015-01-17 01:34:21 -0600
commit899ff7fa98ea4aad5beb837524a8bee8c899df3e (patch)
tree32f8ce190c0f68fa3dd28d22093a0dc6ae58cd75
parent9d42904e47c50c5ff2306da04993b2a32bc9cd16 (diff)
downloadmal-899ff7fa98ea4aad5beb837524a8bee8c899df3e.tar.gz
mal-899ff7fa98ea4aad5beb837524a8bee8c899df3e.zip
Template cleanup.
-rw-r--r--template/step3_env.txt2
-rw-r--r--template/step4_if_fn_do.txt8
-rw-r--r--template/step5_tco.txt10
-rw-r--r--template/step6_file.txt10
-rw-r--r--template/step7_quote.txt10
-rw-r--r--template/step8_macros.txt14
-rw-r--r--template/step9_try.txt8
-rw-r--r--template/stepA_interop.txt8
-rw-r--r--template/stepA_interop2.txt8
9 files changed, 32 insertions, 46 deletions
diff --git a/template/step3_env.txt b/template/step3_env.txt
index a1de572..91beda6 100644
--- a/template/step3_env.txt
+++ b/template/step3_env.txt
@@ -14,7 +14,7 @@ EVAL(ast,env):
if not list?(ast): return eval_ast(ast, env)
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
- 'let*: return EVAL(ast[2], ...)
+ 'let*: let_env = ...; return EVAL(ast[2], let_env)
_default_: f, args = eval_ast(ast, env)
return apply(f, args)
diff --git a/template/step4_if_fn_do.txt b/template/step4_if_fn_do.txt
index d4dc4c5..501ebfc 100644
--- a/template/step4_if_fn_do.txt
+++ b/template/step4_if_fn_do.txt
@@ -14,7 +14,7 @@ EVAL(ast,env):
if not list?(ast): return eval_ast(ast, env)
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
- 'let*: return EVAL(ast[2], ...)
+ 'let*: let_env = ...; return EVAL(ast[2], let_env)
'do: return eval_ast(rest(ast), env)[-1]
'if: return EVAL(EVAL(ast[1], env) ? ast[2] : ast[3], env)
'fn*: return (...a) -> EVAL(ast[2], new Env(env, ast[1], a))
@@ -48,10 +48,6 @@ class Env (outer=null,binds=[],exprs=[])
--- core module ---------------------------------
ns = {'=: equal?,
- 'nil?: nil?,
- 'true?: true?,
- 'false?: false?,
- 'symbol?: symbol?,
'pr-str: (a) -> a.map(|s| pr_str(e,true)).join(" ")),
'str: (a) -> a.map(|s| pr_str(e,false)).join("")),
@@ -69,8 +65,6 @@ ns = {'=: equal?,
'list: list,
'list?: list?,
- 'hash-map: hash_map,
- 'map?: hash_map?,
'empty?: empty?,
'count: count}
diff --git a/template/step5_tco.txt b/template/step5_tco.txt
index 7f77065..450a3bc 100644
--- a/template/step5_tco.txt
+++ b/template/step5_tco.txt
@@ -20,8 +20,8 @@ EVAL(ast,env):
'if: EVAL(ast[1], env) ? ast = ast[2] : ast = ast[3] // TCO
'fn*: return new MalFunc(...)
_default_: f, args = eval_ast(ast, env)
- if malfunc?(ast[0]): ast = ast[0].fn; env = ... // TCO
- else: return apply(f, args)
+ if malfunc?(f): ast = f.fn; env = ... // TCO
+ else: return apply(f, args)
PRINT(exp): return printer.pr_str(exp)
@@ -50,10 +50,6 @@ class Env (outer=null,binds=[],exprs=[])
--- core module ---------------------------------
ns = {'=: equal?,
- 'nil?: nil?,
- 'true?: true?,
- 'false?: false?,
- 'symbol?: symbol?,
'pr-str: (a) -> a.map(|s| pr_str(e,true)).join(" ")),
'str: (a) -> a.map(|s| pr_str(e,false)).join("")),
@@ -71,8 +67,6 @@ ns = {'=: equal?,
'list: list,
'list?: list?,
- 'hash-map: hash_map,
- 'map?: hash_map?,
'empty?: empty?,
'count: count}
diff --git a/template/step6_file.txt b/template/step6_file.txt
index 508f947..b9b9907 100644
--- a/template/step6_file.txt
+++ b/template/step6_file.txt
@@ -20,8 +20,8 @@ EVAL(ast,env):
'if: EVAL(ast[1], env) ? ast = ast[2] : ast = ast[3] // TCO
'fn*: return new MalFunc(...)
_default_: f, args = eval_ast(ast, env)
- if malfunc?(ast[0]): ast = ast[0].fn; env = ... // TCO
- else: return apply(f, args)
+ if malfunc?(f): ast = f.fn; env = ... // TCO
+ else: return apply(f, args)
PRINT(exp): return printer.pr_str(exp)
@@ -55,10 +55,6 @@ class Env (outer=null,binds=[],exprs=[])
--- core module ---------------------------------
ns = {'=: equal?,
- 'nil?: nil?,
- 'true?: true?,
- 'false?: false?,
- 'symbol?: symbol?,
'pr-str: (a) -> a.map(|s| pr_str(e,true)).join(" ")),
'str: (a) -> a.map(|s| pr_str(e,false)).join("")),
@@ -78,8 +74,6 @@ ns = {'=: equal?,
'list: list,
'list?: list?,
- 'hash-map: hash_map,
- 'map?: hash_map?,
'empty?: empty?,
'count: count}
diff --git a/template/step7_quote.txt b/template/step7_quote.txt
index 1e74c84..58360f2 100644
--- a/template/step7_quote.txt
+++ b/template/step7_quote.txt
@@ -25,8 +25,8 @@ EVAL(ast,env):
'if: EVAL(ast[1], env) ? ast = ast[2] : ast = ast[3] // TCO
'fn*: return new MalFunc(...)
_default_: f, args = eval_ast(ast, env)
- if malfunc?(ast[0]): ast = ast[0].fn; env = ... // TCO
- else: return apply(f, args)
+ if malfunc?(f): ast = f.fn; env = ... // TCO
+ else: return apply(f, args)
PRINT(exp): return printer.pr_str(exp)
@@ -60,10 +60,6 @@ class Env (outer=null,binds=[],exprs=[])
--- core module ---------------------------------
ns = {'=: equal?,
- 'nil?: nil?,
- 'true?: true?,
- 'false?: false?,
- 'symbol?: symbol?,
'pr-str: (a) -> a.map(|s| pr_str(e,true)).join(" ")),
'str: (a) -> a.map(|s| pr_str(e,false)).join("")),
@@ -83,8 +79,6 @@ ns = {'=: equal?,
'list: list,
'list?: list?,
- 'hash-map: hash_map,
- 'map?: hash_map?,
'cons: (a) -> concat([a[0]], a[1]),
'concat: (a) -> reduce(concat, [], a),
diff --git a/template/step8_macros.txt b/template/step8_macros.txt
index 3dc74df..3772cbc 100644
--- a/template/step8_macros.txt
+++ b/template/step8_macros.txt
@@ -19,6 +19,10 @@ eval_ast(ast,env):
EVAL(ast,env):
while true:
if not list?(ast): return eval_ast(ast, env)
+
+ ast = macroexpand(ast, env)
+ if not list?(ast): return ast
+
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
'let*: env = ...; ast = ast[2] // TCO
@@ -30,8 +34,8 @@ EVAL(ast,env):
'if: EVAL(ast[1], env) ? ast = ast[2] : ast = ast[3] // TCO
'fn*: return new MalFunc(...)
_default_: f, args = eval_ast(ast, env)
- if malfunc?(ast[0]): ast = ast[0].fn; env = ... // TCO
- else: return apply(f, args)
+ if malfunc?(f): ast = f.fn; env = ... // TCO
+ else: return apply(f, args)
PRINT(exp): return printer.pr_str(exp)
@@ -67,10 +71,6 @@ class Env (outer=null,binds=[],exprs=[])
--- core module ---------------------------------
ns = {'=: equal?,
- 'nil?: nil?,
- 'true?: true?,
- 'false?: false?,
- 'symbol?: symbol?,
'pr-str: (a) -> a.map(|s| pr_str(e,true)).join(" ")),
'str: (a) -> a.map(|s| pr_str(e,false)).join("")),
@@ -90,8 +90,6 @@ ns = {'=: equal?,
'list: list,
'list?: list?,
- 'hash-map: hash_map,
- 'map?: hash_map?,
'cons: (a) -> concat([a[0]], a[1]),
'concat: (a) -> reduce(concat, [], a),
diff --git a/template/step9_try.txt b/template/step9_try.txt
index ad0c3c7..c9cde9e 100644
--- a/template/step9_try.txt
+++ b/template/step9_try.txt
@@ -19,6 +19,10 @@ eval_ast(ast,env):
EVAL(ast,env):
while true:
if not list?(ast): return eval_ast(ast, env)
+
+ ast = macroexpand(ast, env)
+ if not list?(ast): return ast
+
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
'let*: env = ...; ast = ast[2] // TCO
@@ -31,8 +35,8 @@ EVAL(ast,env):
'if: EVAL(ast[1], env) ? ast = ast[2] : ast = ast[3] // TCO
'fn*: return new MalFunc(...)
_default_: f, args = eval_ast(ast, env)
- if malfunc?(ast[0]): ast = ast[0].fn; env = ... // TCO
- else: return apply(f, args)
+ if malfunc?(f): ast = f.fn; env = ... // TCO
+ else: return apply(f, args)
PRINT(exp): return printer.pr_str(exp)
diff --git a/template/stepA_interop.txt b/template/stepA_interop.txt
index f66d227..e28da15 100644
--- a/template/stepA_interop.txt
+++ b/template/stepA_interop.txt
@@ -19,6 +19,10 @@ eval_ast(ast,env):
EVAL(ast,env):
while true:
if not list?(ast): return eval_ast(ast, env)
+
+ ast = macroexpand(ast, env)
+ if not list?(ast): return ast
+
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
'let*: env = ...; ast = ast[2] // TCO
@@ -31,8 +35,8 @@ EVAL(ast,env):
'if: EVAL(ast[1], env) ? ast = ast[2] : ast = ast[3] // TCO
'fn*: return new MalFunc(...)
_default_: f, args = eval_ast(ast, env)
- if malfunc?(ast[0]): ast = ast[0].fn; env = ... // TCO
- else: return apply(f, args)
+ if malfunc?(f): ast = f.fn; env = ... // TCO
+ else: return apply(f, args)
PRINT(exp): return printer.pr_str(exp)
diff --git a/template/stepA_interop2.txt b/template/stepA_interop2.txt
index 71e92ac..92acee3 100644
--- a/template/stepA_interop2.txt
+++ b/template/stepA_interop2.txt
@@ -19,6 +19,10 @@ eval_ast(ast,env):
EVAL(ast,env):
while true:
if not list?(ast): return eval_ast(ast, env)
+
+ ast = macroexpand(ast, env)
+ if not list?(ast): return ast
+
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
'let*: env = ...; ast = ast[2] // TCO
@@ -31,8 +35,8 @@ EVAL(ast,env):
'if: EVAL(ast[1], env) ? ast = ast[2] : ast = ast[3] // TCO
'fn*: return new MalFunc(...)
_default_: f, args = eval_ast(ast, env)
- if malfunc?(ast[0]): ast = ast[0].fn; env = ... // TCO
- else: return apply(f, args)
+ if malfunc?(f): ast = f.fn; env = ... // TCO
+ else: return apply(f, args)
PRINT(exp): return printer.pr_str(exp)