| 1 | module scheme |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | // These flags describe this implementation, not standards modes. In particular, |
| 6 | // bounded exact arithmetic and selected libraries do not imply full R7RS/R6RS. |
| 7 | fn feature_names() []string { |
| 8 | mut names := ['vile', 'vile-0.0.0', 'ieee-float', 'exact-complex'] |
| 9 | match os.user_os() { |
| 10 | 'linux' { names << ['posix', 'unix', 'gnu-linux'] } |
| 11 | 'macos' { names << ['posix', 'unix', 'darwin'] } |
| 12 | 'freebsd', 'openbsd', 'netbsd', 'dragonfly' { |
| 13 | names << ['posix', 'unix', 'bsd', os.user_os()] |
| 14 | } |
| 15 | 'windows' { names << 'windows' } |
| 16 | else {} |
| 17 | } |
| 18 | $if amd64 { |
| 19 | names << 'x86-64' |
| 20 | } |
| 21 | $if i386 { |
| 22 | names << 'i386' |
| 23 | } |
| 24 | $if arm64 { |
| 25 | names << 'aarch64' |
| 26 | } |
| 27 | $if arm32 { |
| 28 | names << 'arm' |
| 29 | } |
| 30 | return names |
| 31 | } |
| 32 | |
| 33 | fn (mut vm VM) install_features() { |
| 34 | names := feature_names() |
| 35 | mut result := nil_value() |
| 36 | for i := names.len - 1; i >= 0; i-- { |
| 37 | result = literal_value(cons(text_value(.symbol, names[i]), result)) |
| 38 | } |
| 39 | vm.feature_list = result |
| 40 | vm.bind_global('features', procedure_value(&Procedure{ owner: vm.owner, mode: .native, name: 'features', native: builtin_features })) |
| 41 | } |
| 42 | |
| 43 | fn builtin_features(mut vm VM, args []Value) !Value { |
| 44 | check_arity('features', args.len, 0, 0)! |
| 45 | return vm.feature_list |
| 46 | } |
| 47 | |
| 48 | fn (code &Code) feature_present(name string) bool { |
| 49 | if isnil(code.compiler_vm) { return name in feature_names() } |
| 50 | vm := unsafe { &VM(code.compiler_vm) } |
| 51 | mut current := vm.feature_list |
| 52 | for current.tag == .pair { |
| 53 | pair := current.pair_pointer() |
| 54 | if pair.car.text() == name { return true } |
| 55 | current = pair.cdr |
| 56 | } |
| 57 | return false |
| 58 | } |
| 59 | |