hex.pointers.ptr_init¶
One-time initialisation of the pointer dispatch infrastructure: global opcodes, pointer-copies, and the read-byte handling table. Must be called once at program start, immediately after stl.startup so the read-byte table lands at address 256. Bundled into stl.startup_and_init_all.
Signature¶
def ptr_init @ read_ptr_byte_table > to_flip, to_jump, to_flip_var, to_jump_var, read_byte, ret_after_read_byte, nth_ptr { ... }
Defined in hex/pointers/basic_pointers.fj — lines 17–47 (view on GitHub).
Complexity¶
Time:
O(1)Space:
0.75w+261
See the complexity glossary for what @, w, dw, dbit, n mean.
Output labels¶
This macro exposes labels into the caller’s scope via >:
read_byte— hex[:2] variable. You want to zero it before jumping into ptr_jump.ret_after_read_byte— The return address. Jumps to it after finishing reading a byte.to_flip— address of opcode that holds a flipping address in its first word. jumping into it will flip wanted bit.to_flip_var— the hex-vector (pointer) that also holds the flipping address.to_jump— address of opcode that holds a jumping address in its second word. jumping into it will jump to the wanted address.to_jump_var— the hex-vector (pointer) that also holds the jumping address.
Source¶
Click to view the macro body
def ptr_init @ read_ptr_byte_table > to_flip, to_jump, to_flip_var, to_jump_var, \
read_byte, ret_after_read_byte, nth_ptr {
pad 256
// Time Complexity: 4/8 (when jumping to hex.pointers.to_jump, until finished)
// (4 is for reading from an hex memory, 8 is for byte memory).
read_ptr_byte_table:
rep(256, d) stl.fj \
d==0?0: (#d)<=4 \
? (.read_byte +dbit+(#d)-1) \
: (.read_byte+dw+dbit+(#d)-5), \
(d==((1<<(#d))>>1)) ? .ret_after_read_byte : read_ptr_byte_table+(d^((1<<(#d))>>1))*dw
read_byte:
hex.vec 2
ret_after_read_byte:
;0
to_flip:
0;0
to_jump:
;0
to_flip_var:
hex.vec w/4, 0
to_jump_var:
hex.vec w/4, 0
// Shared scratch pointer for the indexed read_nth_*/write_nth_* macros.
nth_ptr:
hex.vec w/4, 0
}
Depends on¶
Used by¶
Example uses¶
stl.ptr_initinptrlib.fj
Next: hex.pointers.set_jump_pointer →