-
-
Save MasterDuke17/8704274029932ab82023c2659d8d216f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git src/core/coerce.c src/core/coerce.c | |
index 021e77073..87f67acf0 100644 | |
--- src/core/coerce.c | |
+++ src/core/coerce.c | |
@@ -14,8 +14,11 @@ typedef struct { | |
MVMRegister res_reg; | |
} BoolMethReturnData; | |
-MVMint64 MVM_coerce_istrue_s(MVMThreadContext *tc, MVMString *str) { | |
- return str == NULL || !IS_CONCRETE(str) || MVM_string_graphs_nocheck(tc, str) == 0 ? 0 : 1; | |
+MVMint64 MVM_coerce_istrue_s(MVMThreadContext *tc, MVMString *str, MVMuint8 flip) { | |
+ MVMint64 result = str == NULL || !IS_CONCRETE(str) || MVM_string_graphs_nocheck(tc, str) == 0 ? 0 : 1; | |
+ if (flip) | |
+ result = result ? 0 : 1; | |
+ return result; | |
} | |
/* Tries to do the boolification. It may be that a method call is needed. In | |
@@ -76,7 +79,7 @@ void MVM_coerce_istrue(MVMThreadContext *tc, MVMObject *obj, MVMRegister *res_re | |
break; | |
} | |
str = REPR(obj)->box_funcs.get_str(tc, STABLE(obj), obj, OBJECT_BODY(obj)); | |
- result = MVM_coerce_istrue_s(tc, str); | |
+ result = MVM_coerce_istrue_s(tc, str, 0); | |
break; | |
} | |
case MVM_BOOL_MODE_UNBOX_STR_NOT_EMPTY_OR_ZERO: { | |
diff --git src/core/coerce.h src/core/coerce.h | |
index b5c3b69c7..66bcced0c 100644 | |
--- src/core/coerce.h | |
+++ src/core/coerce.h | |
@@ -1,5 +1,5 @@ | |
/* Boolification. */ | |
-MVMint64 MVM_coerce_istrue_s(MVMThreadContext *tc, MVMString *str); | |
+MVMint64 MVM_coerce_istrue_s(MVMThreadContext *tc, MVMString *str, MVMuint8 flip); | |
void MVM_coerce_istrue(MVMThreadContext *tc, MVMObject *obj, MVMRegister *res_reg, | |
MVMuint8 *true_addr, MVMuint8 *false_addr, MVMuint8 flip); | |
diff --git src/core/interp.c src/core/interp.c | |
index a36f46a4f..1da36f1db 100644 | |
--- src/core/interp.c | |
+++ src/core/interp.c | |
@@ -320,7 +320,7 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex | |
} | |
OP(if_s0): { | |
MVMString *str = GET_REG(cur_op, 0).s; | |
- if (!MVM_coerce_istrue_s(tc, str)) | |
+ if (MVM_coerce_istrue_s(tc, str, 1)) | |
cur_op += 6; | |
else | |
cur_op = bytecode_start + GET_UI32(cur_op, 2); | |
@@ -329,7 +329,7 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex | |
} | |
OP(unless_s0): { | |
MVMString *str = GET_REG(cur_op, 0).s; | |
- if (!MVM_coerce_istrue_s(tc, str)) | |
+ if (MVM_coerce_istrue_s(tc, str, 1)) | |
cur_op = bytecode_start + GET_UI32(cur_op, 2); | |
else | |
cur_op += 6; | |
@@ -1843,11 +1843,11 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex | |
cur_op += 6; | |
goto NEXT; | |
OP(istrue_s): | |
- GET_REG(cur_op, 0).i64 = MVM_coerce_istrue_s(tc, GET_REG(cur_op, 2).s); | |
+ GET_REG(cur_op, 0).i64 = MVM_coerce_istrue_s(tc, GET_REG(cur_op, 2).s, 0); | |
cur_op += 4; | |
goto NEXT; | |
OP(isfalse_s): | |
- GET_REG(cur_op, 0).i64 = MVM_coerce_istrue_s(tc, GET_REG(cur_op, 2).s) ? 0 : 1; | |
+ GET_REG(cur_op, 0).i64 = MVM_coerce_istrue_s(tc, GET_REG(cur_op, 2).s, 1); | |
cur_op += 4; | |
goto NEXT; | |
OP(null): | |
diff --git src/jit/core_templates.expr src/jit/core_templates.expr | |
index bf5e28c86..b33a63093 100644 | |
--- src/jit/core_templates.expr | |
+++ src/jit/core_templates.expr | |
@@ -755,15 +755,15 @@ | |
(call (^func &MVM_coerce_istrue_s) | |
(arglist | |
(carg (tc) ptr) | |
- (carg $1 ptr)) int_sz)) | |
+ (carg $1 ptr) | |
+ (carg (^zero) int)) int_sz)) | |
(template: isfalse_s | |
- (flagval | |
- (zr | |
- (call (^func &MVM_coerce_istrue_s) | |
- (arglist | |
- (carg (tc) ptr) | |
- (carg $1 ptr)) int_sz)))) | |
+ (call (^func &MVM_coerce_istrue_s) | |
+ (arglist | |
+ (carg (tc) ptr) | |
+ (carg $1 ptr) | |
+ (carg (^one) int)) int_sz)) | |
(template: null (^vmnull)) | |
diff --git src/jit/graph.c src/jit/graph.c | |
index 0747d938a..5d0e82f8e 100644 | |
--- src/jit/graph.c | |
+++ src/jit/graph.c | |
@@ -159,6 +159,7 @@ static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) { | |
case MVM_OP_unbox_s: return MVM_repr_get_str; | |
case MVM_OP_unbox_n: return MVM_repr_get_num; | |
case MVM_OP_istrue: case MVM_OP_isfalse: return MVM_coerce_istrue; | |
+ case MVM_OP_istrue_s: case MVM_OP_isfalse_s: return MVM_coerce_istrue_s; | |
case MVM_OP_istype: return MVM_6model_istype; | |
case MVM_OP_isint: case MVM_OP_isnum: case MVM_OP_isstr: /* continued */ | |
case MVM_OP_islist: case MVM_OP_ishash: return MVM_repr_compare_repr_id; | |
@@ -2276,6 +2277,16 @@ start: | |
jg_append_call_c(tc, jg, op_to_func(tc, op), 6, args, MVM_JIT_RV_VOID, -1); | |
break; | |
} | |
+ case MVM_OP_isfalse_s: | |
+ case MVM_OP_istrue_s: { | |
+ MVMint16 result = ins->operands[0].reg.orig; | |
+ MVMint16 str = ins->operands[1].reg.orig; | |
+ MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, { MVM_JIT_INTERP_TC } }, | |
+ { MVM_JIT_REG_VAL, { str } }, | |
+ { MVM_JIT_LITERAL, { op == MVM_OP_isfalse_s } }}; | |
+ jg_append_call_c(tc, jg, op_to_func(tc, op), 3, args, MVM_JIT_RV_INT, result); | |
+ break; | |
+ } | |
case MVM_OP_capturelex: { | |
MVMint16 code = ins->operands[0].reg.orig; | |
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, { MVM_JIT_INTERP_TC } }, | |
diff --git src/jit/x64/emit.dasc src/jit/x64/emit.dasc | |
index 868dddbd8..1b016d04c 100644 | |
--- src/jit/x64/emit.dasc | |
+++ src/jit/x64/emit.dasc | |
@@ -3048,6 +3048,7 @@ void MVM_jit_emit_block_branch(MVMThreadContext *tc, MVMJitCompiler *compiler, M | |
case MVM_OP_unless_s0: | |
| mov ARG1, TC; | |
| mov ARG2, WORK[val]; | |
+ | xor ARG3, ARG3; | |
| callp &MVM_coerce_istrue_s; | |
| test RV, RV; | |
if (ins->info->opcode == MVM_OP_unless_s0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment