summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2024-01-29 14:58:49 -0500
committerPeter Zhu <peter@peterzhu.ca>2024-01-29 16:34:25 -0500
commit8e1fe15b4a73e511731accc5e244cead990e3cba (patch)
tree2ba275a1c5c24a35774e0d14901e79afacadbd27
parentbc10b958d2cc45b61e23c41d0aa892cbb82efafd (diff)
[PRISM] Implement opt_str_uminus
-rw-r--r--prism_compile.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 8342337023..702428dd76 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -3972,13 +3972,18 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
PM_PUTSELF;
pm_compile_call(iseq, call_node, ret, src, popped, scope_node, method_id, start);
}
- else if (method_id == idFreeze &&
+ else if ((method_id == idUMinus || method_id == idFreeze) &&
PM_NODE_TYPE_P(call_node->receiver, PM_STRING_NODE) &&
call_node->arguments == NULL &&
call_node->block == NULL &&
ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
VALUE str = rb_fstring(parse_string_encoded(call_node->receiver, &((pm_string_node_t *)call_node->receiver)->unescaped, parser));
- ADD_INSN2(ret, &dummy_line_node, opt_str_freeze, str, new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE));
+ if (method_id == idUMinus) {
+ ADD_INSN2(ret, &dummy_line_node, opt_str_uminus, str, new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE));
+ }
+ else {
+ ADD_INSN2(ret, &dummy_line_node, opt_str_freeze, str, new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE));
+ }
}
else {
PM_COMPILE_NOT_POPPED(call_node->receiver);