Início / Backends experimentais

Backends experimentais

Todos consomem IR2 verificada. O pipeline Go padrão e os cinco perfis permanecem disponíveis. Somente Basic com int/bool, operações escalares, chamadas, CFG e impressão. Floats, strings, divisão, módulo, coleções, registros, enum, DOM e bibliotecas não são suportados nestes três backends alternativos.

BackendToolchain e saídaValidação
LLVMclang, libc; build/llvm/app (app.exe no Windows com linker/CRT)Linux amd64
NativeAssembly x86-64 próprio; clang assembler/linker, libc; build/native/appSomente Linux amd64, até 6 parâmetros
WASMLLVM wasm32, clang e wasm-ld; build/wasm/app.wasmNode.js, host explícito

Exemplo

fn fact(n: int) -> int {
    if n == 0 {
        return 1
    }
    return n * fact(n - 1)
}
fn main() {
    let x = 0
    let sum = 0
    while x < 5 {
        sum += x
        x += 1
    }
    print(fact(5), sum, true, false)
}
nextlang backend llvm
nextlang backend native
nextlang backend wasm

LLVM e native: execute o artefato correspondente no Linux. O WASM exporta nl_main, não é o frontend DOM. Salve o host abaixo como run-wasm.cjs na raiz do projeto:

const fs = require('node:fs');
const path = require('node:path');
let output = '';
WebAssembly.instantiate(fs.readFileSync(path.join(__dirname, 'build', 'wasm', 'app.wasm')), {
  env: {
    nl_print_int: value => { output += String(value); },
    nl_print_bool: value => { output += String(Boolean(value)); },
    nl_space: () => { output += ' '; },
    nl_newline: () => { output += '\n'; }
  }
}).then(({instance}) => {
  instance.exports.nl_main();
  process.stdout.write(output);
}).catch(error => { console.error(error); process.exitCode = 1; });
node run-wasm.cjs

Resultado esperado: 120 10 true false. Benchmark · Contrato e limites

Documentação 6.5.0 alpha — experimental.