JanetDocsPlaygroundI'm feeling luckyGitHub sign in

disasm



    cfunction
    src/core/asm.c on line 986, column 1

    (disasm func &opt field)

    Returns assembly that could be used to compile the given function. 
    func must be a function, not a c function. Will throw on error on a 
    badly typed argument. If given a field name, will only return that 
    part of the function assembly. Possible fields are:

    * :arity - number of required and optional arguments.
    * :min-arity - minimum number of arguments function can be called 
      with.
    * :max-arity - maximum number of arguments function can be called 
      with.
    * :vararg - true if function can take a variable number of 
      arguments.
    * :bytecode - array of parsed bytecode instructions. Each 
      instruction is a tuple.
    * :source - name of source file that this function was compiled 
      from.
    * :name - name of function.
    * :slotcount - how many virtual registers, or slots, this function 
      uses. Corresponds to stack space used by function.
    * :constants - an array of constants referenced by this function.
    * :sourcemap - a mapping of each bytecode instruction to a line and 
      column in the source file.
    * :environments - an internal mapping of which enclosing functions 
      are referenced for bindings.
    * :defs - other function definitions that this function may 
      instantiate.


2 examplesSign in to add an example
Loading...
(disasm (fn []) :bytecode)
# => @[(retn)]
sogaiuPlayground
(disasm +)
# {:max-arity 2147483647
#  :constants @[]
#  :name "+"
#  :defs @[]
#  :vararg true
#  :environments @[]
#  :arity 0
#  :slotcount 6

#  :bytecode
#  @[(len 1 0)
#    (eqim 2 1 0)
#    (jmpno 2 3)
#    (ldi 3 0)
#    (ret 3)
#    (eqim 2 1 1)
#    (jmpno 2 5)
#    (ldi 3 0)
#    (geti 4 0 0)
#    (add 3 3 4)
#    (ret 3)
#    (geti 3 0 0)
#    (ldi 5 1)
#    (in 4 0 5)
#    (add 3 3 4)
#    (addim 5 5 1)
#    (eq 2 5 1)
#    (jmpno 2 -4)
#    (ret 3)]
#  :min-arity 0}
skuzzymigletPlayground