| 823 | /* ── lambda + dict-literal-dispatch registries ────────────────── */ |
| 824 | |
| 825 | static void py_register_lambda(PyLSPContext *ctx, const char *name, TSNode lambda_node) { |
| 826 | if (!ctx || !name) |
| 827 | return; |
| 828 | if (ctx->lambda_count >= ctx->lambda_cap) { |
| 829 | int new_cap = ctx->lambda_cap == 0 ? 8 : ctx->lambda_cap * 2; |
| 830 | CBMLambdaEntry *grown = |
| 831 | (CBMLambdaEntry *)cbm_arena_alloc(ctx->arena, (size_t)new_cap * sizeof(CBMLambdaEntry)); |
| 832 | if (!grown) |
| 833 | return; |
| 834 | if (ctx->lambdas && ctx->lambda_count > 0) { |
| 835 | memcpy(grown, ctx->lambdas, (size_t)ctx->lambda_count * sizeof(CBMLambdaEntry)); |
| 836 | } |
| 837 | ctx->lambdas = grown; |
| 838 | ctx->lambda_cap = new_cap; |
| 839 | } |
| 840 | // Overwrite if name already registered. |
| 841 | for (int i = 0; i < ctx->lambda_count; i++) { |
| 842 | if (ctx->lambdas[i].name && strcmp(ctx->lambdas[i].name, name) == 0) { |
| 843 | ctx->lambdas[i].lambda_node = lambda_node; |
| 844 | return; |
| 845 | } |
| 846 | } |
| 847 | ctx->lambdas[ctx->lambda_count].name = cbm_arena_strdup(ctx->arena, name); |
| 848 | ctx->lambdas[ctx->lambda_count].lambda_node = lambda_node; |
| 849 | ctx->lambda_count++; |
| 850 | } |
| 851 | |
| 852 | static TSNode py_lookup_lambda(PyLSPContext *ctx, const char *name) { |
| 853 | TSNode null_node = {0}; |
no test coverage detected