comptime storage and function values
This commit is contained in:
@@ -74,6 +74,18 @@ may_fail func(flag bool) i32 ! Error {
|
||||
return 7
|
||||
}
|
||||
|
||||
increment func(value i32) i32 {
|
||||
return value + 1
|
||||
}
|
||||
|
||||
call_native func(callback *func(value i32) i32, value i32) i32 {
|
||||
return callback(value)
|
||||
}
|
||||
|
||||
call_fallible func(callback *func(flag bool) i32 ! Error, flag bool) i32 ! Error {
|
||||
return try callback(flag)
|
||||
}
|
||||
|
||||
use_try func() i32 ! Error {
|
||||
value :: try may_fail(false)
|
||||
return value + 1
|
||||
@@ -87,6 +99,41 @@ recover func() i32 {
|
||||
}
|
||||
}
|
||||
|
||||
bump_ptr func(value @mut i32) void {
|
||||
value^ += 1
|
||||
}
|
||||
|
||||
alias_add func(left @mut i32, right @mut i32) void {
|
||||
left^ += 2
|
||||
right^ += 3
|
||||
}
|
||||
|
||||
storage_mutation func() i32 {
|
||||
values [3]mut i32 = [1, 2, 3]
|
||||
values[0] += 1
|
||||
bump_ptr(&values[1])
|
||||
|
||||
view []mut i32 = values[..]
|
||||
for view |@item| {
|
||||
item^ += 1
|
||||
}
|
||||
|
||||
pointer *mut i32 = view.ptr
|
||||
pointer[2] += 1
|
||||
alias_add(&values[0], &view[0])
|
||||
|
||||
box Box = Box { point = Point { x = 2, y = 3 } }
|
||||
match box {
|
||||
.point |@p|: p.x += values[1]
|
||||
.empty: values[0] = values[0]
|
||||
}
|
||||
|
||||
if view.len != 3 {
|
||||
return 0
|
||||
}
|
||||
return values[0] + view[1] + pointer[2] + box.point.x
|
||||
}
|
||||
|
||||
GLOBAL :: $sum_loop(4)
|
||||
|
||||
main func() i32 {
|
||||
@@ -100,6 +147,15 @@ main func() i32 {
|
||||
optional i32 :: $maybe(true)?
|
||||
tried i32 :: $use_try() catch 0
|
||||
recovered i32 :: $recover()
|
||||
storage i32 :: $storage_mutation()
|
||||
called i32 :: $call_native(increment, 11)
|
||||
fallible_ok i32 :: $call_fallible(may_fail, false) catch 0
|
||||
fallible_err i32 :: $call_fallible(may_fail, true) catch |e| {
|
||||
result i32 :: match e {
|
||||
.bad: 13
|
||||
}
|
||||
yield result
|
||||
}
|
||||
|
||||
if point.x + point.y != 7 {
|
||||
return 1
|
||||
@@ -134,5 +190,20 @@ main func() i32 {
|
||||
if GLOBAL != 8 {
|
||||
return 11
|
||||
}
|
||||
if storage != 23 {
|
||||
return 12
|
||||
}
|
||||
if called != 12 {
|
||||
return 13
|
||||
}
|
||||
if call_native(increment, 20) != 21 {
|
||||
return 14
|
||||
}
|
||||
if fallible_ok != 7 {
|
||||
return 15
|
||||
}
|
||||
if fallible_err != 13 {
|
||||
return 16
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user