| 1 | module scheme |
| 2 | |
| 3 | // A scope can be retained by a generated identifier alias until syntax is |
| 4 | // detached. Register only this scope, never its borrowed parent chain. |
| 5 | fn new_compile_scope(initial Scope) &Scope { |
| 6 | mut code := initial.function.code |
| 7 | mut scope := &Scope{ ...initial, scratch_next: code.compile_scopes } |
| 8 | code.compile_scopes = scope |
| 9 | return scope |
| 10 | } |
| 11 | |
| 12 | // Run only after all compilation borrows and generated aliases are detached. |
| 13 | // Emitted names and frozen lookup frames do not borrow the map's cloned keys. |
| 14 | fn (mut code Code) release_compile_names() { |
| 15 | mut table := code.compile_tables |
| 16 | code.compile_tables = unsafe { nil } |
| 17 | for !isnil(table) { |
| 18 | next := table.scratch_next |
| 19 | unsafe { |
| 20 | table.indices.free() |
| 21 | free(table) |
| 22 | } |
| 23 | table = next |
| 24 | } |
| 25 | mut scope := code.compile_scopes |
| 26 | code.compile_scopes = unsafe { nil } |
| 27 | for !isnil(scope) { |
| 28 | next := scope.scratch_next |
| 29 | unsafe { |
| 30 | scope.names.free() |
| 31 | free(scope) |
| 32 | } |
| 33 | scope = next |
| 34 | } |
| 35 | } |
| 36 | |