arcis-interpreter 0.1.45

Arcis Interpreter
Documentation
## Table of contents

* [Expression support]#expression-support
  * [Binary expressions]#binary-expressions
  * [Casts]#cast-expressions
  * [Functions]#function-calls
  * [Literals]#literal-expressions
  * [Methods]#method-calls
  * [Paths]#paths
* [Item support]#item-support
* [Pattern support]#pattern-support
* [Type support]#type-support

# Expression support:

| Expression Name   | Example                        | Support         | Comments                                                                                             |
|:------------------|:-------------------------------|:----------------|:-----------------------------------------------------------------------------------------------------|
| Array literal     | `[a, b]`                       | Supported       |                                                                                                      |
| Assignment        | `a = b;`                       | Supported       |                                                                                                      |
| Async block       | `async { ... }`                | Unsupported     |                                                                                                      |
| Await             | `foo().await`                  | Unsupported     |                                                                                                      |
| Binary expression | `a + b`                        | Partial Support | [See table below]#binary-expressions for supported binary expressions.                             |
| Block expression  | `{ ... }`                      | Supported       |                                                                                                      |
| Break             | `break;`                       | Unsupported     |                                                                                                      |
| Function call     | `f(a, b)`                      | Partial Support | [See table below]#function-calls for supported functions.                                          |
| Casts             | `a as u16`                     | Partial Support | [See table below]#cast-expressions for supported conversions.                                      |
| Closures          | `\|a, b \| a + b`              | Unsupported yet |                                                                                                      |
| Const block       | `const { ... }`                | Supported       |                                                                                                      | 
| Continue          | `continue;`                    | Unsupported     |                                                                                                      |
| Field access/set  | `obj.field`                    | Supported       |                                                                                                      |
| For loop          | `for i in 0..a { ... }`        | Partial Support | `for <var> in min..max` is the only supported loop. `min` and `max` should be known at compile-time. |
| If                | `if cond { ... } else { ... }` | Supported       | Complexity is in O( then_block + else_block).                                                        | 
| Indexing          | `a[idx]`                       | Supported       | Complexity will be in O(`a.len()`) if `idx` isn't known at compile-time.                             |
| If let            | `if let Some(x) = ...`         | Unsupported     |                                                                                                      |
| Literals          | `1u128`                        | Partial Support | [See table below]#literal-expressions for supported literals.                                      |
| Loops             | `loop { ... }`                 | Unsupported     | Cannot be supported as the number of iterations is not known.                                        |
| Macros            | `format!("{}", q)`             | Unsupported     |                                                                                                      |
| Match             | `match n { ... }`              | Unsupported     |                                                                                                      |
| Method calls      | `x.foo(a, b)`                  | Partial Support | [See table below]#method-calls for supported methods.                                              |
| Parentheses       | `(a + b)`                      | Supported       |                                                                                                      |
| Paths             | `Foo::bar`                     | Partial Support | [See table below]#paths for supported paths.                                                       |
| Ranges            | `4..5`                         | Partial Support | Only supported in `for name in 4..=5`.                                                               |
| Raw addresses     | `&raw const foo`               | Unsupported     |                                                                                                      |
| References        | `&mut foo`                     | Supported       |                                                                                                      |
| Repeat arrays     | `[4u8; 128]`                   | Supported       |                                                                                                      |
| Return            | `return false;`                | Unsupported     |                                                                                                      |
| Struct literals   | `MyStruct { a: 12, b }`        | Supported       |                                                                                                      |
| Try expression    | `this_call_can_err()?;`        | Unsupported     |                                                                                                      |
| Tuple literal     | `(a, 4, c)`                    | Supported       |                                                                                                      |
| Unary expressions | `!x`                           | Partial Support | User-defined unary operations are not supported.                                                     |
| Unsafe            | `unsafe { ... }`               | Unsupported     |                                                                                                      |
| While loops       | `while x < 64 { ... }`         | Unsupported     | Cannot be supported as the number of iterations is not known.                                        |

## Binary expressions

Note: user-defined binary operations are currently unsupported.

| Example    | Supported types                            |
|:-----------|:-------------------------------------------|
| `a + b`    | Integers, floats                           |
| `a - b`    | Integers, floats                           |
| `a * b`    | Integers, floats                           |
| `a / b`    | Integers, floats                           |
| `a % b`    | Integers                                   |
| `a && b`   | Booleans                                   |
| `a \|\| b` | Booleans                                   |
| `a ^ b`    | Booleans                                   |
| `a & b`    | Booleans                                   |
| `a \| b`   | Booleans                                   |
| `a << b`   | None                                       |
| `a >> b`   | Integers, if `b` is known at compile time. |
| `a == b`   | All. Use `derive(PartialEq)` for structs.  |
| `a != b`   | All. Use `derive(PartialEq)` for structs.  |
| `a < b`    | Booleans, integers, floats                 |
| `a <= b`   | Booleans, integers, floats                 |
| `a >= b`   | Booleans, integers, floats                 |
| `a > b`    | Booleans, integers, floats                 |
| `a += b`   | Integers, floats                           |
| `a -= b`   | Integers, floats                           |
| `a *= b`   | Integers, floats                           |
| `a /= b`   | Integers, floats                           |
| `a %= b`   | Integers                                   |
| `a ^= b`   | Booleans                                   |
| `a &= b`   | Booleans                                   |
| `a \|= b`  | Booleans                                   |
| `a <<= b`  | None                                       |
| `a >>= b`  | Integers, if `b` is known at compile time  |

