import vec:* import str:* // for decent to string // should be fixed by UFCS or decent scoping on template types import ast:* import type2:* var bindings: *vec<*void> fun binding(): *binding { return binding(null()) } fun binding_p(it: T): *binding { var p = new() p->copy_construct(&it) return binding(p) } fun binding(it: *T): *binding { var to_ret = new>()->construct(it) if (bindings == null>()) bindings = new>()->construct() bindings->add( (to_ret) cast *void ) return to_ret } obj binding (Object) { var bound_to: *T fun construct(): *binding { bound_to = null() return this } fun construct(it: *T): *binding { bound_to = it return this } fun copy_construct(old: *binding): void { bound_to = old->bound_to } fun destruct() { bound_to = null() } fun bound(): bool { return bound_to != null() } fun set(to: T) { var p = new() p->copy_construct(&to) set(p) } fun set(to: *T) { // don't set null, that will set all unbound ones if (bound_to == null()) { bound_to = to return } var from = bound_to for (var i = 0; i < bindings->size; i++;) if ( ((bindings->get(i)) cast *binding)->bound_to == from) ((bindings->get(i)) cast *binding)->bound_to = to } fun set_single(to: *T) { bound_to = to } fun to_string(): str { /*return "binding(" + to_string(bound_to) + ")"*/ return "binding(" + deref_to_string(bound_to) + ")" } }