This commit is contained in:
2025-08-30 17:29:31 +02:00
parent 0a342f4164
commit b19a6ad0a0
2 changed files with 13 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
(:t "- " hd)) (:t "- " hd))
(:macro seq (hd .. tl) (:macro seq (hd .. tl)
(:seq hd) (:seq tl)) (':seq hd) (':seq tl))
(:macro @ (k) (:macro @ (k)
(:t k ":")) (:t k ":"))

View File

@@ -702,7 +702,10 @@ module SExprMacroExp = struct
Cons(Id(l), Cons(a,b)) -> l, (a,b) Cons(Id(l), Cons(a,b)) -> l, (a,b)
| _ -> raise @@ Misformated_Macro s | _ -> raise @@ Misformated_Macro s
in in
Nil, false, (a :: ctx) let ctx = (a :: ctx)
|> List.sort (fun a b -> macro_req_score (fst (snd b)) - macro_req_score (fst (snd a)))
in
Nil, false, ctx
end end
| Cons(Id(i), r) when String.starts_with ~prefix:":" i -> | Cons(Id(i), r) when String.starts_with ~prefix:":" i ->
let i = String.sub i 1 ((String.length i) - 1) in let i = String.sub i 1 ((String.length i) - 1) in
@@ -736,6 +739,13 @@ module SExprMacroExp = struct
| Cons(_), Cons(Id(".."), Cons(Id(rem),Nil)) -> [rem, args] | Cons(_), Cons(Id(".."), Cons(Id(rem),Nil)) -> [rem, args]
| Cons(v,rl), Cons(Id(k), rr) -> [k,li1 v] @ match_macro_arg rl rr | Cons(v,rl), Cons(Id(k), rr) -> [k,li1 v] @ match_macro_arg rl rr
| _ -> raise Macro_Doesnt_App | _ -> raise Macro_Doesnt_App
and macro_req_score args =
let open SExpr in
match args with
Nil -> 0
| Cons(Id(".."), Cons(Id(rem),Nil)) -> 1
| Cons(Id _, rr) -> 100 + macro_req_score rr
| _ -> raise Not_SExpr_List
and expand_macro_eval expr defs = and expand_macro_eval expr defs =
let open SExpr in let open SExpr in
let perfm expr = let perfm expr =
@@ -746,7 +756,7 @@ module SExprMacroExp = struct
Some x -> x Some x -> x
| None -> li1 expr | None -> li1 expr
end end
| x when is_list x -> expand_macro_eval x defs | x when is_list x -> li1 (expand_macro_eval x defs)
| x -> li1 x | x -> li1 x
end end
in in