-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Const enum variants no longer backed by functions (#507)
Rather than having constant enum variants backed by a function call like how container enum variants work, store them as constant `data` values instead. Constant enum variants don't contain variables or data which could vary depending on construction, so this is a pretty straightforward (if minor) performance improvement. The real main change hidden in this changeset is the solving of a sneaky and nefarious bug that's been hidden in here for a while - when storing Byte instances into a Pointer value using the intrinsic `Pointer#store` method, it would actually use a `storel` qbe instruction behind the scenes which would result in _4_ bytes being written to the underlying memory. This had the evil side effect of overwriting the neighboring memory segment's value, most likely to be `0`. This was most apparent in `Array#toString` which I had actually already noticed a while ago but never got around to actually digging in to figure out what was wrong. This solution was the result of many hours' work (unfortunately) so it's no wonder why I punted on it for so long. Oh well, it was fun.
- Loading branch information
Showing
6 changed files
with
102 additions
and
163 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,14 @@ | ||
// // enum Foo { | ||
// // Bar(a: Int, b: String = "default") | ||
// // } | ||
// val str: String? = None | ||
|
||
// // val f = Foo.Bar(a: 123) | ||
// // println(f) | ||
// println(str?.isEmpty()) | ||
|
||
// func foo(a: Int, b = "asdf", c = 123) { | ||
// println(a, b, c) | ||
// } | ||
// println("a s d f".split(by: " ")) | ||
// println("asdf".split()) | ||
|
||
// foo(a: 1) | ||
// foo(a: 1, c: 456) | ||
// foo(a: 1, b: "456") | ||
// foo(a: 1, b: "456", c: 456) | ||
val arr = [1, 2, 3, 4] | ||
|
||
// type Foo { | ||
// func bar(self, a: Int, b = "asdf", c = 123) { | ||
// println(a, b, c) | ||
// } | ||
|
||
// func baz(a: Int, b = "asdf", c = 123) { | ||
// println(a, b, c) | ||
// } | ||
// } | ||
|
||
// // Foo.baz(a: 1) | ||
// // Foo.baz(a: 1, c: 456) | ||
// // Foo.baz(a: 1, b: "456") | ||
// // Foo.baz(a: 1, b: "456", c: 456) | ||
|
||
// val f = Foo() | ||
// // f.bar(a: 1) | ||
// // f.bar(a: 1, c: 456) | ||
// // f.bar(a: 1, b: "456") | ||
// // f.bar(a: 1, b: "456", c: 456) | ||
|
||
|
||
// func callFn2(fn: (Int, String) => Unit) { | ||
// fn(24, "foo") | ||
// } | ||
|
||
// func callFn3(fn: (Int, String, Int, String) => Unit) { | ||
// fn(24, "foo", 24, "foo") | ||
// } | ||
|
||
// callFn1(foo) | ||
// callFn2(foo) | ||
// callFn3(foo) | ||
|
||
// callFn1(f.bar) | ||
// callFn2(f.bar) | ||
// callFn3(f.bar) | ||
|
||
// callFn1(Foo.baz) | ||
// callFn2(Foo.baz) | ||
// callFn3(Foo.baz) | ||
|
||
enum Color { | ||
Red | ||
Green | ||
Blue | ||
RGB(r: Int = 0, g: Int = 0, b: Int = 0) | ||
} | ||
|
||
val black = Color.RGB() | ||
println(black) | ||
val white = Color.RGB(r: 255, g: 255, b: 255) | ||
println(white) | ||
val red = Color.RGB(r: 255) | ||
println(red) | ||
val green = Color.RGB(g: 255) | ||
println(green) | ||
val pink = Color.RGB(r: 255, b: 255) | ||
println(pink) | ||
val cyan = Color.RGB(g: 255, b: 255) | ||
println(cyan) | ||
val yellow = Color.RGB(r: 255, g: 255) | ||
println(yellow) | ||
/// Expect: [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] | ||
val arr2 = arr.flatMap(i => Array.fill(i, i)) | ||
println(arr2) | ||
println(arr2.length) | ||
println(arr2) |
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
Oops, something went wrong.