| 1 | module scheme |
| 2 | |
| 3 | import arena |
| 4 | import reader |
| 5 | |
| 6 | // Independent source53 detached/live boundary parity. Authored, not run here. |
| 7 | fn test_independent_overlay_zero_slot_boundary_does_not_reenable_old_syntax_entries() { |
| 8 | code := &Code{ doc: reader.read_all('') or { panic(err.msg()) } } |
| 9 | function := &Function{ code: code } |
| 10 | mut boundary := &Scope{ function: function, syntax: &SyntaxBindings{} } |
| 11 | mut builder := Builder{ code: code, function: function, scope: boundary } |
| 12 | mark := &SyntaxWrap{ domain: &SyntaxLexicalDomain{}, mark: 1 } |
| 13 | mut storage := arena.new(chunk_size: 1024) |
| 14 | key := syntax_capture_family(mark, storage) + '/x' |
| 15 | old := &SyntaxTransformer{} |
| 16 | boundary.syntax.entries[key] = SyntaxBinding{ kind: .transformer, name: key, transformer: old } |
| 17 | base := &SyntaxLookupContext{ |
| 18 | globals: { |
| 19 | 'x': SyntaxBinding{ kind: .global, name: 'x', global_slot: 7 } |
| 20 | } |
| 21 | } |
| 22 | alias := IdentifierAlias{ context: base, capture_scope: boundary, capture_slots: 0 } |
| 23 | boundary.declare('unrelated-new-slot') |
| 24 | // Live lookup refuses the old transformer even after a new runtime slot exists. |
| 25 | assert scope_capture_binding(boundary, key, boundary, 0) == none |
| 26 | current := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 27 | mut origins := SyntaxInputOrigins{ storage: storage } |
| 28 | overlay := builder.overlay_identifier_context(base, alias, current, mut origins) |
| 29 | assert overlay.overlay_boundary |
| 30 | assert overlay.overlay_slots == 0 |
| 31 | actual := overlay.binding_with_marks('x', mark) |
| 32 | assert actual.kind == .global && actual.global_slot == 7 |
| 33 | storage.free() |
| 34 | } |
| 35 | |
| 36 | fn test_independent_overlay_zero_slot_boundary_accepts_new_enumeration_hidden_slot_zero() { |
| 37 | domain := &SyntaxLexicalDomain{} |
| 38 | mark := &SyntaxWrap{ domain: domain, mark: 1 } |
| 39 | mut storage := arena.new(chunk_size: 1024) |
| 40 | key := syntax_capture_family(mark, storage) + '/x' |
| 41 | hidden := SyntaxBinding{ kind: .lexical, name: 'hidden', slot: 0, lexical_domain: domain, lexical_id: 1 } |
| 42 | transformer := &SyntaxTransformer{ enumeration: &EnumerationSyntax{ binding: hidden } } |
| 43 | frame := &SyntaxLexicalFrame{ |
| 44 | domain: domain |
| 45 | function_id: 1 |
| 46 | syntax: { |
| 47 | key: SyntaxBinding{ kind: .transformer, name: key, transformer: transformer } |
| 48 | } |
| 49 | } |
| 50 | base := &SyntaxLookupContext{ |
| 51 | globals: { |
| 52 | 'x': SyntaxBinding{ kind: .global, name: 'x', global_slot: 7 } |
| 53 | } |
| 54 | } |
| 55 | overlay := &SyntaxLookupContext{ origin: base, lexical: frame, overlay_boundary: true, overlay_slots: 0 } |
| 56 | actual := overlay.binding_with_marks('x', mark) |
| 57 | assert actual.kind == .transformer |
| 58 | assert voidptr(actual.transformer) == voidptr(transformer) |
| 59 | storage.free() |
| 60 | } |
| 61 | |
| 62 | fn test_independent_overlay_publication_retains_no_temporary_scope_or_origins_storage() { |
| 63 | mut published := arena.new(chunk_size: 1048576) |
| 64 | published.push() |
| 65 | mark := &SyntaxWrap{ domain: &SyntaxLexicalDomain{}, mark: 1 } |
| 66 | mut scratch := arena.new(chunk_size: 4096) |
| 67 | key := syntax_capture_family(mark, scratch) + '/x' |
| 68 | base := &SyntaxLookupContext{ |
| 69 | globals: { |
| 70 | 'x': SyntaxBinding{ kind: .global, name: 'x', global_slot: 7 } |
| 71 | } |
| 72 | } |
| 73 | scratch.push() |
| 74 | code := &Code{ doc: reader.read_all('') or { panic(err.msg()) } } |
| 75 | function := &Function{ code: code } |
| 76 | mut boundary := &Scope{ function: function } |
| 77 | mut child := &Scope{ parent: boundary, function: function } |
| 78 | child.declare(key) |
| 79 | mut builder := Builder{ code: code, function: function, scope: child } |
| 80 | scratch.pop() |
| 81 | current := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 82 | mut origins := SyntaxInputOrigins{ storage: scratch } |
| 83 | overlay := builder.overlay_identifier_context(base, IdentifierAlias{ context: base, capture_scope: boundary, capture_slots: 0 }, current, mut origins) |
| 84 | assert published.owns(overlay) |
| 85 | assert published.owns(overlay.lexical) |
| 86 | assert published.owns(overlay.lexical.domain) |
| 87 | scratch.free() |
| 88 | gc_collect() |
| 89 | actual := overlay.binding_with_marks('x', mark) |
| 90 | assert actual.kind == .lexical && actual.slot == 0 |
| 91 | assert isnil(actual.function) |
| 92 | assert voidptr(actual.lexical_domain) == voidptr(overlay.lexical.domain) |
| 93 | published.pop() |
| 94 | published.free() |
| 95 | } |
| 96 | |