Skip to content

Commit

Permalink
rename Symbolic to Text
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Sep 17, 2023
1 parent 802f1d8 commit 650face
Show file tree
Hide file tree
Showing 35 changed files with 211 additions and 240 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ val filename : string = "test/passing/quickstart.wast"
match Parse.Module.from_file ~filename with
| Ok script -> script
| Error e -> failwith e;;
val m : Symbolic.modul =
val m : Text.modul =
...
# let module_to_run, link_state =
match Compile.until_link Link.empty_state ~optimize:false ~name:None m with
Expand Down
20 changes: 10 additions & 10 deletions src/assigned.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ let equal_func_types (a : func_type) (b : func_type) : bool =
type t =
{ id : string option
; typ : str_type Named.t
; global : (Symbolic.global, global_type) Runtime.t Named.t
; global : (Text.global, global_type) Runtime.t Named.t
; table : (table, table_type) Runtime.t Named.t
; mem : (mem, limits) Runtime.t Named.t
; func : (Symbolic.func, Symbolic.block_type) Runtime.t Named.t
; elem : Symbolic.elem Named.t
; data : Symbolic.data Named.t
; func : (Text.func, Text.block_type) Runtime.t Named.t
; elem : Text.elem Named.t
; data : Text.data Named.t
; exports : Grouped.opt_exports
; start : Symbolic.indice option
; start : Text.indice option
}

