Skip to content

Commit

Permalink
Simplify type checking functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vygr committed Aug 13, 2024
1 parent 79fc8cc commit a42cbc7
Show file tree
Hide file tree
Showing 51 changed files with 219 additions and 231 deletions.
2 changes: 1 addition & 1 deletion apps/chess/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 3 'error)
(errorif-lisp-args-sig 'error :r1 3)

(vp-alloc local_size)
(assign '(:r0 :r1) '((:rsp local_this) (:rsp local_args)))
Expand Down
4 changes: 2 additions & 2 deletions apps/mandelbrot/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 2 'error)
(errorif-lisp-args-sig 'error :r1 2)

(vp-push :r0)
(list-bind-args :r1 `(,x0 ,y0) '(:num :num))
Expand Down Expand Up @@ -76,7 +76,7 @@

(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 2 'error)
(errorif-lisp-args-sig 'error :r1 2)

(push-scope)
(assign '(:r0) {this})
Expand Down
2 changes: 1 addition & 1 deletion apps/netspeed/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(push-scope)
(entry {this, args})

(errorif-lisp-args-sig :r1 0 'error)
(errorif-lisp-args-sig 'error :r1 0)

;reg ops test
(call 'sys_pii :time :nil {start})
Expand Down
6 changes: 3 additions & 3 deletions apps/pcb/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(push-scope)
(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 9 'error)
(errorif-lisp-args-sig 'error :r1 9)

(list-bind-args :r1 '(:r1 :r2 :r3 :r4 :r5 :r6 :r7 :r8 :r9)
'(:list :num :num :num :num :num :obj :list :obj))
Expand Down Expand Up @@ -83,7 +83,7 @@

(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 7 'error)
(errorif-lisp-args-sig 'error :r1 7)

(vp-def (bucket record this buckets minx miny maxx maxy width buckets_iter buckets_iter_end)
(cat (method-input 'list :push_back) '(:r6 :r7 :r8 :r9 :r10 :r11 :r12 :r13 :r14)))
Expand Down Expand Up @@ -140,7 +140,7 @@
(push-scope)
(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 7 'error)
(errorif-lisp-args-sig 'error :r1 7)

(list-bind-args :r1 '(:r1 :r2 :r3 :r4 :r5 :r6 :r7)
'(:list :num :num :num :num :num :fixeds))
Expand Down
6 changes: 3 additions & 3 deletions apps/raymarch/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 1 'error)
(errorif-lisp-args-sig 'error :r1 1)

(array-bind-args :r1 '(:r2))

Expand Down Expand Up @@ -64,7 +64,7 @@

(entry '(:r13 :r14))

(errorif-lisp-args-sig :r14 6 'error)
(errorif-lisp-args-sig 'error :r14 6)

(array-bind-args :r14 '(:r0 :r1 :r2 :r3 :r4 :r5))

Expand Down Expand Up @@ -126,7 +126,7 @@

(entry '(:r0 :r1))

(errorif-lisp-args-sig :r1 2 'error)
(errorif-lisp-args-sig 'error :r1 2)

(push-scope)
(assign '(:r0) {this})
Expand Down
8 changes: 4 additions & 4 deletions class/array/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

(defun to-array (_)
(entry 'array (sym (cat :lisp_ _)) '(:r0 :r1))
(errorif-lisp-args-match :r1 num (:r1 array_length) 'error)
(errorif-lisp-args-match 'error :r1 num (:r1 array_length))
(assign '(:r0 :r1) '(:r6 :r8))
(call _ :create :nil '(:r7))
(assign '((:r8 array_length)) '(:r1))
Expand Down Expand Up @@ -130,7 +130,7 @@

(entry 'array :lisp_clear '(:r0 :r1))

(errorif-lisp-args-type :r1 array 1 'error)
(errorif-lisp-args-type 'error :r1 array 1)

(vp-alloc local_size)
(class/array/get_both :r1 :r1 :r2)
Expand Down Expand Up @@ -165,7 +165,7 @@

(entry 'array :lisp_pop '(:r0 :r1))

(errorif-lisp-args-sig :r1 1 'error)
(errorif-lisp-args-sig 'error :r1 1)

(vp-push :r0)
(array-bind-args :r1 '(:r0))
Expand Down Expand Up @@ -288,7 +288,7 @@

(entry 'array :lisp_set '(:r0 :r1))

(errorif-lisp-args-sig :r1 3 'error1)
(errorif-lisp-args-sig 'error1 :r1 3)

(vp-push :r0 :r1)
(bind '(a v i) (method-input 'array :set_elem))
Expand Down
6 changes: 3 additions & 3 deletions class/dim/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

(entry 'dim :lisp_dim '(:r0 :r1))

(errorif-lisp-args-sig :r1 2 'error)
(errorif-lisp-args-sig 'error :r1 2)

(vp-push :r0 :r1)
(bind '(dims elems) (method-input 'dim :create))
Expand Down Expand Up @@ -53,7 +53,7 @@

(entry 'dim :lisp_get '(:r0 :r1))

(errorif-lisp-args-sig :r1 2 'error)
(errorif-lisp-args-sig 'error :r1 2)

(vp-def (elems index dims indexs dims_len indexs_len
dims_iter_begin dims_iter_end indexs_iter_begin acc d i)
Expand Down Expand Up @@ -114,7 +114,7 @@

(entry 'dim :lisp_set '(:r0 :r1))

(errorif-lisp-args-sig :r1 3 'error)
(errorif-lisp-args-sig 'error :r1 3)

(vp-def (elems obj index dims indexs dims_len indexs_len
dims_iter_begin dims_iter_end indexs_iter_begin acc d i)
Expand Down
4 changes: 2 additions & 2 deletions class/fixed/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;generic fixed math op
(redefun mathop (_)
(entry 'fixed (sym (cat :lisp_ (rest _))) '(:r0 :r1))
(errorif-lisp-args-sig :r1 1 'error)
(errorif-lisp-args-sig 'error :r1 1)
(vp-push :r0)
(assign '((:r1 array_begin)) '(:r2))
(call 'fixed _ '((:r2 0)) '(_ :r1))
Expand Down Expand Up @@ -102,7 +102,7 @@

(entry 'fixed :lisp_recip '(:r0 :r1))

(errorif-lisp-args-sig :r1 1 'error)
(errorif-lisp-args-sig 'error :r1 1)

(vp-push :r0)
(assign '((:r1 array_begin)) '(:r0))
Expand Down
12 changes: 6 additions & 6 deletions class/hmap/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@

(entry 'hmap :lisp_get '(:r0 :r1))

(errorif-lisp-args-sig-range :r1 1 2 'error)
(errorif-lisp-args-sig 'error :r1 1 2)

(assign '((:r1 array_length)) '(:r2))
(vp-push :r0)
Expand Down Expand Up @@ -270,7 +270,7 @@

(entry 'hmap :lisp_defx '(:r0 :r1))

(errorif-lisp-args-sig-range :r1 1 2 'error)
(errorif-lisp-args-sig 'error :r1 1 2)

(assign '((:r1 array_length)) '(:r2))
(vp-push :r0)
Expand Down Expand Up @@ -350,7 +350,7 @@

(entry 'hmap :lisp_list '(:r0 :r1))

(errorif-lisp-args-sig :r1 1 'error)
(errorif-lisp-args-sig 'error :r1 1)

(vp-push :r0)
(array-bind-args :r1 '(:r0))
Expand Down Expand Up @@ -385,7 +385,7 @@
(entry 'hmap :lisp_undef '(:r0 :r1))
(assign '(:r0 :r1) '((:rsp local_this) (:rsp local_args)))

(errorif-lisp-args-len :r1 < 2 'error1)
(errorif-lisp-args-len 'error1 :r1 < 2)

(class/array/get_both :r1 :r3 :r2)
(array-get-args :r3 '(:r0))
Expand Down Expand Up @@ -442,7 +442,7 @@

(entry 'hmap :lisp_parent '(:r0 :r1))

(errorif-lisp-args-sig-range :r1 0 1 'error)
(errorif-lisp-args-sig 'error :r1 0 1)

(assign '((:r1 array_length)) '(:r2))
(vpif '(:r2 = 0))
Expand Down Expand Up @@ -478,7 +478,7 @@

(entry 'hmap :lisp_resize '(this args))

(errorif-lisp-args-sig-range :r1 1 2 'error)
(errorif-lisp-args-sig 'error :r1 1 2)

(vp-push this args)
(bind '(hmap size) (method-input 'hmap :resize))
Expand Down
4 changes: 2 additions & 2 deletions class/in/lisp.vp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

(entry 'in :lisp_create '(:r0 :r1))

(errorif-lisp-args-len :r1 /= 0 'error)
(errorif-lisp-args-len 'error :r1 /= 0)

(vp-push :r0)
(call 'in :create '(0) '(:r1))
Expand All @@ -41,7 +41,7 @@

(entry 'in :lisp_next_msg '(:r0 :r1))

(errorif-lisp-args-sig :r1 1 'error)
(errorif-lisp-args-sig 'error :r1 1)

(vp-push :r0)
(defq in (method-input 'in :next_msg))
Expand Down
2 changes: 1 addition & 1 deletion class/lisp/class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(dec-method :env_pop class/lisp/env_pop :static (:r0) (:r0 :r1))
(dec-method :env_bind class/lisp/env_bind :static (:r0 :r1 :r2) (:r0 :r1))
(dec-method :env_args_set class/lisp/env_args_set :static (:r0 :r3 :r5))
(dec-method :env_args_sig class/lisp/env_args_sig :static (:r1 :r3 :r4) (:r2))
(dec-method :env_args_sig class/lisp/env_args_sig :static (:r1 :r3 :r4 :r5) (:r2))
(dec-method :env_args_type class/lisp/env_args_type :static (:r1 :r3 :r4) (:r2))
(dec-method :env_args_match class/lisp/env_args_match :static (:r1 :r3 :r4) (:r2))
(dec-method :read class/lisp/read :static (:r0 :r1 :r2) (:r0 :r1 :r2))
Expand Down
19 changes: 10 additions & 9 deletions class/lisp/env_args_type.vp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
(def-method 'lisp :env_args_sig)
;inputs
;:r1 = args list object (ptr)
;:r3 = signiture pointer (pushort)
;:r4 = number of args (int)
;:r3 = signature pointer (pushort)
;:r4 = min number of args (int)
;:r5 = max number of args (int)
;outputs
;:r2 = 0 if error, else ok
;trashes
;:r2-:r7

(entry 'lisp :env_args_sig '(:r1 :r3 :r4))
(entry 'lisp :env_args_sig '(:r1 :r3 :r4 :r5))

(assign '(:r0 :r1 (:r1 array_length)) '(:r6 :r7 :r2))
(switch 'fail)
;must be exactly this number and match signiture
(breakif '(:r2 /= :r4) 'fail)
;must be in range and match signature
(breakif '(:r2 < :r4) '(:r2 > :r5) 'fail)
(class/array/get_both :r1 :r4 :r5)
(loop-while '(:r4 /= :r5))
(vp-cpy-ir-us :r3 0 :r1)
Expand All @@ -42,7 +43,7 @@
;inputs
;:r1 = args list object (ptr)
;:r3 = vtable pointer (ptr)
;:r4 = minimum number of args (int)
;:r4 = min number of args (int)
;outputs
;:r2 = 0 if error, else ok
;trashes
Expand All @@ -52,7 +53,7 @@

(assign '(:r0 :r1 (:r1 array_length)) '(:r6 :r7 :r2))
(switch 'fail)
;must be at least this number of this type
;must be in range and of this type
(breakif '(:r2 < :r4) 'fail)
(class/array/get_both :r1 :r4 :r5)
(loop-while '(:r4 /= :r5))
Expand All @@ -76,7 +77,7 @@
;inputs
;:r1 = args list object (ptr)
;:r3 = vtable pointer (ptr)
;:r4 = minimum number of args (int)
;:r4 = min number of args (int)
;outputs
;:r2 = 0 if error, else ok
;trashes
Expand All @@ -86,7 +87,7 @@

(assign '(:r0 :r1 (:r1 array_length)) '(:r6 :r7 :r2))
(switch 'fail)
;must be at least this number of this type and all identical
;must be in range and of this type and all identical
(breakif '(:r2 < :r4) 'fail)
(vpif '(:r2 /= 0))
(class/array/get_both :r1 :r4 :r5)
Expand Down
4 changes: 2 additions & 2 deletions class/lisp/lisp_apply.vp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

(entry 'lisp :lisp_apply '(:r0 :r1))

(errorif-lisp-args-sig :r1 2 'error)
(errorif-lisp-args-sig 'error :r1 2)

(array-bind-args :r1 '(:r2 :r1))
(jump 'lisp :repl_apply '(:r0 :r1 :r2))
Expand Down Expand Up @@ -44,7 +44,7 @@
(entry 'lisp :lisp_mcall '(:r0 :r1))
(assign '(:r0 :r1) '((:rsp local_this) (:rsp local_args)))

(errorif-lisp-args-len :r1 < 2 'error)
(errorif-lisp-args-len 'error :r1 < 2)

(array-bind-args :r1 '(:r0 :r13))

Expand Down
2 changes: 1 addition & 1 deletion class/lisp/lisp_bind.vp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(entry 'lisp :lisp_bind '(:r0 :r1))

(errorif-lisp-args-len :r1 /= 2 'error)
(errorif-lisp-args-len 'error :r1 /= 2)

(array-bind-args :r1 '(:r1 :r2))
(jump 'lisp :env_bind '(:r0 :r1 :r2))
Expand Down
2 changes: 1 addition & 1 deletion class/lisp/lisp_eval.vp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(jump 'lisp :repl_eval '(:r0 :r1))
(endif)

(errorif-lisp-args-sig :r1 2 'error)
(errorif-lisp-args-sig 'error :r1 2)

(array-bind-args :r1 '(:r1 :r2))
(assign '((:r0 lisp_environment) :r2) '(:r3 (:r0 lisp_environment)))
Expand Down
2 changes: 1 addition & 1 deletion class/lisp/lisp_ffi.vp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(push-scope)
(entry 'lisp :lisp_ffi {this, args})

(errorif-lisp-args-sig :r1 4 'error)
(errorif-lisp-args-sig 'error :r1 4)

(call 'list :get_begin {args} {_, iter_begin})
(call 'sys_load :bind {&iter_begin[+ptr_size * 2]->str_data} {value})
Expand Down
2 changes: 1 addition & 1 deletion class/lisp/lisp_macroexpand.vp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(entry 'lisp :lisp_macroexpand '(:r0 :r1))

(errorif-lisp-args-len :r1 /= 1 'error)
(errorif-lisp-args-len 'error :r1 /= 1)

(array-bind-args :r1 '(:r1))
(class/obj/ref :r1 :r2)
Expand Down
2 changes: 1 addition & 1 deletion class/lisp/lisp_prebind.vp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(entry 'lisp :lisp_prebind '(:r0 :r1))

(errorif-lisp-args-len :r1 /= 1 'error)
(errorif-lisp-args-len 'error :r1 /= 1)

(array-bind-args :r1 '(:r1))
(class/obj/ref :r1 :r2)
Expand Down
2 changes: 1 addition & 1 deletion class/lisp/lisp_qquote.vp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

(entry 'lisp :lisp_qquote '(:r0 :r1))

(errorif-lisp-args-len :r1 /= 2 'error)
(errorif-lisp-args-len 'error :r1 /= 2)

(vp-push :r0 :r1)
(class/obj/ref :r1 :r2)
Expand Down
2 changes: 1 addition & 1 deletion class/lisp/lisp_quote.vp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(entry 'lisp :lisp_quote '(:r0 :r1))

(errorif-lisp-args-len :r1 /= 2 'error)
(errorif-lisp-args-len 'error :r1 /= 2)

(assign '((:r1 array_begin)) '(:r1))
(assign '((:r1 +ptr_size)) '(:r1))
Expand Down
Loading

0 comments on commit a42cbc7

Please sign in to comment.