Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Print docstring for instructions executed in trace as part of report #256

Open
Vaguery opened this issue Feb 15, 2018 · 3 comments

Comments

@Vaguery
Copy link
Contributor

Vaguery commented Feb 15, 2018

I often find myself explaining, step by step, what a trace is doing in each step. The constants and input values are straightforward; the instructions can be more complicated.

I'd like to suggest printing the docstring for each instruction as it's executed in a trace, for the reader. Needless to say, if there's some other use (besides being read by a human being) for the trace itself, this could be an option. But it seems like it would be almost universally helpful for any trace, especially for people unfamiliar with the details of complex instructions, like 'exec_do*range.

@Shalmezad
Copy link

Still learning clojure, but would something like this work for what you need?

@Vaguery
Copy link
Contributor Author

Vaguery commented Feb 16, 2018

Yes, though I'm not sure how those would work for some of the indirectly-constructed instruction functions, like integer_add, which is built form an adder in the Clojush code.

But I was just thinking of adding a line to the report in each step like this (untested) code

(defn trace-event-string
  "Describes an item being processed in this step, or gives its docstring if it's an instruction"
  [item]
  (let [push-type (util/recognize-literal item)]
    (cond
      push-type
        (str item " is a " push-type " literal")
      (and (symbol? item) 
           (re-seq #"in\d+" (name item)))
        (str item " is an input instruction")
      (contains? @instruction-table item)
        (str item "instruction: " (:doc (meta (var item))))
      :else
        (str item)
      )))

@Shalmezad
Copy link

Shalmezad commented Feb 16, 2018

It looks like integer_add still uses defined_registered:

(define-registered integer_add (with-meta (adder :integer) {:stack-types [:integer]}))

Meaning it could still be documented the same way:

(define-registered integer_add (with-meta (adder :integer) {:stack-types [:integer]})
  "Pushes the sum of the top two items.")

Definitely agree on moving it from within eval-push to it's own function though (and handling non-instructions as well), will take another stab at it this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants