-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Object registry for foreign objects and binary_tree module #12
base: main
Are you sure you want to change the base?
Conversation
…at/js-object-registry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add some tests to the tests
folder too!
parameters: [ | ||
{ | ||
type: "primary", | ||
primaryDataType: "signed int" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do specify somewhere in the docs that this defers from normal make_tree
source academy module as you are only able to take in signed ints as your node value, whereas the module itself could have any JS type
} | ||
const objIdentifier = new Uint8Array([ | ||
(FOREIGN_OBJ_IDENTIFIER >> 8) & 0xFF, // High byte (0xF0) | ||
FOREIGN_OBJ_IDENTIFIER & 0xFF // Low byte (0xBA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of FOREIGN_OBJ_IDENTIFIER ? it does not seem to be used anywhere. It seems you're just using it as a placeholder value for the address that you give your foreign object for the value of its void *
. In that case you could just leave it as zeros since from the C code deferencing the void *
would be UB. Unless you need it on the JS side, which dosent seem to be the case in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively the C standard does not specify that the value of a pointer must be an actual address in memory, merely a "reference". In that case you could instead come up with a solution to giving a unique value for your foreign object void *
variables which are guaranteed to not be equal to any other foreign object or actual C object or NULL. To do this, you could reserve a portion of the addressable memory range beforehand and assign foreign object void *
values from there, or even just increase the underlying primitive type of pointers from unsigned int
to unsigned long int
(32bit to 64bit), while the WASM addressable space is still 32bit (limitation of WASM memory addressing AFAIK). You could modify this in c-slang/ctowasm/src/common/constants.ts (might be some other changes needed too). That way you can just assign your foreign object void *
values from outside the unsigned 32bit numeric range.
Features:
ATTENTION:
This PL should be merged after #10 and #11 .
If needed, rebase it first with main branch then merge it.
Tests:
All of the tests are passed.