Compiler in Rust (lexer, parser, checker, C codegen), maps, chars, dino fmt, dino lsp (diagnostics, formatting, outline, definition, hover, completion, signature help), docs, examples, VS Code/Vim files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
24 lines
408 B
Plaintext
24 lines
408 B
Plaintext
// Enums with data, generics, interfaces.
|
|
enum Shape {
|
|
Circle(r: f64)
|
|
Rect(w, h: f64)
|
|
}
|
|
|
|
func area(s: Shape): f64 {
|
|
return match s {
|
|
Circle(r) => 3.14159 * r * r
|
|
Rect(w, h) => w * h
|
|
}
|
|
}
|
|
|
|
interface Drawable { draw() }
|
|
|
|
func draw_all[T: Drawable](items: []T) {
|
|
for item in items { item.draw() }
|
|
}
|
|
|
|
func max[T: Ordered](a, b: T): T {
|
|
if a > b { return a }
|
|
return b
|
|
}
|