aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/config/GcConfig.java
blob: 312c2f963d9073dda943d5c4cbdc8cdc30fd1a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.shedlang.compiler.config;

import org.shedlang.compiler.config.json.Json5ObjectWithSource;

import java.util.List;

public sealed interface GcConfig permits GcBumpConfig, GcMarkAndSweepConfig {
    GcConfig BUMP = new GcBumpConfig();
    GcConfig DEFAULT = GcMarkAndSweepConfig.DEFAULT;

    static GcConfig fromJson5(Json5ObjectWithSource object) {
        var name = object.getString("name").value();

        return switch (name) {
            case "bump" ->
                BUMP;

            case "mark-and-sweep" ->
                GcMarkAndSweepConfig.fromJson5(object);

            default ->
                throw new IllegalArgumentException("Unrecognised GC name: \"%s\"".formatted(name));
        };
    }

    String name();
    List<String> runtimeBuildOptions();
}