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

How to load the byte code generated by v7_compile? #576

Open
Jayatubi opened this issue Oct 25, 2016 · 4 comments
Open

How to load the byte code generated by v7_compile? #576

Jayatubi opened this issue Oct 25, 2016 · 4 comments
Assignees

Comments

@Jayatubi
Copy link

Can I pre-compile the javascript code via v7_compile and then directly load the byte code and execute? I haven't found any interface that could deal with the generate byte code.

@Jayatubi
Copy link
Author

After review the code I found the b_exec has already handled pre-compiled AST internally. However, since b_exec is not public I have to expose it manually somehow.

@mkmik
Copy link
Collaborator

mkmik commented Oct 25, 2016

hi! currently v7_exec_file will recognize the header of the precompiled file (filename extension is not significant):

$ ./v7 -c test.js >test.jsc                                        
$ ./v7 test.jsc

Do you need to exec a precompiled script from memory?

@Jayatubi
Copy link
Author

Jayatubi commented Oct 25, 2016

Yes. What I want to is to execute the bytecode from memory. I have wrapped another interface v7_exec_bytes to accept another src_len argument, instead of the strlen.

It would be perfect If the the interface could be official supported.

enum v7_err v7_exec_bytes(struct v7 *v7, const char *js_code, size_t src_len, v7_val_t *res) {
    return b_exec(v7, js_code, src_len, NULL, V7_UNDEFINED, V7_UNDEFINED,
        V7_UNDEFINED, 0, 0, 0, res);
}

@mkmik
Copy link
Collaborator

mkmik commented Oct 25, 2016

yes, it makes sense; there are other reasons where the user doesn't have a null terminated string. The rest of the API always accepts string+len

@mkmik mkmik self-assigned this Oct 25, 2016
cesantabot pushed a commit to cesanta/mongoose-os that referenced this issue Oct 25, 2016
Requested in cesanta/v7#576

PUBLISHED_FROM=f950c3ef6db3d69a54e1588544f6f84570584a66
cesantabot pushed a commit that referenced this issue Oct 26, 2016
Requested in #576

PUBLISHED_FROM=f950c3ef6db3d69a54e1588544f6f84570584a66
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

No branches or pull requests

2 participants