ref: 6a277f5b5fd8b91b71aba6352118f004b1f4fc3a
dir: /macro.ml/
module T = Types.Types let rec expand ast env args sym meta = print_endline (" THIS IS A MACRO: " ^ Printer.print sym true); print_endline (" META: " ^ Printer.print meta true); print_endline (" ARGS: " ^ Printer.dump args); print_endline (" AST: " ^ Printer.print ast true); (* and expand args env sym meta = *) (* let sub_env = Env.make (Some env) in * Env.set * sub_env * (Types.symbol "_") * (Types.proc (function * | [ ast ] -> eval ast sub_env * | _ -> T.Nil)); *) match meta with | T.Map { T.value = m } -> (try let literals = Types.M9map.find Types.macro_literals m in let transformers = Types.M9map.find Types.macro_transformers m in print_endline ("--EVAL_MACRO: literals: " ^ Printer.print literals true ^ " transformers: " ^ Printer.print transformers true); let rec match_transform transforms = match transforms with | hd :: tl -> print_endline ("__ hd: " ^ Printer.print hd true); print_endline ("__ args: " ^ Printer.dump args); (match hd with | T.List { T.value = [ T.List { T.value = pattern }; T.List { T.value = template } ] } -> print_endline (" _ multi pattern: " ^ Printer.dump pattern) | T.List { T.value = [ T.List { T.value = pattern }; atom ] } -> let rec foobar p a pp = (match p, a with | ph :: pt, ah :: at -> print_endline "one"; foobar pt at (pp @ [T.Nil]) | ph :: pt, [] -> print_endline "two"; foobar pt [] (pp @ [T.Nil]) | _, _ -> print_endline ("three: " ^ Printer.dump pp); pp) in print_endline ("foobar: " ^ Printer.dump (foobar pattern args [])); print_endline "out"; (* let tweaked = Str.global_replace (Str.regexp "^_") (Printer.print sym true) (Printer.dump pattern) in * print_endline ("tweaked: " ^ tweaked); *) print_endline (" _ single pattern: " ^ Printer.dump pattern) | _ -> ()); match_transform tl | [] -> () in match_transform (Core.seq transformers) with | Not_found -> ()) | _ -> ()