Skip to content

Commit

Permalink
Push through spans further
Browse files Browse the repository at this point in the history
Still nowhere near actually Doing Productive
Stuff yet.
  • Loading branch information
MattWindsor91 committed Nov 10, 2020
1 parent 986ebbe commit 585ccd2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
8 changes: 3 additions & 5 deletions lib/fuzz/src/path_filter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,12 @@ let add_if (x : t) ~(when_ : bool) ~(add : t) : t =
if when_ then x + add else x

module Anchor_check = struct
type t = {is_nested: bool; pos: int; len: int; block_len: int}
type t = {is_nested: bool; span: Utils.My_list.Span.t; block_len: int}
[@@deriving sexp]

let of_path (path : Path.Stms.t) ~(block_len : int) : t =
Path.Stms.
{ pos= path.@(index)
; len= len path
{ span= {pos= path.@(index); len= len path}
; is_nested= is_nested path
; block_len }
end
Expand All @@ -140,8 +139,7 @@ let is_anchored (anc : Path_meta.Anchor.t) ~(check : Anchor_check.t) : bool =
check.is_nested
|| Path_meta.Anchor.(
incl_opt ~includes:anc
(of_dimensions ~index:check.pos ~len:check.len
~block_len:check.block_len))
(of_dimensions ~span:check.span ~block_len:check.block_len))

let check_anchor (anc : Path_meta.Anchor.t) ~(path : Path.Stms.t)
~(block_len : int) : unit Or_error.t =
Expand Down
10 changes: 6 additions & 4 deletions lib/fuzz/src/path_meta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ module Anchor = struct
let incl_opt ?(includes : t option) (x : t option) : bool =
[%equal: t option] x (merge_opt x includes)

let of_dimensions ~(index : int) ~(len : int) ~(block_len : int) : t option
=
let top = Option.some_if (0 = index) Top in
let bot = Option.some_if (block_len <= index + len) Bottom in
let of_dimensions ~(span : Utils.My_list.Span.t) ~(block_len : int) :
t option =
let top = Option.some_if (0 = span.pos) Top in
let bot =
Option.some_if (block_len <= Utils.My_list.Span.end_pos span) Bottom
in
merge_opt top bot
end

Expand Down
6 changes: 3 additions & 3 deletions lib/fuzz/src/path_meta.mli
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ module Anchor : sig
(** [merge_opt l r] merges two optional anchors, according to the lattice
formed by [incl_opt]. *)

val of_dimensions : index:int -> len:int -> block_len:int -> t option
(** [of_dimensions ~index ~len ~block_len] determines the anchor, if any,
from the given dimensions. *)
val of_dimensions : span:Utils.My_list.Span.t -> block_len:int -> t option
(** [of_dimensions ~span ~block_len] determines the anchor, if any, from
the given dimensions. *)
end

(** {1 Metadata structures} *)
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/src/my_list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
open Base

module Span = struct
type t = {pos: int; len: int}
type t = {pos: int; len: int} [@@deriving sexp]

let end_pos ({pos; len} : t) : int = pos + len
end

let find_at_most_one (type a b) ?(item_name : string = "item")
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/src/my_list.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ open Base

module Span : sig
(** A span, containing a position and length. *)
type t = {pos: int; len: int}
type t = {pos: int; len: int} [@@deriving sexp]

val end_pos : t -> int
(** [end_pos] is the end position of the span: [pos + len]. *)
end

(** {1 Finding and transforming specific amounts of items} *)
Expand Down

0 comments on commit 585ccd2

Please sign in to comment.