vile / scheme / transcoder_library.v
27 lines · 24 sloc · 1.8 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3const transcoder_library_names = 'latin-1-codec utf-8-codec utf-16-codec native-eol-style native-transcoder eol-style error-handling-mode make-transcoder transcoder-codec transcoder-eol-style transcoder-error-handling-mode bytevector->string string->bytevector transcoded-port port-transcoder'
4
5// Existing procedures retain pristine identities and the shared dialect's
6// behavior; these exports add no wrappers or alternate compatibility runtime.
7const selected_common_port_names = 'port? input-port? output-port? binary-port? textual-port? input-port-open? output-port-open? close-input-port close-output-port close-port call-with-port current-input-port current-output-port current-error-port eof-object eof-object? flush-output-port'
8
9// Selected I/O procedures use the shared runtime and R7RS-small imports. The
10// R6RS condition hierarchy and versioned library references remain excluded.
11fn (mut vm VM) selected_transcoder_library(name LibraryName) ?&Library {
12 environment := vm.report_environment(5) or { return none }
13 space := vm.environment_space(environment) or { return none }
14 names := (transcoder_library_names + ' ' + get_put_port_names + ' ' + position_port_names + ' ' + memory_port_names + ' ' + selected_file_port_names + ' ' + standard_binary_port_names + ' ' + selected_common_port_names + ' ' + custom_port_names).split(' ')
15 mut exports := []LibraryBinding{cap: names.len}
16 for key in names {
17 binding := vm.namespace_binding(space, key)
18 if binding.kind == .global && binding.global_slot < 0 && !report_slot(binding.namespace, binding.global_slot) {
19 return none
20 }
21 exports << compact_library_export(key, binding)
22 }
23 library := &Library{ name: name, space: space, status: .ready, exports: exports }
24 mut registry := vm.library_registry()
25 registry.entries[name.key] = library
26 return library
27}
28