Installation
Varse is a single executable with no external dependencies. Build from source with NASM and GoLink:
git clone https://github.com/varse-lang/varse
cd varse
nasm -f win64 varse.asm -o varse.obj
golink /entry:main /console varse.obj kernel32.dll user32.dll gdi32.dll gdiplus.dll
Hello World
Create a file called hello.var:
fn main() {
print(42);
}
Running Code
Every Varse program must have a fn main() function. The interpreter parses all definitions first, then finds and executes main.
varse hello.var
Variables
Variables store values that can be changed. Declared with let.
let name = expression;
fn main() {
let x = 10;
let y = x + 5;
print(y);
x = 20;
print(x);
}
Constants
Constants are immutable values declared with def. They are resolved at the start of execution.
def name: value;
def pi: 314;
def max_retries: 3;
fn main() {
print(pi);
}
Functions
Functions are declared with fn and contain a block of statements. Functions can be nested.
fn name(params) {
statements
}
fn add(a + b) {
return a + b;
}
fn main() {
print(add(10 + 20));
}
Parameters
Parameters are separated by + (or ,) in both the definition and the call. When calling a function, + acts as the argument separator. To pass an arithmetic expression as a single argument, wrap it in parentheses.
| Syntax | Description |
|---|---|
fn(a + b) | Two parameters |
fn(x) | One parameter |
fn() | No parameters |
add(10 + 20) | Call with 2 arguments (10 and 20) |
add((x + y)) | Call with 1 argument (the expression x + y) |
Return Values
Use return to send a value back from a function.
fn fib(n) {
if n <= 1 {
return n;
}
return fib(n - 1) + fib(n - 2);
}
fn main() {
print(fib(10));
}
Operators
Arithmetic
| Op | Description | Example |
|---|---|---|
+ | Addition / parameter separator | x + y |
- | Subtraction / unary negation | x - y, -x |
* | Multiplication | x * y |
/ | Integer division | x / y |
Comparison
| Op | Description |
|---|---|
== | Equal to |
!= | Not equal to |
< | Less than |
> | Greater than |
<= | Less than or equal |
>= | Greater than or equal |
Precedence (high to low)
| Level | Operators |
|---|---|
| 1 | Unary - |
| 2 | *, / |
| 3 | +, - |
| 4 | <, >, <=, >=, ==, != |
Comments
// This is a single-line comment
/*
This is a
block comment
*/
If / Else
Conditional execution with if, else if, and else.
fn classify(n) {
if n < 10 {
return 1;
} else if n < 100 {
return 2;
} else {
return 3;
}
}
fn main() {
print(classify(4));
print(classify(42));
print(classify(999));
}
Blocks & Scope
Variables declared inside a function are scoped to that function. Nested functions can access variables from enclosing scopes.
def base: 10;
fn main() {
fn add(x + y) {
return x + y;
}
let sum = add(base + 2);
print(sum);
}
print()
Built-in function that outputs a number to the console.
| Parameter | Type | Description |
|---|---|---|
| expression | number | The value to output. Any expression that evaluates to a number. |
Multiple print() calls concatenate on the same line with no separator.
fn main() {
print(197);
print(12345);
}
GUI Framework
Varse includes a built-in GUI system for creating native Windows applications with styled widgets, rounded corners, and click handlers. The GUI uses Win32 API and GDI under the hood.
A GUI program defines widgets, registers click handlers, then calls show to enter the message loop.
window
Creates the application window. Must be the first GUI statement.
window "title" width height bg=#HEX;
| Parameter | Type | Description |
|---|---|---|
| title | string | Window title bar text |
| width | number | Width in pixels |
| height | number | Height in pixels |
| bg | hex | Background color #RRGGBB (optional) |
window "My App" 800 600 bg=#121212;
button
Creates a clickable button with optional rounded corners and color.
button name x y w h "text" radius=N color=#HEX;
| Parameter | Type | Description |
|---|---|---|
| name | identifier | Unique name for onclick |
| x, y | number | Position from top-left |
| w, h | number | Width and height in pixels |
| text | string | Label text, centered |
| radius | number | Corner radius, default 8 (optional) |
| color | hex | Background color #RRGGBB (optional) |
label
Creates a text label. Not clickable.
label name x y w h "text" color=#HEX;
| Parameter | Type | Description |
|---|---|---|
| name | identifier | Unique name |
| x, y | number | Position from top-left |
| w, h | number | Text bounding box |
| text | string | Text to display |
| color | hex | Text color #RRGGBB (optional, default #000000) |
show
Creates the window and enters the message loop. Blocks until the window is closed.
show;
onclick
Registers a callback that runs when a button is clicked.
onclick button_name {
statements
};
window "Clicker" 400 200 bg=#222222;
button btn1 20 20 160 50 "Print 42" radius=25 color=#1DB954;
onclick btn1 {
print(42);
};
show;
Example: Fibonacci
fn fib(n) {
if n <= 1 {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
fn classify(n) {
if n < 10 { return 1; }
else if n < 100 { return 2; }
else { return 3; }
}
fn main() {
let z = fib(10);
print(z);
print(classify(4));
print(classify(10));
print(classify(99));
}
Example: GUI App
window "Varse GUI" 600 400 bg=#222222;
label title 20 20 300 40 "Hello from Varse!" color=#FFFFFF;
button btn1 20 130 180 50 "Print Number" radius=10 color=#CC4422;
button btn2 220 130 180 50 "Say Hello" radius=10 color=#226644;
button btn3 20 200 180 50 "Big Radius" radius=25 color=#4444CC;
onclick btn1 { print(42); };
onclick btn2 { print(100); };
onclick btn3 { print(999); };
show;