Skip to content
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

var-get should throw a runtime error if variable does not exist #381

Open
csgui opened this issue Apr 17, 2024 · 1 comment
Open

var-get should throw a runtime error if variable does not exist #381

csgui opened this issue Apr 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@csgui
Copy link
Collaborator

csgui commented Apr 17, 2024

For now, var-get on an non-existing variable could lead to the generation of invalid Wasm code.

To remedy this, there is an "easy enough" fix to write:

  1. Change the linked function link_get_variable_fn to write an optional Value to the memory;
  2. Adapt the traverse function of get-var to unwrap the optional, and return a runtime error if it's none.
@Acaccia Acaccia added this to the WASM Phase 1 milestone Apr 17, 2024
@Acaccia Acaccia added the bug Something isn't working label Apr 17, 2024
@csgui csgui changed the title var-get should thrown a runtime error if variable does not exists var-get should throw a runtime error if variable does not exist Apr 17, 2024
@Acaccia
Copy link
Collaborator

Acaccia commented Jun 18, 2024

@csgui found something AMAZING in link_get_variable_fn: the type of the returned variable varies depending on if the var exists or not. If it exists, the type is the type of the var. If not, it's an optional.

So in this case, we will need a horrible workaround, where we will have to check if the fetched variable has the same type as the computed return type:

  • if yes, we have to wrap both the var and the type in Optional to make it coherent,
  • if not, we have to change only the return type to Optional.

Actually,if not, we could just write a "None" on the first byte which will contain the result, and in the wasm function check the first byte to see if we runtime-error or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Status: 📋 Backlog
Development

No branches or pull requests

2 participants