Written by Uchio Kondo (@udzura on Twitter / GitHub)
https://github.com/udzura/niao
// No explicit type declaration
some := 1;
value := "str";
// comment with //
// reassign
some = 2;
i8 (char)
i32
i64
u8 (uchar)
u32
u64
boolean
// Has string type
string
// slice type exists(internally?)
// Type detection
// Variables without type are assumed as i32(!)
// It is clear when:
// boolean literal: boolean(i8?)
// string liretal
// Tuple also has liretal
// TODO
// pointers
bar_p := &bar; // is?
// How about type declaration?
some :: u64
some = 9; // is u64
some := 1;
if some < 2 {
do_some();
} else {
do_hoge();
}
// Loop
for i in step(1, 4) {
puts(i * 2);
}
// Not yet implemented slice/array literals
ar := array(1, 2, 3, 4)
for e in range(ar) {
puts("element:");
puts(e);
}
// while loop
for n while(n < 3) {
puts(n);
n = n + 1;
}
// infinit
for _ while(true) {
}
fun max(x, y) {
if x > y or x == y {
return x;
} else {
return y;
}
}
puts(max(3, 5));
// Typed
// When not explicitly typed, it is forced to i32 (!!)
fun max(x : i32, y : i32) {
if x > y or x == y {
return x;
} else {
return y;
}
}
// Tuple
t1 := {{"hoge", 1, -2}}
// access by number
t1.0 // => "hoge"
// Named Tuple
// can be accompanied with type
struct Person {{name : string, age : i32}}
p1 := Person {{"udzura", 37}}
p1.name // => "udzura"
// by number. it is still a tuple
p1.0 // => also "udzura"
// update
p1.name = "akubi"
p1.name
// TODO: method like syntax sugar
@bpf("kprobe/foo")
fun get_by_bpf(ctx) {
if ctx.addr == 0 {
//...
}
}