Skip to content

Thinking about dynamic linking #61

Description

@nperez

Hi there,

This isn't a bug report or anything, but I wanted to get your perspective on a change I'd like to make.

I've been studying WAForth with my own host using wasmer in Go where I'd ideally store the compiled modules given to the host via $shell_load and be able to load them later (via Forth word such as LOAD-WORD and a new imported function $shell_load_by_name).

I got a proof of concept working by exporting the $create function and also exposing the dictionary index. I manually patch the modules to align with the current state of the dictionary before instantiating (basically driving WAForth from the outside). For simple words that only rely on the core words, this works great, but as soon as I reference other self-written words, ordering on loading starts to matter due to how calls are compiled.

So I am considering evolving the compiler to switch to referencing imported global vals for dictionary indexes beyond the core words when compiling words. Then, prior to instantiation, I can interrogate the module for what imports it is expecting and also interrogate the current dictionary state and supply the right indexes. And if there are words referenced but not in the dictionary, the host can attempt to load them.

I recognize that this will probably induce a big performance hit by replacing the constants with global.gets, but I am not super concerned for my project.

Do you think this approach could work? Are there any caveats I should consider? Is there another approach I should consider? Would my changes be of interest to upstream?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions