Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[enhance] compiler: Tools for build typed ident from opa api

  • Loading branch information...
commit 99fb2f288d6ca031f80ae02b68242a723b9d890a 1 parent 5242af3
@BourgerieQuentin BourgerieQuentin authored
Showing with 38 additions and 0 deletions.
  1. +22 −0 opalang/opaMapToIdent.ml
  2. +16 −0 opalang/opaMapToIdent.mli
View
22 opalang/opaMapToIdent.ml
@@ -99,6 +99,23 @@ let val_ ?(side=`server) s =
pp_stringmap
!(get_rmap side)
+let default_pos ?(label=Annot.nolabel "OpaMapToIdent") name =
+ QmlAst.Ident (label, Ident.source name)
+
+
+let typed_val ?(label=Annot.nolabel "OpaMapToIdent") ?(side=`server) ?(ty=[]) ?(ty_row=[]) name annotmap gamma =
+ try
+ let ident = val_ ~side name in
+ let tsc = QmlTypes.Env.Ident.find ident gamma in
+ let ty = QmlTypes.Scheme.specialize ~typeident:ident ~ty ~ty_row tsc in
+ let (annotmap, ident) = QmlAstCons.TypedExpr.ident annotmap ident ty in
+ let annotmap = QmlAnnotMap.add_tsc_inst (QmlAst.QAnnot.expr ident) tsc annotmap in
+ (annotmap, ident)
+ with Not_found ->
+ let context = QmlError.Context.annoted_expr annotmap (default_pos ~label name) in
+ QmlError.cond_violation QmlAlphaConv.Check.unbound_id context
+ "Missing ident"
+
let typ s =
opacapi_check s ;
try StringMap.find s !r_type
@@ -109,6 +126,11 @@ let typ s =
pp_stringmap
!r_type
+let specialized_typ ?(ty = []) ?(ty_row = []) name gamma =
+ let typeident = typ name in
+ let (scheme, _) = QmlTypes.Env.TypeIdent.find ~visibility_applies:false typeident gamma in
+ QmlTypes.Scheme.specialize ~typeident ~ty ~ty_row scheme
+
let val_opt ?(side=`server) s =
opacapi_check s ;
StringMap.find_opt s !(get_rmap side)
View
16 opalang/opaMapToIdent.mli
@@ -56,6 +56,17 @@ val val_ : ?side:side -> string -> QmlAst.ident
of raising an exception
*)
+(**
+ same as [val_], but return an expr corresponding to the typed ident
+*)
+val typed_val :
+ ?label:Annot.label -> ?side:side ->
+ ?ty:QmlAst.ty list ->
+ ?ty_row:QmlAst.ty_row list ->
+ string -> QmlAst.annotmap -> QmlTypes.gamma ->
+ QmlAst.annotmap * QmlAst.expr
+
+
(** Get the optional ident of the value originally named by the
given [string]. *)
val val_opt : ?side:side -> string -> QmlAst.ident option
@@ -88,6 +99,11 @@ val val_start_server : unit -> QmlAst.ident option
corresponding [side]. *)
val typ : string -> QmlAst.ident
+(** Like [typ] but search type scheme in gamma and specilize it
+*)
+val specialized_typ : ?ty:QmlAst.ty list -> ?ty_row:QmlAst.ty_row list -> string -> QmlTypes.gamma
+ -> QmlAst.ty
+
(** {6 Map setter & getter}*)
(** Directly get the map of values *)
val get_val_map : ?side: side -> unit -> QmlAst.ident StringMap.t
Please sign in to comment.
Something went wrong with that request. Please try again.