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

Less verbose opcode definition #1

Open
rodentrabies opened this issue Jul 30, 2019 · 0 comments
Open

Less verbose opcode definition #1

rodentrabies opened this issue Jul 30, 2019 · 0 comments

Comments

@rodentrabies
Copy link
Owner

Ideally it should look like this:

(defmacro define-opcode (op-name op-code op-hex-code
                         (&rest args)
                         &body (doc &rest body))
  "Define opcode function named OP-NAME for a given OP-CODE.
OP-HEX-CODE is ignored and used only for documentation purposes.

  - Arithmetic:

      (define-opcode op_add 147 #x93 (state (a :integer) (b :integer)) :integer
        (@push (+ a b))
        t)

      (define-opcode op_add 147 #x93 (state)
        (when (>= (length (@stack state)) 2)
          (let ((b (decode-integer (pop (@stack state))))
                (a (decode-integer (pop (@stack state)))))
            (push (encode-integer (+ a b)) (@stack state))
            t)))

  - Stack:

      (define-opcode op_pick 121 #x79 (state (n :integer) :null
        (when (>= (length (@stack state)) (1- n))
          (push (nth (1- n) (@stack state)) (@stack state))
          t))))

      (define-opcode op_pick 121 #x79 (state)
        (when (>= (length (@stack state)) 1)
          (let ((n (decode-integer (pop (@stack state)))))
            (when (>= (length (@stack state)) (1- n))
              (push (nth (1- n) (@stack state)) (@stack state))
              t))))

  - Crypto:

      (define-opcode op_ripemd160 166 #xa6 (state (a :bytes)) :bytes
        (@push (ripemd160 a))
        t)

      (define-opcode op_ripemd160 166 #xa6 (state)
        (when (>= (length (@stack state)) 1)
          (push (ripemd160 (pop (@stack state))) (@stack state))
          t))
"
  )
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

1 participant