1 import Base 2 import ./entity_key.bend as Key 3 import ./world.bend as W 4 import ./restore_data.bend as Basic 5 import ./relation_types.bend as G 6 import ./relation_graph.bend as Graph 7 8 type Mapped is Data: 9 Mapped{graph:G.Graph} 10 MissingBinding{saved:Key.Key} 11 def target(~S:Data,descriptor:G.Descriptor,source:W.Handle,saved:Key.Key,result:Maybe<&2,W.Handle>,graph:G.Graph,next:G.Graph -> Mapped) -> Mapped: 12 match source result graph: 13 case _ None{} _:MissingBinding{saved} 14 case W.Handle{_,source} Some{W.Handle{_,target}} G.Graph{edges,inverses}:next(Graph.updated(~S,False{},edges,inverses,descriptor,source,target)) 15 def source(~S:Data,descriptor:G.Descriptor,saved:Key.Key,+other:Key.Key,+bindings:List<&2,Basic.Binding>,result:Maybe<&2,W.Handle>,graph:G.Graph,next:G.Graph -> Mapped) -> Mapped: 16 match result: 17 case None{}:MissingBinding{saved} 18 case Some{handle}:target(~S,descriptor,handle,other,Basic.lookup(~S,other,bindings),graph,next) 19 def edges(~S:Data,values:List<&2,G.Edge>,+bindings:List<&2,Basic.Binding>,graph:G.Graph) -> Mapped: 20 match values: 21 case []:Mapped{graph} 22 case G.Edge{descriptor,+saved,other} <> rest:source(~S,descriptor,saved,other,bindings,Basic.lookup(~S,saved,bindings),graph,graph => edges(~S,rest,bindings,graph)) 23 def remap(~S:Data,graph:G.Graph,bindings:List<&2,Basic.Binding>) -> Mapped: 24 match graph: 25 case G.Graph{values,_}:edges(~S,values,bindings,G.Graph{[],[]})