-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #995 from WardBrian/rewrite-typechecker
Refactor typechecker
- Loading branch information
Showing
47 changed files
with
1,848 additions
and
2,455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
open Core_kernel | ||
open Middle | ||
|
||
type originblock = | ||
| MathLibrary | ||
| Functions | ||
| Data | ||
| TData | ||
| Param | ||
| TParam | ||
| Model | ||
| GQuant | ||
[@@deriving sexp] | ||
|
||
type varinfo = {origin: originblock; global: bool; readonly: bool} | ||
[@@deriving sexp] | ||
|
||
type info = | ||
{ type_: UnsizedType.t | ||
; kind: | ||
[ `Variable of varinfo | ||
| `UserDeclared of Location_span.t | ||
| `StanMath | ||
| `UserDefined ] } | ||
[@@deriving sexp] | ||
|
||
type t = info list String.Map.t | ||
|
||
let create () = | ||
let functions = | ||
Hashtbl.to_alist Stan_math_signatures.stan_math_signatures | ||
|> List.map ~f:(fun (key, values) -> | ||
( key | ||
, List.map values ~f:(fun (rt, args, mem) -> | ||
let type_ = | ||
UnsizedType.UFun | ||
(args, rt, Fun_kind.suffix_from_name key, mem) | ||
in | ||
{type_; kind= `StanMath} ) ) ) | ||
|> String.Map.of_alist_exn | ||
in | ||
functions | ||
|
||
let add env key type_ kind = Map.add_multi env ~key ~data:{type_; kind} | ||
let set_raw env key data = Map.set env ~key ~data | ||
let find env key = Map.find_multi env key | ||
let mem env key = Map.mem env key | ||
let iter env f = Map.iter env ~f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(** Type environments used during typechecking. Maps from strings to function or variable information *) | ||
|
||
open Middle | ||
|
||
(** Origin blocks, to keep track of where variables are declared *) | ||
type originblock = | ||
| MathLibrary | ||
| Functions | ||
| Data | ||
| TData | ||
| Param | ||
| TParam | ||
| Model | ||
| GQuant | ||
[@@deriving sexp] | ||
|
||
(** Information available for each variable *) | ||
type varinfo = {origin: originblock; global: bool; readonly: bool} | ||
[@@deriving sexp] | ||
|
||
type info = | ||
{ type_: UnsizedType.t | ||
; kind: | ||
[ `Variable of varinfo | ||
| `UserDeclared of Location_span.t | ||
| `StanMath | ||
| `UserDefined ] } | ||
[@@deriving sexp] | ||
|
||
type t | ||
|
||
val create : unit -> t | ||
(** Return a new type environment which contains the Stan math library functions | ||
*) | ||
|
||
val find : t -> string -> info list | ||
|
||
val add : | ||
t | ||
-> string | ||
-> Middle.UnsizedType.t | ||
-> [ `UserDeclared of Location_span.t | ||
| `StanMath | ||
| `UserDefined | ||
| `Variable of varinfo ] | ||
-> t | ||
(** Add a new item to the type environment. Does not overwrite existing, but shadows *) | ||
|
||
val set_raw : t -> string -> info list -> t | ||
(** Overwrite the existing items bound to a name *) | ||
|
||
val mem : t -> string -> bool | ||
val iter : t -> (info list -> unit) -> unit |
Oops, something went wrong.