FrançaisEnglish

1 · Premiers pas

Ce qu'il faut savoir avant tout

Amalgame transpile vers du C portable. Compiler un programme Amalgame est toujours un processus en deux étapes :

  1. amc your.am -o your produit your.c (un fichier .c, PAS un binaire).
  2. gcc your.c -lgc -lm -o your produit le véritable binaire natif.

Le amc que vous invoquez à l'étape 1 est lui-même le résultat de ce même pipeline appliqué aux sources du compilateur dans src/.

Installation

Linux (Debian/Ubuntu)

sudo apt install -y gcc libgc-dev

git clone https://github.com/amalgame-lang/Amalgame.git
cd Amalgame
gcc -O2 -Iruntime snapshot/amc_lib.c \
    -lgc -lm -o snapshot/amc   # one-time: bootstrap from tracked C
./build_amc.sh                         # builds the self-hosted amc into ./amc (~5s)
./tests/run_all_tests.sh               # full suite: 578 PASS in ~42s

Les suites de tests individuelles peuvent être lancées via ./amc test ./tests/<bundle>/<bundle> est l'un des suivants : fmt, amc_new, stdlib_bundle ou core_bundle — voir 06-build-and-tooling.md.

macOS (Apple Silicon ou Intel)

brew install bdw-gc curl
git clone https://github.com/amalgame-lang/Amalgame.git
cd Amalgame
gcc -O2 -Iruntime src/amc_lib.c \
    -lgc -lm -o amc
./amc --version

amc_lib.c est le snapshot canonique multiplateforme du compilateur auto-hébergé — il est versionné dans git, donc n'importe quelle plateforme disposant d'un gcc fonctionnel peut bootstrapper depuis un clone propre.

Windows (MSYS2 MINGW64)

pacman -S mingw-w64-x86_64-{gcc,gc,curl}
git clone https://github.com/amalgame-lang/Amalgame.git
cd Amalgame
gcc -O2 -Iruntime src/amc_lib.c \
    -lgc -lm -o amc.exe
./amc.exe --version

Pour un installeur .exe pré-packagé qui embarque un MinGW64 portable, voir install/windows/amalgame.iss (script Inno Setup).

Binaire pré-compilé

Chaque release taguée dans les GitHub Releases livre des archives amc-X.Y.Z-{linux,macos,windows}-.... La commande en une ligne sélectionne la bonne pour votre OS/architecture :

curl -fsSL https://raw.githubusercontent.com/amalgame-lang/Amalgame/main/install/install.sh | sh

Raspberry Pi (et autres Linux ARM64)

amc livre un build natif linux-arm64, donc la commande en une ligne ci-dessus fonctionne sur un Raspberry Pi tournant sous un OS 64 bits (Raspberry Pi OS 64-bit, Ubuntu pour Pi, …) — c'est-à-dire que uname -m retourne aarch64. Installez d'abord les dépendances runtime, comme sur n'importe quelle machine Debian/Ubuntu :

sudo apt-get install -y build-essential libgc-dev libssl-dev curl
curl -fsSL https://raw.githubusercontent.com/amalgame-lang/Amalgame/main/install/install.sh | sh
amc --version

Le 32 bits n'est pas pris en charge. Sur un Pi 3/4/5 tournant sous un OS 32 bits, uname -m affiche armv7l/armv6l et l'installeur s'arrête avec un message explicite — reflashez un OS 64 bits, ou compilez depuis les sources (le snapshot amc_lib.c compile partout avec une toolchain C + Boehm GC). L'archive linux-arm64 est compilée nativement en CI sur un vrai runner aarch64, pas en cross-compilation.

Développer dans VS Code (la voie facile)

install.sh installe automatiquement l'extension Amalgame pour VS Code s'il détecte VS Code (la release embarque le .vsix ; définissez AMC_NO_EDITORS=1 pour passer cette étape). Si vous avez installé amc d'une autre façon, installez-la manuellement une seule fois :

code --install-extension <amalgame-X.Y.Z.vsix>   # from share/amalgame/editors/vscode/

Il suffit ensuite d'ouvrir n'importe quel fichier .am — l'extension démarre amc lsp et vous obtenez un véritable IDE, sans configuration :

Une bonne première session : mkdir hello && cd hello, ouvrez le dossier dans VS Code, créez hello.am (section suivante), et lancez amc run hello.am dans le terminal. Diagnostics, complétion et recherche fonctionnent immédiatement.

L'extension est basée sur LSP/DAP et ne nécessite aucune configuration pour le cas courant. Pour la liste complète des fonctionnalités, les réglages de l'éditeur, les autres éditeurs (Neovim, …), et les internals du débogueur, voir le chapitre 15, Outillage éditeur & débogage.

Bonjour, monde

Enregistrez sous hello.am :

namespace App
import Amalgame.IO

public class Program {
    public static void Main(string[] args) {
        Console.WriteLine("Hello, Amalgame!")
    }
}

Compilez et exécutez :

./amc hello.am -o hello
gcc -Iruntime hello.c -lgc -lm -o hello
./hello
# → Hello, Amalgame!

Quelques conventions importantes :

Un premier programme un peu plus grand

// add.am
namespace App
import Amalgame.IO

public class Program {
    public static int Add(int a, int b) {
        return a + b
    }

    public static void Main(string[] args) {
        let n = Program.Add(2, 3)
        Console.WriteLine("2 + 3 = {String.FromInt(n)}")
    }
}
./amc add.am -o add && gcc -Iruntime add.c -lgc -lm -o add && ./add
# → 2 + 3 = 5

Mode bibliothèque (sans main())

// greeter.am
namespace MyLib

public class Greeter {
    public Name: string
    public Greeter(string name) { this.Name = name }
    public string Hello() { return "Hello, " + this.Name + "!" }
}
./amc --lib greeter.am -o greeter
# → Generated: greeter.c (... lines) [Library]
gcc -Iruntime -c greeter.c -o greeter.o
# Link greeter.o into another program from C, Amalgame, or another lib.

Où aller ensuite