-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refining and cleaning up Pointer.atField for unboxed fields, with mor…
…e tests, etc. (#342)
- Loading branch information
Showing
31 changed files
with
468 additions
and
88 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//@execute 11=11; -55=-55 | ||
component C { | ||
var a: Array<int>; | ||
} | ||
|
||
def main(n: int) -> int { | ||
C.a = [14]; | ||
var p = Pointer.atField(C.a); | ||
var aa: Array<int> = [n]; | ||
p.cmpswp(C.a, aa); | ||
return C.a[0]; | ||
} |
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,25 +1,22 @@ | ||
//@execute 0=0; 6=6 | ||
//@execute 0=0; 12=12 | ||
// tests possible issues related to unboxed field and parameterized types | ||
|
||
type A(i: int) #unboxed { } | ||
type B(a: A, b: u32) #unboxed { } | ||
type A<T>(i: T) #unboxed { } | ||
type B<T>(a: A<T>, b: u32) #unboxed { } | ||
|
||
class P { } | ||
class Q extends P { } | ||
class R<T> extends Q { | ||
var x: T; | ||
var x: B<T>; | ||
def y: int; | ||
new(x, y) { } | ||
} | ||
class S extends R<B> { | ||
def getPtr() -> Pointer { | ||
def getPtrx() -> Pointer { | ||
// legality depends on what T is | ||
return Pointer.atField(x.a.i); | ||
} | ||
new(x: B, y: int) super(x, y) { } | ||
} | ||
|
||
def main(n: int) -> int { | ||
var s = S.new(B(A(n), 17), 5); | ||
var p = s.getPtr(); | ||
var r = R<int>.new(B<int>(A<int>(n), 13), 15); | ||
var p = r.getPtrx(); | ||
return p.load<int>(); | ||
} |
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 @@ | ||
//@execute 6=6; 10=10 | ||
// tests possible issues related to unboxed field and parameterized types | ||
|
||
class C #unboxed { | ||
var x: int; | ||
new(x) { } | ||
} | ||
class D { | ||
var c: C; | ||
new(x: int) { c = C.new(x); } | ||
} | ||
|
||
def main(n: int) -> int { | ||
var d = D.new(n); | ||
var p = Pointer.atField(d.c.x); | ||
return p.load<int>() + d.c.x - n; | ||
} |
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 @@ | ||
//@execute 6=6; 10=10 | ||
// tests possible issues related to unboxed field and parameterized types | ||
|
||
class C #unboxed { | ||
var x: int; | ||
new(x) { } | ||
} | ||
|
||
component CC { | ||
var c: C; | ||
} | ||
|
||
def main(n: int) -> int { | ||
CC.c = C.new(n); | ||
var p = Pointer.atField(CC.c.x); | ||
return p.load<int>() + CC.c.x - n; | ||
} |
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,10 +1,8 @@ | ||
//@seman = TypeError @ 7:33 | ||
// Disallow pointer to *boxed* field of a global variable | ||
// Disallow pointer to *boxed* field of a local variable | ||
type V(x: int); | ||
|
||
def main() -> int { | ||
component C { | ||
var v = V(13); | ||
var p = Pointer.atField(v.x); | ||
p.store<int>(17); | ||
return v.x; | ||
} |
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,13 +1,8 @@ | ||
//@seman = TypeError @ 10:33 | ||
//@seman = TypeError @ 7:33 | ||
// Disallow pointer to *boxed* field of a component | ||
|
||
type V(x: int); | ||
component C { | ||
var v = V(13); | ||
} | ||
|
||
def main() -> int { | ||
var p = Pointer.atField(C.v.x); | ||
p.store<int>(17); | ||
return C.v.x; | ||
var p = Pointer.atField(v.x); | ||
} |
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,13 +1,8 @@ | ||
//@seman = TypeError @ 10:33 | ||
//@seman = TypeError @ 7:33 | ||
// Disallow pointer to *packed* field of a global variable | ||
type V(x: u4, y: u4) #packing 0b_xxxxyyyy; | ||
|
||
component C { | ||
var v = V(13, 7); | ||
} | ||
|
||
def main() -> int { | ||
var p = Pointer.atField(C.v.x); | ||
p.store<int>(17); | ||
return C.v.x; | ||
var p = Pointer.atField(v.x); | ||
} |
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,18 +1,15 @@ | ||
//@seman = TypeError @ 15:33 | ||
//@seman = TypeError @ 14:33 | ||
// Disallow pointer to *packed* field of a local variable | ||
type V(x: u4, y: u4) #packing 0b_xxxxyyyy; | ||
|
||
type V(x: int); | ||
class C { | ||
var v: V; | ||
new(i: int) { | ||
v = V(i, 3); | ||
v = V(u4.view(i), 3); | ||
} | ||
} | ||
|
||
def main() -> int { | ||
component Comp { | ||
var c = C.new(13); | ||
var p = Pointer.atField(c.v.x); | ||
p.store<int>(17); | ||
return c.v.x; | ||
} |
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,11 +1,6 @@ | ||
//@seman = TypeError @ 8:33 | ||
//@seman = TypeError @ 5:33 | ||
// Disallow pointer to component tuple | ||
component C { | ||
var tup = (1, 13); | ||
} | ||
|
||
def main() -> int { | ||
var p = Pointer.atField(C.tup.1); | ||
p.store<int>(17); | ||
return C.tup.1; | ||
var p = Pointer.atField(tup.1); | ||
} |
Oops, something went wrong.