-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Constant fold all kinds of constants #2819
Conversation
cfa9ab6
to
f3bf084
Compare
src/parser.y
Outdated
} | ||
|
||
if (jv_get_kind(res) == JV_KIND_INVALID) | ||
if (!jv_is_valid(res)) { | ||
jv_free(res); |
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.
Is there a way to generate a constant error block? That would be cool. =)
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.
I added a way to do it!
I noticed that string comparison, string division, string-number multiplication, etc were not being constant folded, so I decided to finally export the binary operators' implementations from |
3907aa4
to
bfdfff6
Compare
src/opcode_list.h
Outdated
@@ -47,3 +47,5 @@ OP(GENLABEL, NONE, 0, 1) | |||
|
|||
OP(DESTRUCTURE_ALT, BRANCH, 0, 0) | |||
OP(STOREVN, VARIABLE, 1, 0) | |||
|
|||
OP(ERROR, CONSTANT, 1, 0) |
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.
Is 1, 0
correct here? I think stack_in == 1
is correct, but the second value (stack_out
) is not used for anything so I am not sure what it should be.
4e3ddb5
to
e18aa67
Compare
I renamed the opcode to |
This patch exports all the binary operator builtins functions from builtin.c and uses them for constant folding in the parser, allowing constant folding to work will all kinds and combinations of constants. Now string*number, $ARGS+$ARGS, string/string, etc will also be constant folded and the implementation of constant folded operators and runtime operators will be the same. And thanks to the new ERRORK bytecode operation, errors are constant folded too! (e.g. 1 / 0 [] * {} etc)
I made a mistake when renaming |
Well done! |
Thanks! |
Also use
jv_equal()
to constant fold==
and!=
instead ofjv_cmp()
to match the implementation of_equal
and_notequal
.