# ReMiX

## Overview

Remix is a programming language for the Java Virtual Machine.

At the source level, Remix brings new features and freedom. At the VM level, Remix adds safety and security.

### Goals

Remix is aimed for small, self-contained serverside progams that are not designed to interact with external resources or other JVM applications.

For beginners, it adds safety and reduces common risks with its strict object-oriented design and encapsulation. For advanced developers, it adds the freedom of organising code in a fluid style and inserting low-level compilation instructions for efficiency.

### Simplicity

Remix has only two distinct language elements: **words** and **boxes**. Everything can be categorised as one or the other.

{% hint style="info" %}
Operators are source-level syntax sugar for their built-in functions.
{% endhint %}

```
type home <-- words
    is building <-- more words
        {...} <-- box
```

Words are distinct (whitespace-separated) character sequences, including all keywords, types, member and variable names. Each word is read and dealt with in sequence by the compiler.

```
type <-- keyword
    home <-- type name
    is <-- keyword
    building <-- type name
```

Boxes are matched pairs of curly `{` and `}` brackets. These denote ownership or possession of the content inside.

```
type home { <-- box starts
    string address <-- inside box
} <-- box ends
```

Each box must belong to a word, but not all boxes need to directly follow their word. This allows the programmer to organise their code in a way that they find convenient.

```
var = true if { <-- belongs to `if`
}
if var = true { <-- belongs to `if`
}
```

### Language Features

#### Operator Overloading

The behaviour for all of the default operators can be overloaded by user-defined types. This allows developers to alter how `a + b` should be handled, and create more advanced polymorphic structures.

Logic-based algorithms can be set up to operate almost entirely according to operators.

<table><thead><tr><th width="150">Symbol</th><th width="150">Name</th><th>Description</th></tr></thead><tbody><tr><td><code>+</code></td><td>Add</td><td>Sums the two objects.</td></tr><tr><td><code>-</code></td><td>Sub</td><td>Subtracts the second object from the first.</td></tr><tr><td><code>*</code></td><td>Mul</td><td>Multiplies the two objects.</td></tr><tr><td><code>/</code></td><td>Div</td><td>Divides the first object by the second.</td></tr><tr><td><code>&#x3C;&#x3C;</code></td><td>Push</td><td>Pushes the second object into the first. This is used for the binary left-shift.</td></tr><tr><td><code>>></code></td><td>Pull</td><td>Pulls the second object from the first. This is used for the binary right-shift.</td></tr><tr><td><code>=</code></td><td>Equals</td><td>Compares the two objects and returns their boolean equality.</td></tr><tr><td><code>?</code></td><td>Bool</td><td>Evaluates an object as a boolean.</td></tr><tr><td><code>!</code></td><td>Neg</td><td>Returns the boolean opposite of the given object.</td></tr><tr><td><code>&#x26;</code></td><td>And</td><td>Gives the and-result. This is distinct from <code>+</code> to account for binary <code>&#x26;</code> operations.</td></tr><tr><td><code>|</code></td><td>Or</td><td>Gives the or-result.</td></tr></tbody></table>

#### Zero Allocation

The RMX schema is not designed to support `null` pointers. This is partly as a safety feature to prevent null-pointer exceptions that new developers often struggle with, and partly to cater for RMX's value-based object design.

All types support a 'zero instance', which is effectively the object if all of its binary values were zero. Semantically, the value of any zero-instance `object.Bool {}` should always be `0` but this is not enforced.

A zero-instance can be created using the `alloc` keyword. Using this keyword guarantees a new instance of the object is created.

```
integer num { alloc integer }
if integer = 0 { <-- always true
}
```

Unlike the `new` keyword, `alloc` never accepts any parameters and has no box attached.

{% hint style="info" %}
The `alloc` keyword does not call a constructor. This allows constructor-less objects to be created.
{% endhint %}

It is generally not advised to allocate objects directly when there is a `new` constructor available, since it may produce an unsupported result.

Zero-allocation is used in several places under the hood, such as when a variable is declared with no value `integer num {}` or a constructor hits an uncaught error and cannot produce a value.

### Implementation

All objects and operations are handled as pointers rather than via primitive values. This is done to add safety and allow advanced overloading or creation of new raw-data types (e.g. numbers) at the small cost of speed in some cases.

After the introduction of [primitive classes](http://openjdk.java.net/jeps/401) as a VM feature, all types will be primitive unless the advanced pointer feature is used.
