~tim/scheme-vm

b2181e29a08f44fd6516b8b0eb552d709aa34514 — Tim Morgan 2 years ago 97bdc6d
Add string->symbol function
5 files changed, 19 insertions(+), 0 deletions(-)

M compiler/lib/scheme/base.rb
M lib/scheme/base.scm
M spec/lib/symbol-spec.scm
M vm.rb
M vm/operations.rb
M compiler/lib/scheme/base.rb => compiler/lib/scheme/base.rb +8 -0
@@ 189,6 189,14 @@ class Compiler
          ]
        end

        def base_string_to_symbol((string, *_rest), options)
          [
            compile_sexp_use(string, options),
            VM::TO_ATOM,
            pop_maybe(options)
          ]
        end

        def base_symbol_to_string((symbol, *_rest), options)
          [
            compile_sexp_use(symbol, options),

M lib/scheme/base.scm => lib/scheme/base.scm +2 -0
@@ 88,6 88,7 @@
   string-ref
   string->list
   string->number
   string->symbol
   string-append
   symbol?
   symbol=?


@@ 137,6 138,7 @@
    (--define-native string? base_string?)
    (--define-native string-length base_string_length)
    (--define-native string-ref base_string_ref)
    (--define-native string->symbol base_string_to_symbol)
    (--define-native symbol? base_symbol?)
    (--define-native symbol->string base_symbol_to_string)


M spec/lib/symbol-spec.scm => spec/lib/symbol-spec.scm +3 -0
@@ 8,6 8,9 @@
(assert (equal? (symbol->string 'a) "a"))
(assert (not (equal? (symbol->string 'b) "a")))

(assert (equal? 'a (string->symbol "a")))
(assert (not (equal? 'a (string->symbol "b"))))

(assert (symbol=?))
(assert (symbol=? 'a))
(assert (symbol=? 'a 'a 'a))

M vm.rb => vm.rb +1 -0
@@ 74,6 74,7 @@ class VM
    ['STR_LEN',       0],
    ['STR_REF',       0],
    ['SUB',           0],
    ['TO_ATOM',       0],
    ['TO_CHAR',       0],
    ['TO_STR',        0],
    ['TYPE',          0]

M vm/operations.rb => vm/operations.rb +5 -0
@@ 24,6 24,11 @@ class VM
      do_call(new_ip)
    end

    def do_to_atom
      name = pop_val
      push_val(Atom.new(name))
    end

    def do_to_char
      code = pop_raw
      push_val(Char.new(code))