Repository navigation
Violette v0.3.0
This release introduces revising compiler architecture via using typed AST, many language syntax improvements and fixes, new features, like slices and many more...
-
Typed AST: Made new module in the compiler and revised typechecker logic from checking type mismatches to building a new AST, with which the codegen works. It allows removing any logic, connected with type checking, from codegen, so, since now it literally only generates code. Since adding that feature Violette will be able to have more than one way to be compiled, like, generating LLVM IR or CLIF for Cranelift.
-
Arrays and Slices: Added arrays and slices for all primitive and
structtypes. Supported indexing and slicing arrays via range syntax constructs,..<or..=. -
Labeled Params: Added Swift-like labeling function parameters model with two identifiers: external label and internal name, for example:
func greet(to name: String, from sender: String) { println("Hello, " + name + " from " + sender) } greet(to: "Alice", from: "me") greet(from: "you", to: "Alice") greet("Alice", from: "her")
Unlike Swift, in Violette you can change labeled parameters order in function call. All
greetfunction call in this example are correct in Violette. -
New Syntax for Methods: Since this release you can give your own name to the object, like in Go
struct Point { x: Float64, y: Float64, } extend Point { func new(x: Float64, y: Float64) -> Point { return Point { x: x, y: y } } func (p: Self) distance(other: Point) -> Float64 { let dx = p.x - other.x let dy = p.y - other.y return ((dx * dx) + (dy * dy)).sqrt() } }
If function declared in
extend-block without parens afterfunckeyword, like thenewfunction in this example, it will be a static method. Otherwise, the name you will give in the parens will be assigned to the object. No reserved keywords likeselforthis. -
Enums:
variantis changed toenumfor greater familiarity in case you are Rust/Swift/Scala 3 developer -
New Lambda Syntax: Since now lambdas are just blocks of code, which use numbered parameters, e.g.
#0,#1, etc.
Named parameters in lambdas are just variableslet add: fun(Int, Int) -> Int = { #0 + #1 } // lambda which takes two integer numbers and return their sum let subtract: fun(Float64, Float64) -> Float64 = { let a = #0 // first named parameter let b = #1 // second named parameter a - b // result }
-
Optional Parens in Operator Sections: Parens are no more required in functions/methods calls
func filter_print(x: Int, predicate: fun(Int) -> Bool) { if predicate(x) { println(x) } } func main() { filter_print(10, > 5) filter_print(3, > 5) filter_print(7, != 7) filter_print(42, != 7) }
But you can still use them
-
Double Inequalities: Added support for double comparison operators (e.g.,
a < b < c)func inc(var num: Int) -> Int { num++ return num } func main() { let x = 0 if 0 < inc(x) < 2 { println("x: " + inc(x).toString()) } else { println("unreachable") } }