~subsetpark/ec

abc31353ceec7d77d397cc0be4b5ac9f989e6a31 — Zach Smith 1 year, 4 months ago 5165e93
update for with-slots and @ syntax
3 files changed, 24 insertions(+), 22 deletions(-)

M src/adverbs.janet
M src/operations.janet
M src/repl.janet
M src/adverbs.janet => src/adverbs.janet +5 -5
@@ 87,7 87,7 @@
  ```
  (let [q (calc/pop stack)
        r (calc/pop stack)
        s (calc/quote-wrap ;(calc/Quotation/data r) ;(calc/Quotation/data q))]
        s (calc/quote-wrap ;(@ calc/Quotation r :data) ;(@ calc/Quotation q :data))]
    (calc/push stack s)))

(defadv concat 2


@@ 97,7 97,7 @@
  ```
  (let [q (calc/pop stack)
        r (calc/pop stack)
        s (calc/wrap ;(calc/Vector/data r) ;(calc/Vector/data q))]
        s (calc/wrap ;(@ calc/Vector r :data) ;(@ calc/Vector q :data))]
    (calc/push stack s)))

(defadv clear-stack 0


@@ 105,7 105,7 @@
  S -- <>
  Clear the entire stack.
  ```
  (array/clear (calc/Stack/data stack)))
  (array/clear (@ calc/Stack stack :data)))

(defadv dup 1
  ```


@@ 231,14 231,14 @@
  ```
  Push a quotation containing all the elements of the stack.
  ```
  (let [s (calc/wrap ;(calc/Stack/data stack))]
  (let [s (calc/wrap ;(@ calc/Stack stack :data))]
    (calc/push stack s)))

(defadv push-stack 0
  ```
  Push a quotation containing all the elements of the stack.
  ```
  (let [s (calc/quote-wrap ;(calc/Stack/data stack))]
  (let [s (calc/quote-wrap ;(@ calc/Stack stack :data))]
    (calc/push stack s)))

(defadv unstack 1

M src/operations.janet => src/operations.janet +1 -1
@@ 12,7 12,7 @@
    (if (calc/Vector? x)
      (calc/new-Vector
        (x :shape)
        (map (partial inner-apply op) ;(map |(calc/Vector/data $) args)))
        (map (partial inner-apply op) ;(map |(@ calc/Vector $ :data) args)))
      (let [f (fun-ref op)
            unwrapped (map |(calc/value $) args)]
        (->> (f ;unwrapped)

M src/repl.janet => src/repl.janet +18 -16
@@ 1,3 1,5 @@
(use fugue)

(import rl)
(import /src/env)
(import /src/print)


@@ 110,28 112,28 @@
  Interactive read-eval-print-loop.
  ```
  []
  (def s (env/new-env))
  (while true
    (def bak (array/slice (s :data)))
    (try (->> (getline s (prompt s) @"")
              (handle-signal)
              (parser/parse)
              (handle-commands s))

      ([err fib]
        (eprint err)
        (if (os/getenv "EC_TRACEBACK")
          (propagate err fib)
          (put s :data bak))))))
  (with-slots calc/Stack (env/new-env)
    (while true
      (def bak (array/slice (@ data)))
      (try (->> (getline this (prompt this) @"")
                (handle-signal)
                (parser/parse)
                (handle-commands this))

           ([err fib]
            (eprint err)
            (if (os/getenv "EC_TRACEBACK")
              (propagate err fib)
              (set (@ data) bak)))))))

(defn handle-lines
  ```
  Handle a single input line from the command line.
  ```
  [lines]
  (let [s (env/new-env)]
  (with-slots calc/Stack (env/new-env)
    (each line lines
      (->> line
           (parser/parse)
           (handle-commands s)))
    (display-all (s :data))))
           (handle-commands this)))
    (display-all (@ data))))