## Cast expressions

`a as MyType` is only supported:

| From Type    | To Type      |
|:-------------|:-------------|
| integer type | integer type |
| `bool`       | integer type |
| integer type | `bool`       |
| `&...&T`     | `&T`         | 

## Function calls

The following function calls are supported:

* user-defined function calls (without generics and without recursion)
* `ArcisRNG::bool()` to generate a boolean.
* `ArcisRNG::gen_integer_from_width(width: usize) -> u128`. Generates an integer between 0 and 2^width - 1 included.
* `ArcisRNG::gen_integer_in_range(min: u128, max: u128, n_attempts: usize) -> (result: u128, success: bool)`. See function doc for more information.
* `ArcisRNG::shuffle(slice)` on slices. Complexity is in `O(n*log³(n) + n*log²(n)*sizeof(T))`.


## Literal expressions

| Example     | Support     |
|:------------|:------------|
| `"foo"`     | Unsupported |
| `b"foo"`    | Unsupported |
| `c"foo"`    | Unsupported |
| `b'f'`      | Supported   |
| `'a'`       | Unsupported |
| `1`         | Supported   |
| `1u16`      | Supported   |
| `1f64`      | Supported   |
| `1.0e10f64` | Supported   |
| `true`      | Supported   |

## Method calls

The following method calls are supported:

* user-defined method calls (without generics and without recursion)
* `.len()` on arrays
* `.sort()` on arrays of integers. Complexity is in `O(n*log²(n)*bit_size)`.
* `.reveal()` if not inside a `if` or a `else`
* `.to_arcis()` on `Enc`s
* `.from_arcis(x)` on `Owner`s (objects of types `Mxe` or `Shared`) if not inside a `if` or a `else`
* `.min(x)` and `.max(x)` on integers and floats
* `.exp()`, `.exp2()`, `.ln()`, `.log2()`, `.sqrt()` on floats.

## Paths

The following paths are supported:

* `IntType::MIN` and `IntType::MAX` where `IntType` is an integer type.
* Paths to user-defined constants, functions and structs, as long as they don't use the unsupported `Self`.

# Item support:

Lifetimes are the only generics that are supported on any user-defined object.

| Item Name         | Example                   | Support         | Comments                                                                                                       |
|:------------------|:--------------------------|:----------------|:---------------------------------------------------------------------------------------------------------------|
| Constant          | `const MAX: u16 = 65535`  | Supported       |                                                                                                                |
| Enum              | `enum MyEnum { ... }`     | Unsupported     |                                                                                                                |
| Extern            | `extern ...`              | Unsupported     |                                                                                                                |
| Functions         | `fn foo() -> u8 { 0 }`    | Partial Support | Recursive functions are not supported.                                                                         |
| Impls             | `impl MyType { ... }`     | Partial Support | Traits are not supported. `MyType` should not be a reference. Also, `MyType` should be used instead of `Self`. |
| Macro Definitions | `macro_rules! ...`        | Unsupported     |                                                                                                                |
| Macro Invocations | `println!(...)`           | Unsupported     |                                                                                                                |
| Modules           | `mod my_module { ... }`   | Supported       |                                                                                                                |
| Statics           | `static ...`              | Unsupported     |                                                                                                                |
| Structs           | `struct MyStruct { ... }` | Supported       |                                                                                                                |
| Traits            | `trait MyTrait { ... }`   | Unsupported     |                                                                                                                |
| Type Aliases      | `type MyId = usize;`      | Unsupported     |                                                                                                                |
| Union             | `union MyUnion { ... }`   | Unsupported     |                                                                                                                |                   
| Use               | `use arcis_imports::*`    | Partial Support | Only `use arcis_imports::` is supported.                                                                       |

# Pattern support:

The following patterns are supported in function arguments and `let` statements:

* simple idents: `let ident = ...;`
* mutable idents: `let mut ident = ...;`
* ref idents: `let ref ident = ...;`
* mutable ref idents: `let ref mut ident = ...;`
* parentheses around a supported pattern: `let (...) = ...;`
* reference of a supported pattern: `let &... = ...;`
* array of supported patterns: `let [...] = ...;`
* struct of supported patterns: `let MyStruct { ... } = ...;`
* tuple of supported patterns: `let (...) = ...;`
* tuple struct of supported patterns: `let MyStruct(...) = ...;`
* type pattern of a supported pattern: `let ...: ty = ...;`
* wild pattern: `let _ = ...;`

Note: in particular, the `..` pattern is currently unsupported.

# Type support:

The following types are supported:

* `u8`, `u16`, `u32`, `u64`, `u128`, `usize`, `i8`, `i16`, `i32`, `i64`, `i128`, `isize`
* `f64`, `f32` (Note: these types are emulated by the fixed-point numbers `k*2^-52`, for `k` between `-2^250` and `2^250`.)
* tuples of supported types, including `()`
* fixed-length arrays of a supported type
* (mutable) references to a supported type
* user-defined structs of supported types
* Arcis-defined `Enc`, `Mxe` and `Shared`.

In particular, we do not support `HashMap`, `Vec`, slices, nor anything related to strings.