Move types

This commit is contained in:
Denis Merigoux 2023-05-26 16:03:26 +02:00
parent 6bc4cbd066
commit 1f23f701bc
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
7 changed files with 34 additions and 29 deletions

View File

@ -25,7 +25,7 @@ type scope_var_ctx = {
type scope_input_var_ctx = {
scope_input_name : StructField.t;
scope_input_io : Desugared.Ast.io_input Mark.pos;
scope_input_io : io_input Mark.pos;
scope_input_typ : naked_typ;
}
@ -191,9 +191,9 @@ let thunk_scope_arg ~is_func io_in e =
let silent_var = Var.make "_" in
let pos = Mark.get io_in in
match Mark.remove io_in with
| Desugared.Ast.NoInput -> invalid_arg "thunk_scope_arg"
| Desugared.Ast.OnlyInput -> Expr.eerroronempty e (Mark.get e)
| Desugared.Ast.Reentrant ->
| NoInput -> invalid_arg "thunk_scope_arg"
| OnlyInput -> Expr.eerroronempty e (Mark.get e)
| Reentrant ->
(* we don't need to thunk expressions that are already functions *)
if is_func then e
else Expr.make_abs [| silent_var |] e [TLit TUnit, pos] pos
@ -256,7 +256,7 @@ let rec translate_expr (ctx : 'm ctx) (e : 'm Scopelang.Ast.expr) :
(fun var_name (str_field : scope_input_var_ctx option) expr ->
let expr =
match str_field, expr with
| Some { scope_input_io = Desugared.Ast.Reentrant, _; _ }, None ->
| Some { scope_input_io = Reentrant, _; _ }, None ->
Some (Expr.unbox (Expr.eemptyerror (mark_tany m pos)))
| _ -> expr
in

View File

@ -91,7 +91,6 @@ module ExprMap = Map.Make (struct
let compare = Expr.compare
end)
type io_input = NoInput | OnlyInput | Reentrant
type io = { io_output : bool Mark.pos; io_input : io_input Mark.pos }
type exception_situation =

View File

@ -84,20 +84,6 @@ type meta_assertion =
| FixedBy of reference_typ Mark.pos
| VariesWith of unit * variation_typ Mark.pos option
(** This type characterizes the three levels of visibility for a given scope
variable with regards to the scope's input and possible redefinitions inside
the scope.. *)
type io_input =
| NoInput
(** For an internal variable defined only in the scope, and does not
appear in the input. *)
| OnlyInput
(** For variables that should not be redefined in the scope, because they
appear in the input. *)
| Reentrant
(** For variables defined in the scope that can also be redefined by the
caller as they appear in the input. *)
type io = {
io_output : bool Mark.pos;
(** [true] is present in the output of the scope. *)

View File

@ -1286,9 +1286,9 @@ let attribute_to_io (attr : Surface.Ast.scope_decl_context_io) : Ast.io =
Mark.map
(fun io ->
match io with
| Surface.Ast.Input -> Ast.OnlyInput
| Surface.Ast.Internal -> Ast.NoInput
| Surface.Ast.Context -> Ast.Reentrant)
| Surface.Ast.Input -> OnlyInput
| Surface.Ast.Internal -> NoInput
| Surface.Ast.Context -> Reentrant)
attr.scope_decl_context_io_input;
}
@ -1333,7 +1333,7 @@ let init_scope_defs
(let original_io = attribute_to_io v_sig.var_sig_io in
let io_input =
if i = 0 then original_io.io_input
else Ast.NoInput, Mark.get (StateName.get_info state)
else NoInput, Mark.get (StateName.get_info state)
in
let io_output =
if i = List.length states - 1 then original_io.io_output

View File

@ -30,7 +30,7 @@ let detect_empty_definitions (p : program) : unit =
&& (not scope_def.scope_def_is_condition)
&&
match Mark.remove scope_def.scope_def_io.io_input with
| Ast.NoInput -> true
| NoInput -> true
| _ -> false
then
Errors.format_spanned_warning

View File

@ -225,7 +225,7 @@ let rule_to_exception_graph (scope : Desugared.Ast.scope) = function
((match
Mark.remove scope_def.Desugared.Ast.scope_def_io.io_input
with
| Desugared.Ast.NoInput -> true
| NoInput -> true
| _ -> false)
&& RuleName.Map.is_empty scope_def.scope_def_rules))
scope.scope_defs
@ -244,7 +244,7 @@ let rule_to_exception_graph (scope : Desugared.Ast.scope) = function
(match
Mark.remove scope_def.Desugared.Ast.scope_def_io.io_input
with
| Desugared.Ast.NoInput ->
| NoInput ->
Errors.raise_multispanned_error
(( Some "Incriminated subscope:",
Mark.get (SubScopeName.get_info sscope) )
@ -627,7 +627,7 @@ let translate_rule
((match
Mark.remove scope_def.Desugared.Ast.scope_def_io.io_input
with
| Desugared.Ast.NoInput -> true
| NoInput -> true
| _ -> false)
&& RuleName.Map.is_empty scope_def.scope_def_rules))
scope.scope_defs
@ -647,7 +647,7 @@ let translate_rule
(match
Mark.remove scope_def.Desugared.Ast.scope_def_io.io_input
with
| Desugared.Ast.NoInput -> assert false (* error already raised *)
| NoInput -> assert false (* error already raised *)
| OnlyInput when RuleName.Map.is_empty def && not is_cond ->
assert false (* error already raised *)
| _ -> ());

View File

@ -150,12 +150,32 @@ and naked_typ =
| TArray of typ
| TAny
(** This type characterizes the three levels of visibility for a given scope
variable with regards to the scope's input and possible redefinitions inside
the scope. *)
type io_input =
| NoInput
(** For an internal variable defined only in the scope, and does not
appear in the input. *)
| OnlyInput
(** For variables that should not be redefined in the scope, because they
appear in the input. *)
| Reentrant
(** For variables defined in the scope that can also be redefined by the
caller as they appear in the input. *)
(** {2 Constants and operators} *)
type date = Runtime.date
type date_rounding = Runtime.date_rounding
type duration = Runtime.duration
type var_def_log = {
log_typ : naked_typ;
log_io_input : io_input;
log_io_output : bool;
}
type log_entry =
| VarDef of naked_typ
(** During code generation, we need to know the type of the variable being