module scheme import arena fn test_goops_bootstrap_does_not_consume_the_callers_step_limit() { mut vm := new_with_options(Options{ max_steps: 1 }) or { panic(err) } initialize := vm.lookup('initialize') or { panic(err) } assert initialize.is_callable() if _ := vm.eval('42') { panic('bootstrap replaced the caller step limit') } else { assert err.msg().contains('evaluation step limit exceeded'), err.msg() } // Management remains usable after the deliberately exhausted evaluation. assert vm.lookup('initialize') or { panic(err) } == initialize } fn test_goops_bootstrap_restores_the_callers_frame_limit() { mut vm := new_with_options(Options{ max_frames: 1 }) or { panic(err) } if _ := vm.eval('(define (f n) (if (= n 0) 0 (+ 1 (f (- n 1))))) (f 4)') { panic('bootstrap replaced the caller frame limit') } else { assert err.msg().contains('continuation frame limit exceeded'), err.msg() } assert (vm.eval('7') or { panic(err) }).as_integer() or { panic(err) } == 7 } fn test_goops_bootstrap_restores_the_callers_expansion_limit() { mut vm := new_with_options(Options{ max_expansions: 1 }) or { panic(err) } if _ := vm.eval('(define-syntax first (syntax-rules () ((_ x) (second x)))) (define-syntax second (syntax-rules () ((_ x) x))) (first 42)') { panic('bootstrap replaced the caller expansion limit') } else { assert err.msg().contains('macro expansion limit exceeded'), err.msg() } assert (vm.eval('9') or { panic(err) }).as_integer() or { panic(err) } == 9 } fn test_built_in_protocols_remain_vm_local_and_user_syntax_is_staged() { mut first := new() mut second := new() program := '(define-class () (x #:init-value 7)) (define original initialize) (define probe (make )) (define-syntax read-test-slot (syntax-rules () ((_ obj) (slot-ref obj (quote x))))) (list (eq? make make-instance) (read-test-slot probe) (generic? original))' first_value := first.eval(program) or { panic(err) } second_value := second.eval(program) or { panic(err) } for value in [first_value, second_value] { text := write(value) or { panic(err) } if text != '(#t 7 #t)' { panic('incorrect protocol installation: ${text}') } } first.eval('(slot-set! probe (quote x) 11) (set! initialize #f)') or { panic(err) } value := second.eval('(list (eq? original initialize) (read-test-slot probe))') or { panic(err) } text := write(value) or { panic(err) } if text != '(#t 7)' { panic('VM protocol state crossed instances: ${text}') } } fn test_protocol_source_outlives_each_vm_arena() { mut temporary := arena.new() temporary.push() mut first := new() first_value := first.lookup('class-slot-ref') or { panic(err) } first_function := first_value.procedure_pointer().function temporary.pop() mut second := new() second_value := second.lookup('class-slot-ref') or { panic(err) } second_function := second_value.procedure_pointer().function if voidptr(first_function) == voidptr(second_function) { panic('protocol function shared executable state across VMs') } if first_function.instructions.data != second_function.instructions.data { panic('read-only protocol instructions were copied into each VM') } if first_function.global_slots.len == 0 || first_function.global_slots.data == second_function.global_slots.data { panic('protocol global lookup caches must belong to each VM') } if !temporary.owns(first_function.global_slots.data) || temporary.owns(first_function.instructions.data) { panic('protocol code or binding cache has the wrong allocation owner') } if first_function.code.doc.forms.data != second_function.code.doc.forms.data || first_function.code.doc.arena.source_text().str != second_function.code.doc.arena.source_text().str { panic('built-in protocol source was copied per VM') } if temporary.owns(second_function.code.doc.forms.data) || temporary.owns(second_function.code.doc.arena.source_text().str) { panic('protocol source retained a temporary VM arena') } temporary.free() probe := second.eval("(define-class () (x #:allocation #:class #:init-value 73)) (class-slot-ref 'x)") or { panic(err) } if (probe.as_integer() or { panic(err) }) != 73 { panic('surviving VM lost its protocol state') } }