Make examples use scopes

This commit is contained in:
Joshua Suskalo 2021-09-15 12:47:06 -05:00
parent a568c1c5d6
commit c5df70ac1a

View file

@ -244,11 +244,12 @@
"Gets some output value" "Gets some output value"
"someFunc" [::pointer] ::int "someFunc" [::pointer] ::int
[] []
(let [out-int (alloc-instance ::int) (with-open [scope (stack-scope)]
(let [out-int (alloc-instance ::int scope)
success? (zero? (some-func (address-of out-int)))] success? (zero? (some-func (address-of out-int)))]
(if success? (if success?
(deserialize ::int out-int) (deserialize ::int out-int)
(throw (ex-info (getErrorString) {}))))) (throw (ex-info (getErrorString) {}))))))
;; This function probably wouldn't actually get wrapped, since the cost of ;; This function probably wouldn't actually get wrapped, since the cost of
;; marshalling is greater than the speed boost of using an in-place sort. That ;; marshalling is greater than the speed boost of using an in-place sort. That
@ -259,14 +260,14 @@
[::pointer ::long ::long (fn [::pointer ::pointer] ::int)] [::pointer ::long ::long (fn [::pointer ::pointer] ::int)]
::void ::void
[type comparator list] [type comparator list]
(let [copied-list (alloc (* (count list) (size-of type))) (with-open [scope (stack-scope)]
_ (for [segment (seq-of type copied-list)] (let [copied-list (alloc (* (count list) (size-of type)) scope)
(serialize type segment)) _ (dorun (map #(serialize* %1 type %2 scope) list (seq-of type copied-list)))
comp-fn (fn [addr1 addr2] comp-fn (fn [addr1 addr2]
(let [obj1 (deserialize type (slice-global addr1 (size-of type))) (let [obj1 (deserialize type (slice-global addr1 (size-of type)))
obj2 (deserialize type (slice-global addr2 (size-of type)))] obj2 (deserialize type (slice-global addr2 (size-of type)))]
(comparator obj1 obj2)))] (comparator obj1 obj2)))]
(qsort copied-list (count list) (size-of type) comp-fn) (qsort copied-list (count list) (size-of type) comp-fn)
(for [segment (seq-of type copied-list)] (for [segment (seq-of type copied-list)]
(deserialize type segment)))) (deserialize type segment)))))
) )