Skip to content

Commit

Permalink
New Unif intermediate language
Browse files Browse the repository at this point in the history
This commit introduces a new Unif intermediate language: it is designed
for type inference. Effect inference will be done in the next phase of
the compiler and will produce a program in another representation.
Currently, TypeInference and ToCore translations are commented-out.
  • Loading branch information
ppolesiuk committed Dec 2, 2024
1 parent 9789161 commit 89c7c37
Show file tree
Hide file tree
Showing 72 changed files with 719 additions and 861 deletions.
91 changes: 22 additions & 69 deletions src/Lang/Unif.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Scope = UnifPriv.Scope

module Name = UnifPriv.Name

module Effect = UnifPriv.Effect

module Type = struct
include UnifPriv.TypeBase
include UnifPriv.Type
Expand All @@ -28,10 +30,9 @@ module Type = struct
let subst = UnifPriv.Subst.in_type
end

module Effect = UnifPriv.Effect

module Scheme = struct
let of_type = UnifPriv.Type.mono_scheme
let to_type = UnifPriv.Type.scheme_to_type
let is_monomorphic = UnifPriv.Type.scheme_is_monomorphic
let uvars = UnifPriv.Type.scheme_uvars
let collect_uvars = UnifPriv.Type.collect_scheme_uvars
Expand All @@ -56,70 +57,22 @@ end
module Subst = UnifPriv.Subst
module BuiltinType = UnifPriv.BuiltinType

type var = Var.t

type data_def =
| DD_Data of
{ tvar : tvar;
proof : var;
args : named_tvar list;
ctors : ctor_decl list;
strictly_positive : bool
}

| DD_Label of
{ tvar : tvar;
var : var;
delim_tp : typ;
delim_eff : effrow
}

type pattern = pattern_data node
and pattern_data =
| PWildcard
| PVar of var * scheme
| PCtor of string * int * expr * ctor_decl list * tvar list * pattern list

and expr = expr_data node
and expr_data =
| EUnitPrf
| ENum of int
| ENum64 of int64
| EStr of string
| EChr of char
| EVar of var
| EPureFn of var * scheme * expr
| EFn of var * scheme * expr
| ETFun of tvar * expr
| EApp of expr * expr
| ETApp of expr * typ
| ELet of var * scheme * expr * expr
| ELetRec of rec_def list * expr
| ECtor of expr * int * typ list * expr list
| EData of data_def list * expr
| EMatchEmpty of expr * expr * typ * effrow option
| EMatch of expr * match_clause list * typ * effrow option
| EHandle of tvar * var * typ * expr * expr
| EHandler of
{ label : var;
effect : tvar;
delim_tp : typ;
delim_eff : effect;
cap_type : typ;
cap_body : expr;
ret_var : var;
body_tp : typ;
ret_body : expr;
fin_var : var;
fin_body : expr;
}
| EEffect of expr * var * expr * typ
| EExtern of string * typ
| ERepl of (unit -> expr) * typ * effrow
| EReplExpr of expr * string * expr

and rec_def = var * scheme * expr

and match_clause = pattern * expr

type program = expr
include UnifPriv.Syntax

module TypeExpr = struct
let to_type = UnifPriv.TypeExpr.to_type
end

module SchemeExpr = struct
let of_type_expr = UnifPriv.TypeExpr.mono_scheme_expr
let to_type_expr = UnifPriv.TypeExpr.of_scheme_expr
let to_scheme = UnifPriv.TypeExpr.to_scheme
end

module NamedSchemeExpr = struct
let to_named_scheme = UnifPriv.TypeExpr.to_named_scheme
end

module CtorDeclExpr = struct
let to_ctor_decl = UnifPriv.TypeExpr.to_ctor_decl
end
Loading

0 comments on commit 89c7c37

Please sign in to comment.