Skip to content

Commit

Permalink
Implement more of Spec.t initialization
Browse files Browse the repository at this point in the history
Reduction initialization still isn't implemented, nor any reporting besides
`prec`.
  • Loading branch information
Jason Evans committed Mar 29, 2022
1 parent 3c0401f commit 45b0097
Show file tree
Hide file tree
Showing 17 changed files with 578 additions and 50 deletions.
21 changes: 18 additions & 3 deletions bootstrap/bin/hocc/nonterm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ open Basis
open Basis.Rudiments

module T = struct
type type_ = {
module_: string;
type_: string;
}

type t = {
index: uns;
name: string;
start: bool;
type_: type_ option;
prec: Prec.t option;
prods: (Prod.t, Prod.cmper_witness) Ordset.t;
stmt: Parse.nonterm;
}

let hash_fold {index; _} state =
Expand All @@ -16,17 +23,25 @@ module T = struct
let cmp {index=index0; _} {index=index1; _} =
Uns.cmp index0 index1

let pp {index; name; start; prec; prods} formatter =
let pp_type {module_; type_} formatter =
formatter
|> Fmt.fmt "{module_=" |> String.pp module_
|> Fmt.fmt "; type_=" |> String.pp type_
|> Fmt.fmt "}"

let pp {index; name; start; type_; prec; prods; stmt} formatter =
formatter
|> Fmt.fmt "{index=" |> Uns.pp index
|> Fmt.fmt "; name=" |> String.pp name
|> Fmt.fmt "; start=" |> Bool.pp start
|> Fmt.fmt "; type_=" |> (Option.pp pp_type) type_
|> Fmt.fmt "; prec=" |> (Option.pp Prec.pp) prec
|> Fmt.fmt "; prods=" |> (List.pp Prod.pp) (Ordset.to_list prods)
|> Fmt.fmt "; stmt=" |> Parse.fmt_nonterm stmt
|> Fmt.fmt "}"
end
include T
include Identifiable.Make(T)

let init ~index ~name ~start ~prec ~prods =
{index; name; start; prec; prods}
let init ~index ~name ~start ~type_ ~prec ~prods ~stmt =
{index; name; start; type_; prec; prods; stmt}
11 changes: 9 additions & 2 deletions bootstrap/bin/hocc/nonterm.mli
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
open Basis
open Basis.Rudiments

type type_ = {
module_: string;
type_: string;
}

type t = {
index: uns;
name: string;
start: bool;
type_: type_ option;
prec: Prec.t option;
prods: (Prod.t, Prod.cmper_witness) Ordset.t;
stmt: Parse.nonterm;
}

include IdentifiableIntf.S with type t := t

val init: index:uns -> name:string -> start:bool -> prec:Prec.t option
-> prods:(Prod.t, Prod.cmper_witness) Ordset.t -> t
val init: index:uns -> name:string -> start:bool -> type_:type_ option -> prec:Prec.t option
-> prods:(Prod.t, Prod.cmper_witness) Ordset.t -> stmt:Parse.nonterm -> t
8 changes: 5 additions & 3 deletions bootstrap/bin/hocc/prod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module T = struct
lhs_index: uns;
rhs_indexes: uns array;
prec: Prec.t option;
stmt: Parse.prod;
}

let hash_fold {index; _} state =
Expand All @@ -15,16 +16,17 @@ module T = struct
let cmp {index=index0; _} {index=index1; _} =
Uns.cmp index0 index1

let pp {index; lhs_index; rhs_indexes; prec} formatter =
let pp {index; lhs_index; rhs_indexes; prec; stmt} formatter =
formatter
|> Fmt.fmt "{index=" |> Uns.pp index
|> Fmt.fmt "; lhs_index=" |> Uns.pp lhs_index
|> Fmt.fmt "; rhs_indexes=" |> (Array.pp Uns.pp) rhs_indexes
|> Fmt.fmt "; prec=" |> (Option.pp Prec.pp) prec
|> Fmt.fmt "; stmt=" |> Parse.fmt_prod stmt
|> Fmt.fmt "}"
end
include T
include Identifiable.Make(T)

let init ~index ~lhs_index ~rhs_indexes ~prec =
{index; lhs_index; rhs_indexes; prec}
let init ~index ~lhs_index ~rhs_indexes ~prec ~stmt =
{index; lhs_index; rhs_indexes; prec; stmt}
4 changes: 3 additions & 1 deletion bootstrap/bin/hocc/prod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ type t = {
lhs_index: uns;
rhs_indexes: uns array;
prec: Prec.t option;
stmt: Parse.prod;
}

include IdentifiableIntf.S with type t := t

val init: index:uns -> lhs_index:uns -> rhs_indexes:uns array -> prec:Prec.t option -> t
val init: index:uns -> lhs_index:uns -> rhs_indexes:uns array -> prec:Prec.t option
-> stmt:Parse.prod -> t
52 changes: 52 additions & 0 deletions bootstrap/bin/hocc/reduction.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
open Basis
open Basis.Rudiments

module T = struct
type type_ = {
module_: string;
type_: string;
}

type param = {
name: string option;
type_: type_;
}

type t = {
index: uns;
lhs: type_;
rhs: param array;
code: Parse.code option;
}

let hash_fold {index; _} state =
Uns.hash_fold index state

let cmp {index=index0; _} {index=index1; _} =
Uns.cmp index0 index1

let pp_type {module_; type_} formatter =
formatter
|> Fmt.fmt "{module_=" |> String.pp module_
|> Fmt.fmt "; type_=" |> String.pp type_
|> Fmt.fmt "}"

let pp_param {name; type_} formatter =
formatter
|> Fmt.fmt "{name=" |> (Option.pp String.pp) name
|> Fmt.fmt "; type_=" |> pp_type type_
|> Fmt.fmt "}"

let pp {index; lhs; rhs; code} formatter =
formatter
|> Fmt.fmt "{index=" |> Uns.pp index
|> Fmt.fmt "; lhs=" |> pp_type lhs
|> Fmt.fmt "; rhs=" |> (Array.pp pp_param) rhs
|> Fmt.fmt "; code=" |> (Option.pp Parse.fmt_code) code
|> Fmt.fmt "}"
end
include T
include Identifiable.Make(T)

let init ~index ~lhs ~rhs ~code =
{index; lhs; rhs; code}
23 changes: 23 additions & 0 deletions bootstrap/bin/hocc/reduction.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
open Basis
open Basis.Rudiments

type type_ = {
module_: string;
type_: string;
}

type param = {
name: string option;
type_: type_;
}

type t = {
index: uns;
lhs: type_;
rhs: param array;
code: Parse.code option;
}

include IdentifiableIntf.S with type t := t

val init: index:uns -> lhs:type_ -> rhs:param array -> code:Parse.code option -> t
Loading

0 comments on commit 45b0097

Please sign in to comment.