Core
/ internals

Compiler

The compiler is implemented in Rust.

To work around Rust's restrictions on circular references, index-based data-structures are used heavily.

Standard Library

The standard library is implemented in Core itself, though some types and functions exposed in the standard library are implemented as intrinsics provided by the runtime.

Intermediate Representation

There is currently no real intermediate representation or even a persisted compilation artifact, the core executable both compiles and runs the code on-the-fly.

Runtime

The runtime is implemented in Rust.

Code Generation

Code is generated at runtime, just-in-time.

The backend is implemented specifically for Core and does not rely on the LLVM or other frameworks.

Supported architectures are AMD64 and ARM64. A backend for the RISC-V architecture (RV64G) is work-in-progress.

Garbage Collection

While the language encourages the use of immutable value types (keyword value), reference-based types (keyword class) are available and managed by precise garbage collection.

Memory Layout

This is a design draft.

These days, most common architectures support a 48bit virtual address space, in which the lower bits from 0 to 47 denote a valid address, and the higher bits from 48 to 63 are required to be equal to bit 47.

This means the usable virtual address space consists of high addresses, commonly used as kernel-space addresses and low addresses, available to user-space processes.
The gap in the middle is not usable; addresses referring to this region are called non-canonical.

                 high addresses                         non-canonical addresses                      low addresses
               ┌ - - - - - - - ┬ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +---------------+
OS process:                      ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ |               |
               └ - - - - - - - ┴ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +---------------+
                                                                                                   ╰───────┬───────╯
                                                          available user-space virtual memory (128TiB address space)
      

From the available user-space virtual memory, the Core runtime reserves slices of different sizes for various purposes:

               +---------------------------------------------------------------------------------------------------+
Core runtime:  |          ┊   ┊                                    ┊┊                                    ┊ ┊       |
               +---------------------------------------------------------------------------------------------------+
                          ╰─┬─╯                                    ╰┤                                    ╰┬╯
               1TiB: reserved object space             2MiB: reserved code space         1GiB: reserved vtable space
      

Each of those slices is governed by an allocator that manages the available memory, commits memory by placing data in those spaces and reclaims memory that is not used anymore.

The allocators are in turn controlled by various subsystems of the Core runtime:
For instance the code space allocator is directed by Core's JIT compiler, while the object space is controlled by Core's garbage collector.

Object Layout

Values

Numbers
integer values (64 bit)
+---------------+---------------+
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |
+---------------+---------------+
╰───────────────┬───────────────╯
        64 bits: signed value
      
integer values (32 bit)
+---------------+
|   ┊   ┊   ┊   |
+---------------+
╰───────┬───────╯
32 bits: signed value
      
floating-point values (64 bit)
11 bits: exponent
 ╭──┴─╮
+---------------+---------------+
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |
+---------------+---------------+
│     ╰─────────────┬───────────╯
1 bit: sign        52 bits: mantissa
      
floating-point values (32 bit)
8 bits: exponent
 ╭─┴─╮
+---------------+
|   ┊   ┊   ┊   |
+---------------+
│    ╰────────┬─╯
1 bit: sign  23 bits: mantissa
      
Unions
tag-based union values
+---------------+ - - - - - - - -
|   ┊   ┊   ┊   | union value ...
+---------------+ - - - - - - - -
╰───────┬───────╯
32 bits: tag bits
      

References

There is ongoing work to reduce the size of the object headers (which contain a vtable pointer and forwarding pointer) from 16 bytes to 8 bytes.

This will decrease the size of everything reference-based – of regular class instances, array and string instances, trait-boxed instances and reference-based union instances.

regular class instances
      38 bits: forwarding pointer
            ╭───────┴──────────╮
+---------------+---------------+ - - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   | instance fields ...
+---------------+---------------+ - - - - - - - -
╰─────┬─────╯                  ╰┤
24 bits: vtable pointer    2 bits: gc bits
          

array instances
      38 bits: forwarding pointer       64 bits: array size
            ╭───────┴──────────╮╭───────────────┴───────────────╮
+---------------+---------------+---------------+---------------+ - - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   | array elements ...
+---------------+---------------+---------------+---------------+ - - - - - - - -
╰─────┬─────╯                  ╰┤
24 bits: vtable pointer    2 bits: gc bits
          

string instances
      38 bits: forwarding pointer     36 bits: string size
            ╭───────┴──────────╮╭───────┴─────────╮
+---------------+---------------+---------------+---------------+ - - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   | utf8 bytes ...
+---------------+---------------+---------------+---------------+ - - - - - - - -
╰─────┬─────╯                  ╰┤               ╰───────┬───────╯
24 bits: vtable pointer    2 bits: gc bits        32 bits: hash code
          

trait-boxed instances
      38 bits: forwarding pointer
            ╭───────┴──────────╮
+---------------+---------------+ - - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   | instance ...
+---------------+---------------+ - - - - - - - -
╰─────┬─────╯                  ╰┤
24 bits: vtable pointer    2 bits: gc bits
          
Classes
regular class instances
    62 bits: vtable pointer       61 bits: forwarding pointer
╭───────────────┴──────────────╮╭───────────────┴─────────────╮
+---------------+---------------+---------------+---------------+ - - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   ┊   ┊   ┊   ┊   | instance fields ...
+---------------+---------------+---------------+---------------+ - - - - - - - -
                               ╰┤                             ╰─┤
                               2 bits: forward bits            3 bits: mark bits
      
array instances
    62 bits: vtable pointer       61 bits: forwarding pointer         64 bits: array size
╭───────────────┴──────────────╮╭───────────────┴─────────────╮ ╭───────────────┴───────────────╮
+---------------+---------------+---------------+---------------+---------------+---------------+ - - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   ┊   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   | array elements ...
+---------------+---------------+---------------+---------------+---------------+---------------+ - - - - - - - -
                               ╰┤                             ╰─┤
                               2 bits: forward bits            3 bits: mark bits
      
string instances
    62 bits: vtable pointer       61 bits: forwarding pointer   36 bits: string size
╭───────────────┴──────────────╮╭───────────────┴─────────────╮ ╭───────┴─────────╮
+---------------+---------------+---------------+---------------+---------------+---------------+ - - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   ┊   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   | utf8 bytes ...
+---------------+---------------+---------------+---------------+---------------+---------------+ - - - - - - - -
                               ╰┤                             ╰─┤               ╰───────┬───────╯
                               2 bits: forward bits            3 bits: mark bits    32 bits: hash code
      
Traits
trait-boxed instances
    62 bits: vtable pointer       61 bits: forwarding pointer
╭───────────────┴──────────────╮╭───────────────┴─────────────╮
+---------------+---------------+---------------+---------------+ - - - - - - -
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |   ┊   ┊   ┊   ┊   ┊   ┊   ┊   | instance ...
+---------------+---------------+---------------+---------------+ - - - - - - -
                               ╰┤                             ╰─┤
                               2 bits: forward bits            3 bits: mark bits
      
Unions
trait-boxed union instances
...
reference-based union instances
+---------------+---------------+
|   ┊   ┊   ┊   |   ┊   ┊   ┊   |
+---------------+---------------+
╰───────────────┬───────────────╯
64 bits: reference or null-pointer