| 1 | module scheme |
| 2 | |
| 3 | import arena |
| 4 | |
| 5 | // Prospective custom-combined attachment tests; immutable101, no execution. |
| 6 | fn ccx_review_eval(mut vm VM, source string) string { |
| 7 | return write(vm.eval(source) or { panic('${source}: ${err.msg()}') }) or { panic(err.msg()) } |
| 8 | } |
| 9 | |
| 10 | fn ccx_review_original(mut _vm VM, _args []Value) !Value { |
| 11 | return EvalError{ message: 'ccx-original-writer', source_path: 'ccx-writer.scm', offset: 73, line: 7, column: 11 } |
| 12 | } |
| 13 | |
| 14 | fn ccx_review_secondary(mut _vm VM, _args []Value) !Value { |
| 15 | return EvalError{ message: 'ccx-secondary-closer', source_path: 'ccx-closer.scm', offset: 901, line: 99, column: 6 } |
| 16 | } |
| 17 | |
| 18 | struct CcxReviewError { |
| 19 | message string |
| 20 | path string |
| 21 | offset int |
| 22 | line int |
| 23 | column int |
| 24 | } |
| 25 | |
| 26 | fn ccx_review_error(err IError) CcxReviewError { |
| 27 | if err is EvalError { |
| 28 | return CcxReviewError{err.message, err.source_path, err.offset, err.line, err.column} |
| 29 | } |
| 30 | panic(err.msg()) |
| 31 | } |
| 32 | |
| 33 | fn ccx_review_expected() CcxReviewError { |
| 34 | return CcxReviewError{'ccx-original-writer', 'ccx-writer.scm', 73, 7, 11} |
| 35 | } |
| 36 | |
| 37 | fn ccx_review_packet_probe(mut vm VM, args []Value) !Value { |
| 38 | packet := args[0] |
| 39 | p := args[1] |
| 40 | for _ in 0 .. 2 { |
| 41 | if _ := vm.call(vm.lookup('bytevector-u8-set!')!, [packet, integer(0), integer(0)]) { |
| 42 | return failure('encoded callback packet was mutable') |
| 43 | } else { |
| 44 | if is_control_transfer(err) { return err } |
| 45 | } |
| 46 | for name in ['get-char', 'close-input-port', 'close-output-port', 'close-port'] { |
| 47 | if _ := vm.call(vm.lookup(name)!, [p]) { |
| 48 | return failure('same combined resource reentered ${name}') |
| 49 | } else { |
| 50 | if is_control_transfer(err) { return err } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | if args[2].tag == .output_port { |
| 55 | vm.call(vm.lookup('put-string')!, [args[2], string_value('Q')])! |
| 56 | } |
| 57 | gc_collect() |
| 58 | return boolean(true) |
| 59 | } |
| 60 | |
| 61 | fn ccx_review_busy_attach(mut vm VM, args []Value) !Value { |
| 62 | for _ in 0 .. 2 { |
| 63 | if _ := vm.transcoded_port(args[0], args[1]) { |
| 64 | return failure('busy binary resource was transferred') |
| 65 | } else { |
| 66 | if is_control_transfer(err) { return err } |
| 67 | } |
| 68 | } |
| 69 | if !(vm.call(vm.lookup('input-port-open?')!, [args[0]])!).is_true() || !(vm.call(vm.lookup('output-port-open?')!, [args[0]])!).is_true() { |
| 70 | return failure('failed attachment changed binary half ownership') |
| 71 | } |
| 72 | gc_collect() |
| 73 | return boolean(true) |
| 74 | } |
| 75 | |
| 76 | fn ccx_review_setup(mut vm VM) { |
| 77 | vm.register('ccx-original', ccx_review_original) or { panic(err.msg()) } |
| 78 | vm.register('ccx-secondary', ccx_review_secondary) or { panic(err.msg()) } |
| 79 | vm.register('ccx-probe', ccx_review_packet_probe) or { panic(err.msg()) } |
| 80 | vm.register('ccx-busy-attach', ccx_review_busy_attach) or { panic(err.msg()) } |
| 81 | vm.eval('(define ccx-p #f) (define ccx-raw #f) (define ccx-sink #f) (define ccx-other #f) |
| 82 | (define ccx-reads 0) (define ccx-writes 0) (define ccx-closes 0) |
| 83 | (define ccx-read-buffer #f) (define ccx-packet #f) |
| 84 | (define ccx-arm-prefix #f) (define ccx-fail #f) |
| 85 | (define ccx-read-hook #f) (define ccx-write-hook #f) (define ccx-close-hook #f) |
| 86 | (define ccx-after-read #f) (define ccx-after-write #f) |
| 87 | (define ccx-options (make-transcoder (utf-8-codec) (eol-style none) (error-handling-mode raise))) |
| 88 | (define (ccx-new-raw data stride) |
| 89 | (set! ccx-sink (open-output-bytevector)) |
| 90 | (set! ccx-raw |
| 91 | (let ((index 0)) |
| 92 | (make-custom-binary-input/output-port "independent-custom-combined" |
| 93 | (lambda (b s n) (if (not (bytevector? b)) (car 0)) |
| 94 | (set! ccx-reads (+ ccx-reads 1)) (set! ccx-read-buffer b) |
| 95 | (if ccx-read-hook (ccx-read-hook b)) |
| 96 | (let ((count (min n stride (- (bytevector-length data) index)))) |
| 97 | (do ((i 0 (+ i 1))) ((= i count)) |
| 98 | (bytevector-u8-set! b (+ s i) (bytevector-u8-ref data (+ index i)))) |
| 99 | (set! index (+ index count)) |
| 100 | (if ccx-after-read (ccx-after-read)) count)) |
| 101 | (lambda (b s n) (if (not (bytevector? b)) (car 0)) |
| 102 | (set! ccx-writes (+ ccx-writes 1)) (set! ccx-packet b) |
| 103 | (if ccx-write-hook (ccx-write-hook b)) |
| 104 | (cond (ccx-arm-prefix |
| 105 | (set! ccx-arm-prefix #f) (set! ccx-fail #t) |
| 106 | (put-bytevector ccx-sink b s 1) (if ccx-after-write (ccx-after-write)) 1) |
| 107 | (ccx-fail (ccx-original)) |
| 108 | (else (put-bytevector ccx-sink b s n) |
| 109 | (if ccx-after-write (ccx-after-write)) n))) #f #f |
| 110 | (lambda () (set! ccx-closes (+ ccx-closes 1)) |
| 111 | (if ccx-close-hook (ccx-close-hook)) (values 1 2))))) ccx-raw) |
| 112 | (define (ccx-make data stride options) |
| 113 | (ccx-new-raw data stride) (set! ccx-p (transcoded-port ccx-raw options)) ccx-p)') or { panic(err.msg()) } |
| 114 | } |
| 115 | |
| 116 | fn ccx_review_pending_closed_output(mut vm VM) { |
| 117 | vm.eval('(ccx-make #u8(65 66) 1 ccx-options) (set! ccx-arm-prefix #t)') or { panic(err.msg()) } |
| 118 | for source in ['(put-string ccx-p "λ")', '(close-output-port ccx-p)'] { |
| 119 | if _ := vm.eval(source) { |
| 120 | assert false, source |
| 121 | } else { |
| 122 | assert ccx_review_error(err) == ccx_review_expected() |
| 123 | } |
| 124 | } |
| 125 | assert ccx_review_eval(mut vm, '(list (get-output-bytevector ccx-sink) ccx-closes (input-port-open? ccx-p) (output-port-open? ccx-p))') == '(#u8(206) 0 #t #f)' |
| 126 | assert vm.active.len == 0 |
| 127 | } |
| 128 | |
| 129 | fn test_ccx_review_raw_lookahead_transfer_keeps_independent_rx_and_tx_and_one_closer() { |
| 130 | mut vm := new() |
| 131 | ccx_review_setup(mut vm) |
| 132 | assert ccx_review_eval(mut vm, '(ccx-new-raw #u8(255 254 65 0 66 0) 1) |
| 133 | (define first (lookahead-u8 ccx-raw)) |
| 134 | (set! ccx-p (transcoded-port ccx-raw (make-transcoder (utf-16-codec) (eol-style none)))) |
| 135 | (define attach-reads ccx-reads) |
| 136 | (close-port ccx-raw) (define a (char->integer (get-char ccx-p))) |
| 137 | (put-string ccx-p "Ω") |
| 138 | (list first attach-reads a (get-string-all ccx-p) (get-output-bytevector ccx-sink) |
| 139 | (input-port? ccx-p) (output-port? ccx-p) (textual-port? ccx-p) ccx-closes)') == '(255 1 65 "B" #u8(3 169) #t #t #t 0)' |
| 140 | assert ccx_review_eval(mut vm, '(close-input-port ccx-p) (define before ccx-closes) |
| 141 | (close-output-port ccx-p) (close-port ccx-p) (list before ccx-closes (binary-port? ccx-raw))') == '(0 1 #t)' |
| 142 | assert vm.active.len == 0 |
| 143 | } |
| 144 | |
| 145 | fn test_ccx_review_final_input_close_drains_encoded_suffix_after_failed_output_half_close() { |
| 146 | mut vm := new() |
| 147 | ccx_review_setup(mut vm) |
| 148 | ccx_review_pending_closed_output(mut vm) |
| 149 | assert ccx_review_eval(mut vm, '(char->integer (get-char ccx-p))') == '65' |
| 150 | vm.eval('(set! ccx-fail #f) |
| 151 | (set! ccx-write-hook (lambda (b) (ccx-probe b ccx-p #f))) |
| 152 | (close-input-port ccx-p)') or { panic(err.msg()) } |
| 153 | assert ccx_review_eval(mut vm, '(close-port ccx-p) (close-port ccx-raw) |
| 154 | (list (get-output-bytevector ccx-sink) ccx-closes (input-port-open? ccx-p) (output-port-open? ccx-p))') == '(#u8(206 187) 1 #f #f)' |
| 155 | assert vm.active.len == 0 |
| 156 | } |
| 157 | |
| 158 | fn test_ccx_review_final_input_flush_and_closer_failure_preserve_original_located_error() { |
| 159 | mut vm := new() |
| 160 | ccx_review_setup(mut vm) |
| 161 | ccx_review_pending_closed_output(mut vm) |
| 162 | vm.eval('(set! ccx-close-hook ccx-secondary)') or { panic(err.msg()) } |
| 163 | if _ := vm.eval('(close-input-port ccx-p)') { |
| 164 | assert false |
| 165 | } else { |
| 166 | assert ccx_review_error(err) == ccx_review_expected() |
| 167 | } |
| 168 | assert ccx_review_eval(mut vm, '(close-port ccx-p) (close-port ccx-raw) |
| 169 | (list ccx-closes (input-port-open? ccx-p) (output-port-open? ccx-p))') == '(1 #f #f)' |
| 170 | assert vm.active.len == 0 |
| 171 | assert ccx_review_eval(mut vm, '(+ 20 22)') == '42' |
| 172 | } |
| 173 | |
| 174 | fn test_ccx_review_final_input_closer_only_failure_propagates_once_after_healthy_output_close() { |
| 175 | mut vm := new() |
| 176 | ccx_review_setup(mut vm) |
| 177 | vm.eval('(ccx-make #u8(65) 1 ccx-options) (put-string ccx-p "Ω") |
| 178 | (close-output-port ccx-p) (set! ccx-close-hook ccx-secondary)') or { panic(err.msg()) } |
| 179 | assert ccx_review_eval(mut vm, 'ccx-closes') == '0' |
| 180 | if _ := vm.eval('(close-input-port ccx-p)') { |
| 181 | assert false |
| 182 | } else { |
| 183 | assert ccx_review_error(err) == CcxReviewError{'ccx-secondary-closer', 'ccx-closer.scm', 901, 99, 6} |
| 184 | } |
| 185 | assert ccx_review_eval(mut vm, '(close-port ccx-p) (close-port ccx-raw) |
| 186 | (list ccx-closes (get-output-bytevector ccx-sink) (input-port-open? ccx-p) (output-port-open? ccx-p))') == '(1 #u8(206 169) #f #f)' |
| 187 | assert vm.active.len == 0 |
| 188 | } |
| 189 | |
| 190 | fn test_ccx_review_final_closer_escape_multishot_keeps_controller_values_and_physical_close_once() { |
| 191 | mut vm := new() |
| 192 | ccx_review_setup(mut vm) |
| 193 | ccx_review_pending_closed_output(mut vm) |
| 194 | assert ccx_review_eval(mut vm, '(define ccx-k #f) (define ccx-leave #f) (define ccx-after 0) |
| 195 | (define ccx-events (quote ())) (set! ccx-fail #f) |
| 196 | (set! ccx-close-hook (lambda () |
| 197 | (dynamic-wind (lambda () (set! ccx-events (cons (quote before) ccx-events))) |
| 198 | (lambda () (call/cc (lambda (k) (set! ccx-k k) (ccx-leave 99))) |
| 199 | (set! ccx-after (+ ccx-after 1)) (values 1 2)) |
| 200 | (lambda () (set! ccx-events (cons (quote after) ccx-events)))))) |
| 201 | (call/cc (lambda (leave) (set! ccx-leave leave) |
| 202 | (call-with-values (lambda () (call-with-port ccx-p (lambda (q) (values 7 8)))) list)))') == '99' |
| 203 | assert ccx_review_eval(mut vm, '(list ccx-closes ccx-after (get-output-bytevector ccx-sink))') == '(1 0 #u8(206 187))' |
| 204 | gc_collect() |
| 205 | assert ccx_review_eval(mut vm, '(ccx-k)') == '(7 8)' |
| 206 | assert ccx_review_eval(mut vm, '(ccx-k 1 2 3)') == '(7 8)' |
| 207 | assert ccx_review_eval(mut vm, '(close-port ccx-p) (list ccx-closes ccx-after (reverse ccx-events) (get-output-bytevector ccx-sink))') == '(1 2 (before after before after before after) #u8(206 187))' |
| 208 | assert vm.active.len == 0 |
| 209 | } |
| 210 | |
| 211 | fn test_ccx_review_pending_drain_capture_after_physical_write_replays_close_without_duplicate_tx() { |
| 212 | mut vm := new() |
| 213 | ccx_review_setup(mut vm) |
| 214 | ccx_review_pending_closed_output(mut vm) |
| 215 | assert ccx_review_eval(mut vm, '(define ccx-k #f) (define ccx-leave #f) (define ccx-arm #t) |
| 216 | (set! ccx-fail #f) |
| 217 | (set! ccx-after-write (lambda () (if ccx-arm (begin (set! ccx-arm #f) |
| 218 | (call/cc (lambda (k) (set! ccx-k k) (ccx-leave 77))))))) |
| 219 | (call/cc (lambda (leave) (set! ccx-leave leave) (close-input-port ccx-p) 17))') == '77' |
| 220 | assert ccx_review_eval(mut vm, '(close-port ccx-p) |
| 221 | (list ccx-closes (get-output-bytevector ccx-sink) (input-port-open? ccx-p) (output-port-open? ccx-p))') == '(0 #u8(206 187) #f #f)' |
| 222 | gc_collect() |
| 223 | assert ccx_review_eval(mut vm, '(ccx-k 1)') == '17' |
| 224 | assert ccx_review_eval(mut vm, '(ccx-k 2)') == '17' |
| 225 | assert ccx_review_eval(mut vm, '(list ccx-closes (get-output-bytevector ccx-sink))') == '(1 #u8(206 187))' |
| 226 | assert vm.active.len == 0 |
| 227 | } |
| 228 | |
| 229 | fn test_ccx_review_read_callback_escape_and_multishot_keep_independent_output_and_shared_buffer() { |
| 230 | mut vm := new() |
| 231 | ccx_review_setup(mut vm) |
| 232 | assert ccx_review_eval(mut vm, '(define ccx-k #f) (define ccx-leave #f) (define ccx-arm #t) |
| 233 | (ccx-make #u8(65 66) 1 ccx-options) |
| 234 | (set! ccx-after-read (lambda () (if ccx-arm (begin (set! ccx-arm #f) |
| 235 | (call/cc (lambda (k) (set! ccx-k k) (ccx-leave 23))))))) |
| 236 | (call/cc (lambda (leave) (set! ccx-leave leave) (char->integer (get-char ccx-p))))') == '23' |
| 237 | vm.eval('(put-string ccx-p "Ω")') or { panic(err.msg()) } |
| 238 | gc_collect() |
| 239 | assert ccx_review_eval(mut vm, '(ccx-k 1)') == '65' |
| 240 | assert ccx_review_eval(mut vm, '(ccx-k 1)') == '65' |
| 241 | assert ccx_review_eval(mut vm, '(list (char->integer (get-char ccx-p)) (get-output-bytevector ccx-sink) ccx-closes)') == '(66 #u8(206 169) 0)' |
| 242 | vm.eval('(close-port ccx-p)') or { panic(err.msg()) } |
| 243 | assert ccx_review_eval(mut vm, 'ccx-closes') == '1' |
| 244 | } |
| 245 | |
| 246 | fn test_ccx_review_busy_attachment_packet_immutability_and_nested_different_custom_resource() { |
| 247 | mut vm := new() |
| 248 | ccx_review_setup(mut vm) |
| 249 | assert ccx_review_eval(mut vm, '(ccx-new-raw #u8(65 66) 1) |
| 250 | (set! ccx-read-hook (lambda (b) (ccx-busy-attach ccx-raw ccx-options))) |
| 251 | (get-u8 ccx-raw)') == '65' |
| 252 | vm.eval('(set! ccx-read-hook #f) (set! ccx-p (transcoded-port ccx-raw ccx-options)) |
| 253 | (define ccx-other-sink (open-output-bytevector)) (define ccx-other-closes 0) |
| 254 | (set! ccx-other (transcoded-port |
| 255 | (make-custom-binary-output-port "nested-other" |
| 256 | (lambda (b s n) (put-bytevector ccx-other-sink b s n) n) #f #f |
| 257 | (lambda () (set! ccx-other-closes (+ ccx-other-closes 1)))) ccx-options)) |
| 258 | (set! ccx-write-hook (lambda (b) (ccx-probe b ccx-p ccx-other))) |
| 259 | (put-string ccx-p "λ")') or { panic(err.msg()) } |
| 260 | assert ccx_review_eval(mut vm, '(list (char->integer (get-char ccx-p)) (get-output-bytevector ccx-sink) (get-output-bytevector ccx-other-sink))') == '(66 #u8(206 187) #u8(81))' |
| 261 | vm.eval('(close-port ccx-p) (close-port ccx-other)') or { panic(err.msg()) } |
| 262 | assert ccx_review_eval(mut vm, '(list ccx-closes ccx-other-closes)') == '(1 1)' |
| 263 | assert vm.active.len == 0 |
| 264 | } |
| 265 | |
| 266 | fn test_ccx_review_foreign_invalid_and_preclosed_attachment_preserve_ownership_without_extra_callbacks() { |
| 267 | for closed_side in ['neither', 'input', 'output', 'both'] { |
| 268 | mut vm := new() |
| 269 | ccx_review_setup(mut vm) |
| 270 | raw := vm.eval('(ccx-new-raw #u8(65) 1)') or { panic(err.msg()) } |
| 271 | options := vm.lookup('ccx-options') or { panic(err.msg()) } |
| 272 | mut other := new() |
| 273 | if _ := other.transcoded_port(raw, options) { |
| 274 | assert false |
| 275 | } |
| 276 | if _ := vm.transcoded_port(raw, boolean(true)) { |
| 277 | assert false |
| 278 | } |
| 279 | assert ccx_review_eval(mut vm, '(list ccx-reads ccx-writes ccx-closes (input-port-open? ccx-raw) (output-port-open? ccx-raw))') == '(0 0 0 #t #t)' |
| 280 | match closed_side { |
| 281 | 'input' { vm.close_input_port(raw) or { panic(err.msg()) } } |
| 282 | 'output' { vm.close_output_port(raw) or { panic(err.msg()) } } |
| 283 | 'both' { vm.close_port(raw) or { panic(err.msg()) } } |
| 284 | else {} |
| 285 | } |
| 286 | if closed_side == 'both' { |
| 287 | if _ := vm.transcoded_port(raw, options) { |
| 288 | assert false |
| 289 | } |
| 290 | assert ccx_review_eval(mut vm, 'ccx-closes') == '1' |
| 291 | continue |
| 292 | } |
| 293 | p := vm.transcoded_port(raw, options) or { panic(err.msg()) } |
| 294 | vm.define('ccx-p', p) or { panic(err.msg()) } |
| 295 | if closed_side == 'input' { |
| 296 | if _ := vm.read_char(p) { |
| 297 | assert false |
| 298 | } |
| 299 | vm.call(vm.lookup('put-string') or { panic(err.msg()) }, [p, string_value('Z')]) or { panic(err.msg()) } |
| 300 | } else { |
| 301 | assert (vm.read_char(p) or { panic(err.msg()) }).whole() == 65 |
| 302 | if closed_side == 'output' { |
| 303 | if _ := vm.call(vm.lookup('put-string') or { panic(err.msg()) }, [p, string_value('Z')]) { |
| 304 | assert false |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | vm.close_port(raw) or { panic(err.msg()) } |
| 309 | vm.close_port(p) or { panic(err.msg()) } |
| 310 | assert ccx_review_eval(mut vm, 'ccx-closes') == '1' |
| 311 | assert (vm.port_transcoder(p) or { panic(err.msg()) }).whole() == options.whole() |
| 312 | assert vm.active.len == 0 |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // Parent-suggested callback replay diagnostic. Vile restores private operation |
| 317 | // progress, so resuming with another count can repeat future I/O after capture. |
| 318 | // These deliberately changed counts illustrate Vile policy, not a normative |
| 319 | // guarantee for callbacks whose count must describe bytes actually written. |
| 320 | fn ccx_review_packet_replay(combined bool) { |
| 321 | mut vm := new() |
| 322 | constructor := if combined { |
| 323 | 'make-custom-binary-input/output-port' |
| 324 | } else { |
| 325 | 'make-custom-binary-output-port' |
| 326 | } |
| 327 | input := if combined { '(lambda (b s n) 0)' } else { '' } |
| 328 | assert ccx_review_eval(mut vm, '(define ccx-sink (open-output-bytevector)) (define ccx-k #f) |
| 329 | (define ccx-writes 0) (define ccx-closes 0) (define ccx-first #t) |
| 330 | (define ccx-raw (${constructor} "physical-replay" ${input} |
| 331 | (lambda (b s n) (set! ccx-writes (+ ccx-writes 1)) (put-bytevector ccx-sink b s n) |
| 332 | (if ccx-first (begin (set! ccx-first #f) (call/cc (lambda (k) (set! ccx-k k) n))) n)) #f #f |
| 333 | (lambda () (set! ccx-closes (+ ccx-closes 1))))) |
| 334 | (define ccx-p (transcoded-port ccx-raw (make-transcoder (utf-8-codec) (eol-style none)))) |
| 335 | (put-string ccx-p "λ") (list ccx-writes (get-output-bytevector ccx-sink))') == '(1 #u8(206 187))' |
| 336 | gc_collect() |
| 337 | assert ccx_review_eval(mut vm, '(ccx-k 0)') == '(2 #u8(206 187 206 187))' |
| 338 | assert ccx_review_eval(mut vm, '(ccx-k 1)') == '(3 #u8(206 187 206 187 187))' |
| 339 | assert ccx_review_eval(mut vm, '(close-port ccx-p) (list ccx-writes ccx-closes (get-output-bytevector ccx-sink))') == '(3 1 #u8(206 187 206 187 187))' |
| 340 | assert vm.active.len == 0 |
| 341 | } |
| 342 | |
| 343 | fn test_ccx_review_parent_suggested_one_way_callback_replay_restores_private_offset() { |
| 344 | ccx_review_packet_replay(false) |
| 345 | } |
| 346 | |
| 347 | fn test_ccx_review_parent_suggested_combined_callback_replay_restores_private_offset() { |
| 348 | ccx_review_packet_replay(true) |
| 349 | } |
| 350 | |
| 351 | fn test_ccx_review_caller_arena_final_input_cleanup_releases_transient_packets_before_free() { |
| 352 | mut vm := new() |
| 353 | ccx_review_setup(mut vm) |
| 354 | factory := vm.eval('(lambda () (ccx-make #u8(65 66) 1 ccx-options))') or { panic(err.msg()) } |
| 355 | put := vm.lookup('put-string') or { panic(err.msg()) } |
| 356 | close_output := vm.lookup('close-output-port') or { panic(err.msg()) } |
| 357 | close_input := vm.lookup('close-input-port') or { panic(err.msg()) } |
| 358 | text := vm.eval('"λ"') or { panic(err.msg()) } |
| 359 | for _ in 0 .. 3 { |
| 360 | mut region := arena.new() |
| 361 | region.push() |
| 362 | p := vm.call(factory, []) or { panic(err.msg()) } |
| 363 | vm.define('ccx-arm-prefix', boolean(true)) or { panic(err.msg()) } |
| 364 | if _ := vm.call(put, [p, text]) { |
| 365 | assert false |
| 366 | } |
| 367 | if _ := vm.call(close_output, [p]) { |
| 368 | assert false |
| 369 | } |
| 370 | gc_collect() |
| 371 | vm.define('ccx-fail', boolean(false)) or { panic(err.msg()) } |
| 372 | vm.call(close_input, [p]) or { panic(err.msg()) } |
| 373 | assert (vm.get_output_bytevector(vm.lookup('ccx-sink') or { panic(err.msg()) }) or { panic(err.msg()) }).bytevector_pointer().bytes == [ |
| 374 | u8(206), |
| 375 | 187, |
| 376 | ] |
| 377 | assert vm.active.len == 0 |
| 378 | for name in ['ccx-p', 'ccx-raw', 'ccx-sink', 'ccx-read-buffer', 'ccx-packet'] { |
| 379 | vm.define(name, boolean(false)) or { panic(err.msg()) } |
| 380 | } |
| 381 | region.pop() |
| 382 | region.free() |
| 383 | } |
| 384 | gc_collect() |
| 385 | assert ccx_review_eval(mut vm, '(list ccx-closes (+ 20 22))') == '(3 42)' |
| 386 | } |
| 387 | |