Commit 13988a4f authored by POTTIER Francois's avatar POTTIER Francois

Split off [InspectionTableFormat] and [InspectionTableInterpreter].

This might allow the ocaml compiler to not link these modules when
--inspection is off.
parent 40334621
......@@ -85,6 +85,8 @@ LIBFILES := \
src/IncrementalEngine.ml \
src/engineTypes.ml \
src/engine.{ml,mli} \
src/inspectionTableFormat.ml \
src/inspectionTableInterpreter.{ml,mli} \
src/tableFormat.ml \
src/tableInterpreter.{ml,mli} \
src/convert.{ml,mli}
......
......@@ -8,6 +8,8 @@ In the following, "the Library" refers to the following files:
src/IncrementalEngine.ml
src/engineTypes.ml
src/engine.{ml,mli}
src/inspectionTableFormat.ml
src/inspectionTableInterpreter.{ml,mli}
src/tableFormat.ml
src/tableInterpreter.{ml,mli}
src/convert.{ml,mli}
......
* Split TableFormat and TableInterpreter?
* Possibly re-implement the function [symbol] using a packed
int array (going through [terminal] or [nonterminal] later).
......
......@@ -26,6 +26,8 @@
<IncrementalEngine.cmx>: for-pack(MenhirLib)
<engineTypes.cmx>: for-pack(MenhirLib)
<engine.cmx>: for-pack(MenhirLib)
<inspectionTableFormat.cmx>: for-pack(MenhirLib)
<inspectionTableInterpreter.cmx>: for-pack(MenhirLib)
<tableFormat.cmx>: for-pack(MenhirLib)
<tableInterpreter.cmx>: for-pack(MenhirLib)
<convert.cmx>: for-pack(MenhirLib)
(* This signature defines the format of the tables that are produced (in
addition to the tables described in [TableFormat]) when the command line
switch [--inspection] is enabled. It is used as an argument to
[InspectionTableInterpreter.Make]. *)
module type TABLES = sig
(* These types are used in the types of the functions that follow.
In the generated [.ml] file, ['a lr1state] will be implemented
e.g. as [int], whereas the types ['a symbol] and [xsymbol] are
(generated) algebraic data types. *)
type 'a lr1state
type 'a symbol
type xsymbol
(* Some of the tables that follow use encodings of (terminal and
nonterminal) symbols as integers. So, we need functions that
map the integer encoding of a symbol to its algebraic encoding. *)
val terminal: int -> xsymbol
val nonterminal: int -> xsymbol
(* A mapping of every (non-initial) state to its incoming symbol. *)
val incoming_symbol: 'a lr1state -> 'a symbol
(* The left-hand side of every production. (Same as in [TableFormat.TABLES].) *)
val lhs: PackedIntArray.t
(* The right-hand side of every production. This a linearized array
of arrays of integers, whose [data] and [entry] components have
been packed. The encoding of symbols as integers in described in
[TableBackend]. *)
val rhs: PackedIntArray.t * PackedIntArray.t
(* A mapping of every (non-initial) state to its LR(0) core. *)
val lr0_core: PackedIntArray.t
(* A mapping of every LR(0) state to its set of LR(0) items. Each item is
represented in its packed form (see [Item]) as an integer. Thus the
mapping is an array of arrays of integers, which is linearized and
packed, like [rhs]. *)
val lr0_items: PackedIntArray.t * PackedIntArray.t
end
module Make (T : InspectionTableFormat.TABLES) = struct
(* This auxiliary function decodes a packed linearized array, as created by
[TableBackend.linearize_and_marshal1]. Here, we read a row all at once. *)
let read_packed_linearized ((data, entry) : PackedIntArray.t * PackedIntArray.t) (i : int) : int list =
LinearizedArray.read_row_via
(PackedIntArray.get data)
(PackedIntArray.get entry)
i
(* The function [incoming_symbol] is generated by the table back-end.
We just expose it. *)
let incoming_symbol =
T.incoming_symbol
(* The function [lhs] reads the table [lhs] and uses [T.nonterminal]
to decode the symbol. *)
let lhs prod =
T.nonterminal (PackedIntArray.get T.lhs prod)
(* The function [rhs] reads the table [rhs] and uses [decode_symbol]
to decode the symbol. The encoding was done by [encode_symbol] in
the table back-end. *)
let decode_symbol symbol =
let kind = symbol land 1 in
(if kind = 0 then T.terminal else T.nonterminal) (symbol lsr 1)
let rhs prod =
List.map decode_symbol (read_packed_linearized T.rhs prod)
(* The function [items] maps the LR(1) state [s] to its LR(0) core,
then uses [core] as an index into the table [lr0_items]. The
items are then decoded by the function [export] below, which is
essentially a copy of [Item.export]. *)
let export t =
(t lsr 7, t mod 128)
let items s =
(* Map [s] to its LR(0) core. *)
let core = PackedIntArray.get T.lr0_core s in
(* Now use [core] to look up the [lr0_items] table. *)
List.map export (read_packed_linearized T.lr0_items core)
end
(* This functor is invoked inside the generated parser, in [--table] mode. It
constructs the inspection API on top of the inspection tables described in
[InspectionTableFormat]. *)
module Make (T : InspectionTableFormat.TABLES
with type 'a lr1state = int)
: IncrementalEngine.INSPECTION
with type 'a lr1state := 'a T.lr1state
and type 'a symbol := 'a T.symbol
and type xsymbol := T.xsymbol
and type production := int
......@@ -8,6 +8,8 @@ RowDisplacement
IncrementalEngine
EngineTypes
Engine
InspectionTableFormat
InspectionTableInterpreter
TableFormat
TableInterpreter
Convert
......@@ -24,7 +24,7 @@ let make =
tableInterpreter ^ ".Make"
let make_inspection =
tableInterpreter ^ ".MakeInspection"
menhirlib ^ ".InspectionTableInterpreter.Make"
let accept =
tableInterpreter ^ ".Accept"
......@@ -1020,7 +1020,7 @@ let program =
SIInclude (MVar more) ::
SIInclude (MApp (MVar make_inspection, MStruct (
(* This module must satisfy [INSPECTION_TABLES]. *)
(* This module must satisfy [InspectionTableFormat.TABLES]. *)
(* [lr1state] *)
interface_to_structure [
lr1state_redef;
......
......@@ -115,53 +115,3 @@ module type TABLES = sig
end
(* This signature defines the format of the tables that are produced (in
addition to the above) when [--inspection] is enabled. It is used as an
argument to [TableInterpreter.Inspection]. *)
module type INSPECTION_TABLES = sig
(* These types are used in the types of the functions that follow.
In the generated [.ml] file, ['a lr1state] will be implemented
e.g. as [int], whereas the types ['a symbol] and [xsymbol] are
(generated) algebraic data types. *)
type 'a lr1state
type 'a symbol
type xsymbol
(* Some of the tables that follow use encodings of (terminal and
nonterminal) symbols as integers. So, we need functions that
map the integer encoding of a symbol to its algebraic encoding. *)
val terminal: int -> xsymbol
val nonterminal: int -> xsymbol
(* A mapping of every (non-initial) state to its incoming symbol. *)
val incoming_symbol: 'a lr1state -> 'a symbol
(* A left-hand side of every production. (Same as in [TABLES].) *)
val lhs: PackedIntArray.t
(* The right-hand side of every production. This a linearized array
of arrays of integers, whose [data] and [entry] components have
been packed. The encoding of symbols as integers in described in
[TableBackend]. *)
val rhs: PackedIntArray.t * PackedIntArray.t
(* A mapping of every (non-initial) state to its LR(0) core. *)
val lr0_core: PackedIntArray.t
(* A mapping of every LR(0) state to its set of LR(0) items. Each item is
represented in its packed form (see [Item]) as an integer. Thus the
mapping is an array of arrays of integers, which is linearized and
packed, like [rhs]. *)
val lr0_items: PackedIntArray.t * PackedIntArray.t
end
......@@ -167,54 +167,3 @@ module Make (T : TableFormat.TABLES)
end)
(* This functor constructs the inspection API. *)
module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct
(* This auxiliary function decodes a packed linearized array, as created by
[TableBackend.linearize_and_marshal1]. Here, we read a row all at once. *)
let read_packed_linearized ((data, entry) : PackedIntArray.t * PackedIntArray.t) (i : int) : int list =
LinearizedArray.read_row_via
(PackedIntArray.get data)
(PackedIntArray.get entry)
i
(* The function [incoming_symbol] is generated by the table back-end.
We just expose it. *)
let incoming_symbol =
T.incoming_symbol
(* The function [lhs] reads the table [lhs] and uses [T.nonterminal]
to decode the symbol. *)
let lhs prod =
T.nonterminal (PackedIntArray.get T.lhs prod)
(* The function [rhs] reads the table [rhs] and uses [decode_symbol]
to decode the symbol. The encoding was done by [encode_symbol] in
the table back-end. *)
let decode_symbol symbol =
let kind = symbol land 1 in
(if kind = 0 then T.terminal else T.nonterminal) (symbol lsr 1)
let rhs prod =
List.map decode_symbol (read_packed_linearized T.rhs prod)
(* The function [items] maps the LR(1) state [s] to its LR(0) core,
then uses [core] as an index into the table [lr0_items]. The
items are then decoded by the function [export] below, which is
essentially a copy of [Item.export]. *)
let export t =
(t lsr 7, t mod 128)
let items s =
(* Map [s] to its LR(0) core. *)
let core = PackedIntArray.get T.lr0_core s in
(* Now use [core] to look up the [lr0_items] table. *)
List.map export (read_packed_linearized T.lr0_items core)
end
......@@ -18,15 +18,3 @@ module Make (T : TableFormat.TABLES)
and type semantic_value = Obj.t
and type production = int
(* This functor is also invoked inside the generated parser. It
constructs the inspection API on top of the inspection tables. *)
module MakeInspection (T : TableFormat.INSPECTION_TABLES
with type 'a lr1state = int)
: IncrementalEngine.INSPECTION
with type 'a lr1state := 'a T.lr1state
and type 'a symbol := 'a T.symbol
and type xsymbol := T.xsymbol
and type production := int
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment