-
Notifications
You must be signed in to change notification settings - Fork 3
Machine independent QLF files and states
Currently, saved states and .QLF files are dumps of VM instructions. They are independent from endianness, but rely on:
- Word size (32/64 bit)
- VM instruction numbering
- (saved states) migration of built-ins from C to Prolog or visa versa.
Notably the word size dependency stops using a native Prolog version for doing the Prolog build steps for cross-compiling as well as deploying cross-platform applications as .QLF files or saved states. Sensitivity to VM instruction numbering typically breaks .QLF files and states if the VM is being extended.
It is probably wise to make states and QLF files more portable and robust against changes to the Prolog VM. Basically, this implies that some data that is embedded in the instruction sequence must be rewritten. In particular this implies to the various integer representations, floats and and strings.
There are some issues and solutions:
- Some optimized instructions rely on data that can be stored in a single cell.
- By default use these optimized versions only if the data fits the 32-bit version.
- Integers come in 4 formats: as inlined cell, as raw word-sized integer, as explicit int64 or as
GMP number. Depending on the word size an integer may need to move to a different representation.
- Only use H_SMALLINT/B_SMALLINT for integers that fit in a 32-bit cell.
- Use and abstract H/B/A integer VMI with a portable representation for all larger numbers.
- Wide strings may be 4 bytes per character or 2 bytes (Windows).
- Use UTF-8 for wide strings.
The instruction renumbering can be mitigated by having a mapping table to fixed VMI opcode numbers that are used in QLF files and states.
Changes built-in predicates are harder to mitigate. They only apply to states. A possible solution might be
to split the state in two parts: a fixed part that belongs to Prolog (the current bootXX.prc) and a generated
part that merely contains the user program. The fixed part can be embedded into libswipl.so/dll/...