Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- constants:
- x :: 42;
- y :: []cell{ 1, 2, 3 };
- variables:
- x : cell
- y : [x]cell ; x is an int
- z : byte ; z is a number at compile time and does not exist at runtime
- assignment:
- x = 0
- x = 5
- y[3] = 4 ; 3 is an int at compile time
- y[x] = 6 ; x is a cell at runtime (we don't support >1 byte numbers at runtime natively yet)
- arrays:
- x : [5]cell
- x[0] = 4
- x[1] = 2
- type inference in declaration:
- x := 5 ; x : cell = 5
- copying:
- x := 5
- y : cell
- y = x
- addition / subtraction:
- x := 5
- y := 3
- x += y
- y -= x
- while loops:
- x := 5
- while x { ; does not clear x
- x -= 1
- ...
- }
- for loops:
- x := 5
- for x { ; does not clear x
- ...
- }
- if statements:
- x := 1
- if x { ; does not clear x
- ...
- } /* else { ... } */
- macros:
- blah :: macro(x: cell) {
- x -= 5
- }
- y := 8
- blah(y)
- // y = 3
- code as (compile time) data:
- blah :: macro(x: block) {
- x()
- }
- blah({
- ...
- })
- static for:
- #for i in 0..5 {
- ...
- }
- static if:
- x :: macro(y: byte) {
- #if y > 5 {
- ...
- }
- }
- x(7)
- polymorphism in array parameters:
- zero :: macro(x: [y]cell) {
- #for i in 0..y-1 {
- x[i] = 0
- }
- }
- with restrictions:
- copy :: macro(src: [x]cell, dst: [x]cell) {
- #for i in 0..x-1 {
- dst[i] = src[i]
- }
- }
- x in arg 0 must equal x in arg 1
- type coercion:
- zero :: macro(x: [y]cell) { ... }
- a : cell = 5
- zero(a) ; 'zero' treats 'a' as `[1]cell` instead of just `cell`
- ; all `cell`s are desugared into this behind the scenes
- custom data structures:
- struct Foo {
- x: cell;
- y: cell;
- }
- x : Foo
- x.x = 5;
- x.y = 1;
- blah :: macro(x: Foo) {
- x.x += x.y;
- }
- blah(x);
- with compile-time data too:
- Stack :: struct<n: int> {
- data: [n]cell;
- ptr: cell;
- }
- push :: macro(stack: Stack, data: cell) {
- stack.data[stack.ptr] = data;
- stack.ptr += 1;
- }
- pop :: macro(stack: Stack, result: cell) {
- stack.ptr -= 1;
- result = stack.data[stack.ptr];
- }
- */
- zero :: macro(x: [y]cell) {
- #for i in 0..y-1 {
- x[i] = 0;
- }
- }
- x := 5;
- zero(x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement