jmp-compile

This is the tool used to turn your Python syntax source into the internal representation used. It can also dump the internal representation.

You can use Python 2.6+ or 3.1+ to run jmp-compile.

Compiling

jmp-compile [options] input.py [output.jmp]

Produces an internal representation from input.py. By default the output is alongside the input with a .jmp extension.

--print-function

If you run under Python 2 then print will be treated as a statement. Supplying this flag will treat it is as a function. If you run jmp-compile under Python 3 then print is always treated as a function.

--asserts

By default asserts are ignored. If you supply this flag then asserts will be evaluated and an exception to be thrown if it does not evaluate to a true value.

--omit-line-table

Normally a table that maps between internal program counter value and the corresponding source line number is included in the output. This allows line numbers to be given in exceptions. However it consumes 4 bytes per line of executable code so you can save space by specifying this flag. You can always work out the line number from a program counter using annotated output.

--annotate

Places a file alongside the output with an extension of .i that has the source lines intermingled with the internal representation like --dump output. It is recommended you use this option if omitting the line table so that later you can map the program counter to the corresponding line as this output always includes the line information. You can see an example annotated file below.

--syntax

Does not produce an output file. This checks the syntax and that various limits (eg string length, jmp size) are not exceeded. The exit code will be non-zero on any error.

--no-optimization

Turns off optimizations such as constant expressions (replacing 3+4 with 7 and True or 7 with True) and omitting unreachable code (eg if False).

--constant name=value

Can be supplied multiple times. value must be in Python syntax and can be any expression. For example --constant DEBUG=True, --constant VERSION="2alpha1", --constant mapping={3: "Three", 4: "a"*7, 5: func(1,2,3)}. Be careful of the shell altering what you provide on the command line.

Dumping

jmp-compile –dump [options] file.jmp

This prints the internal representation from a .jmp file.

--dump

Turns on dump mode

--dump-source <input.py>

Optional input file the .jmp was produced from. The source lines are intermingled with the output. By default a .py file alongside the .jmp file is looked for.

Dumping Example

This is an example of --dump or --annotate output. Internals describes what is going on in more detail.

#    1 x=3+4

    0 PUSH_INT 3
    3 PUSH_INT 4
    6 ADD
    7 STORE_NAME 0   	# string 0 = 'x'

#    2 if x>5:

   10 LOAD_NAME 0   	# string 0 = 'x'
   13 PUSH_INT 5
   16 GT
   17 IF_FALSE 28

#    3   print "greater"

   20 PUSH_STR 1   	# string 1 = 'greater'
   23 PUSH_TRUE
   24 PUSH_INT 1
   27 PRINT

#    5 def fact(n):

   28 MAKE_METHOD 37
   31 STORE_NAME 2   	# string 2 = 'fact'
   34 GOTO 77
   37 PUSH_INT 1
   40 FUNCTION_PROLOG
   41 STORE_NAME 3   	# string 3 = 'n'

#    6   if n<=1:

   44 LOAD_NAME 3   	# string 3 = 'n'
   47 PUSH_INT 1
   50 LTE
   51 IF_FALSE 58

#    7      return 1

   54 PUSH_INT 1
   57 RETURN

#    8   return n*fact(n-1)

   58 LOAD_NAME 3   	# string 3 = 'n'
   61 LOAD_NAME 3   	# string 3 = 'n'
   64 PUSH_INT 1
   67 SUB
   68 PUSH_INT 1
   71 LOAD_NAME 2   	# string 2 = 'fact'
   74 CALL
   75 MULT
   76 RETURN

#   10 print fact(10)

   77 PUSH_INT 10
   80 PUSH_INT 1
   83 LOAD_NAME 2   	# string 2 = 'fact'
   86 CALL
   87 PUSH_TRUE
   88 PUSH_INT 1
   91 PRINT
   92 EXIT_LOOP

Table Of Contents

Previous topic

Python reference

Next topic

Quirks and differences

This Page