Go to the first, previous, next, last section, table of contents.


disassembleCompiledFunction

Function: disassembleCompiledFunction { cfn stream -> }
file: 15-C-debugger.t
package: debug
status: tentative

This function accepts a compiledFunction and lists a human-readable disassembly of it to the given stream. It is intended to be invoked by (for example) a debugger.

Note that the Muq bytecode instruction set is not frozen, and should not be depended on to be the same in future releases. You have been warned!

stack:
: x234 2 3.4 * ;
stack:
#'x234 @$s.standardOutput debug:disassembleCompiledFunction
name: x234
source: 2 3.4 *
constants:
 0: 3.39999
code bytes:
00: 33 02 34 00 0e 2e 
code disassembly:
000:      33 02       GETi   2
002:      34 00       GETk   0
004:      0e          MUL    
005:      2e          RETURN 

It is currently implemented as:

: disassembleCompiledFunction { $ $ -> } -> s -> cfn
    cfn isACompiledFunction

    ( Do a nice disassembly of a compiled function for human consumption: )

    cfn$s.source -> fn
    fn function? if

        fn$s.name -> name
        name string? if
            "name: "   s writeStream
            name       s writeStream
            "\n"       s writeStream
        fi

        fn$s.source -> src
        src  string? if
            "source: " s writeStream
            src        s writeStream
            "\n"       s writeStream
        fi
    fi

    "constants:\n" s writeStream
    cfn compiledFunctionConstants[
        |for v i do{
            [ "%2d: " i | ]print  s writeStream
            v toDelimitedString s writeStream
            "\n"                  s writeStream
        }
    ]pop
    
    "code bytes:" s writeStream
    cfn compiledFunctionBytecodes[    
        |for v i do{
            i 15 logand 0 = if [ "\n%02x: " i | ]print s writeStream fi
            [ "%02x " v | ]print                       s writeStream
        }
    ]pop
    "\n" s writeStream

    "code disassembly:\n"             s writeStream
    cfn compiledFunctionDisassembly s writeStream
;


Go to the first, previous, next, last section, table of contents.