Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/codegen/comp_wasm_prim.re
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ let op_map = {
};

let get_op = name =>
try(OpHash.find(op_map, name)) {
| Not_found =>
failwith(Printf.sprintf("internal: Wasm instruction not registered"))
switch (OpHash.find_opt(op_map, name)) {
| Some(op) => op
| None => failwith("internal: Wasm instruction not registered")
};

let compile_wasm_prim1 = (wasm_mod, env, instr, ret_type, arg) => {
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/codegen/concatlist.re
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ let rec rev = cl =>
let rec hd = cl =>
switch (cl) {
| Singleton(e)
| Cons(e, _) => e
| Snoc(l, e) when is_empty(l) => e
| Cons(e, _) => Some(e)
| Snoc(l, e) when is_empty(l) => Some(e)
| Snoc(l, _) => hd(l)
| Append(l1, _) when !is_empty(l1) => hd(l1)
| Append(_, l2) => hd(l2)
| Wrapped([hd, ..._]) => hd
| Wrapped([hd, ..._]) => Some(hd)
| Wrapped([])
| Empty => raise(Not_found)
| Empty => None
};

let rec tl = cl =>
Expand Down
6 changes: 1 addition & 5 deletions compiler/src/codegen/concatlist.rei
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ let rev: t('a) => t('a);

/** Returns the first element of the given concatlist. If the list has
no elements, [Failure "hd"] is raised. */
/** Returns all but the first element of the given concatlist. If the list has no tail,
[Failure "tl"] is raised. */

let hd: t('a) => 'a;
let hd: t('a) => option('a);

/** Returns all but the first element of the given concatlist. If the list has no tail,
[Failure "tl"] is raised. */
/** Returns the last element of the given concatlist. If the list has no tail,
[Failure "last"] is raised. */

let tl: t('a) => t('a);

Expand Down
30 changes: 13 additions & 17 deletions compiler/src/codegen/transl_anf.re
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,19 @@ let get_stack_size = () => {
};

let find_id = (id, env) =>
try(Ident.find_same(id, env.ce_binds)) {
| Not_found =>
let alloc = Ident.find_same(id, global_table^);
MGlobalBind(global_name(id), alloc);
switch (Ident.find_same_opt(id, env.ce_binds)) {
| Some(v) => v
| None =>
switch (Ident.find_same_opt(id, global_table^)) {
| Some(alloc) => MGlobalBind(global_name(id), alloc)
| None => raise(Not_found)
}
};

let worklist_reset = () => Queue.clear(compilation_worklist);
let worklist_enqueue = elt => Queue.add(elt, compilation_worklist);
let worklist_empty = () => Queue.is_empty(compilation_worklist);
let worklist_pop = () =>
switch (Queue.take_opt(compilation_worklist)) {
| None => raise(Not_found)
| Some(hd) => hd
};
let worklist_pop = () => Queue.take_opt(compilation_worklist);

let wasm_import_name = (mod_, name) =>
Printf.sprintf("wimport_%s_%s", mod_, name);
Expand Down Expand Up @@ -734,14 +733,11 @@ let compile_worklist_elt = ({body, env}: worklist_elt) =>
| Precompiled(block, stack_size) => (block, stack_size)
};

let fold_left_pop = (f, base) => {
let rec help = acc =>
if (worklist_empty()) {
acc;
} else {
help(f(acc, worklist_pop()));
};
help(base);
let rec fold_left_pop = (f, base) => {
switch (worklist_pop()) {
| None => base
| Some(elt) => fold_left_pop(f, f(base, elt))
};
};

let compile_remaining_worklist = () => {
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/language_server/hover.re
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@ let declaration_lens = (ident: Ident.t, decl: Types.type_declaration) => {

let include_lens = (env: Env.t, path: Path.t) => {
let header = grain_code_block("module " ++ Path.name(path));
let decl = Env.find_module(path, None, env);
let module_decl =
switch (Modules.get_provides(decl)) {
| [_, ..._] => Some(module_lens(decl))
| [] => None
switch (Env.find_module_opt(path, None, env)) {
| Some(decl) =>
let module_decl =
switch (Modules.get_provides(decl)) {
| [_, ..._] => Some(module_lens(decl))
| [] => None
};
switch (module_decl) {
| Some(mod_sig) => Some(markdown_join(header, mod_sig))
| None => Some(header)
};
switch (module_decl) {
| Some(mod_sig) => markdown_join(header, mod_sig)
| None => header
| None => None
};
};

Expand Down Expand Up @@ -188,10 +191,7 @@ let process =
| [Module({decl, loc}), ..._] =>
send_hover(~id, ~range=Utils.loc_to_range(loc), module_lens(decl))
| [Include({path, loc}), ..._] =>
let hover_lens =
try(Some(include_lens(program.env, path))) {
| Not_found => None
};
let hover_lens = include_lens(program.env, path);
switch (hover_lens) {
| Some(lens) => send_hover(~id, ~range=Utils.loc_to_range(loc), lens)
| None => send_no_result(~id)
Expand Down
9 changes: 4 additions & 5 deletions compiler/src/language_server/sourcetree.re
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ module Sourcetree: Sourcetree = {
switch (stmt.ttop_desc) {
| TTopModule(decl) =>
let path = Path.PIdent(decl.tmod_id);
try({
let mod_decl = Env.find_module(path, None, stmt.ttop_env);
switch (Env.find_module_opt(path, None, stmt.ttop_env)) {
| Some(mod_decl) =>
segments :=
[
(
Expand All @@ -545,9 +545,8 @@ module Sourcetree: Sourcetree = {
}),
),
...segments^,
];
}) {
| Not_found => ()
]
| None => ()
};
| TTopInclude(inc) =>
segments :=
Expand Down
10 changes: 4 additions & 6 deletions compiler/src/middle_end/optimize_constants.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ module ConstantPropagationArg: Anf_mapper.MapArgument = {
let leave_imm_expression = ({imm_desc: desc} as i) =>
switch (desc) {
| ImmId(id) =>
try({
let value = Ident.find_same(id, known_constants^);
{
switch (Ident.find_same_opt(id, known_constants^)) {
| Some(value) => {
...i,
imm_desc: value,
};
}) {
| Not_found => i
}
| None => i
}
| _ => i
};
Expand Down
11 changes: 6 additions & 5 deletions compiler/src/parsing/identifier.re
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ let last =
| IdentExternal(_, s) => s.txt;

let rec split_at_dots = (s, pos) =>
try({
let dot = String.index_from(s, pos, '.');
[String.sub(s, pos, dot - pos), ...split_at_dots(s, dot + 1)];
}) {
| Not_found => [String.sub(s, pos, String.length(s) - pos)]
switch (String.index_from_opt(s, pos, '.')) {
| Some(dot) => [
String.sub(s, pos, dot - pos),
...split_at_dots(s, dot + 1),
]
| None => [String.sub(s, pos, String.length(s) - pos)]
};

let flatten = n => {
Expand Down
Loading