Returns false when the binding could NOT be recorded in THIS frame. * * The failure that matters is arena exhaustion in alloc_chunk: the old void * form returned silently, so a caller that then consulted the scope CHAIN saw * the parent's binding for the same name and concluded the child had been * bound. For callable-value proof that is a fabricated identity -- the shadow * never took effec
| 43 | * needing that distinction must use the checked form and consult the LOCAL |
| 44 | * result, not a chain lookup. */ |
| 45 | static bool cbm_scope_bind_value(CBMScope *scope, const char *name, const CBMType *type, |
| 46 | const char *callable_qn) { |
| 47 | if (!scope || !name) { |
| 48 | return false; |
| 49 | } |
| 50 | for (CBMScopeChunk* c = scope->chunks; c != NULL; c = c->next) { |
| 51 | for (int i = 0; i < c->used; i++) { |
| 52 | if (c->bindings[i].name && strcmp(c->bindings[i].name, name) == 0) { |
| 53 | c->bindings[i].type = type; |
| 54 | c->bindings[i].callable_qn = callable_qn; |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | CBMScopeChunk* head = scope->chunks; |
| 60 | if (!head || head->used >= CBM_SCOPE_CHUNK_BINDINGS) { |
| 61 | head = alloc_chunk(scope); |
| 62 | if (!head) { |
| 63 | return false; /* arena exhausted: the shadow did NOT take effect */ |
| 64 | } |
| 65 | } |
| 66 | head->bindings[head->used].name = name; |
| 67 | head->bindings[head->used].type = type; |
| 68 | head->bindings[head->used].callable_qn = callable_qn; |
| 69 | head->used++; |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | void cbm_scope_bind(CBMScope *scope, const char *name, const CBMType *type) { |
| 74 | (void)cbm_scope_bind_value(scope, name, type, NULL); |
no test coverage detected