| 34 | } |
| 35 | |
| 36 | void cbm_scope_bind(CBMScope* scope, const char* name, const CBMType* type) { |
| 37 | if (!scope || !name) { |
| 38 | return; |
| 39 | } |
| 40 | for (CBMScopeChunk* c = scope->chunks; c != NULL; c = c->next) { |
| 41 | for (int i = 0; i < c->used; i++) { |
| 42 | if (c->bindings[i].name && strcmp(c->bindings[i].name, name) == 0) { |
| 43 | c->bindings[i].type = type; |
| 44 | return; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | CBMScopeChunk* head = scope->chunks; |
| 49 | if (!head || head->used >= CBM_SCOPE_CHUNK_BINDINGS) { |
| 50 | head = alloc_chunk(scope); |
| 51 | if (!head) { |
| 52 | return; |
| 53 | } |
| 54 | } |
| 55 | head->bindings[head->used].name = name; |
| 56 | head->bindings[head->used].type = type; |
| 57 | head->used++; |
| 58 | } |
| 59 | |
| 60 | const CBMType* cbm_scope_lookup(const CBMScope* scope, const char* name) { |
| 61 | if (!name) { |
no test coverage detected