mirror of
https://github.com/janet-lang/janet
synced 2025-11-18 08:15:13 +00:00
Fix optimization of do_get.
When the target slot (register) is the same as the default register, do not clobber it.
This commit is contained in:
@@ -145,9 +145,16 @@ static JanetSlot do_get(JanetFopts opts, JanetSlot *args) {
|
|||||||
if (janet_v_count(args) == 3) {
|
if (janet_v_count(args) == 3) {
|
||||||
JanetCompiler *c = opts.compiler;
|
JanetCompiler *c = opts.compiler;
|
||||||
JanetSlot t = janetc_gettarget(opts);
|
JanetSlot t = janetc_gettarget(opts);
|
||||||
|
int target_is_default = janetc_sequal(t, args[2]);
|
||||||
|
JanetSlot dflt_slot = args[2];
|
||||||
|
if (target_is_default) {
|
||||||
|
dflt_slot = janetc_farslot(c);
|
||||||
|
janetc_copy(c, dflt_slot, t);
|
||||||
|
}
|
||||||
janetc_emit_sss(c, JOP_GET, t, args[0], args[1], 1);
|
janetc_emit_sss(c, JOP_GET, t, args[0], args[1], 1);
|
||||||
int32_t label = janetc_emit_si(c, JOP_JUMP_IF_NOT_NIL, t, 0, 0);
|
int32_t label = janetc_emit_si(c, JOP_JUMP_IF_NOT_NIL, t, 0, 0);
|
||||||
janetc_copy(c, t, args[2]);
|
janetc_copy(c, t, dflt_slot);
|
||||||
|
if (target_is_default) janetc_freeslot(c, dflt_slot);
|
||||||
int32_t current = janet_v_count(c->buffer);
|
int32_t current = janet_v_count(c->buffer);
|
||||||
c->buffer[label] |= (current - label) << 16;
|
c->buffer[label] |= (current - label) << 16;
|
||||||
return t;
|
return t;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ int32_t janetc_allocfar(JanetCompiler *c) {
|
|||||||
return reg;
|
return reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a register less than 256 */
|
/* Get a register less than 256 for temporary use. */
|
||||||
int32_t janetc_allocnear(JanetCompiler *c, JanetcRegisterTemp tag) {
|
int32_t janetc_allocnear(JanetCompiler *c, JanetcRegisterTemp tag) {
|
||||||
return janetc_regalloc_temp(&c->scope->ra, tag);
|
return janetc_regalloc_temp(&c->scope->ra, tag);
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ static int32_t janetc_regnear(JanetCompiler *c, JanetSlot s, JanetcRegisterTemp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if two slots are equal */
|
/* Check if two slots are equal */
|
||||||
static int janetc_sequal(JanetSlot lhs, JanetSlot rhs) {
|
int janetc_sequal(JanetSlot lhs, JanetSlot rhs) {
|
||||||
if ((lhs.flags & ~JANET_SLOTTYPE_ANY) == (rhs.flags & ~JANET_SLOTTYPE_ANY) &&
|
if ((lhs.flags & ~JANET_SLOTTYPE_ANY) == (rhs.flags & ~JANET_SLOTTYPE_ANY) &&
|
||||||
lhs.index == rhs.index &&
|
lhs.index == rhs.index &&
|
||||||
lhs.envindex == rhs.envindex) {
|
lhs.envindex == rhs.envindex) {
|
||||||
@@ -245,8 +245,8 @@ void janetc_copy(
|
|||||||
janetc_moveback(c, dest, nearreg);
|
janetc_moveback(c, dest, nearreg);
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
janetc_regalloc_freetemp(&c->scope->ra, nearreg, JANETC_REGTEMP_3);
|
janetc_regalloc_freetemp(&c->scope->ra, nearreg, JANETC_REGTEMP_3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Instruction templated emitters */
|
/* Instruction templated emitters */
|
||||||
|
|
||||||
static int32_t emit1s(JanetCompiler *c, uint8_t op, JanetSlot s, int32_t rest, int wr) {
|
static int32_t emit1s(JanetCompiler *c, uint8_t op, JanetSlot s, int32_t rest, int wr) {
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ int32_t janetc_emit_ssi(JanetCompiler *c, uint8_t op, JanetSlot s1, JanetSlot s2
|
|||||||
int32_t janetc_emit_ssu(JanetCompiler *c, uint8_t op, JanetSlot s1, JanetSlot s2, uint8_t immediate, int wr);
|
int32_t janetc_emit_ssu(JanetCompiler *c, uint8_t op, JanetSlot s1, JanetSlot s2, uint8_t immediate, int wr);
|
||||||
int32_t janetc_emit_sss(JanetCompiler *c, uint8_t op, JanetSlot s1, JanetSlot s2, JanetSlot s3, int wr);
|
int32_t janetc_emit_sss(JanetCompiler *c, uint8_t op, JanetSlot s1, JanetSlot s2, JanetSlot s3, int wr);
|
||||||
|
|
||||||
|
/* Check if two slots are equivalent */
|
||||||
|
int janetc_sequal(JanetSlot x, JanetSlot y);
|
||||||
|
|
||||||
/* Move value from one slot to another. Cannot copy to constant slots. */
|
/* Move value from one slot to another. Cannot copy to constant slots. */
|
||||||
void janetc_copy(JanetCompiler *c, JanetSlot dest, JanetSlot src);
|
void janetc_copy(JanetCompiler *c, JanetSlot dest, JanetSlot src);
|
||||||
|
|
||||||
|
|||||||
@@ -325,4 +325,7 @@ neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02
|
|||||||
(assert-no-error "issue 428 1" (loop [{:a x} :generate (fiber/new f)] (set result x)))
|
(assert-no-error "issue 428 1" (loop [{:a x} :generate (fiber/new f)] (set result x)))
|
||||||
(assert (= result :ok) "issue 428 2")
|
(assert (= result :ok) "issue 428 2")
|
||||||
|
|
||||||
|
# Inline 3 argument get
|
||||||
|
(assert (= 10 (do (var a 10) (set a (get '{} :a a)))) "inline get 1")
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
|||||||
Reference in New Issue
Block a user