-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
18 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
42 changes: 29 additions & 13 deletions
42
code-samples/appendices-annotations-likely-and-unlikely-annotations.pony
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,16 +1,32 @@ | ||
if \likely\ cond then | ||
foo | ||
end | ||
type T is (U32|U8) | ||
|
||
while \unlikely\ cond then | ||
bar | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
let foo = "foo" | ||
let bar = "bar" | ||
let baz = "baz" | ||
var cond = true | ||
let obj: U32 = 42 | ||
let expr: U32 = 42 | ||
|
||
if \likely\ cond then | ||
foo | ||
end | ||
|
||
repeat | ||
baz | ||
until \likely\ cond end | ||
cond = false | ||
while \unlikely\ cond do | ||
bar | ||
end | ||
|
||
match obj | ||
| \likely\ expr => foo | ||
| \unlikely\ let capt: T => bar | ||
end | ||
cond = true | ||
repeat | ||
baz | ||
until \likely\ cond end | ||
|
||
let res = | ||
match obj | ||
| \likely\ expr => foo | ||
| \unlikely\ let capt: T => bar | ||
end | ||
|
||
env.out.print("res = " + res) |
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,3 +1,11 @@ | ||
struct \packed\ MyPackedStruct | ||
var x: U8 | ||
var y: U32 | ||
var y: U32 | ||
|
||
new create() => | ||
x = 0 | ||
y = 1 | ||
|
||
actor Main | ||
new create(env: Env) => | ||
env.out.print("{\n\t\"x\": " + MyPackedStruct.x.string() + ",\n\t\"y\": " + MyPackedStruct.y.string() + "\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