Skip to content

Commit

Permalink
hash_map now have get and set methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hinsley committed Oct 5, 2017
1 parent 7aed841 commit 9816b1b
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 93 deletions.
2 changes: 2 additions & 0 deletions class/hash_map/hash_map.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
(def-method 'copy 'class/hash_map/copy)
(def-method 'insert 'class/hash_map/insert 'static '(r0 r1 r2) '(r0 r1 r2))
(def-method 'search 'class/hash_map/search 'static '(r0 r1) '(r0 r1 r2))
(def-method 'set 'class/hash_map/set 'static '(r0 r1 r2) '(r0 r1))
(def-method 'get 'class/hash_map/get 'static '(r0 r1) '(r0 r1))
(def-method 'get_parent 'class/hash_map/get_parent 'static '(r0) '(r0 r1))
(def-method 'set_parent 'class/hash_map/set_parent 'static '(r0 r1) '(r0))
Expand Down
70 changes: 70 additions & 0 deletions class/hash_map/hash_map.vp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@
;r0 = hash_map object
;r1 = 0, else iterator
;r2 = bucket vector
;trashes
;all but r0

(def-struct 'local)
(ptr 'this)
Expand All @@ -228,3 +230,71 @@
(vp-ret)

(def-func-end)

(def-func 'class/hash_map/set)
;inputs
;r0 = hash_map object
;r1 = key object
;r2 = value object
;outputs
;r0 = hash_map object
;r1 = 0 if not found, else value object
;trashes
;all but r0

(def-struct 'local)
(ptr 'this)
(ptr 'key)
(ptr 'value)
(def-struct-end)

(vp-alloc local_size)
(f-entry 'hash_map 'set '(r0 r1 r2))

(assign '(r2) '((rsp local_value)))
(f-call 'hash_map 'search '(r0 r1) '(r0 r1 _))
(vpif '(r1 != 0))
(assign '(r0) '((rsp local_this)))
(vp-cpy-rr r1 r2)
(f-call 'ref 'ref '((rsp local_value)) '(r0))
(f-call 'ref 'ref '(r0) '(r0))
(f-call 'pair 'set_second '((r2 0) r0))
(assign '((rsp local_this) (rsp local_value)) '(r0 r1))
(endif)

(f-exit 'hash_map 'set '(r0 r1))
(vp-free local_size)
(vp-ret)

(def-func-end)

(def-func 'class/hash_map/get)
;inputs
;r0 = hash_map object
;r1 = key object
;outputs
;r0 = hash_map object
;r1 = 0 if not found, else value object
;trashes
;all but r0

(def-struct 'local)
(ptr 'this)
(ptr 'key)
(def-struct-end)

(vp-alloc local_size)
(f-entry 'hash_map 'get '(r0 r1))

(f-call 'hash_map 'search '(r0 r1) '(r0 r1 _))
(vpif '(r1 != 0))
(assign '(r0) '((rsp local_this)))
(f-call 'pair 'ref_second '((r1 0)) '(_ r1))
(assign '((rsp local_this)) '(r0))
(endif)

(f-exit 'hash_map 'get '(r0 r1))
(vp-free local_size)
(vp-ret)

(def-func-end)
35 changes: 0 additions & 35 deletions class/lisp/env_get.vp

This file was deleted.

39 changes: 0 additions & 39 deletions class/lisp/env_set.vp

This file was deleted.

20 changes: 10 additions & 10 deletions class/lisp/func_repl.vp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
(errorifnot {old_file} 'error3))

;push old file and line, set to this stream info
(f-call 'lisp 'env_get {this, this->lisp_sym_stream_name} {_, old_file})
(f-call 'lisp 'env_get {this, this->lisp_sym_stream_line} {_, old_line})
(f-call 'lisp 'env_set {this, this->lisp_environment, this->lisp_sym_stream_name, value} {_, value})
(f-call 'ref 'deref {value})
(f-call 'hash_map 'get {this->lisp_environment, this->lisp_sym_stream_name} {_, old_file})
(f-call 'hash_map 'get {this->lisp_environment, this->lisp_sym_stream_line} {_, old_line})
(f-call 'hash_map 'set {this->lisp_environment, this->lisp_sym_stream_name, value} {_, value})
(f-call 'ref 'deref_if {value})
(f-call 'boxed_long 'create {} {value})
(f-call 'boxed_long 'set_value {value, 1})
(f-call 'lisp 'env_set {this, this->lisp_environment, this->lisp_sym_stream_line, value} {_, ast})
(f-call 'hash_map 'set {this->lisp_environment, this->lisp_sym_stream_line, value} {_, ast})
(f-call 'ref 'deref {value})
(f-call 'ref 'deref {ast})
(f-call 'ref 'deref_if {ast})

(f-call 'stream 'read_char {stream} {_, char})
(loop-start)
Expand Down Expand Up @@ -71,12 +71,12 @@
(loop-end)

;pop old file and line info
(f-call 'lisp 'env_set {this, this->lisp_environment, this->lisp_sym_stream_name, old_file} {_, value})
(f-call 'hash_map 'set {this->lisp_environment, this->lisp_sym_stream_name, old_file} {_, value})
(f-call 'ref 'deref {old_file})
(f-call 'ref 'deref {value})
(f-call 'lisp 'env_set {this, this->lisp_environment, this->lisp_sym_stream_line, old_line} {_, value})
(f-call 'ref 'deref_if {value})
(f-call 'hash_map 'set {this->lisp_environment, this->lisp_sym_stream_line, old_line} {_, value})
(f-call 'ref 'deref {old_line})
(f-call 'ref 'deref {value})
(f-call 'ref 'deref_if {value})

(f-call 'ref 'ref {this->lisp_sym_t} {value})

Expand Down
8 changes: 6 additions & 2 deletions class/lisp/func_set.vp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(import 'sys/func.inc)
(import 'class/hash_map/hash_map.inc)
(import 'class/lisp/lisp.inc)

(def-func 'class/lisp/func_set)
Expand Down Expand Up @@ -31,9 +32,9 @@
(f-call 'lisp 'repl_eval {this, iter_begin[ptr_size * 1]} {_, val})
(errorif (cat {val->obj_vtable == @} (f-path 'class 'error)) 'exit)
(assign {val} {eval})
(f-call 'lisp 'env_set {this, env, var, eval} {_, val})
(f-call 'hash_map 'set {env, var, eval} {_, val})
(f-call 'ref 'deref {eval})
(errorif (cat {val->obj_vtable == @} (f-path 'class 'error)) 'exit)
(errorifnot {val} 'error4)
(assign {&iter_begin[ptr_size * 2]} {iter_begin})
(loop-until {iter_begin == iter_end})

Expand All @@ -50,6 +51,9 @@
(goto 'exit)
(vp-label 'error3)
(f-call 'lisp 'repl_error {this, "(set env var val ...)", error_msg_not_a_symbol, args} {_, val})
(goto 'exit)
(vp-label 'error4)
(f-call 'lisp 'repl_error {this, "(set env var val ...)", error_msg_symbol_not_bound, args} {_, val})
(goto 'exit))

(pop-scope-syms)
Expand Down
8 changes: 6 additions & 2 deletions class/lisp/func_setq.vp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(import 'sys/func.inc)
(import 'class/hash_map/hash_map.inc)
(import 'class/lisp/lisp.inc)

(def-func 'class/lisp/func_setq)
Expand Down Expand Up @@ -28,9 +29,9 @@
(f-call 'lisp 'repl_eval {this, iter_begin[ptr_size * 1]} {_, val})
(errorif (cat {val->obj_vtable == @} (f-path 'class 'error)) 'exit)
(assign {val} {eval})
(f-call 'lisp 'env_set {this, this->lisp_environment, var, eval} {_, val})
(f-call 'hash_map 'set {this->lisp_environment, var, eval} {_, val})
(f-call 'ref 'deref {eval})
(errorif (cat {val->obj_vtable == @} (f-path 'class 'error)) 'exit)
(errorifnot {val} 'error3)
(assign {&iter_begin[ptr_size * 2]} {iter_begin})
(loop-until {iter_begin == iter_end})

Expand All @@ -44,6 +45,9 @@
(goto 'exit)
(vp-label 'error2)
(f-call 'lisp 'repl_error {this, "(setq var val ...)", error_msg_not_a_symbol, args} {_, val})
(goto 'exit)
(vp-label 'error3)
(f-call 'lisp 'repl_error {this, "(setq var val ...)", error_msg_symbol_not_bound, args} {_, val})
(goto 'exit))

(pop-scope-syms)
Expand Down
2 changes: 0 additions & 2 deletions class/lisp/lisp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

(def-method 'env_push 'class/lisp/env_push 'static '(r0) '(r0))
(def-method 'env_pop 'class/lisp/env_pop 'static '(r0) '(r0))
(def-method 'env_set 'class/lisp/env_set 'static '(r0 r1 r2 r3) '(r0 r1))
(def-method 'env_get 'class/lisp/env_get 'static '(r0 r1) '(r0 r1))
(def-method 'env_bind 'class/lisp/env_bind 'static '(r0 r1 r2) '(r0 r1))
(def-method 'env_args_set 'class/lisp/env_args_set 'static '(r0 r1 r2 r3) '(r0))
(def-method 'env_args_type 'class/lisp/env_args_type 'static '(r0 r1 r2 r3) '(r0 r1))
Expand Down
2 changes: 0 additions & 2 deletions class/lisp/make.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
(import 'class/lisp/built_in_func.vp)
(import 'class/lisp/deinit.vp)
(import 'class/lisp/env_bind.vp)
(import 'class/lisp/env_get.vp)
(import 'class/lisp/env_pop.vp)
(import 'class/lisp/env_push.vp)
(import 'class/lisp/env_set.vp)
(import 'class/lisp/env_args_set.vp)
(import 'class/lisp/env_args_type.vp)
(import 'class/lisp/func_add.vp)
Expand Down
7 changes: 6 additions & 1 deletion class/lisp/repl_eval.vp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(import 'sys/func.inc)
(import 'class/symbol/symbol.inc)
(import 'class/boxed_ptr/boxed_ptr.inc)
(import 'class/hash_map/hash_map.inc)
(import 'class/lisp/lisp.inc)

(def-func 'class/lisp/repl_eval)
Expand All @@ -21,7 +22,8 @@
(switch)
(case (cat {func == @} (f-path 'class 'symbol)))
;eval to symbol value
(f-call 'lisp 'env_get {this, form} {_, value})
(f-call 'hash_map 'get {this->lisp_environment, form} {_, value})
(errorifnot {value} 'error2)
(break)
(case (cat {func == @} (f-path 'class 'vector)))
;apply function, eval args if needed
Expand Down Expand Up @@ -65,6 +67,9 @@
(errorcases
(vp-label 'error1)
(f-call 'lisp 'repl_error {this, "(lambda vars body)", error_msg_not_a_lambda, form} {_, value})
(goto 'exit)
(vp-label 'error2)
(f-call 'lisp 'repl_error {this, "(eval sym)", error_msg_symbol_not_bound, form} {_, value})
(goto 'exit))

(pop-scope-syms)
Expand Down

0 comments on commit 9816b1b

Please sign in to comment.