Documentation

The main function

Every Dime program begins with a main function that returns with the exit code.

function main(): int {
    return 0
}

Functions

You can create functions with the function keyword.

function multiply(int a, int b): int {
    return a * b
}

Note: You may omit the return statement. Doing so will be the same as returning the null value of the data type such as

0
,
false
or
'\x00'
.

Variables

To declare a variable use the var keyword:

var name: type = value
.
To redefine a variable use the equals operator:
name = value
.

You may 'shadow' variables.

var a: int = 0
{
    var a: int = 1
    printNumber(a) //prints 1
}
printNumber(a) //prints 0

Data types

Currently the following data types are implemented:

  • bool:
    true
    and
    false
  • Integers:
    • byte literal
      'A'
    • int literal
      65
    • float literal
      65.0
  • pointer
    • As a result of
      allocate(byteCount)
    • SimpleString literal
      #"Hello world!"
      (UTF-8 encoded)
  • void
    for functions with no return value

For strings and bytes you can also use escapes such as

\n
or
\x0A
.
'Real' strings will be implemented using linked lists.

Operators

  • Working with numbers:
    + - / *
  • Comparisons:
    == != < > <= >=
  • Logical:
    && ||
  • Pointer operations
    • Read:
      ptr->byte
    • Write:
      ptr<-'A'
  • Redefine value:
    something = 0
  • Increment/Decrement operators:
    i++
    i--
  • Cast:
    'A'|>int

Conditions

The condition of an if block can be any expression that evaluates to a boolean value.

if (condition) {
 
} else if (otherCondition) {
 
} else {
 
}

Loops

While loop

while (true) {
    //code
}

For loop

for (var i: int = 0; i < 10; i++) {
    //code
}

Note: The head of a for loop is the only place where you have to use semicolons.

Standard library

readByte(bool echo): byte

writeByte(byte b): void

writeBytes(pointer ptr, int byteCount): void

print(int number): void

print(float number): void

print(double number): void

allocate(int byteCount): pointer

free(pointer ptr): void

getConsoleWidth(): int

getConsoleHeight(): int

randomInt(int min, int max): int
(min is inclusive and max is exclusive)