Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c6a62b8
first stab at 2nd class modules with type components
crusso Feb 14, 2019
b038fd0
fix path bugs
crusso Feb 14, 2019
5637f0b
revamp typechecker to deal with nested modules
crusso Feb 17, 2019
8217fd1
revamp infer_dec_valdecs to reconstruct entire scope
crusso Feb 18, 2019
d0d9bd5
test separation of type/value namespaces
crusso Feb 18, 2019
c0132b5
remove debug code; add test module3.as test and refresh expected test…
crusso Feb 18, 2019
c0594e1
remove debug again (really, this time)
crusso Feb 18, 2019
fccc75b
merget with master, builds but fails tests
crusso Mar 6, 2019
1f80761
merged with master, builds but fails tests
crusso Mar 6, 2019
5254cd3
got it working, but needs fixing
crusso Mar 7, 2019
c4e2b8a
working modules (but not the implementation I want)
crusso Mar 8, 2019
d4e7239
added a sample
crusso Mar 8, 2019
c7a839e
merge with master
crusso Apr 12, 2019
ef5eb80
Update samples/modules.as
ggreif Apr 16, 2019
6be253b
Update samples/modules.as
ggreif Apr 16, 2019
ac55b62
merge with master
crusso Apr 16, 2019
2427f27
Merge branch 'master' into crusso/modules
crusso Apr 17, 2019
047e6a9
implement importing sequence of decs as module binding, supporting ty…
crusso Apr 18, 2019
0873633
cleanup infer_path
crusso Apr 18, 2019
fb59472
add List Library sample; using import
crusso Apr 18, 2019
420badd
update test
crusso Apr 18, 2019
b95247b
Merge branch 'master' into crusso/modules
crusso Apr 18, 2019
9a44650
Merge branch 'master' into crusso/modules; handporting necessary chan…
crusso Apr 23, 2019
a5b64e7
address (some) of Andreas code review
crusso Apr 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions samples/counter.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Checking counter.as:
type Counter <: actor {dec : shared () -> (); read : shared () -> async Int}
let Counter : class Int -> Counter
let c : Counter
type Counter = actor {dec : shared () -> (); read : shared () -> async Int}
let Counter : Int -> Counter
let c : actor {dec : shared () -> (); read : shared () -> async Int}
let show : (Text, Int) -> ()
let showAsync : (Text, async Int) -> ()
let testDec : () -> ()
Expand Down Expand Up @@ -287,8 +287,8 @@ testRead()
<= ()
<= ()
-- Finished counter.as:
let Counter : class Int -> Counter = func
let c : Counter = {dec = func; read = func}
let Counter : Int -> Counter = func
let c : actor {dec : shared () -> (); read : shared () -> async Int} = {dec = func; read = func}
let show : (Text, Int) -> () = func
let showAsync : (Text, async Int) -> () = func
let testDec : () -> () = func
Expand Down
10 changes: 5 additions & 5 deletions samples/quicksort.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Checking quicksort.as:
type Array<T> = [var T]
type QS<T> <: {quicksort : (Array<T>, Nat, Nat) -> ()}
let QS : class <T>((T, T) -> Int) -> QS<T>
type QS<T> = {quicksort : (Array<T>, Nat, Nat) -> ()}
let QS : <T>((T, T) -> Int) -> QS<T>
let a : [var Int]
let cmpi : (Int, Int) -> Int
let qs : QS<Int>
let qs : {quicksort : (Array<Int>, Nat, Nat) -> ()}
-- Interpreting quicksort.as:
QS(func)
<= {quicksort = func}
Expand Down Expand Up @@ -97,8 +97,8 @@ quicksort([8, 3, 9, 5, 2], 0, 4)
<= ()
<= ()
-- Finished quicksort.as:
let QS : class <T>((T, T) -> Int) -> QS<T> = func
let QS : <T>((T, T) -> Int) -> QS<T> = func
let a : [var Int] = [2, 3, 5, 8, 9]
let cmpi : (Int, Int) -> Int = func
let qs : QS<Int> = {quicksort = func}
let qs : {quicksort : (Array<Int>, Nat, Nat) -> ()} = {quicksort = func}

11 changes: 10 additions & 1 deletion src/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ and control c = match c with
and obj_sort' s = match s with
| Type.Object sh -> Atom ("Object " ^ sharing sh)
| Type.Actor -> Atom "Actor"
| Type.Module -> Atom "Module"

and obj_sort s = obj_sort' s.it

Expand All @@ -130,6 +131,10 @@ and exp_field (ef : exp_field)

and operator_type t = Atom (Type.string_of_typ t)

and path p = match p.it with
| IdH i -> "IdH" $$ [id i]
| DotH (p,i) -> "DotH" $$ [path p; id i]

