@@ -50,30 +50,55 @@ Naturally, a real interpreter would be much more complicated that this.
The following operations are supported:
-====================== ======================== =============== ==============
-Operation Meaning Old Stack New Stack
-====================== ======================== =============== ==============
-DUP Duplicate top of stack. ``[..., x]`` ``[..., x, x]``
-ROT Swap top two elements ``[..., x, y]`` ``[..., y, x]``
- of stack.
-BINARY_ADD Add the top two elements ``[..., x, y]`` ``[..., (x+y)]``
- on the stack.
-BINARY_SUBTRACT Likewise, but subtract. ``[..., x, y]`` ``[..., (x-y)]``
-BINARY_MULT Likewise, but multiply. ``[..., x, y]`` ``[..., (x*y)]``
-BINARY_COMPARE_LT Compare the top two ``[..., x, y]`` ``[..., (x<y)]``
- elements on the stack
- and push a nonzero/zero
- if (x<y).
-RECURSE Recurse, passing the top ``[..., x]`` ``[..., fn(x)]``
- of the stack, and
- popping the result.
-RETURN Return the top of the ``[x]`` ``[]``
- stack.
-PUSH_CONST `arg` Push an int const. ``[...]`` ``[..., arg]``
-JUMP_ABS_IF_TRUE `arg` Pop; if top of stack was ``[..., x]`` ``[...]``
- nonzero, jump to
- ``arg``.
-====================== ======================== =============== ==============
+.. list-table::
+ :header-rows: 1
+ :widths: 35 50 25 25
+
+ * - Operation
+ - Meaning
+ - Old Stack
+ - New Stack
+
+ * - DUP
+ - Duplicate top of stack.
+ - ``[..., x]``
+ - ``[..., x, x]``
+ * - ROT
+ - Swap top two elements of stack.
+ - ``[..., x, y]``
+ - ``[..., y, x]``
+ * - BINARY_ADD
+ - Add the top two elements on the stack.
+ - ``[..., x, y]``
+ - ``[..., (x+y)]``
+ * - BINARY_SUBTRACT
+ - Likewise, but subtract.
+ - ``[..., x, y]``
+ - ``[..., (x-y)]``
+ * - BINARY_MULT
+ - Likewise, but multiply.
+ - ``[..., x, y]``
+ - ``[..., (x*y)]``
+ * - BINARY_COMPARE_LT
+ - Compare the top two elements on the stack and push a nonzero/zero if (x<y).
+ - ``[..., x, y]``
+ - ``[..., (x<y)]``
+ * - RECURSE
+ - Recurse, passing the top of the stack, and popping the result.
+ - ``[..., x]``
+ - ``[..., fn(x)]``
+ * - RETURN
+ - Return the top of the stack.
+ - ``[x]``
+ - ``[]``
+ * - PUSH_CONST `arg`
+ - Push an int const.
+ - ``[...]``
+ - ``[..., arg]``
+ * - JUMP_ABS_IF_TRUE `arg`
+ - Pop; if top of stack was nonzero, jump to ``arg``.
+ - ``[..., x]``
+ - ``[...]``
Programs can be interpreted, disassembled, and compiled to machine code.
@@ -48,30 +48,55 @@ Naturally, a real interpreter would be much more complicated that this.
The following operations are supported:
-====================== ======================== =============== ==============
-Operation Meaning Old Stack New Stack
-====================== ======================== =============== ==============
-DUP Duplicate top of stack. ``[..., x]`` ``[..., x, x]``
-ROT Swap top two elements ``[..., x, y]`` ``[..., y, x]``
- of stack.
-BINARY_ADD Add the top two elements ``[..., x, y]`` ``[..., (x+y)]``
- on the stack.
-BINARY_SUBTRACT Likewise, but subtract. ``[..., x, y]`` ``[..., (x-y)]``
-BINARY_MULT Likewise, but multiply. ``[..., x, y]`` ``[..., (x*y)]``
-BINARY_COMPARE_LT Compare the top two ``[..., x, y]`` ``[..., (x<y)]``
- elements on the stack
- and push a nonzero/zero
- if (x<y).
-RECURSE Recurse, passing the top ``[..., x]`` ``[..., fn(x)]``
- of the stack, and
- popping the result.
-RETURN Return the top of the ``[x]`` ``[]``
- stack.
-PUSH_CONST `arg` Push an int const. ``[...]`` ``[..., arg]``
-JUMP_ABS_IF_TRUE `arg` Pop; if top of stack was ``[..., x]`` ``[...]``
- nonzero, jump to
- ``arg``.
-====================== ======================== =============== ==============
+.. list-table::
+ :header-rows: 1
+ :widths: 35 50 25 25
+
+ * - Operation
+ - Meaning
+ - Old Stack
+ - New Stack
+
+ * - DUP
+ - Duplicate top of stack.
+ - ``[..., x]``
+ - ``[..., x, x]``
+ * - ROT
+ - Swap top two elements of stack.
+ - ``[..., x, y]``
+ - ``[..., y, x]``
+ * - BINARY_ADD
+ - Add the top two elements on the stack.
+ - ``[..., x, y]``
+ - ``[..., (x+y)]``
+ * - BINARY_SUBTRACT
+ - Likewise, but subtract.
+ - ``[..., x, y]``
+ - ``[..., (x-y)]``
+ * - BINARY_MULT
+ - Likewise, but multiply.
+ - ``[..., x, y]``
+ - ``[..., (x*y)]``
+ * - BINARY_COMPARE_LT
+ - Compare the top two elements on the stack and push a nonzero/zero if (x<y).
+ - ``[..., x, y]``
+ - ``[..., (x<y)]``
+ * - RECURSE
+ - Recurse, passing the top of the stack, and popping the result.
+ - ``[..., x]``
+ - ``[..., fn(x)]``
+ * - RETURN
+ - Return the top of the stack.
+ - ``[x]``
+ - ``[]``
+ * - PUSH_CONST `arg`
+ - Push an int const.
+ - ``[...]``
+ - ``[..., arg]``
+ * - JUMP_ABS_IF_TRUE `arg`
+ - Pop; if top of stack was nonzero, jump to ``arg``.
+ - ``[..., x]``
+ - ``[...]``
Programs can be interpreted, disassembled, and compiled to machine code.
@@ -42,19 +42,30 @@ within the array.
brainf is hard for humans to read, but it's trivial to write a parser for
it, as there is no lexing; just a stream of bytes. The operations are:
-====================== =============================
-Character Meaning
-====================== =============================
-``>`` ``idx += 1``
-``<`` ``idx -= 1``
-``+`` ``data[idx] += 1``
-``-`` ``data[idx] -= 1``
-``.`` ``output (data[idx])``
-``,`` ``data[idx] = input ()``
-``[`` loop until ``data[idx] == 0``
-``]`` end of loop
-Anything else ignored
-====================== =============================
+.. list-table::
+ :header-rows: 1
+
+ * - Character
+ - Meaning
+
+ * - ``>``
+ - ``idx += 1``
+ * - ``<``
+ - ``idx -= 1``
+ * - ``+``
+ - ``data[idx] += 1``
+ * - ``-``
+ - ``data[idx] -= 1``
+ * - ``.``
+ - ``output (data[idx])``
+ * - ``,``
+ - ``data[idx] = input ()``
+ * - ``[``
+ - loop until ``data[idx] == 0``
+ * - ``]``
+ - end of loop
+ * - Anything else
+ - ignored
Unlike the previous example, we'll implement an ahead-of-time compiler,
which reads ``.bf`` scripts and outputs executables (though it would
@@ -169,14 +169,20 @@ For linking in object files, use :c:func:`gcc_jit_context_add_driver_option`.
The available kinds of output are:
-============================================== ==============
-Output kind Typical suffix
-============================================== ==============
-:c:macro:`GCC_JIT_OUTPUT_KIND_ASSEMBLER` .s
-:c:macro:`GCC_JIT_OUTPUT_KIND_OBJECT_FILE` .o
-:c:macro:`GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY` .so or .dll
-:c:macro:`GCC_JIT_OUTPUT_KIND_EXECUTABLE` None, or .exe
-============================================== ==============
+.. list-table::
+ :header-rows: 1
+
+ * - Output kind
+ - Typical suffix
+
+ * - :c:macro:`GCC_JIT_OUTPUT_KIND_ASSEMBLER`
+ - .s
+ * - :c:macro:`GCC_JIT_OUTPUT_KIND_OBJECT_FILE`
+ - .o
+ * - :c:macro:`GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY`
+ - .so or .dll
+ * - :c:macro:`GCC_JIT_OUTPUT_KIND_EXECUTABLE`
+ - None, or .exe
.. c:macro:: GCC_JIT_OUTPUT_KIND_ASSEMBLER
@@ -313,14 +313,20 @@ Unary Operations
The available unary operations are:
-========================================== ============
-Unary Operation C equivalent
-========================================== ============
-:c:macro:`GCC_JIT_UNARY_OP_MINUS` `-(EXPR)`
-:c:macro:`GCC_JIT_UNARY_OP_BITWISE_NEGATE` `~(EXPR)`
-:c:macro:`GCC_JIT_UNARY_OP_LOGICAL_NEGATE` `!(EXPR)`
-:c:macro:`GCC_JIT_UNARY_OP_ABS` `abs (EXPR)`
-========================================== ============
+.. list-table::
+ :header-rows: 1
+
+ * - Unary Operation
+ - C equivalent
+
+ * - :c:macro:`GCC_JIT_UNARY_OP_MINUS`
+ - `-(EXPR)`
+ * - :c:macro:`GCC_JIT_UNARY_OP_BITWISE_NEGATE`
+ - `~(EXPR)`
+ * - :c:macro:`GCC_JIT_UNARY_OP_LOGICAL_NEGATE`
+ - `!(EXPR)`
+ * - :c:macro:`GCC_JIT_UNARY_OP_ABS`
+ - `abs (EXPR)`
.. c:macro:: GCC_JIT_UNARY_OP_MINUS
@@ -380,22 +386,36 @@ Binary Operations
The available binary operations are:
-======================================== ============
-Binary Operation C equivalent
-======================================== ============
-:c:macro:`GCC_JIT_BINARY_OP_PLUS` `x + y`
-:c:macro:`GCC_JIT_BINARY_OP_MINUS` `x - y`
-:c:macro:`GCC_JIT_BINARY_OP_MULT` `x * y`
-:c:macro:`GCC_JIT_BINARY_OP_DIVIDE` `x / y`
-:c:macro:`GCC_JIT_BINARY_OP_MODULO` `x % y`
-:c:macro:`GCC_JIT_BINARY_OP_BITWISE_AND` `x & y`
-:c:macro:`GCC_JIT_BINARY_OP_BITWISE_XOR` `x ^ y`
-:c:macro:`GCC_JIT_BINARY_OP_BITWISE_OR` `x | y`
-:c:macro:`GCC_JIT_BINARY_OP_LOGICAL_AND` `x && y`
-:c:macro:`GCC_JIT_BINARY_OP_LOGICAL_OR` `x || y`
-:c:macro:`GCC_JIT_BINARY_OP_LSHIFT` `x << y`
-:c:macro:`GCC_JIT_BINARY_OP_RSHIFT` `x >> y`
-======================================== ============
+.. list-table::
+ :header-rows: 1
+
+ * - Binary Operation
+ - C equivalent
+
+ * - :c:macro:`GCC_JIT_BINARY_OP_PLUS`
+ - `x + y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_MINUS`
+ - `x - y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_MULT`
+ - `x * y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_DIVIDE`
+ - `x / y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_MODULO`
+ - `x % y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_BITWISE_AND`
+ - `x & y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_BITWISE_XOR`
+ - `x ^ y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_BITWISE_OR`
+ - `x | y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_LOGICAL_AND`
+ - `x && y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_LOGICAL_OR`
+ - `x || y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_LSHIFT`
+ - `x << y`
+ * - :c:macro:`GCC_JIT_BINARY_OP_RSHIFT`
+ - `x >> y`
.. c:macro:: GCC_JIT_BINARY_OP_PLUS
@@ -536,17 +556,24 @@ Comparisons
.. enum:: gcc_jit_comparison
-======================================= ============
-Comparison C equivalent
-======================================= ============
-:c:macro:`GCC_JIT_COMPARISON_EQ` `x == y`
-:c:macro:`GCC_JIT_COMPARISON_NE` `x != y`
-:c:macro:`GCC_JIT_COMPARISON_LT` `x < y`
-:c:macro:`GCC_JIT_COMPARISON_LE` `x <= y`
-:c:macro:`GCC_JIT_COMPARISON_GT` `x > y`
-:c:macro:`GCC_JIT_COMPARISON_GE` `x >= y`
-======================================= ============
-
+.. list-table::
+ :header-rows: 1
+
+ * - Comparison
+ - C equivalent
+
+ * - :c:macro:`GCC_JIT_COMPARISON_EQ`
+ - `x == y`
+ * - :c:macro:`GCC_JIT_COMPARISON_NE`
+ - `x != y`
+ * - :c:macro:`GCC_JIT_COMPARISON_LT`
+ - `x < y`
+ * - :c:macro:`GCC_JIT_COMPARISON_LE`
+ - `x <= y`
+ * - :c:macro:`GCC_JIT_COMPARISON_GT`
+ - `x > y`
+ * - :c:macro:`GCC_JIT_COMPARISON_GE`
+ - `x >= y`
Function calls
**************
@@ -57,45 +57,78 @@ Standard types
Access a specific type. The available types are:
- ========================================== ================================
- `enum gcc_jit_types` value Meaning
- ========================================== ================================
- :c:data:`GCC_JIT_TYPE_VOID` C's ``void`` type.
- :c:data:`GCC_JIT_TYPE_VOID_PTR` C's ``void *``.
- :c:data:`GCC_JIT_TYPE_BOOL` C++'s ``bool`` type; also C99's
- ``_Bool`` type, aka ``bool`` if
- using stdbool.h.
- :c:data:`GCC_JIT_TYPE_CHAR` C's ``char`` (of some signedness)
- :c:data:`GCC_JIT_TYPE_SIGNED_CHAR` C's ``signed char``
- :c:data:`GCC_JIT_TYPE_UNSIGNED_CHAR` C's ``unsigned char``
- :c:data:`GCC_JIT_TYPE_SHORT` C's ``short`` (signed)
- :c:data:`GCC_JIT_TYPE_UNSIGNED_SHORT` C's ``unsigned short``
- :c:data:`GCC_JIT_TYPE_INT` C's ``int`` (signed)
- :c:data:`GCC_JIT_TYPE_UNSIGNED_INT` C's ``unsigned int``
- :c:data:`GCC_JIT_TYPE_LONG` C's ``long`` (signed)
- :c:data:`GCC_JIT_TYPE_UNSIGNED_LONG` C's ``unsigned long``
- :c:data:`GCC_JIT_TYPE_LONG_LONG` C99's ``long long`` (signed)
- :c:data:`GCC_JIT_TYPE_UNSIGNED_LONG_LONG` C99's ``unsigned long long``
- :c:data:`GCC_JIT_TYPE_UINT8_T` C99's ``uint8_t``
- :c:data:`GCC_JIT_TYPE_UINT16_T` C99's ``uint16_t``
- :c:data:`GCC_JIT_TYPE_UINT32_T` C99's ``uint32_t``
- :c:data:`GCC_JIT_TYPE_UINT64_T` C99's ``uint64_t``
- :c:data:`GCC_JIT_TYPE_UINT128_T` C99's ``__uint128_t``
- :c:data:`GCC_JIT_TYPE_INT8_T` C99's ``int8_t``
- :c:data:`GCC_JIT_TYPE_INT16_T` C99's ``int16_t``
- :c:data:`GCC_JIT_TYPE_INT32_T` C99's ``int32_t``
- :c:data:`GCC_JIT_TYPE_INT64_T` C99's ``int64_t``
- :c:data:`GCC_JIT_TYPE_INT128_T` C99's ``__int128_t``
- :c:data:`GCC_JIT_TYPE_FLOAT`
- :c:data:`GCC_JIT_TYPE_DOUBLE`
- :c:data:`GCC_JIT_TYPE_LONG_DOUBLE`
- :c:data:`GCC_JIT_TYPE_CONST_CHAR_PTR` C type: ``(const char *)``
- :c:data:`GCC_JIT_TYPE_SIZE_T` C's ``size_t`` type
- :c:data:`GCC_JIT_TYPE_FILE_PTR` C type: ``(FILE *)``
- :c:data:`GCC_JIT_TYPE_COMPLEX_FLOAT` C99's ``_Complex float``
- :c:data:`GCC_JIT_TYPE_COMPLEX_DOUBLE` C99's ``_Complex double``
- :c:data:`GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE` C99's ``_Complex long double``
- ========================================== ================================
+ .. list-table::
+ :header-rows: 1
+
+ * - `enum gcc_jit_types` value
+ - Meaning
+
+ * - :c:data:`GCC_JIT_TYPE_VOID`
+ - C's ``void`` type.
+ * - :c:data:`GCC_JIT_TYPE_VOID_PTR`
+ - C's ``void *``.
+ * - :c:data:`GCC_JIT_TYPE_BOOL`
+ - C++'s ``bool`` type; also C99's ``_Bool`` type, aka ``bool`` if using stdbool.h.
+ * - :c:data:`GCC_JIT_TYPE_CHAR`
+ - C's ``char`` (of some signedness)
+ * - :c:data:`GCC_JIT_TYPE_SIGNED_CHAR`
+ - C's ``signed char``
+ * - :c:data:`GCC_JIT_TYPE_UNSIGNED_CHAR`
+ - C's ``unsigned char``
+ * - :c:data:`GCC_JIT_TYPE_SHORT`
+ - C's ``short`` (signed)
+ * - :c:data:`GCC_JIT_TYPE_UNSIGNED_SHORT`
+ - C's ``unsigned short``
+ * - :c:data:`GCC_JIT_TYPE_INT`
+ - C's ``int`` (signed)
+ * - :c:data:`GCC_JIT_TYPE_UNSIGNED_INT`
+ - C's ``unsigned int``
+ * - :c:data:`GCC_JIT_TYPE_LONG`
+ - C's ``long`` (signed)
+ * - :c:data:`GCC_JIT_TYPE_UNSIGNED_LONG`
+ - C's ``unsigned long``
+ * - :c:data:`GCC_JIT_TYPE_LONG_LONG`
+ - C99's ``long long`` (signed)
+ * - :c:data:`GCC_JIT_TYPE_UNSIGNED_LONG_LONG`
+ - C99's ``unsigned long long``
+ * - :c:data:`GCC_JIT_TYPE_UINT8_T`
+ - C99's ``uint8_t``
+ * - :c:data:`GCC_JIT_TYPE_UINT16_T`
+ - C99's ``uint16_t``
+ * - :c:data:`GCC_JIT_TYPE_UINT32_T`
+ - C99's ``uint32_t``
+ * - :c:data:`GCC_JIT_TYPE_UINT64_T`
+ - C99's ``uint64_t``
+ * - :c:data:`GCC_JIT_TYPE_UINT128_T`
+ - C99's ``__uint128_t``
+ * - :c:data:`GCC_JIT_TYPE_INT8_T`
+ - C99's ``int8_t``
+ * - :c:data:`GCC_JIT_TYPE_INT16_T`
+ - C99's ``int16_t``
+ * - :c:data:`GCC_JIT_TYPE_INT32_T`
+ - C99's ``int32_t``
+ * - :c:data:`GCC_JIT_TYPE_INT64_T`
+ - C99's ``int64_t``
+ * - :c:data:`GCC_JIT_TYPE_INT128_T`
+ - C99's ``__int128_t``
+ * - :c:data:`GCC_JIT_TYPE_FLOAT`
+ -
+ * - :c:data:`GCC_JIT_TYPE_DOUBLE`
+ -
+ * - :c:data:`GCC_JIT_TYPE_LONG_DOUBLE`
+ -
+ * - :c:data:`GCC_JIT_TYPE_CONST_CHAR_PTR`
+ - C type: ``(const char *)``
+ * - :c:data:`GCC_JIT_TYPE_SIZE_T`
+ - C's ``size_t`` type
+ * - :c:data:`GCC_JIT_TYPE_FILE_PTR`
+ - C type: ``(FILE *)``
+ * - :c:data:`GCC_JIT_TYPE_COMPLEX_FLOAT`
+ - C99's ``_Complex float``
+ * - :c:data:`GCC_JIT_TYPE_COMPLEX_DOUBLE`
+ - C99's ``_Complex double``
+ * - :c:data:`GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE`
+ - C99's ``_Complex long double``
.. function:: gcc_jit_type *\
gcc_jit_context_get_int_type (gcc_jit_context *ctxt, \