feat(pbs): add sprite animation and shared Studio authoring
Implement DEC-0084 with factory-only Sprite/Animator structs, complete result lowering, validated animation sidecars, generated PBS factories and JavaFX/MCP authoring through shared services. Qualify native dev/release with ordinary and optimized producers, zero-allocation playback, private-cycle reclamation, canonical Composer pixels, installed JARs and JavaFX lifecycle. Preserve the runtime checkout and existing host ABI.
This commit is contained in:
+8
-1
@@ -7,8 +7,15 @@ import com.tngtech.archunit.lang.ArchRule;
|
||||
|
||||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
|
||||
|
||||
@AnalyzeClasses(packages = {"p.studio", "p.packer"}, importOptions = ImportOption.DoNotIncludeTests.class)
|
||||
@AnalyzeClasses(packages = {"p.studio", "p.packer", "p.animation"}, importOptions = ImportOption.DoNotIncludeTests.class)
|
||||
class StudioBoundaryArchTest {
|
||||
@ArchTest
|
||||
static final ArchRule animationModelIsNeutral = noClasses()
|
||||
.that().resideInAPackage("p.animation..")
|
||||
.should().dependOnClassesThat().resideInAnyPackage(
|
||||
"p.studio..", "p.packer..", "javafx..", "org.springframework..")
|
||||
.because("DEC-0084 shares authoring DTOs and validation without a provider or UI dependency");
|
||||
|
||||
@ArchTest
|
||||
static final ArchRule automationTransportStaysInTheApp = noClasses()
|
||||
.that().resideInAnyPackage("p.studio.api..", "p.studio.core..", "p.studio.ui..")
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package p.studio.compiler.backend.irvm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.models.registry.IRRegistry;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.nio.file.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Production producers; results are independently checked by the native verifier. */
|
||||
class PbsResultTest {
|
||||
@Test void resultFunctionsCannotBecomePlainFunctionValues() {
|
||||
for(String value:new String[]{"let f:Fn()->int=fallible;","let f=fallible;"}){
|
||||
var diagnostics=p.studio.compiler.source.diagnostics.DiagnosticSink.empty();
|
||||
assertDoesNotThrow(()->new p.studio.compiler.pbs.PbsFrontendCompiler().compileFile(new p.studio.compiler.source.identifiers.FileId(0),
|
||||
"declare error E {bad;} fn fallible()->result<E> int {return err(E.bad);} fn check(){"+value+"}",diagnostics));
|
||||
assertTrue(diagnostics.hasErrors(),value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test void completeResultGroupsAndControlFlowReachProductionPbx() throws Exception {
|
||||
var fixtures = new LinkedHashMap<String, String>();
|
||||
String errors = "declare error E { bad; other; } declare error F { retry; abort; }\n";
|
||||
fixtures.put("unit-ok", "fn main() -> result<E> { return ok(()); }");
|
||||
fixtures.put("unit-err", "fn main() -> result<E> { return err(E.other); }");
|
||||
fixtures.put("scalar", "fn main() -> result<E> int { return ok(42); }");
|
||||
fixtures.put("error", "fn main() -> result<E> long { return err(E.bad); }");
|
||||
fixtures.put("tuple", "fn main() -> result<E> (a: long, b: int) { return ok((a: 9007199254740993, b: 42)); }");
|
||||
fixtures.put("reference", "fn main() -> result<E> array<int> { return err(E.other); }");
|
||||
fixtures.put("propagate", "fn source() -> result<E> int { return err(E.other); } fn main() -> result<E> (a: long, b: str) { let v = Probe.source()!; return ok((a: v as long, b: \"unused\")); }");
|
||||
fixtures.put("nested", "fn source() -> result<E> int { return err(E.other); } fn main() -> result<E> int { return ok(100 + Probe.source()!); }");
|
||||
fixtures.put("recover", "fn source() -> result<E> int { return err(E.bad); } fn main() -> result<F> int { let v = handle Probe.source() { E.bad -> { ok(42) }, E.other -> F.abort }; return ok(v); }");
|
||||
fixtures.put("remap", "fn source() -> result<E> int { return err(E.other); } fn main() -> result<F> int { let v = handle Probe.source() { E.bad -> { ok(42) }, E.other -> F.abort }; return ok(v); }");
|
||||
fixtures.put("success", "fn source() -> result<E> int { return ok(42); } fn main() -> result<F> int { let v = handle Probe.source() { _ -> { ok(99) } }; return ok(v); }");
|
||||
fixtures.put("trait", "fn main() -> result<E> Reader { return err(E.bad); }");
|
||||
fixtures.put("fn", "fn main() -> result<E> Fn() -> int { return err(E.bad); }");
|
||||
fixtures.put("once", "fn source() -> result<E> int { calls=calls+1; return err(E.bad); } fn unused() -> int { calls=calls+100; return 99; } fn main() -> result<F> int { let value=handle Probe.source() { E.bad -> { ok(42) }, E.other -> { ok(Probe.unused()) } }; if calls!=1 { let fail=1/0; } return ok(value); }");
|
||||
fixtures.put("block-remap", "fn source() -> result<E> int { return err(E.bad); } fn main() -> result<F> int { let value=handle Probe.source() { E.bad -> { err(F.abort) }, _ -> { ok(42) } }; return ok(value); }");
|
||||
fixtures.put("reference-ok", "fn source() -> result<E> array<int> { return ok([42]); } fn main() -> result<E> int { let values=Probe.source()!; return ok(values[0] else 0); }");
|
||||
fixtures.put("fn-ok", "fn source() -> result<E> Fn() -> int { return ok(answer); } fn main() -> result<E> int { let f=Probe.source()!; return ok(f()); }");
|
||||
fixtures.put("trait-ok", "fn source() -> result<E> Fallible { return ok(new ReaderValue(42)); } fn main() -> result<E> int { let reader=Probe.source()!; return ok(reader.read()!); }");
|
||||
fixtures.put("color-ok", "fn main() -> result<E> Color { return ok(Color.from_raw(42)); }");
|
||||
fixtures.put("color-err", "fn main() -> result<E> Color { return err(E.bad); }");
|
||||
fixtures.put("trap", "fn source() -> result<E> int { let fail=1/0; return ok(1); } fn main() -> result<F> int { let value=handle Probe.source() { _ -> { ok(42) } }; return ok(value); }");
|
||||
String color;
|
||||
try(var input=p.studio.compiler.pbs.PbsFrontendCompiler.class.getResourceAsStream("/game/stdlib/1/core/color/main.pbs")){assertNotNull(input);color=new String(input.readAllBytes(),java.nio.charset.StandardCharsets.UTF_8);}
|
||||
String support="declare global calls: int=0; fn answer() -> int { return 42; } declare contract Fallible { fn read() -> result<E> int; } declare struct ReaderValue(pub value:int); implements Fallible for ReaderValue using reader { fn read() -> result<E> int { return ok(reader.value); } }\n";
|
||||
var manifest = new StringBuilder();
|
||||
for (var entry : fixtures.entrySet()) for (var suffix : new String[]{"", "-optimized"}) {
|
||||
var source = errors + support + color + "declare contract Reader { fn read() -> int; }\n" + entry.getValue().replace("Probe.", "");
|
||||
var module = PbsRuntimeAlignmentTest.compile("result-" + entry.getKey() + suffix, source, SourceKind.SDK_INTERFACE, "main");
|
||||
assertEquals(IRRegistry.TypeRef.builtin(0x10), module.functions().getFirst().metadata().signature().results().getFirst());
|
||||
manifest.append(entry.getKey()).append(suffix).append('\n');
|
||||
}
|
||||
Files.writeString(Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("pbs-result-manifest.txt"), manifest);
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -20,6 +20,9 @@ class PbsRuntimeAlignmentTest {
|
||||
return compile(name, source, SourceKind.SDK_INTERFACE);
|
||||
}
|
||||
static BytecodeModule compile(String name,String source,SourceKind sourceKind) throws Exception {
|
||||
return compile(name,source,sourceKind,"Probe.main");
|
||||
}
|
||||
static BytecodeModule compile(String name,String source,SourceKind sourceKind,String entryPoint) throws Exception {
|
||||
var diagnostics=DiagnosticSink.empty();
|
||||
var fileId = new FileId(0);
|
||||
var ast = p.studio.compiler.pbs.parser.PbsParser.parse(p.studio.compiler.pbs.lexer.PbsLexer.lex(source,fileId,diagnostics),fileId,diagnostics,p.studio.compiler.pbs.parser.PbsParser.ParseMode.INTERFACE_MODULE);
|
||||
@@ -27,7 +30,7 @@ class PbsRuntimeAlignmentTest {
|
||||
new p.studio.compiler.source.identifiers.ModuleId(0),p.studio.utilities.structures.ReadOnlyList.empty(),
|
||||
p.studio.compiler.messages.HostAdmissionContext.permissiveDefault(),p.studio.compiler.messages.FESurfaceContext.empty(),new p.studio.compiler.source.tables.NameTable());
|
||||
assertFalse(diagnostics.hasErrors(), ()->diagnostics.stream().map(d->d.getCode()+":"+d.getMessage()).toList().toString());
|
||||
var backend=IRBackend.builder().entryPointCallableName("Probe.main").entryPointModuleId(new p.studio.compiler.source.identifiers.ModuleId(0)).executableFunctions(file.executableFunctions())
|
||||
var backend=IRBackend.builder().entryPointCallableName(entryPoint).entryPointModuleId(new p.studio.compiler.source.identifiers.ModuleId(0)).executableFunctions(file.executableFunctions())
|
||||
.globals(file.globals()).registry(file.registry()).intrinsicPool(file.intrinsicPool()).callableSignatures(file.callableSignatures()).build();
|
||||
var program=new LowerToIRVMService().lower(backend);
|
||||
if (name.endsWith("-optimized")) program = new OptimizeIRVMService().optimize(program);
|
||||
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
package p.studio.compiler.backend.irvm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.pbs.PbsFrontendCompiler;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class PbsSpriteAnimationTest {
|
||||
static String core() throws Exception {
|
||||
var text = new StringBuilder();
|
||||
for (var path : new String[]{"sprite", "animation"}) {
|
||||
try (var input = PbsFrontendCompiler.class.getResourceAsStream("/game/stdlib/1/core/"+path+"/main.pbs")) {
|
||||
assertNotNull(input);
|
||||
text.append(new String(input.readAllBytes(), StandardCharsets.UTF_8).replace("import { SpriteView } from @core:sprite;", ""));
|
||||
}
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
@Test void directCoreLibraryUsesTheProductionCompiler() throws Exception {
|
||||
for (var suffix : new String[]{"", "-optimized"}) {
|
||||
PbsRuntimeAlignmentTest.compile("animation-basic"+suffix, core()+"""
|
||||
declare service Probe {
|
||||
fn main() -> result<AnimationError> int {
|
||||
let builder = animator_builder(3, "idle")!;
|
||||
builder.begin_clip("idle", PlaybackMode.Loop)!;
|
||||
builder.add_frame(7, 2)!; builder.add_frame(11, 3)!; builder.add_frame(4, 1)!;
|
||||
builder.end_clip()!;
|
||||
let first = builder.build()!; let second = builder.build()!;
|
||||
first.play("idle")!; first.advance(2)!;
|
||||
if second.sprite().glyph_id != 7 { let failed = 1 / 0; }
|
||||
if first.sprite().glyph_id != 11 { let failed = 1 / 0; }
|
||||
first.advance(4)!;
|
||||
if first.sprite().glyph_id != 7 { let failed = 1 / 0; }
|
||||
let frame = first.frame_at("idle", 1)!;
|
||||
if frame.glyph_id != 11 { let failed = 1 / 0; }
|
||||
return ok(42);
|
||||
}
|
||||
}
|
||||
""", SourceKind.PROJECT);
|
||||
}
|
||||
}
|
||||
@Test void playbackFailuresAndAllocationPathsHaveNativeFixtures() throws Exception {
|
||||
var cases = new java.util.LinkedHashMap<String, String>();
|
||||
var build = """
|
||||
fn fixture(mode: PlaybackMode) -> result<AnimationError> Animator {
|
||||
let b = animator_builder(3, "idle")!;
|
||||
b.begin_clip("idle", mode)!;
|
||||
b.add_frame(7, 2)!; b.add_frame(11, 3)!; b.add_frame(4, 1)!;
|
||||
b.end_clip()!; return ok(b.build()!);
|
||||
}
|
||||
""";
|
||||
cases.put("loop", """
|
||||
let a = fixture(PlaybackMode.Loop)!; a.play("idle")!;
|
||||
let view: SpriteView = a;
|
||||
let start = 162000001;
|
||||
if view.sprite().glyph_id != 7 { let fail = 1 / 0; }
|
||||
a.advance(1)!; if a.sprite().glyph_id != 7 { let fail = 1 / 0; }
|
||||
a.advance(1)!; if a.sprite().glyph_id != 11 { let fail = 1 / 0; }
|
||||
a.advance(3)!; if a.sprite().glyph_id != 4 { let fail = 1 / 0; }
|
||||
a.advance(1)!; if a.sprite().glyph_id != 7 { let fail = 1 / 0; }
|
||||
a.advance(601)!; if a.sprite().glyph_id != 7 { let fail = 1 / 0; }
|
||||
a.advance(2147483647)!; if a.sprite().glyph_id != 11 { let fail = 1 / 0; }
|
||||
for i: int from 0 until 100 { a.advance(0)!; view.sprite(); }
|
||||
let end = 162000002;
|
||||
return ok(42);
|
||||
""");
|
||||
cases.put("once", """
|
||||
let a = fixture(PlaybackMode.Once)!; a.play("idle")!;
|
||||
let start = 162000001;
|
||||
a.advance(5)!; if a.state() != PlaybackState.Playing { let fail = 1 / 0; }
|
||||
if a.sprite().glyph_id != 4 { let fail = 1 / 0; }
|
||||
a.advance(1)!; if a.state() != PlaybackState.Finished { let fail = 1 / 0; }
|
||||
a.resume(); a.advance(100)!;
|
||||
if a.sprite().glyph_id != 4 || a.state() != PlaybackState.Finished { let fail = 1 / 0; }
|
||||
a.restart(); if a.sprite().glyph_id != 7 || a.state() != PlaybackState.Playing { let fail = 1 / 0; }
|
||||
a.advance(2)!; a.pause(); a.advance(100)!;
|
||||
if a.sprite().glyph_id != 11 { let fail = 1 / 0; }
|
||||
a.resume(); a.play("idle")!;
|
||||
if a.sprite().glyph_id != 7 { let fail = 1 / 0; }
|
||||
a.select("idle")!; if a.state() != PlaybackState.Stopped { let fail = 1 / 0; }
|
||||
let end = 162000002; return ok(42);
|
||||
""");
|
||||
cases.put("negative", """
|
||||
let a = fixture(PlaybackMode.Loop)!;
|
||||
let start = 162000001;
|
||||
handle a.advance(-1) { AnimationError.invalid_ticks -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
if a.state() != PlaybackState.Stopped || a.sprite().glyph_id != 7 { let fail = 1 / 0; }
|
||||
a.play("idle")!; a.advance(2)!;
|
||||
handle a.advance(-1) { AnimationError.invalid_ticks -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
if a.sprite().glyph_id != 11 || a.state() != PlaybackState.Playing { let fail = 1 / 0; }
|
||||
let end = 162000002; return ok(42);
|
||||
""");
|
||||
cases.put("overflow", """
|
||||
// Isolated test-only near-limit setup; calls the unchanged production advance.
|
||||
let maximum: long = 9223372036854775807;
|
||||
let frame = new _AnimationFrame.make(7, maximum, maximum);
|
||||
let clip = new _AnimationClip.make("idle", PlaybackMode.Once);
|
||||
clip.head = frame; clip.tail = frame; clip.count = 1; clip.total = maximum;
|
||||
let a = new Animator(3, clip, clip, frame, maximum - 2, PlaybackState.Playing, 1);
|
||||
let start = 162000001;
|
||||
handle a.advance(3) { AnimationError.overflow -> { ok(()) }, _ -> AnimationError.invalid_ticks };
|
||||
if a.sprite().glyph_id != 7 || a.state() != PlaybackState.Playing { let fail = 1 / 0; }
|
||||
let end = 162000002; return ok(42);
|
||||
""");
|
||||
cases.put("draft", """
|
||||
let b = animator_builder(3, "idle")!;
|
||||
handle b.build() { AnimationError.empty_animator -> { ok(new Animator(0, new _AnimationClip.make("", PlaybackMode.Once), new _AnimationClip.make("", PlaybackMode.Once), new _AnimationFrame.make(0, 1, 1), 0, PlaybackState.Stopped, 0)) }, _ -> AnimationError.empty_animator };
|
||||
b.begin_clip("idle", PlaybackMode.Once)!;
|
||||
handle b.end_clip() { AnimationError.empty_clip -> { ok(()) }, _ -> AnimationError.empty_clip };
|
||||
b.add_frame(7, 2)!; b.end_clip()!;
|
||||
let a = b.build()!; b.remove_clip("idle")!;
|
||||
if a.sprite().glyph_id != 7 || a.clip_count() != (1 as long) { let fail = 1 / 0; }
|
||||
b.begin_clip("idle", PlaybackMode.Loop)!; b.add_frame(11, 3)!; b.end_clip()!;
|
||||
let other = b.build()!;
|
||||
if other.sprite().glyph_id != 11 || a.sprite().glyph_id != 7 { let fail = 1 / 0; }
|
||||
return ok(42);
|
||||
""");
|
||||
cases.put("limits", """
|
||||
let maximum: long = 9223372036854775807;
|
||||
let b = animator_builder(255, "idle")!;
|
||||
handle b.add_frame(-1, 0) { AnimationError.no_open_clip -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
handle b.discard_clip() { AnimationError.no_open_clip -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
b.begin_clip("idle", PlaybackMode.Once)!;
|
||||
handle b.begin_clip("", PlaybackMode.Once) { AnimationError.clip_already_open -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
handle b.add_frame(-1, 0) { AnimationError.invalid_glyph -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
handle b.add_frame(0, 0) { AnimationError.invalid_duration -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
b.add_frame(65535, maximum)!;
|
||||
handle b.add_frame(0, 1) { AnimationError.overflow -> { ok(()) }, _ -> AnimationError.invalid_duration };
|
||||
handle b.remove_clip("") { AnimationError.unfinished_clip -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
b.end_clip()!;
|
||||
handle b.begin_clip("idle", PlaybackMode.Loop) { AnimationError.duplicate_clip -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
handle b.begin_clip("", PlaybackMode.Loop) { AnimationError.invalid_name -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
let a = b.build()!;
|
||||
handle a.frame_at("missing", -1) { AnimationError.unknown_clip -> { ok((glyph_id: 0, duration_ticks: 0 as long)) }, _ -> AnimationError.overflow };
|
||||
handle a.frame_at("idle", 1) { AnimationError.index_out_of_range -> { ok((glyph_id: 0, duration_ticks: 0 as long)) }, _ -> AnimationError.overflow };
|
||||
handle a.select("missing") { AnimationError.unknown_clip -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
handle a.play("missing") { AnimationError.unknown_clip -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
if a.sprite().glyph_id != 65535 || a.state() != PlaybackState.Stopped { let fail=1/0; }
|
||||
let alias = a; alias.play("idle")!;
|
||||
if a.state() != PlaybackState.Playing { let fail=1/0; }
|
||||
// Test-only count setup avoids billions of allocations; production add_frame executes.
|
||||
let frame = new _AnimationFrame.make(7, 1, 1);
|
||||
let clip = new _AnimationClip.make("idle", PlaybackMode.Once);
|
||||
clip.head=frame;clip.tail=frame;clip.count=4294967295;clip.total=1;
|
||||
let full = new AnimatorBuilder(0,"idle",clip,clip,clip,0,true);
|
||||
handle full.add_frame(0,1) { AnimationError.limit_exceeded -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
let countMaximum: long = 4294967295;
|
||||
if clip.count != countMaximum { let fail=1/0; }
|
||||
return ok(42);
|
||||
""");
|
||||
cases.put("matrix", """
|
||||
let a = fixture(PlaybackMode.Once)!;
|
||||
for stage: int from 0 until 4 {
|
||||
a.stop();
|
||||
if stage == 1 { a.play("idle")!;a.advance(2)!; }
|
||||
if stage == 2 { a.play("idle")!;a.advance(2)!;a.pause(); }
|
||||
if stage == 3 { a.play("idle")!;a.advance(6)!; }
|
||||
let before = a.sprite().glyph_id;let state = a.state();
|
||||
handle a.advance(-1) { AnimationError.invalid_ticks -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
a.advance(0)!;if a.state()!=state || a.sprite().glyph_id!=before {let fail=1/0;}
|
||||
a.select("idle")!;if a.state()!=PlaybackState.Stopped || a.sprite().glyph_id!=7 {let fail=1/0;}
|
||||
a.play("idle")!;a.advance(2)!;a.play("idle")!;
|
||||
if a.sprite().glyph_id!=7 || a.state()!=PlaybackState.Playing {let fail=1/0;}
|
||||
a.pause();a.pause();a.advance(100)!;if a.state()!=PlaybackState.Paused || a.sprite().glyph_id!=7 {let fail=1/0;}
|
||||
a.resume();a.resume();a.advance(2)!;if a.sprite().glyph_id!=11 {let fail=1/0;}
|
||||
a.stop();a.resume();if a.state()!=PlaybackState.Stopped {let fail=1/0;}
|
||||
a.restart();if a.sprite().glyph_id!=7 || a.state()!=PlaybackState.Playing {let fail=1/0;}
|
||||
}
|
||||
return ok(42);
|
||||
""");
|
||||
cases.put("errors", """
|
||||
let s = handle make_sprite(255,65535) { _ -> AnimationError.invalid_glyph };
|
||||
let s0 = handle make_sprite(0,0) { _ -> AnimationError.invalid_glyph };
|
||||
let view: SpriteView = s;
|
||||
let b = animator_builder(0,"idle")!;let a=fixture(PlaybackMode.Once)!;
|
||||
let start=162000001;
|
||||
if view.sprite().bank_id!=255 || view.sprite().glyph_id!=65535 || s0.sprite().glyph_id!=0 {let fail=1/0;}
|
||||
handle make_sprite(-1,-1) { SpriteError.invalid_bank -> {ok(s)}, _ -> AnimationError.overflow };
|
||||
handle make_sprite(256,0) { SpriteError.invalid_bank -> {ok(s)}, _ -> AnimationError.overflow };
|
||||
handle make_sprite(0,-1) { SpriteError.invalid_glyph -> {ok(s)}, _ -> AnimationError.overflow };
|
||||
handle make_sprite(0,65536) { SpriteError.invalid_glyph -> {ok(s)}, _ -> AnimationError.overflow };
|
||||
handle animator_builder(256,"") { AnimationError.invalid_bank -> {ok(b)}, _ -> AnimationError.overflow };
|
||||
handle animator_builder(0,"") { AnimationError.invalid_name -> {ok(b)}, _ -> AnimationError.overflow };
|
||||
handle b.build() { AnimationError.empty_animator -> {ok(a)}, _ -> AnimationError.overflow };
|
||||
handle b.remove_clip("missing") { AnimationError.unknown_clip -> {ok(())}, _ -> AnimationError.overflow };
|
||||
handle b.end_clip() { AnimationError.no_open_clip -> {ok(())}, _ -> AnimationError.overflow };
|
||||
let end=162000002;
|
||||
b.begin_clip("jump",PlaybackMode.Once)!;
|
||||
handle b.build() { AnimationError.unfinished_clip -> {ok(a)}, _ -> AnimationError.overflow };
|
||||
b.add_frame(0,1)!;b.end_clip()!;
|
||||
handle b.build() { AnimationError.initial_clip_missing -> {ok(a)}, _ -> AnimationError.overflow };
|
||||
b.begin_clip("discard",PlaybackMode.Loop)!;b.add_frame(1,1)!;b.discard_clip()!;
|
||||
handle b.build() { AnimationError.initial_clip_missing -> {ok(a)}, _ -> AnimationError.overflow };
|
||||
if a.sprite().glyph_id!=7 {let fail=1/0;}
|
||||
return ok(42);
|
||||
""");
|
||||
var manifest = new StringBuilder("basic\n");
|
||||
for (var entry : cases.entrySet()) {
|
||||
for (var suffix : new String[]{"", "-optimized"})
|
||||
PbsRuntimeAlignmentTest.compile("animation-"+entry.getKey()+suffix,
|
||||
core()+build+"declare service Probe { fn main() -> result<AnimationError> int {"+entry.getValue()+"} }", SourceKind.PROJECT);
|
||||
manifest.append(entry.getKey()).append('\n');
|
||||
}
|
||||
java.nio.file.Files.writeString(java.nio.file.Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("pbs-animation-manifest.txt"), manifest);
|
||||
}
|
||||
|
||||
@Test void privateCyclesHaveAnExplicitNativeGcOracle() throws Exception {
|
||||
String source=core()+"""
|
||||
fn keep(owners: array<Animator>) -> result<AnimationError> {
|
||||
let b=animator_builder(3,"idle")!;b.begin_clip("idle",PlaybackMode.Loop)!;
|
||||
b.add_frame(7,2)!;b.add_frame(11,3)!;b.add_frame(4,1)!;b.end_clip()!;
|
||||
owners[0]=b.build()!;return ok(());
|
||||
}
|
||||
fn churn() -> result<AnimationError> {
|
||||
for i:int from 0 until 200 { let b=animator_builder(0,"x")!;b.begin_clip("x",PlaybackMode.Once)!;b.add_frame(0,1)!;b.end_clip()!;b.build(); }
|
||||
return ok(());
|
||||
}
|
||||
declare service Probe { fn main() -> result<AnimationError> int {
|
||||
let owners:array<Animator> = new array(1);keep(owners)!;
|
||||
for round:int from 0 until 2 {
|
||||
if round==1 { owners.clear(0); }churn()!;
|
||||
let marker=314159;
|
||||
}
|
||||
return ok(42);
|
||||
} }
|
||||
""";
|
||||
for(String suffix:new String[]{"","-optimized"}){
|
||||
var module=PbsRuntimeAlignmentTest.compile("animation-gc"+suffix,source,SourceKind.PROJECT);
|
||||
module=PbsStructuredValuesTest.withTestSafepoint(module);
|
||||
java.nio.file.Files.write(java.nio.file.Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("pbs-animation-gc"+suffix+".pbx"),module.serialize());
|
||||
}
|
||||
}
|
||||
|
||||
@Test void actualCoreImportsFactoriesAndConstructionBoundary(@org.junit.jupiter.api.io.TempDir java.nio.file.Path root) throws Exception {
|
||||
java.nio.file.Files.createDirectories(root.resolve("src"));
|
||||
java.nio.file.Files.writeString(root.resolve("prometeu.json"), """
|
||||
{"name":"app","version":"1.0.0","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
|
||||
""");
|
||||
java.nio.file.Files.writeString(root.resolve("src/mod.barrel"),"pub fn frame() -> void;");
|
||||
String imports="import { Sprite, SpriteView, SpriteError, make_sprite } from @core:sprite;\nimport { Animator, AnimatorBuilder, AnimationError, PlaybackMode, animator_builder } from @core:animation;\n";
|
||||
java.nio.file.Files.writeString(root.resolve("src/main.pbs"),imports+"""
|
||||
fn verify() -> result<AnimationError> {
|
||||
let b=animator_builder(3,"idle")!;b.begin_clip("idle",PlaybackMode.Loop)!;
|
||||
b.add_frame(7,2)!;b.end_clip()!;let a=b.build()!;a.play("idle")!;a.advance(2)!;
|
||||
if a.sprite().glyph_id!=7 { let fail=1/0; } return ok(());
|
||||
}
|
||||
[Frame] fn frame() -> void { verify(); }
|
||||
""");
|
||||
var context=p.studio.compiler.models.BuilderPipelineContext.fromConfig(new p.studio.compiler.messages.BuilderPipelineConfig(false,root.toString()));
|
||||
var analysis=p.studio.compiler.workspaces.BuilderPipelineService.INSTANCE.analyze(context,p.studio.utilities.logs.LogAggregator.stdout());
|
||||
assertFalse(analysis.diagnostics().stream().anyMatch(d->d.isError()),analysis.diagnostics().toString());
|
||||
var compiled=p.studio.compiler.workspaces.BuilderPipelineService.INSTANCE.compile(p.studio.compiler.models.BuilderPipelineContext.fromConfig(new p.studio.compiler.messages.BuilderPipelineConfig(false,root.toString())),p.studio.utilities.logs.LogAggregator.stdout());
|
||||
assertTrue(compiled.bytecodeBytes().length>0);
|
||||
java.nio.file.Files.writeString(root.resolve("src/main.pbs"),imports+"[Frame] fn frame() -> void { let forged=new Sprite(3,7); }");
|
||||
analysis=p.studio.compiler.workspaces.BuilderPipelineService.INSTANCE.analyze(p.studio.compiler.models.BuilderPipelineContext.fromConfig(new p.studio.compiler.messages.BuilderPipelineConfig(false,root.toString())),p.studio.utilities.logs.LogAggregator.stdout());
|
||||
assertTrue(analysis.diagnostics().stream().anyMatch(d->d.getCode().equals("E_SEM_STDLIB_FACTORY_ONLY")),analysis.diagnostics().toString());
|
||||
for(String construction:new String[]{"new Alias(3,7)","new Alias.make(3,7)"}){
|
||||
java.nio.file.Files.writeString(root.resolve("src/main.pbs"),"import { Sprite as Alias } from @core:sprite;[Frame] fn frame()->void {let bad="+construction+";}");
|
||||
var denied=p.studio.compiler.workspaces.BuilderPipelineService.INSTANCE.analyze(p.studio.compiler.models.BuilderPipelineContext.fromConfig(new p.studio.compiler.messages.BuilderPipelineConfig(false,root.toString())),p.studio.utilities.logs.LogAggregator.stdout());
|
||||
assertTrue(denied.diagnostics().stream().anyMatch(d->d.getCode().equals("E_SEM_STDLIB_FACTORY_ONLY")),denied.diagnostics().toString());
|
||||
}
|
||||
java.nio.file.Files.writeString(root.resolve("src/main.pbs"),"[StdlibFactoryOnly] declare struct Forged(value:int) {} [Frame]fn frame()->void{}");
|
||||
var forged=p.studio.compiler.workspaces.BuilderPipelineService.INSTANCE.analyze(p.studio.compiler.models.BuilderPipelineContext.fromConfig(new p.studio.compiler.messages.BuilderPipelineConfig(false,root.toString())),p.studio.utilities.logs.LogAggregator.stdout());
|
||||
assertTrue(forged.diagnostics().stream().anyMatch(d->d.isError()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user