Browse Source

Fixed a computed property (setter) bug

Marco Bambini 4 years ago
parent
commit
f67c05b18c
3 changed files with 9 additions and 8 deletions
  1. 3 2
      src/runtime/gravity_vm.c
  2. 3 3
      src/runtime/gravity_vmmacros.h
  3. 3 3
      src/utils/gravity_debug.c

+ 3 - 2
src/runtime/gravity_vm.c

@@ -611,7 +611,7 @@ static bool gravity_vm_exec (gravity_vm *vm) {
                     case EXEC_TYPE_NATIVE: {
                         // invalidate current_fiber because it does not need to be in sync in this case
                         current_fiber = NULL;
-                        if (reset_r1) SETVALUE(rwin+1, v1);
+                        if (reset_r1) {SETVALUE(rwin+1, v1); reset_r1 = false;}
                         // was r1 but it was incorrect, pass r3 as the destination register because I am sure it is a
                         // dummy temp (and unused) register that can be safely set to NULL
                         PUSH_FRAME(closure, &stackstart[rwin], r3, 2);
@@ -620,13 +620,14 @@ static bool gravity_vm_exec (gravity_vm *vm) {
                     case EXEC_TYPE_INTERNAL: {
                         // backup register r1 because it can be overwrite to return a closure
                         gravity_value_t r1copy = STACK_GET(r1);
+                        if (reset_r1) {SETVALUE(rwin+1, r1copy);  reset_r1 = false;}
                         BEGIN_TRUST_USERCODE(vm);
                         bool result = closure->f->internal(vm, &stackstart[rwin], 2, r1);
                         END_TRUST_USERCODE(vm);
                         if (!result) {
                             if (vm->aborted) return false;
 
-                            // check for special getter trick
+                            // check for special setter trick
                             if (VALUE_ISA_CLOSURE(STACK_GET(r1))) {
                                 closure = VALUE_AS_CLOSURE(STACK_GET(r1));
                                 SETVALUE(r1, r1copy);

+ 3 - 3
src/runtime/gravity_vmmacros.h

@@ -307,9 +307,9 @@
 #define RETURN_FIBER()                              return false
 #define RETURN_NOVALUE()                            return true
 #define RETURN_ERROR(...)                           do {                                                                                    \
-                                                        char buffer[4096];                                                                  \
-                                                        snprintf(buffer, sizeof(buffer), __VA_ARGS__);                                      \
-                                                        gravity_fiber_seterror(gravity_vm_fiber(vm), (const char *) buffer);                \
+                                                        char _buffer[4096];                                                                 \
+                                                        snprintf(_buffer, sizeof(_buffer), __VA_ARGS__);                                    \
+                                                        gravity_fiber_seterror(gravity_vm_fiber(vm), (const char *) _buffer);               \
                                                         gravity_vm_setslot(vm, VALUE_FROM_NULL, rindex);                                    \
                                                         return false;                                                                       \
                                                     } while(0)

+ 3 - 3
src/utils/gravity_debug.c

@@ -37,11 +37,11 @@ const char *opcode_name (opcode_t op) {
     return optable[op];
 }
 
-#define DUMP_VM(buffer, bindex, ...)                    bindex += snprintf(&buffer[bindex], balloc-bindex, "%06u\t", pc);    \
-                                                        bindex += snprintf(&buffer[bindex], balloc-bindex, __VA_ARGS__);        \
+#define DUMP_VM(buffer, bindex, ...)                    bindex += snprintf(&buffer[bindex], balloc-bindex, "%06u\t", pc);   \
+                                                        bindex += snprintf(&buffer[bindex], balloc-bindex, __VA_ARGS__);    \
                                                         bindex += snprintf(&buffer[bindex], balloc-bindex, "\n");
 
-#define DUMP_VM_NOCR(buffer, bindex, ...)               bindex += snprintf(&buffer[bindex], balloc-bindex, "%06u\t", pc);    \
+#define DUMP_VM_NOCR(buffer, bindex, ...)               bindex += snprintf(&buffer[bindex], balloc-bindex, "%06u\t", pc);   \
                                                         bindex += snprintf(&buffer[bindex], balloc-bindex, __VA_ARGS__);
 
 #define DUMP_VM_RAW(buffer, bindex, ...)                bindex += snprintf(&buffer[bindex], balloc-bindex, __VA_ARGS__);