Skip to content
Cubed edited this page Mar 25, 2022 · 9 revisions

Welcome to the Ice wiki!

The main feature of ice is assigning the type to a variable anywhere in a program any number of times. Since they affect only the appearance and behaviour of the variable and not the data itself, we call them labels.

@str msg = 'Hello, World!' # @str is a label of size 64 bits since it's a 64-bit pointer.
print(msg) # -> Hello, World!

@bytes msg # We change the type of the variable here. Now it acts as a pointer to an array.
print(msg) # -> [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]

Declaration occurs whenever the first assignment of a label takes place.

Base Labels

All labels derive from base labels. They have a different syntax from derived labels.
@3 @4 @5 @6 represent 8, 16, 32 and 64-bit sizes respectively. (Why those digits? They're the powers of 2)

So here's an example of a declaration using default labels.

@4 new_variable
@3 first_alphabet = 65 # You can assign values in a declaration statement.

Since variables can't start with a digit, we benefit from a shorthand declaration syntax when we use default labels.

4new_variable
3first_alphabet = 65

Label Prefixes

Variants of a label can be used by appending any number of prefixes to it.

@[n]label represents array of n elements of label. @*label represents a pointer to label. @3label @4label @5label @6label represent dynamic arrays whose length is stored using 8 to 64 bits.

@*3 apple # this is a pointer to a byte
@[9]str banana # this is an array of 9 strings
[4]4guava # this is an array of four 16-bit integers (short hand works here too)
63orange # a dynamic array of bytes whose length is stored as a 64-bit integer

# They can also be chained
**3argv # a pointer to pointer to bytes
@[256][256]str s_mat # a matrix of strings

Label Definitions

(TODO: move this to a separate page)

Labels can inherit from derived or from base labels.

# syntax is subject to change
@bytes(*3): # zero ended array
    6__len__(self): # syntax of function definition is similar to variable declaration / label assigning
        6out = 0
        while *self: self += 1; out += 1
        return out
    @str __str__(self):
        63out
        6n = len(self)*5 + 2
        [n]out
        out[0] = '[' # haven't decided if string literals return the value or a pointer
        *3curr = out.ptr
        while *self:
            @str num = str(*self) + ', ' # labels may have a separate namespace from functions and variables
            memcpy(curr, num, len(num))
            curr += len(num)
            self += 1
        if n == 2: curr += 1
        else: curr -= 2
        memcpy(curr, [']', 0], 2)
        return out.ptr

I've also borrowed the data definition methods (aka __dunder__ methods) and the indentation from Python because that's what makes Python great (plus, I am primarily a Python programmer).

Clone this wiki locally