Over the last few months I've been working on a new programming language called Dassie that compiles to .NET CIL. It started as a project to learn about compiler development, but it's slowly been taking shape and getting more features. It's still very early in development and doesn't have a whole lot of features yet, but you can already do some basic stuff with it.
The compiler is located here, documentation and code examples can be found here.
Here is "Hello World" in Dassie:
println "Hello World!"
This uses the built-in function println
, but since Dassie is .NET-based, you can also use the Console
class:
import System
Console.WriteLine "Hello World!"
Assuming you have installed the Dassie compiler and the above code is contained in a file called hello.ds
, it can be compiled using the command dc hello.ds
, yielding a .NET assembly called hello.dll
as well as a native app host.
The following is a short overview of the language, more thorough documentation can be found in the repo I linked above.
Language overview
# Single-line comment
#[
Multi-line comment
]#
All Dassie code needs to be contained in a type. Like C#, Dassie also allows top-level code in one file per project, which is automatically declared as the entry point of the program. Types are defined like this, where a module is equivalent to a C# static class
:
type MyType = {
# Members...
}
module MyModule = {
# Members...
}
Variables and functions
x = 10
x: int = 10
var x = 10
Dassie is statically typed, but has automatic type inference for variables. Variables are immutable by default, but can be declared as mutable using the var modifier.
Functions are defined just like variables, except that they cannot have a var modifier and include a parameter list. Type inference is not yet supported for function parameters, only return types for now.
Add (x: int, y: int) = x + y
The body of a function is an expression or a code block (which is itself just an expression), no need for a return keyword.
Functions are called without parentheses, altough the arguments still need to be separated by commas.
Control flow
Control flow in Dassie is done using operators instead of keywords. Also, all control flow operations are expressions. A loop, for example, returns an array of the return values of every iteration.
Conditionals and loop expressions use the ?
and @
operators respectively, and also have a negated form (known as the unless and until expressions using the operators !?
and !@
). They can be used both in prefix and postfix form.
import System
age = int.Parse Console.ReadLine
Console.WriteLine ? age > 18 = "You are an adult!"
: = "You are a child."
Arrays and Lists
The following example shows how to create and use arrays and lists (List<T>
).
numArray = @[1, 2, 3, 4, 5]
numList = [1, 2, 3, 4, 5]
firstNum = numList::0
Conclusion
The language is still in active development, but I'd love you to try it out. Feel free to download and play around with the compiler!
Top comments (0)