| 672 | /* ── lambda + dict-literal-dispatch registries ────────────────── */ |
| 673 | |
| 674 | static void py_register_lambda(PyLSPContext *ctx, const char *name, TSNode lambda_node) { |
| 675 | if (!ctx || !name) |
| 676 | return; |
| 677 | if (ctx->lambda_count >= ctx->lambda_cap) { |
| 678 | int new_cap = ctx->lambda_cap == 0 ? 8 : ctx->lambda_cap * 2; |
| 679 | CBMLambdaEntry *grown = |
| 680 | (CBMLambdaEntry *)cbm_arena_alloc(ctx->arena, (size_t)new_cap * sizeof(CBMLambdaEntry)); |
| 681 | if (!grown) |
| 682 | return; |
| 683 | if (ctx->lambdas && ctx->lambda_count > 0) { |
| 684 | memcpy(grown, ctx->lambdas, (size_t)ctx->lambda_count * sizeof(CBMLambdaEntry)); |
| 685 | } |
| 686 | ctx->lambdas = grown; |
| 687 | ctx->lambda_cap = new_cap; |
| 688 | } |
| 689 | // Overwrite if name already registered. |
| 690 | for (int i = 0; i < ctx->lambda_count; i++) { |
| 691 | if (ctx->lambdas[i].name && strcmp(ctx->lambdas[i].name, name) == 0) { |
| 692 | ctx->lambdas[i].lambda_node = lambda_node; |
| 693 | return; |
| 694 | } |
| 695 | } |
| 696 | ctx->lambdas[ctx->lambda_count].name = cbm_arena_strdup(ctx->arena, name); |
| 697 | ctx->lambdas[ctx->lambda_count].lambda_node = lambda_node; |
| 698 | ctx->lambda_count++; |
| 699 | } |
| 700 | |
| 701 | static TSNode py_lookup_lambda(PyLSPContext *ctx, const char *name) { |
| 702 | TSNode null_node = {0}; |
no test coverage detected