Skip to content

Commit

Permalink
Merge pull request #10 from AdUhTkJm/main
Browse files Browse the repository at this point in the history
Added support for closures
  • Loading branch information
mengzhuo authored Jan 3, 2025
2 parents a1a0510 + 1ee64cc commit 5022fc0
Show file tree
Hide file tree
Showing 22 changed files with 389 additions and 309 deletions.
4 changes: 2 additions & 2 deletions src/basic_byteseq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ let to_string t =
| Deferred (len, f) -> Vec.push defer (base, len, f)
in
fill ~base:0 t;
Vec.iter defer (fun (base, len, f) ->
Vec.iter (fun (base, len, f) ->
let encoded = f len in
assert (String.length encoded <= len);
Bytes.blit_string encoded 0 bytes base (String.length encoded));
Bytes.blit_string encoded 0 bytes base (String.length encoded)) defer;
Bytes.unsafe_to_string bytes

module O = struct
Expand Down
4 changes: 2 additions & 2 deletions src/basic_vec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let sort d cmp =

let reverse_in_place src = Arr.reverse_range src.arr 0 src.len

let iter d f =
let iter f d =
let arr = d.arr in
for i = 0 to d.len - 1 do
f arr.!(i)
Expand Down Expand Up @@ -172,7 +172,7 @@ let push (d : 'a t) v =

(** Similar to push, but for a whole vector. *)
let append vec other =
iter other (fun x -> push vec x)
iter (fun x -> push vec x) other

let insert (d : 'a t) idx elt =
let enlarge size =
Expand Down
2 changes: 1 addition & 1 deletion src/check_match.ml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ let check_match ~(diagnostics : Local_diagnostics.t) (ty : Stype.t)
(if Vec.length missing_cases > 0 && catch_all_loc = None then
let empty_match = cases = [] in
let cases =
Vec.iter missing_cases
(fun f -> Vec.iter f missing_cases)
|> Iter.flat_map ~f:(fun db ->
Patmatch_static_info.synthesize_missing_case_pattern db ~genv
~empty_match ty
Expand Down
4 changes: 2 additions & 2 deletions src/driver_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ let link_core ~(shrink_wasm : bool) ~(elim_unused_let : bool)
~(exported_functions : string Basic_hash_string.t) ~(target : target) : unit
=
let targets : Core_link.linking_target Basic_vec.t = Basic_vec.empty () in
Basic_vec.iter core_inputs (function
Basic_vec.iter (function
| Core_Path path -> Basic_vec.push targets (Core_link.File_path path)
| Core_Content content ->
Basic_vec.push targets
(Core_link.Core_format (Core_format.of_string content)));
(Core_link.Core_format (Core_format.of_string content))) core_inputs;
let link_output = Core_link.link ~targets in
let mono_core =
monofy_core_link ~link_output
Expand Down
6 changes: 3 additions & 3 deletions src/dwarfsm_encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ let module_with_source_map ~file ?source_map_url ?source_loader m =
| None -> ("moonbit:///@" ^ pkg ^ "/" ^ file, None)
in
let last_code_pos = ref None in
Vec.iter code_pos
(fun ((rel_pc, { pkg; file; line = line1; col = column }) as code_pos) ->
Vec.iter
(fun ((rel_pc, ({ pkg; file; line = line1; col = column }: Ast.source_pos)) as code_pos) ->
match !last_code_pos with
| Some last_code_pos when equal_code_pos code_pos last_code_pos -> ()
| _ ->
Expand Down Expand Up @@ -137,7 +137,7 @@ let module_with_source_map ~file ?source_map_url ?source_loader m =
mappings_buf ^^= field addr last_addr
^^ field file_index last_src_file
^^ field line last_src_line
^^ field column last_src_column);
^^ field column last_src_column) code_pos;
source_map_buf ^^= string ",\"sources\":[" ^^ !sources_buf ^^ string "]";
source_map_buf
^^= string ",\"sourcesContent\":["
Expand Down
5 changes: 3 additions & 2 deletions src/dwarfsm_encode_wasm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,10 @@ struct
funcsec_buf ^^= int_uleb128 (Vec.length ctx.funcs);
codesec_buf ^^= int_uleb128 (Vec.length ctx.funcs);
let low_pc = Byteseq.length codesec_buf.contents in
Vec.iter ctx.funcs (fun fn ->
Vec.iter (fun (fn: func) ->
funcsec_buf ^^= typeuse fn.type_;
codesec_buf ^^= encode_code ~base:(Byteseq.length !codesec_buf) fn);
codesec_buf ^^= encode_code ~base:(Byteseq.length !codesec_buf) fn)
ctx.funcs;
let high_pc = Byteseq.length codesec_buf.contents in
ctx.aux.low_pc <- low_pc;
ctx.aux.high_pc <- high_pc
Expand Down
7 changes: 3 additions & 4 deletions src/lambda_lift.ml
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,21 @@ let lift_item (acc : Core.top_item Vec.t) (item : Core.top_item) =
lift_expr expr ~lift_to_top:(Toplevel { name_hint = "*init*" })
in
Vec.push acc (Ctop_expr { expr; is_main; loc_ });
Vec.iter subtops (fun subtop -> Vec.push acc (subtop_to_top subtop ~loc_))
Vec.iter (fun subtop -> Vec.push acc (subtop_to_top subtop ~loc_)) subtops
| Ctop_let { binder; expr; is_pub_; loc_ } ->
let expr, subtops =
lift_expr expr
~lift_to_top:(Toplevel { name_hint = Ident.base_name binder })
in
Vec.push acc (Ctop_let { binder; expr; is_pub_; loc_ });
Vec.iter subtops (fun subtop -> Vec.push acc (subtop_to_top subtop ~loc_))
Vec.iter (fun subtop -> Vec.push acc (subtop_to_top subtop ~loc_)) subtops
| Ctop_fn { binder; func; subtops = _; ty_params_; is_pub_; loc_ } ->
if Tvar_env.is_empty ty_params_ then (
let expr, subtops =
lift_expr func.body
~lift_to_top:(Toplevel { name_hint = Ident.base_name binder })
in
Vec.iter subtops (fun subtop ->
Vec.push acc (subtop_to_top subtop ~loc_));
Vec.iter (fun subtop -> Vec.push acc (subtop_to_top subtop ~loc_)) subtops;
Vec.push acc
(Ctop_fn
{
Expand Down
Loading

0 comments on commit 5022fc0

Please sign in to comment.