Fixed issue with translation that caused infinite loops if an explicit number of open parentheses is set to 0

This commit is contained in:
Tom Helmuth 2021-11-02 13:12:46 -04:00
parent 0d3b65734b
commit c5b9aece9c
2 changed files with 8 additions and 8 deletions

View File

@ -16,7 +16,12 @@
(let [plushy (if (:diploid argmap) (map first (partition 2 plushy)) plushy) (let [plushy (if (:diploid argmap) (map first (partition 2 plushy)) plushy)
opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
(loop [push () ;; iteratively build the Push program from the plushy (loop [push () ;; iteratively build the Push program from the plushy
plushy (mapcat #(if-let [n (get instructions/opens %)] [% ['open n]] [%]) plushy)] plushy (mapcat #(let [n (get instructions/opens %)]
(if (and n
(> n 0))
[% ['open n]]
[%]))
plushy)]
(if (empty? plushy) ;; maybe we're done? (if (empty? plushy) ;; maybe we're done?
(if (some opener? push) ;; done with plushy, but unclosed open (if (some opener? push) ;; done with plushy, but unclosed open
(recur push '(close)) ;; recur with one more close (recur push '(close)) ;; recur with one more close

View File

@ -36,15 +36,10 @@
:vector_boolean_iterate 1 :vector_boolean_iterate 1
:vector_string_iterate 1 :vector_string_iterate 1
:vector_integer_iterate 1 :vector_integer_iterate 1
:vector_float_iterate 1}) :vector_float_iterate 1
})
#_(generate-instructions
[:boolean :char :code :exec :float :integer :string
:vector_boolean :vector_float :vector_integer :vector_string]
[_dup _dup_times _dup_items _empty _eq _flush _pop _rot _shove
_stack_depth _swap _yank _yank_dup _deep_dup])
#?(:clj #?(:clj
(def cls->type (def cls->type
{Boolean :boolean {Boolean :boolean