Skip to content

Commit

Permalink
Make it work on OCaml v4.14.0 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
hirrolot committed Oct 17, 2024
1 parent 2bdf05a commit 705a5f0
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Algebraic simplification now requires operands to be either variables or constants, not compound values.
- Eliminate let-bindings for "innocent terms" via postprocessing.
- Innocent terms are variables, integer constants, and zero-arity constructor calls.
- The minimum supported OCaml version is now 4.14.0.

### Removed

Expand Down
8 changes: 4 additions & 4 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ let cut_list list =
Array.(to_list first_10 @ [ middle ] @ to_list last_10))
;;

let its_over ?(reduction_path = []) msg =
let its_over ?reduction_path msg =
Spectrum.Simple.eprintf "@{<bold,red>error:@} %s\n" msg;
if not (List.is_empty reduction_path)
then
reduction_path
|> Option.iter (fun reduction_path ->
Spectrum.Simple.eprintf
"%s@{<bold,aqua>note:@} While reducing %s\n"
tab
(String.concat " -> " (cut_list reduction_path));
(String.concat " -> " (cut_list reduction_path)));
exit 1
;;

Expand Down
4 changes: 2 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 3.15)
(lang dune 3.14)

(using menhir 3.0)

Expand All @@ -24,7 +24,7 @@
(synopsis "A modern supercompiler for call-by-value functional languages")
(depends
(ocaml
(>= 5.1))
(>= 4.14))
dune
pprint
(checked_oint
Expand Down
6 changes: 3 additions & 3 deletions lib/abstract_syntax/program.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ let output ~oc ({ f_rules; g_rules; _ } : t) =
in
let f_rules =
f_rules
|> F_rules.to_list
|> F_rules.bindings
|> List.map (fun (f, (params, body)) -> f, params, Term.to_string body)
in
let g_rules =
g_rules
|> G_rules_by_name.to_list
|> G_rules_by_name.bindings
|> List.map (fun (g, rules) ->
( g
, rules
|> G_rules_by_pattern.to_list
|> G_rules_by_pattern.bindings
|> List.map (fun (c, (c_params, params, body)) ->
c, c_params, params, Term.to_string body) ))
in
Expand Down
20 changes: 10 additions & 10 deletions lib/codegen/c_codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ end = struct

and gen_data_call ~ctx (c, args) =
remember_constructor c;
if List.is_empty args
then
match args with
| [] ->
( c_function_call (id "MZ_EMPTY_DATA", [ c_identifier_expression (gen_op c) ])
, Symbol_set.empty )
else (
| _ ->
let args_gen = List.map (gen_thunk_function ~ctx) args in
let args_fv =
Symbol_set.(
Expand All @@ -216,7 +216,7 @@ end = struct
; c_integer_constant_expression (index (List.length args))
]
@ List.map (gen_thunk_call ~ctx) args_gen )
, args_fv ))
, args_fv )

and gen_thunk_call ~ctx (thunk, env) =
match thunk with
Expand Down Expand Up @@ -385,9 +385,9 @@ end = struct
let declaration_specifiers = [ c_static; c_typedef_name (id "mz_Value") ] in
let identifier = gen_op f in
let parameter_list =
if List.is_empty params
then []
else
match params with
| [] -> []
| _ ->
[ c_parameter_declaration
( [ c_typedef_name (id "mz_ArgsPtr") ]
, Some (c_identifier_declarator (id "args")) )
Expand Down Expand Up @@ -416,9 +416,9 @@ end = struct
;;

let main_wrapper_body =
if List.is_empty main_params
then [ c_return_statement (c_function_call (gen_op main_symbol, [])) ]
else
match main_params with
| [] -> [ c_return_statement (c_function_call (gen_op main_symbol, [])) ]
| _ ->
[ c_return_statement
(c_function_call
( id "MZ_CALL_MAIN"
Expand Down
6 changes: 3 additions & 3 deletions lib/evaluator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ let run_exn (input : Raw_program.t) =
go ~env body
in
let main_params, t = find_rule ~program (Symbol.of_string "main") in
if not (List.is_empty main_params)
then (Util.panic [@coverage off]) "The main function cannot accept parameters";
go ~env:Symbol_map.empty t
match main_params with
| [] -> go ~env:Symbol_map.empty t
| _ -> (Util.panic [@coverage off]) "The main function cannot accept parameters"
;;
4 changes: 1 addition & 3 deletions lib/mazeppa.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ exception Panic of string

let wrap_panic f =
try f () with
| Util.Panic { msg; reduction_path } ->
assert (List.is_empty reduction_path);
raise (Panic msg)
| Util.Panic { msg; reduction_path = _ } -> raise (Panic msg)
;;

let supercompile (input : Raw_program.t) : Raw_program.t =
Expand Down
3 changes: 2 additions & 1 deletion lib/raw_syntax/converter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ let to_program (input : t) : Program.t =
let rules =
cases
|> List.map (fun ((c, c_params), t) -> c, (c_params, cases_fv_list, t))
|> Program.G_rules_by_pattern.of_list
|> List.to_seq
|> Program.G_rules_by_pattern.of_seq
in
let fresh_g = Gensym.emit g_gensym in
g_rules := Program.G_rules_by_name.add fresh_g rules !g_rules;
Expand Down
4 changes: 2 additions & 2 deletions mazeppa.opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ homepage: "https://github.com/mazeppa-dev/mazeppa"
doc: "https://github.com/mazeppa-dev/mazeppa"
bug-reports: "https://github.com/mazeppa-dev/mazeppa/issues"
depends: [
"ocaml" {>= "5.1"}
"dune" {>= "3.15"}
"ocaml" {>= "4.14"}
"dune" {>= "3.14"}
"pprint"
"checked_oint" {>= "0.2.0"}
"ppx_deriving"
Expand Down
4 changes: 3 additions & 1 deletion test/test_mazeppa.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ let list xs =
(Raw_term.call ("Nil", []))
;;

let make_subst list = list |> List.map (fun (x, t) -> symbol x, t) |> Symbol_map.of_list
let make_subst list =
list |> List.map (fun (x, t) -> symbol x, t) |> List.to_seq |> Symbol_map.of_seq
;;

let print_constants () =
let check ~expected const =
Expand Down

0 comments on commit 705a5f0

Please sign in to comment.