-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[unboxing] Fix bugs with enum sets (#301)
- Loading branch information
Showing
17 changed files
with
437 additions
and
3 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
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
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,26 @@ | ||
//@execute 0=0; -1=16842753; 16842753=16842753 | ||
enum E { | ||
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Aa, Ab, Ac, Ad, Ae, Af, | ||
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, Ba, Bb, Bc, Bd, Be, Bf | ||
} | ||
|
||
type T(s: E.set) #unboxed { | ||
def intersect(that: T) -> T { | ||
return T(this.s & that.s); | ||
} | ||
} | ||
|
||
def mask = T(E.A0 | E.B0 | E.B8); | ||
|
||
def main(a: int) -> int { | ||
var x: E.set; | ||
for (e in E) { | ||
if ((a & (1 << e.tag)) != 0) x |= e; | ||
} | ||
var t = T(x).intersect(mask); | ||
var r: int; | ||
for (e in t.s) { | ||
r |= (1 << e.tag); | ||
} | ||
return r; | ||
} |
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,27 @@ | ||
//@execute 0=0; -1=16842753; 16842753=16842753 | ||
enum E { | ||
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Aa, Ab, Ac, Ad, Ae, Af, | ||
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, Ba, Bb, Bc, Bd, Be, Bf, | ||
C0 | ||
} | ||
|
||
type T(s: E.set) #unboxed { | ||
def intersect(that: T) -> T { | ||
return T(this.s & that.s); | ||
} | ||
} | ||
|
||
def mask = T(E.A0 | E.B0 | E.B8); | ||
|
||
def main(a: int) -> int { | ||
var x: E.set; | ||
for (e in E) { | ||
if ((a & (1 << e.tag)) != 0) x |= e; | ||
} | ||
var t = T(x).intersect(mask); | ||
var r: int; | ||
for (e in t.s) { | ||
r |= (1 << e.tag); | ||
} | ||
return r; | ||
} |
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,29 @@ | ||
//@execute 0=0; -1=16842753; 16842753=16842753 | ||
enum E { | ||
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Aa, Ab, Ac, Ad, Ae, Af, | ||
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, Ba, Bb, Bc, Bd, Be, Bf, | ||
C0 | ||
} | ||
|
||
class C { } | ||
|
||
type T(c: C, s: E.set) #unboxed { | ||
def intersect(that: T) -> T { | ||
return T(C.new(), this.s & that.s); | ||
} | ||
} | ||
|
||
def mask = T(C.new(), E.A0 | E.B0 | E.B8); | ||
|
||
def main(a: int) -> int { | ||
var x: E.set; | ||
for (e in E) { | ||
if ((a & (1 << e.tag)) != 0) x |= e; | ||
} | ||
var t = T(C.new(), x).intersect(mask); | ||
var r: int; | ||
for (e in t.s) { | ||
r |= (1 << e.tag); | ||
} | ||
return r; | ||
} |
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,44 @@ | ||
//@execute 0=0; -1=16842753; 16842753=16842753 | ||
enum E { | ||
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Aa, Ab, Ac, Ad, Ae, Af, | ||
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, Ba, Bb, Bc, Bd, Be, Bf, | ||
C0 | ||
} | ||
|
||
class C { } | ||
|
||
type T #unboxed { | ||
case None(c0: C, c1: C); | ||
case Set(c0: C, s: E.set); | ||
|
||
def intersect(that: T) -> T { | ||
match (this) { | ||
None => return this; | ||
Set(c0, set0) => match (that) { | ||
None => return that; | ||
Set(_, set1) => return T.Set(c0, set0 & set1); | ||
} | ||
} | ||
} | ||
def set() -> E.set { | ||
return if(T.Set.?(this), T.Set.!(this).s); | ||
} | ||
} | ||
|
||
|
||
|
||
def mask = T.Set(C.new(), E.A0 | E.B0 | E.B8); | ||
|
||
def main(a: int) -> int { | ||
var x: E.set; | ||
for (e in E) { | ||
if ((a & (1 << e.tag)) != 0) x |= e; | ||
} | ||
var t = T.Set(C.new(), x).intersect(mask); | ||
if (a == 9999) t = T.None(C.new(), C.new()); | ||
var r: int; | ||
for (e in t.set()) { | ||
r |= (1 << e.tag); | ||
} | ||
return r; | ||
} |
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,44 @@ | ||
//@execute 0=0; -1=16842753; 16842753=16842753 | ||
enum E { | ||
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Aa, Ab, Ac, Ad, Ae, Af, | ||
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, Ba, Bb, Bc, Bd, Be, Bf, | ||
C0 | ||
} | ||
|
||
class C { } | ||
|
||
type T #unboxed { | ||
case None(c0: C, c1: C); | ||
case Set(c0: C, s: E.set); | ||
|
||
def intersect(that: T) -> T { | ||
match (this) { | ||
None(c0, c1) => return if(c0 == c1, this, this); | ||
Set(c0, set0) => match (that) { | ||
None => return that; | ||
Set(_, set1) => return T.Set(c0, set0 & set1); | ||
} | ||
} | ||
} | ||
def set() -> E.set { | ||
return if(T.Set.?(this), T.Set.!(this).s); | ||
} | ||
} | ||
|
||
|
||
|
||
def mask = T.Set(C.new(), E.A0 | E.B0 | E.B8); | ||
|
||
def main(a: int) -> int { | ||
var x: E.set; | ||
for (e in E) { | ||
if ((a & (1 << e.tag)) != 0) x |= e; | ||
} | ||
var t = T.Set(C.new(), x).intersect(mask); | ||
if (a == 9999) t = T.None(C.new(), C.new()); | ||
var r: int; | ||
for (e in t.set()) { | ||
r |= (1 << e.tag); | ||
} | ||
return r; | ||
} |
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,51 @@ | ||
//@execute 0=0; -1=16842753; 16842753=16842753 | ||
enum E { | ||
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Aa, Ab, Ac, Ad, Ae, Af, | ||
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, Ba, Bb, Bc, Bd, Be, Bf, | ||
C0 | ||
} | ||
|
||
class C { } | ||
|
||
type T #unboxed { | ||
case None(c0: C); | ||
case Set(s: E.set); | ||
|
||
def intersect(that: T) -> T { | ||
match (this) { | ||
None(c0) => return this; | ||
Set(s0) => match (that) { | ||
None => return that; | ||
Set(s1) => return T.Set(s0 & s1); | ||
} | ||
} | ||
} | ||
def set() -> E.set { | ||
return if(T.Set.?(this), T.Set.!(this).s); | ||
} | ||
def bits() -> int { | ||
if (T.None.?(this)) return 0; | ||
var s = T.Set.!(this).s; | ||
var r: int; | ||
for (e in s) r |= (1 << e.tag); | ||
return r; | ||
} | ||
} | ||
|
||
|
||
|
||
def some = [T.Set(E.A0 | E.B0 | E.B8), T.None(C.new())]; | ||
|
||
def make(a: int) -> E.set { | ||
var x: E.set; | ||
for (e in E) { | ||
if ((a & (1 << e.tag)) != 0) x |= e; | ||
} | ||
return x; | ||
} | ||
|
||
def main(a: int) -> int { | ||
var x = make(a); | ||
var t = T.Set(x).intersect(some[0]); | ||
return t.bits(); | ||
} |
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,42 @@ | ||
//@execute 0=0; -1=16842753; 16842753=16842753 | ||
enum E { | ||
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Aa, Ab, Ac, Ad, Ae, Af, | ||
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, Ba, Bb, Bc, Bd, Be, Bf | ||
} | ||
|
||
class C { } | ||
|
||
type T #unboxed { | ||
case None(c0: C, c1: C); | ||
case Set(c0: C, s: E.set); | ||
|
||
def intersect(that: T) -> T { | ||
match (this) { | ||
None(c0, c1) => return if(c0 == c1, this, this); | ||
Set(c0, set0) => match (that) { | ||
None => return that; | ||
Set(_, set1) => return T.Set(c0, set0 & set1); | ||
} | ||
} | ||
} | ||
def set() -> E.set { | ||
return if(T.Set.?(this), T.Set.!(this).s); | ||
} | ||
} | ||
|
||
|
||
|
||
def some = [T.Set(C.new(), E.A0 | E.B0 | E.B8), T.None(C.new(), C.new())]; | ||
|
||
def main(a: int) -> int { | ||
var x: E.set; | ||
for (e in E) { | ||
if ((a & (1 << e.tag)) != 0) x |= e; | ||
} | ||
var t = T.Set(C.new(), x).intersect(some[0]); | ||
var r: int; | ||
for (e in t.set()) { | ||
r |= (1 << e.tag); | ||
} | ||
return r; | ||
} |
Oops, something went wrong.