1 import Base 2 import ./world.bend as W 3 import ./world_namespace.bend as F 4 5 # Ordinary creation uses the checked host IO namespace allocator. 6 # Canonical linked Native execution and a shared JS realm are qualified separately. 7 # with_namespace/convert and raw World construction are trusted integration helpers. 8 # No language-wide constructor/authority confinement is claimed. 9 # Concrete World constructors remain a trusted schema/admin boundary. 10 # World creation outcome: Created owns the new World; Refused returns the 11 # caller's resource owner without constructing a usable World. 12 type Creation is Type: 13 Created{world: W.World} 14 Refused{resource: R} 15 16 def convert(~S: Data,~C: Type,~R: Type,~E: Data,created: W.Creation) -> Creation: 17 match created: 18 case W.Created{_,world}: Created{world} 19 case W.CreateRejected{_,resource}: Refused{resource} 20 21 # Trusted integration constructor with a caller-supplied namespace. Rejects 22 # reserved namespace values and returns the resource on refusal. Does not 23 # allocate a unique namespace: caller must prevent collisions. Prefer create. 24 def with_namespace(~S: Data,~C: Type,~R: Type,~E: Data,~empty: Unit -> C,+namespace: U32,resource: R) -> IO(Creation): 25 IO.pure(Creation,convert(~S,~C,~R,~E,W.create_checked(~S,~C,~R,~E,~empty,Bool.and(U32.is_lt(0,namespace),U32.is_lt(namespace,4294967295)),namespace,resource))) 26 27 # Create an independent World through the host IO namespace allocator. 28 # Consumes resource; Created returns its World, Refused returns resource. 29 # empty is trusted schema setup constructing component storage. Namespace 30 # uniqueness is scoped to the qualified host allocator realm/process, not 31 # arbitrary remote processes or raw constructors. 32 # Example: examples/scheduled-health/main.bend; identity: docs/parity/identity.md. 33 def create(~S: Data,~C: Type,~R: Type,~E: Data,~empty: Unit -> C,resource: R) -> IO(Creation): 34 IO.bind(U32,Creation,F.fresh(),namespace => with_namespace(~S,~C,~R,~E,~empty,namespace,resource))