type type_acc =
Expand Down Expand Up @@ -123,7 +123,7 @@ let check_type_id (types : str_type Named.t) (check : Grouped.type_check) =
let* id =
match id with
| Raw i -> Ok i
| Symbolic name -> (
| Text name -> (
match String_map.find_opt name types.named with
| None -> error_s "internal error: can't find type with name %s" name
| Some t -> Ok t )
Expand All @@ -143,7 +143,7 @@ let of_grouped (modul : Grouped.t) : t Result.t =
let* typ = assign_types modul in
let* global =
name "global"
~get_name:(get_runtime_name (fun ({ id; _ } : Symbolic.global) -> id))
~get_name:(get_runtime_name (fun ({ id; _ } : Text.global) -> id))
modul.global
in
let* table =
Expand All @@ -158,14 +158,14 @@ let of_grouped (modul : Grouped.t) : t Result.t =
in
let* func =
name "func"
~get_name:(get_runtime_name (fun ({ id; _ } : Symbolic.func) -> id))
~get_name:(get_runtime_name (fun ({ id; _ } : Text.func) -> id))
modul.func
in
let* elem =
name "elem" ~get_name:(fun (elem : Symbolic.elem) -> elem.id) modul.elem
name "elem" ~get_name:(fun (elem : Text.elem) -> elem.id) modul.elem
in
let* data =
name "data" ~get_name:(fun (data : Symbolic.data) -> data.id) modul.data
name "data" ~get_name:(fun (data : Text.data) -> data.id) modul.data
in
let+ () = list_iter (check_type_id typ) modul.type_checks in
{ id = modul.id
Expand Down
10 changes: 5 additions & 5 deletions src/assigned.mli
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
type t =
{ id : string option
; typ : Simplified.str_type Named.t
; global : (Symbolic.global, Simplified.global_type) Runtime.t Named.t
; global : (Text.global, Simplified.global_type) Runtime.t Named.t
; table : (Simplified.table, Simplified.table_type) Runtime.t Named.t
; mem : (Types.mem, Types.limits) Runtime.t Named.t
; func : (Symbolic.func, Symbolic.block_type) Runtime.t Named.t
; elem : Symbolic.elem Named.t
; data : Symbolic.data Named.t
; func : (Text.func, Text.block_type) Runtime.t Named.t
; elem : Text.elem Named.t
; data : Text.data Named.t
; exports : Grouped.opt_exports
; start : Symbolic.indice option
; start : Text.indice option
}

val of_grouped : Grouped.t -> t Result.t
4 changes: 2 additions & 2 deletions src/bin/owi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ let simplify_then_link_then_run ~optimize file =
list_fold_left
(fun ((to_run, state) as acc) instruction ->
match instruction with
| Symbolic.Module m ->
| Text.Module m ->
let* m, state = Compile.until_link state ~optimize ~name:None m in
Ok (m :: to_run, state)
| Symbolic.Register (name, id) ->
| Text.Register (name, id) ->
let* state = Link.register_module state ~name ~id in
Ok (to_run, state)
| _ -> Ok acc )
Expand Down
15 changes: 6 additions & 9 deletions src/bin/owi_sym.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let symbolic_extern_module : Sym_state.P.extern_func Link.extern_module =
end
| _ ->
failwith
(Printf.sprintf "Symbolic name %s" (Encoding.Expression.to_string i))
(Printf.sprintf "Text name %s" (Encoding.Expression.to_string i))
in
incr counter;
let r =
Expand Down Expand Up @@ -137,30 +137,27 @@ let simplify_then_link_then_run ~unsafe ~optimize (pc : unit Result.t Choice.t)
list_fold_left
(fun ((to_run, state) as acc) instruction ->
match instruction with
| Symbolic.Module m ->
| Text.Module m ->
let has_start =
List.exists
(function Symbolic.MStart _ -> true | _ -> false)
m.fields
List.exists (function Text.MStart _ -> true | _ -> false) m.fields
in
let has_start_id_function =
List.exists
(function
| Symbolic.MFunc { id = Some "_start"; _ } -> true | _ -> false
)
| Text.MFunc { id = Some "_start"; _ } -> true | _ -> false )
m.fields
in
let fields =
if has_start || not has_start_id_function then m.fields
else MStart (Symbolic "_start") :: m.fields
else MStart (Text "_start") :: m.fields
in
let m = { m with fields } in
let* m, state =
Compile.until_link ~unsafe state ~optimize ~name:None m
in
let m = Sym_state.convert_module_to_run m in
Ok (m :: to_run, state)
| Symbolic.Register (name, id) ->
| Text.Register (name, id) ->
let* state = Link.register_module state ~name ~id in
Ok (to_run, state)
| _ -> Ok acc )
Expand Down
2 changes: 1 addition & 1 deletion src/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(* Copyright © 2021 Léo Andrès *)
(* Copyright © 2021 Pierre Chambart *)

open Symbolic
open Text
open Syntax

type env =
Expand Down
2 changes: 1 addition & 1 deletion src/check.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(** Initial check done on a module. *)

(** check a module *)
val modul : Symbolic.modul -> Symbolic.modul Result.t
val modul : Text.modul -> Text.modul Result.t
8 changes: 4 additions & 4 deletions src/compile.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(** Utility functions to compile a module until a given step. *)

val until_check : ?unsafe:bool -> Symbolic.modul -> Symbolic.modul Result.t
val until_check : ?unsafe:bool -> Text.modul -> Text.modul Result.t

val until_simplify : ?unsafe:bool -> Symbolic.modul -> Simplified.modul Result.t
val until_simplify : ?unsafe:bool -> Text.modul -> Simplified.modul Result.t

(** compile a module with a given link state and produce a new link state and a
runnable module *)
Expand All @@ -11,7 +11,7 @@ val until_link :
-> 'f Link.state
-> optimize:bool
-> name:string option
-> Symbolic.modul
-> Text.modul
-> ('f Link.module_to_run * 'f Link.state) Result.t

(** compile and interpret a module with a given link state and produce a new
Expand All @@ -20,5 +20,5 @@ val until_interpret :
Value.Func.extern_func Link.state
-> optimize:bool
-> name:string option
-> Symbolic.modul
-> Text.modul
-> Value.Func.extern_func Link.state Result.t
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
spectest
stack
string_map
symbolic
syntax
text
trap
typecheck
types
Expand Down
32 changes: 16 additions & 16 deletions src/grouped.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ open Syntax
open Types
open Simplified

type type_check = Symbolic.indice * Symbolic.func_type
type type_check = Text.indice * Text.func_type

type opt_ind =
| Curr of int
| Indice of Symbolic.indice
| Indice of Text.indice

type opt_export =
{ name : string
Expand All @@ -24,29 +24,29 @@ type opt_exports =
; func : opt_export list
}

let curr_id (curr : int) (i : Symbolic.indice option) =
let curr_id (curr : int) (i : Text.indice option) =
match i with None -> Curr (pred curr) | Some id -> Indice id

type t =
{ id : string option
; typ : Symbolic.type_def list
; function_type : Symbolic.func_type list
; typ : Text.type_def list
; function_type : Text.func_type list
(* Types comming from function declarations.
It contains potential duplication *)
; type_checks : type_check list
(* Types checks to perform after assignment.
Come from function declarations with type indicies *)
; global : (Symbolic.global, global_type) Runtime.t Indexed.t list
; global : (Text.global, global_type) Runtime.t Indexed.t list
; table : (table, table_type) Runtime.t Indexed.t list
; mem : (mem, limits) Runtime.t Indexed.t list
; func : (Symbolic.func, Symbolic.block_type) Runtime.t Indexed.t list
; elem : Symbolic.elem Indexed.t list
; data : Symbolic.data Indexed.t list
; func : (Text.func, Text.block_type) Runtime.t Indexed.t list
; elem : Text.elem Indexed.t list
; data : Text.data Indexed.t list
; exports : opt_exports
; start : Symbolic.indice option
; start : Text.indice option
}

let imp (import : Symbolic.import) (assigned_name, desc) : 'a Imported.t =
let imp (import : Text.import) (assigned_name, desc) : 'a Imported.t =
{ modul = import.modul; name = import.name; assigned_name; desc }

let empty_module id =
Expand Down Expand Up @@ -112,11 +112,11 @@ let check_limit { min; max } =
if min > max then Error "size minimum must not be greater than maximum"
else Ok ()

let of_symbolic (modul : Symbolic.modul) : t Result.t =
let of_symbolic (modul : Text.modul) : t Result.t =
Log.debug "grouping ...@\n";
let add ((fields : t), curr) field : (t * curr) Result.t =
match field with
| Symbolic.MType typ ->
| Text.MType typ ->
let typ = typ @ fields.typ in
ok @@ ({ fields with typ }, curr)
| MGlobal global -> ok @@ add_global (Local global) fields curr
Expand Down Expand Up @@ -201,7 +201,7 @@ let of_symbolic (modul : Symbolic.modul) : t Result.t =
| MElem elem ->
let mode =
match elem.mode with
| (Symbolic.Elem_passive | Elem_declarative) as mode -> mode
| (Text.Elem_passive | Elem_declarative) as mode -> mode
| Elem_active (id, expr) ->
let id = Option.value id ~default:(Raw (curr.table - 1)) in
Elem_active (Some id, expr)
Expand All @@ -210,12 +210,12 @@ let of_symbolic (modul : Symbolic.modul) : t Result.t =
| MData data ->
let mode =
match data.mode with
| Data_passive -> Symbolic.Data_passive
| Data_passive -> Text.Data_passive
| Data_active (id, expr) ->
let id = Option.value id ~default:(Raw (curr.mem - 1)) in
Data_active (Some id, expr)
in
let data : Symbolic.data = { id = data.id; init = data.init; mode } in
let data : Text.data = { id = data.id; init = data.init; mode } in
ok @@ add_data data fields curr
| MStart start -> Ok ({ fields with start = Some start }, curr)
in
Expand Down
20 changes: 10 additions & 10 deletions src/grouped.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type opt_ind =
| Curr of int
| Indice of Symbolic.indice
| Indice of Text.indice

type opt_export =
{ name : string
Expand All @@ -14,25 +14,25 @@ type opt_exports =
; func : opt_export list
}

type type_check = Symbolic.indice * Symbolic.func_type
type type_check = Text.indice * Text.func_type

type t =
{ id : string option
; typ : Symbolic.type_def list
; function_type : Symbolic.func_type list
; typ : Text.type_def list
; function_type : Text.func_type list
(* Types comming from function declarations.
It contains potential duplication *)
; type_checks : type_check list
(* Types checks to perform after assignment.
Come from function declarations with type indicies *)
; global : (Symbolic.global, Simplified.global_type) Runtime.t Indexed.t list
; global : (Text.global, Simplified.global_type) Runtime.t Indexed.t list
; table : (Simplified.table, Simplified.table_type) Runtime.t Indexed.t list
; mem : (Types.mem, Types.limits) Runtime.t Indexed.t list
; func : (Symbolic.func, Symbolic.block_type) Runtime.t Indexed.t list
; elem : Symbolic.elem Indexed.t list
; data : Symbolic.data Indexed.t list
; func : (Text.func, Text.block_type) Runtime.t Indexed.t list
; elem : Text.elem Indexed.t list
; data : Text.data Indexed.t list
; exports : opt_exports
; start : Symbolic.indice option
; start : Text.indice option
}

val of_symbolic : Symbolic.modul -> t Result.t
val of_symbolic : Text.modul -> t Result.t
7 changes: 6 additions & 1 deletion src/indexed.mli
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
type 'a t

val get : 'a t -> 'a

val get_index : 'a t -> int

val bind : 'a t -> ('a -> 'b t) -> 'b t

val map : ('a -> 'b) -> 'a t -> 'b t
val return : int -> 'a -> 'a t

val return : int -> 'a -> 'a t

val get_at : int -> 'a t list -> 'a option

val get_at_exn : int -> 'a t list -> 'a

val has_index : int -> 'a t -> bool

val pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
8 changes: 4 additions & 4 deletions src/menhir_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%{

open Types
open Symbolic
open Text

let failwith msg = raise @@ Parse_fail msg

Expand Down Expand Up @@ -56,9 +56,9 @@ let f32 s =
module Owi = struct end
%}

%start <Symbolic.script> script
%start <Symbolic.modul> modul
%start <Symbolic.modul> inline_module
%start <Text.script> script
%start <Text.modul> modul
%start <Text.modul> inline_module

%%

Expand Down
6 changes: 3 additions & 3 deletions src/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ struct
end

module Script = Make (struct
type t = Symbolic.script
type t = Text.script

let rule = Menhir_parser.script
end)

module Module = Make (struct
type t = Symbolic.modul
type t = Text.modul

let rule = Menhir_parser.modul
end)

module Inline_module = Make (struct
type t = Symbolic.modul
type t = Text.modul

let rule = Menhir_parser.inline_module
end)
Loading

0 comments on commit 650face

Please sign in to comment.