fix interop and indexing oversights
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
main func() i32 {
|
||||
n usize = 4
|
||||
items [n]mut i32 = undefined
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
main func() i32 {
|
||||
items [3]mut i32 = undefined
|
||||
i int = 1
|
||||
items[i] = 42
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
main func() i32 {
|
||||
items [3]mut i32 = undefined
|
||||
i i32 = 1
|
||||
items[i] = 42
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
CAP :: 4
|
||||
LEN :: CAP + 1
|
||||
|
||||
Kind :: enum {
|
||||
circle
|
||||
square
|
||||
triangle
|
||||
}
|
||||
|
||||
take_c_int func(value c_int) c_int {
|
||||
return value
|
||||
}
|
||||
|
||||
take_c_uchar func(value c_uchar) c_uchar {
|
||||
return value
|
||||
}
|
||||
|
||||
take_c_float func(value c_float) c_float {
|
||||
return value
|
||||
}
|
||||
|
||||
take_c_double func(value c_double) c_double {
|
||||
return value
|
||||
}
|
||||
|
||||
take_c_string func(value ?*c_char) i32 {
|
||||
_ = value
|
||||
return 0
|
||||
}
|
||||
|
||||
next_kind func(k Kind) Kind {
|
||||
return match k {
|
||||
.circle: .square
|
||||
.square: .triangle
|
||||
.triangle: .circle
|
||||
}
|
||||
}
|
||||
|
||||
score_for func(k Kind) i32 {
|
||||
score :: {
|
||||
yield match k {
|
||||
.circle: 1
|
||||
.square: 2
|
||||
.triangle: 3
|
||||
}
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
main func() i32 {
|
||||
items [LEN]mut i32 = undefined
|
||||
items[0] = 10
|
||||
items[1] = 20
|
||||
|
||||
idx u8 = 2
|
||||
items[idx] = items[0] + items[1]
|
||||
if (items[2] != 30) return 1
|
||||
|
||||
native_i i32 = 12
|
||||
if (take_c_int(native_i) != 12) return 2
|
||||
|
||||
native_u u8 = 7
|
||||
if (take_c_uchar(native_u) != 7) return 3
|
||||
|
||||
native_f f32 = 3.25
|
||||
cf :: take_c_float(native_f)
|
||||
if (cf < 3.0 or cf > 4.0) return 4
|
||||
if (cf == 0.0) return 5
|
||||
|
||||
native_d f64 = 5.0
|
||||
cd :: take_c_double(native_d)
|
||||
if (cd != 5.0) return 6
|
||||
|
||||
as_i32 :: i32(cf)
|
||||
if (as_i32 != 3) return 7
|
||||
as_float :: f32(native_i)
|
||||
if (as_float < 11.5 or as_float > 12.5) return 8
|
||||
as_c_float :: c_float(as_i32)
|
||||
if (as_c_float != 3.0) return 9
|
||||
|
||||
kind :: next_kind(.circle)
|
||||
if (kind != .square) return 10
|
||||
if (score_for(kind) != 2) return 11
|
||||
|
||||
label :: match kind {
|
||||
.circle: "circle"
|
||||
.square: "square"
|
||||
.triangle: "triangle"
|
||||
}
|
||||
if (take_c_string(label) != 0) return 12
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
main func() i32 {
|
||||
flag bool = true
|
||||
value :: i32(flag)
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user