-
Notifications
You must be signed in to change notification settings - Fork 65
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 #388 from tmoux/master
Type members
- Loading branch information
Showing
38 changed files
with
1,180 additions
and
488 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
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 |
---|---|---|
@@ -1,71 +1,28 @@ | ||
module bound | ||
|
||
import raw | ||
import types | ||
import wyvern.collections.llist | ||
type List = llist.LinkedList | ||
type Counter = types.Counter | ||
type Binding = types.Binding | ||
type DeclType = types.DeclType | ||
|
||
resource type Context | ||
val bindings:List[DeclType] | ||
val counter:Counter | ||
val parse:String -> raw.Exp | ||
def extend(b:DeclType):Context | ||
def extendList(b:List[DeclType]):Context | ||
|
||
def Context(bs:List[DeclType], c:Counter, p:String -> raw.Exp) : Context = new | ||
val bindings = bs | ||
val counter = c | ||
val parse = p | ||
def extend(b:DeclType):Context | ||
Context(llist.Cons[DeclType](b, bs), c, p) | ||
def extendList(b:List[DeclType]):Context | ||
val newBindings = b.append(bs) | ||
Context(newBindings,c,p) | ||
|
||
def emptyContext(p:String -> raw.Exp):Context = Context(llist.Nil[DeclType](), types.Counter(), p) | ||
|
||
type Arg | ||
val arg:Binding | ||
val argTyp:types.Type | ||
def Arg(arg:Binding,argTyp:types.Type):Arg = new | ||
val arg = arg | ||
val argTyp = argTyp | ||
|
||
datatype Statement | ||
DeclStatement(decl:Decl, stmt:Statement) | ||
ExprStatement(exp:Exp) | ||
|
||
datatype Decl | ||
Val(binding:Binding, typ:types.Type, exp:Exp) | ||
Def(binding:Binding, args:List[Arg], retTyp:types.Type, body:Statement) | ||
TypeDecl(name:Binding, typ:types.Type) | ||
SubtypeDecl(subtype:types.Type, supertype:types.Type) | ||
|
||
datatype Exp | ||
Var(binding:Binding) | ||
Call(receiver:Exp, name:String, args:List[Exp]) | ||
Field(receiver:Exp, field:String) | ||
New(binding:Binding, typ:types.Type, body:List[Decl]) | ||
Integer(str:String) | ||
UnitVal() | ||
|
||
def lowerStatement(stmt:Statement):Statement = match stmt: | ||
d:DeclStatement => DeclStatement(lowerDecl(d.decl), lowerStatement(d.stmt)) | ||
e:ExprStatement => ExprStatement(lowerExp(e.exp)) | ||
|
||
def lowerDecl(decl:Decl):Decl = match decl: | ||
v:Val => Val(v.binding, v.typ, lowerExp(v.exp)) | ||
d:Def => Def(d.binding, d.args, d.retTyp, lowerStatement(d.body)) | ||
t:TypeDecl => t | ||
s:SubtypeDecl => s | ||
|
||
def lowerExp(exp:Exp):Exp = match exp: | ||
v:Var => v | ||
c:Call => Call(lowerExp(c.receiver), c.name, c.args.map[Exp](e => lowerExp(e))) | ||
f:Field => Field(lowerExp(f.receiver), f.field) | ||
n:New => New(n.binding, n.typ, n.body.map[Decl](d => lowerDecl(d))) | ||
i:Integer => i | ||
u:UnitVal => u | ||
def lowerStatement(stmt:types.Statement):types.Statement = match stmt: | ||
d:types.DeclStatement => types.DeclStatement(lowerDecl(d.decl), lowerStatement(d.stmt)) | ||
e:types.ExprStatement => types.ExprStatement(lowerExp(e.exp)) | ||
|
||
def lowerDecl(decl:types.Decl):types.Decl = match decl: | ||
v:types.Val => types.Val(v.binding, v.typ, lowerExp(v.exp)) | ||
d:types.Def => types.Def(d.binding, d.args, d.retTyp, lowerStatement(d.body)) | ||
t:types.TypeDecl => t | ||
s:types.SubtypeDecl => s | ||
m:types.TypeEq => m | ||
|
||
def lowerExp(exp:types.Exp):types.Exp = match exp: | ||
v:types.Var => v | ||
c:types.Call => types.Call(lowerExp(c.receiver), c.name, c.args.map[types.Exp](e => lowerExp(e))) | ||
f:types.Field => types.Field(lowerExp(f.receiver), f.field) | ||
n:types.New => types.New(n.binding, n.typ, n.body.map[types.Decl](d => lowerDecl(d))) | ||
i:types.Integer => i | ||
u:types.UnitVal => u |
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,17 @@ | ||
type Int:z: | ||
def +(i:Int):Int | ||
def -(i:Int):Int | ||
|
||
type A:z: | ||
type T >= Bottom | ||
|
||
type B:z: | ||
type S <= Unit | ||
type T = A {type T >= B {type S = B {type S = z.S}}} | ||
subtype B extends A | ||
|
||
val bad:A {type T >= B {type S = Int}} = new this:B {type S = Int}: | ||
type S = Int | ||
type T = A {type T >= B {type S = B {type S = this.S}}} | ||
|
||
0 |
Oops, something went wrong.