ref: ae95184e6aa4685bbd13ed4b58df2fcc3e1f625c
parent: 0623a5a458b36ae4cd3f2b4ef0a34b7e124a99ab
author: smazga <[email protected]>
date: Thu Aug 13 18:31:45 EDT 2020
even more macro stuff
--- a/m9.ml
+++ b/m9.ml
@@ -35,7 +35,6 @@
let is_macro_call ast env =
match ast with
| T.List { T.value = s :: args } ->
- print_endline ("is_macro_call: sym: " ^ Printer.print s true ^ " args: " ^ Printer.dump args);
(match
try Env.get env s with
| _ -> T.Nil
@@ -43,11 +42,24 @@
| T.Proc { T.meta = T.Map { T.value = meta } } ->
Types.M9map.mem Core.kw_macro meta
&& Types.to_bool (Types.M9map.find Core.kw_macro meta)
- (* | T.List { T.value = foo } -> print_endline ("foo: " ^ Printer.dump foo); false *)
- | T.List { T.value = [ T.Symbol { T.value = "syntax-rules" }; args ] }-> true
+ | T.List { T.value = macro } -> (match macro with
+ | kw :: _ -> kw = Types.symbol "syntax-rules"
+ | _ -> false)
| _ -> false)
| _ -> false
;;
+let eval_macro sym args macro env =
+ let parsed = Str.global_replace (Str.regexp "(_") ("(" ^ Printer.print sym true) (Printer.dump macro) in
+ print_endline ("eval_macro: sym:" ^ Printer.print sym true ^ " args:" ^ Printer.dump args ^ " macro:" ^ Printer.dump macro);
+ print_endline (" parsed: " ^ parsed)
+(* let sub_env = Env.make (Some env) in
+ * match macro with
+ * | _ :: literals :: cases ->
+ * (match cases with
+ * | hd :: tl ->
+ * (\* TODO: handle literals *\)
+ * )
+ * | _ -> () *)
let rec macroexpand ast env =
if is_macro_call ast env
@@ -55,16 +67,17 @@
print_endline (" YES!: " ^ Printer.print ast true);
match ast with
| T.List { T.value = s :: args } ->
+ print_endline ("one: s: " ^ Printer.print s true ^ " args: " ^ Printer.dump args);
(match
try Env.get env s with
| _ -> T.Nil
with
- | T.Proc { T.value = f } -> macroexpand (f args) env
+ | T.Proc { T.value = f } -> macroexpand (f args) env
+ | T.List { T.value = macro } -> eval_macro s args macro env; ast
| _ -> ast)
| _ -> ast)
else
- (print_endline (" no: " ^ Printer.print ast true);
- ast)
+ ast
;;
let rec eval_ast ast env =