diff options
Diffstat (limited to 'lib/syntax')
-rw-r--r-- | lib/syntax/S.ml | 4 | ||||
-rw-r--r-- | lib/syntax/tree.ml | 8 | ||||
-rw-r--r-- | lib/syntax/tree.mli | 2 | ||||
-rw-r--r-- | lib/syntax/type_of.ml | 29 | ||||
-rw-r--r-- | lib/syntax/type_of.mli | 2 |
5 files changed, 22 insertions, 23 deletions
diff --git a/lib/syntax/S.ml b/lib/syntax/S.ml index e6c472d..6cab8c9 100644 --- a/lib/syntax/S.ml +++ b/lib/syntax/S.ml @@ -95,10 +95,10 @@ module type Instruction = sig end module type Location = sig - type repr + type t type instruction - val location : pos -> instruction list -> repr + val location : pos -> instruction list -> t repr end module type Analyzer = sig diff --git a/lib/syntax/tree.ml b/lib/syntax/tree.ml index db8abd9..e5a60f4 100644 --- a/lib/syntax/tree.ml +++ b/lib/syntax/tree.ml @@ -126,10 +126,10 @@ end module Location = struct type instruction = S.pos Ast.statement S.repr - type repr = S.pos * S.pos Ast.statement list + type t = S.pos * S.pos Ast.statement list - let location : S.pos -> instruction list -> repr = - fun pos block -> + let location : S.pos -> instruction list -> t S.repr = + fun pos block _report -> let block = List.map block ~f:(fun b -> fst @@ b []) in - (pos, block) + ((pos, block), []) end diff --git a/lib/syntax/tree.mli b/lib/syntax/tree.mli index c16a02a..6b864e9 100644 --- a/lib/syntax/tree.mli +++ b/lib/syntax/tree.mli @@ -46,4 +46,4 @@ include S.Analyzer with type Expression.t' = S.pos Ast.expression and type Instruction.t' = S.pos Ast.statement - and type Location.repr = S.pos * S.pos Ast.statement list + and type Location.t = S.pos * S.pos Ast.statement list diff --git a/lib/syntax/type_of.ml b/lib/syntax/type_of.ml index a04d37b..e7222fc 100644 --- a/lib/syntax/type_of.ml +++ b/lib/syntax/type_of.ml @@ -313,6 +313,17 @@ module Instruction = struct let expression : expression -> t S.repr = fun expression report -> ((), snd (expression report)) + (** Helper function used in the [if_] function. *) + let fold_clause : + t * Report.t list -> (expression, t) S.clause -> t * Report.t list = + fun ((), report) (_pos, expr, instructions) -> + let result, report = expr report in + let report = + Helper.compare Helper.Bool (Expression.arg_of_repr result) report + in + List.fold_left instructions ~init:((), report) + ~f:(fun ((), report) instruction -> instruction report) + let if_ : S.pos -> (expression, t) S.clause -> @@ -320,18 +331,6 @@ module Instruction = struct else_:t S.repr list -> t S.repr = fun _pos clause ~elifs ~else_ report -> - (* Helper function *) - let fold_clause : - t * Report.t list -> (expression, t) S.clause -> t * Report.t list = - fun ((), report) (_pos, expr, instructions) -> - let result, report = expr report in - let report = - Helper.compare Helper.Bool (Expression.arg_of_repr result) report - in - List.fold_left instructions ~init:((), report) - ~f:(fun ((), report) instruction -> instruction report) - in - (* Traverse the whole block recursively *) let report = fold_clause ((), report) clause in let report = List.fold_left elifs ~f:fold_clause ~init:report in @@ -371,14 +370,14 @@ module Instruction = struct end module Location = struct - type repr = Report.t list -> Report.t list + type t = unit type instruction = Instruction.t S.repr - let location : S.pos -> instruction list -> repr = + let location : S.pos -> instruction list -> t S.repr = fun _pos instructions report -> let (), report = List.fold_left instructions ~init:((), report) ~f:(fun ((), report) instruction -> instruction report) in - report + ((), report) end diff --git a/lib/syntax/type_of.mli b/lib/syntax/type_of.mli index 719becd..a7850e5 100644 --- a/lib/syntax/type_of.mli +++ b/lib/syntax/type_of.mli @@ -4,4 +4,4 @@ - Assigning a [string] value in an [integer] variable - Comparing a [string] with an [integer] - Giving the wrong type in the argument for a function and so one. *) -include S.Analyzer with type Location.repr = Report.t list -> Report.t list +include S.Analyzer with type Location.t = unit |