and typ t = match t.it with
| VarT (s, ts) -> "VarT" $$ [id s] @ List.map typ ts
| PrimT p -> "PrimT" $$ [Atom p]
Expand All @@ -140,9 +145,11 @@ and typ t = match t.it with
| FuncT (s, tbs, at, rt) -> "FuncT" $$ [Atom (sharing s.it)] @ List.map typ_bind tbs @ [ typ at; typ rt]
| AsyncT t -> "AsyncT" $$ [typ t]
| ParT t -> "ParT" $$ [typ t]
| PathT (p, i, ts) -> "PathT" $$ [path p; id i] @ List.map typ ts


and id i = Atom i.it
and con_id i = Atom i.it
and con_id i = Atom i.it

and name n = Atom (string_of_name n.it)

Expand All @@ -164,5 +171,7 @@ and dec d = match d.it with
"TypD" $$ [con_id i] @ List.map typ_bind tp @ [typ t]
| ClassD (i, j, tp, s, p, i', efs) ->
"ClassD" $$ id i :: con_id j :: List.map typ_bind tp @ [obj_sort s; pat p; id i'] @ List.map exp_field efs
| ModuleD (i,ds) ->
"ModuleD" $$ [id i] @ List.map dec ds

and prog prog = "BlockE" $$ List.map dec prog.it
2 changes: 2 additions & 0 deletions src/arrange_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let control c = match c with
let obj_sort s = match s with
| Type.Object sh -> Atom ("Object " ^ sharing sh)
| Type.Actor -> Atom "Actor"
| Type.Module -> Atom "Module"

let prim p = match p with
| Null -> Atom "Null"
Expand Down Expand Up @@ -48,6 +49,7 @@ let rec typ (t:Type.typ) = match t with
| Any -> Atom "Any"
| Non -> Atom "Non"
| Pre -> Atom "Pre"
| Kind (c,k) -> Atom "Kind ..." (* TBC *)

and typ_bind (tb : Type.bind) =
tb.var $$ [typ tb.bound]
Expand Down
1 change: 1 addition & 0 deletions src/async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ let rec t_typ (t:T.typ) =
| Any -> Any
| Non -> Non
| Pre -> Pre
| Kind (c,k) -> Kind (c, t_kind k)

and t_bind {var; bound} =
{var; bound = t_typ bound}
Expand Down
13 changes: 13 additions & 0 deletions src/check_ir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ let rec check_typ env typ : unit =
check env no_region (sorted fields) "object type's fields are not sorted"
| T.Mut typ ->
check_typ env typ
| T.Kind (c,k) ->
check_kind env k

and check_kind env k =
let (binds,typ) =
match k with
| T.Abs(binds,typ)
| T.Def(binds,typ) -> (binds,typ)
in
let cs,ce = check_typ_binds env binds in
let ts = List.map (fun c -> T.Con(c,[])) cs in
let env' = adjoin_typs env ce in
check_typ env' (T.open_ ts typ);

and check_typ_field env s typ_field : unit =
let {T.name; T.typ} = typ_field in
Expand Down
3 changes: 3 additions & 0 deletions src/definedness.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ let rec exp msgs e : f = match e.it with
begin match s.it with
| Type.Actor -> eagerify f
| Type.Object _ -> f
| Type.Module -> assert false (* TBR *)
end
| DotE (e, _t, i) -> exp msgs e
| AssignE (e1, e2) -> exps msgs [e1; e2]
Expand Down Expand Up @@ -153,6 +154,8 @@ and dec msgs d = match d.it with
| TypD (i, tp, t) -> (M.empty, S.empty)
| ClassD (i, l, tp, s, p, i', efs) ->
(M.empty, S.singleton i.it) +++ delayify (close (exp_fields msgs efs) /// pat msgs p // i'.it)
| ModuleD (i, ds) ->
(M.empty, S.singleton i.it) +++ decs msgs ds (* TBR *)

and decs msgs decs : f =
(* Annotate the declarations with the analysis results *)
Expand Down
4 changes: 3 additions & 1 deletion src/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ and field_to_obj_entry (f : S.exp_field) =

and obj at s class_id self_id es obj_typ =
match s.it with
| Type.Object _ -> build_obj at None s self_id es obj_typ
| Type.Object _ | Type.Module -> build_obj at None s self_id es obj_typ (* TBR *)
| Type.Actor -> I.ActorE (self_id, exp_fields es, obj_typ)

and build_obj at class_id s self_id es obj_typ =
Expand Down Expand Up @@ -182,6 +182,8 @@ and dec' at n d = match d with
{ it = obj at s (Some fun_id) self_id es obj_typ;
at = at;
note = { S.note_typ = obj_typ; S.note_eff = T.Triv } })
| S.ModuleD(id, ds) ->
failwith "NYI"

and cases cs = List.map case cs

Expand Down
4 changes: 4 additions & 0 deletions src/effect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ and infer_effect_dec dec =
T.Triv
| ClassD (v, l, tps, s, p, v', efs) ->
T.Triv
| ModuleD (_,decs) ->
let es = List.map effect_dec decs in
List.fold_left max_eff Type.Triv es


(* effect inference on Ir *)

Expand Down
8 changes: 8 additions & 0 deletions src/interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,10 @@ and declare_dec dec : val_env =
| LetD (pat, _) -> declare_pat pat
| VarD (id, _)
| FuncD (_, id, _, _, _, _)
| ModuleD (id, _)
| ClassD (id, _, _, _, _, _, _) -> declare_id id


and declare_decs decs ve : val_env =
match decs with
| [] -> ve
Expand Down Expand Up @@ -619,6 +621,12 @@ and interpret_dec env dec (k : V.value V.cont) =
let v = V.Func (V.call_conv_of_typ dec.note.note_typ, f) in
define_id env id v;
k v
| ModuleD (id, decs) ->
let ve = ref V.Env.empty in
interpret_block env decs (Some ve) (fun v ->
let v = V.Obj (V.Env.map Lib.Promise.value (!ve)) in
Comment thread
crusso marked this conversation as resolved.
Outdated
define_id env id v;
k v)

and interpret_decs env decs (k : V.value V.cont) =
match decs with
Expand Down
1 change: 1 addition & 0 deletions src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ rule token mode = parse
| "func" { FUNC }
| "if" { IF }
| "in" { IN }
| "module" { MODULE }
| "new" { NEW }
| "not" { NOT }
| "null" { NULL }
Expand Down
14 changes: 14 additions & 0 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ let share_expfield (ef : exp_field) =
%token EQ LT GT
%token PLUSASSIGN MINUSASSIGN MULASSIGN DIVASSIGN MODASSIGN POWASSIGN CATASSIGN
%token ANDASSIGN ORASSIGN XORASSIGN SHLASSIGN SHRASSIGN ROTLASSIGN ROTRASSIGN
%token MODULE
Comment thread
crusso marked this conversation as resolved.
Outdated
%token NULL
%token<string> NAT
%token<string> FLOAT
Expand Down Expand Up @@ -190,6 +191,13 @@ seplist1(X, SEP) :
| (* empty *) { Type.Local @@ no_region }
| SHARED { Type.Sharable @@ at $sloc }

(* paths *)

path :
| x=id
{ IdH x @! at $sloc }
| p=path DOT x=id
{ DotH (p, x) @! at $sloc }

(* Types *)

Expand All @@ -204,6 +212,8 @@ typ_nullary :
{ TupT(ts) @! at $sloc }
| x=id tso=typ_args?
{ VarT(x, Lib.Option.get tso []) @! at $sloc }
| p=path DOT x=id tso=typ_args?
{ PathT(p, x, Lib.Option.get tso []) @! at $sloc }
| LBRACKET m=var_opt t=typ RBRACKET
{ ArrayT(m, t) @! at $sloc }
| tfs=typ_obj
Expand Down Expand Up @@ -545,6 +555,10 @@ dec_nonvar :
let id = xf "class" $sloc in
let con_id = id.it @= at $sloc in
ClassD(id, con_id, tps, s, p, x, efs') @? at $sloc }
| MODULE xf=id_opt id_opt=id? EQ? LCURLY ds=seplist(dec, semicolon) RCURLY
{ let id = xf "module" $sloc in
ModuleD(id, ds) @? at $sloc }


dec :
| d=dec_var
Expand Down
9 changes: 8 additions & 1 deletion src/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ type obj_sort = Type.obj_sort Source.phrase
type mut = mut' Source.phrase
and mut' = Const | Var

and path = (path', Type.typ) Source.annotated_phrase

Comment thread
crusso marked this conversation as resolved.
and path' =
| IdH of id
| DotH of path * id

type typ = (typ',Type.typ) Source.annotated_phrase
and typ' =
| PrimT of string (* primitive *)
Expand All @@ -34,6 +40,7 @@ and typ' =
| FuncT of sharing * typ_bind list * typ * typ (* function *)
| AsyncT of typ (* future *)
| ParT of typ (* parentheses, used to control function arity only *)
| PathT of path * id * typ list (* type projection *)
Comment thread
crusso marked this conversation as resolved.
(*
| UnionT of type * typ (* union *)
| AtomT of string (* atom *)
Expand Down Expand Up @@ -184,7 +191,7 @@ and dec' =
| TypD of con_id * typ_bind list * typ (* type *)
| ClassD of (* class *)
id * con_id * typ_bind list * obj_sort * pat * id * exp_field list

| ModuleD of id * dec list

(* Program *)

Expand Down
Loading