ref: 02e52de48838943242250b85d2bf23c97755111f
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 ("__ arg length: " ^ string_of_int (List.length args)); 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 (" _ pattern: " ^ Printer.dump pattern); print_endline ("__ pattern length: " ^ string_of_int (List.length pattern) ^ " template: " ^ Printer.dump template) | T.List { T.value = [ T.List { T.value = pattern }; atom ] } -> let rec wrangle p a pp = (match (p, a) with | sh :: st, ph :: pt -> print_endline (">>>>> sh:" ^ (Printer.print sh true) ^ " ph:" ^ (Printer.print ph true)); wrangle st pt pp | sh :: st, [] -> print_endline (">>>>> sh:" ^ (Printer.print sh true)); let ss = Printer.print sh true in let x = if ss = "_" then sym else (if List.mem sh (Core.seq literals) then sh else (T.String "")) in wrangle st args [] | _, _ -> "<end>") in print_endline ("wrangle: " ^ wrangle pattern (Core.seq args) []); print_endline (" _ pattern: " ^ Printer.dump pattern); print_endline ("__ atomic pattern length: " ^ string_of_int (List.length pattern) ^ " atom: " ^ Printer.print atom true) | _ -> ()); let foo = Reader.read (Printer.print hd false) in print_endline (" foo: " ^ Printer.print foo true); (* print_endline ("__ transform length: " ^ string_of_int (List.length foo)); *) match_transform tl | [] -> () in match_transform (Core.seq transformers) with | Not_found -> ()) | _ -> ()