Skip to content

add rudimentary kdb-x module support#132

Open
gyorokpeter wants to merge 1 commit intofinos:mainfrom
gyorokpeter:kdbx-module
Open

add rudimentary kdb-x module support#132
gyorokpeter wants to merge 1 commit intofinos:mainfrom
gyorokpeter:kdbx-module

Conversation

@gyorokpeter
Copy link
Copy Markdown
Contributor

THE FOLLOWING DISCLAIMER APPLIES TO ALL SOFTWARE CODE AND OTHER MATERIALS CONTRIBUTED IN CONNECTION WITH THIS SOFTWARE:
THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.
ONLY THE SOFTWARE CODE AND OTHER MATERIALS CONTRIBUTED IN CONNECTION WITH THIS SOFTWARE, IF ANY, THAT ARE ATTACHED TO (OR OTHERWISE ACCOMPANY) THIS SUBMISSION (AND ORDINARY COURSE CONTRIBUTIONS OF FUTURES PATCHES THERETO) ARE TO BE CONSIDERED A CONTRIBUTION. NO OTHER SOFTWARE CODE OR MATERIALS ARE A CONTRIBUTION.

@gyorokpeter
Copy link
Copy Markdown
Contributor Author

Load a legacy module in a similar manner to kdb-x use.

This requires the module to have a module.q that loads whatever we want to return from the „use”.

This will return any new namespaces created by the module. Note that changes to existing namespaces (except .finos.dep as it’s needed as part of the loading mechanism) or variables in the root namespace are not returned.
Example using a modified version of qx86:

~/gyorokpeter/qx86$ cat module.q
.finos.dep.include"util.q";
.finos.dep.include"blockmem.q";
.finos.dep.include"x86das.q";
.finos.dep.include"x86asm.q";
.finos.dep.include"x86emu.q";

$ q
KDB-X 5.0 2026.01.22 Copyright (C) 1993-2026 Kx Systems
...

q)\l /.../finos/kdb/q/finos_init.q
include: loading file /.../finos/kdb/q/dep/dep.q
q).finos.dep.regModule["qx86";"0.0.0";"/.../qx86";"";""]
q).finos.dep.useModule"qx86"
include: loading file //qx86/module.q
include: loading file /.../qx86/util.q
include: loading file /.../qx86/blockmem.q
include: loading file /.../qx86/x86das.q
include: loading file /.../qx86/x86asm.q
include: loading file /.../qx86/x86emu.q
x86util | ``shex`i2le`le2i`sx32`flipTopBit!(::;{first ` vs .Q.s $[-4h=type x;x;0x00 vs x]};{$[-4h=type x;enlist ..
blockmem| ``new`write`read`unitTest!(::;{([]addr:`long$();data:())};{[bm;offset;content]
    offset:`long$offset..
x86das  | ``reg1`reg1alt`reg2`reg4`reg8`sreg`bcHandler`disasm00`disasm010`disasm011`disasm01`disasm0`disasm10`di..
x86asm  | ``parseMemPart`parseMemArg`parseHexNum`parseArg`regCode`oneop`twoop`jump`bitshift`arithm`bitscan`handl..
x86emu  | ``blankState`eflags`uneflags`smv`gmv`lea`evalOperand`push`set`typematch`operandSize`sx`setFlags`handle..

Load a KDB-X module using finos.

$ q
KDB-X 5.0 2026.01.22 Copyright (C) 1993-2026 Kx Systems
...

q).Q.m.SP,:enlist"/.../finos/kdb/q";
q)use`finos;
include: loading file /.../finos/kdb/q/dep/dep.q
q).finos.dep.regModule["qbinparse";"0.0.0";"/.../qbinparse";"";""]
q)binp:use`finos:qbinparse;
q)binp
parse        | {[schema;data;mainType]
    if[debug; `:::lastExample set (schema;data;mainType)];
    lib.parse[..
parseRepeat  | code
unparse      | code
compileSchema| {[schema]
    if[-11h=type schema;
        schema:enlist schema;
    ];
    schema:$[11h=type sch..

This implementation still pollutes the global namespace with .finos (until the finos code itself is modulified), and the target cannot use .finos.dep.include (but it should be using :: paths anyway). Also this is the one where I had to pull out internal bits of the .Q.m functions to make it work so it may be subject to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant