[1136] in Coldmud discussion meeting

root meeting help first previous next last

[COLD] anticipate_assignment

daemon@ATHENA.MIT.EDU (Sun Nov 24 02:03:22 1996 )

Date: Sun, 24 Nov 1996 07:54:24 +0100 (MET)
From: Miroslav.Silovic@public.srce.hr (Miroslav Silovic)
To: coldstuff@cold.org

This patch defines anticipate_assignment function. This function looks
upward (into the calling frame) and checks if the method call is made
from the expression:

	foo = obj.method(...)

or

	foo = (| obj.method(...) |)

If so, variable foo is zeroed. The best time to call this is after doing
the error checking that might cause the method to throw. It allows
using advanced data structures without copying, and it mimicks the
internal driver mechanism with the same purpose.

-----------------------------------------------------------------------

Only in Genesis-1.0p19-new/src: .pure
Only in Genesis-1.0p19/src: coldcc
Common subdirectories: Genesis-1.0p19/src/data and Genesis-1.0p19-new/src/data
diff -C 5 -r Genesis-1.0p19/src/execute.c Genesis-1.0p19-new/src/execute.c
*** Genesis-1.0p19/src/execute.c	Sun Nov 24 07:47:38 1996
--- Genesis-1.0p19-new/src/execute.c	Sun Nov 24 07:47:38 1996
***************
*** 854,877 ****
  */
  void anticipate_assignment(void) {
      Int opcode, ind;
      Long id;
      cData *dp, d;
  
!     opcode = cur_frame->opcodes[cur_frame->pc];
      switch (opcode) {
        case SET_LOCAL:
          /* Zero out local variable value. */
          dp = &stack[cur_frame->var_start +
!                     cur_frame->opcodes[cur_frame->pc + 1]];
          data_discard(dp);
          dp->type = INTEGER;
          dp->u.val = 0;
          break;
        case SET_OBJ_VAR:
          /* Zero out the object variable, if it exists. */
!         ind = cur_frame->opcodes[cur_frame->pc + 1];
          id = object_get_ident(cur_frame->method->object, ind);
          d.type = INTEGER;
          d.u.val = 0;
          object_assign_var(cur_frame->object, cur_frame->method->object,
                            id, &d);
--- 854,881 ----
  */
  void anticipate_assignment(void) {
      Int opcode, ind;
      Long id;
      cData *dp, d;
+     Int pc=cur_frame->pc;
  
!     // skip error handling
!     while ((opcode = cur_frame->opcodes[pc]) == CRITICAL_END)
! 	pc++;
! 
      switch (opcode) {
        case SET_LOCAL:
          /* Zero out local variable value. */
          dp = &stack[cur_frame->var_start +
!                     cur_frame->opcodes[pc + 1]];
          data_discard(dp);
          dp->type = INTEGER;
          dp->u.val = 0;
          break;
        case SET_OBJ_VAR:
          /* Zero out the object variable, if it exists. */
!         ind = cur_frame->opcodes[pc + 1];
          id = object_get_ident(cur_frame->method->object, ind);
          d.type = INTEGER;
          d.u.val = 0;
          object_assign_var(cur_frame->object, cur_frame->method->object,
                            id, &d);
Only in Genesis-1.0p19/src: genesis
diff -C 5 -r Genesis-1.0p19/src/grammar.y Genesis-1.0p19-new/src/grammar.y
*** Genesis-1.0p19/src/grammar.y	Sun Nov 24 07:47:38 1996
--- Genesis-1.0p19-new/src/grammar.y	Sun Nov 24 07:47:38 1996
***************
*** 143,152 ****
--- 143,153 ----
  %token F_NEXT_OBJNUM F_TICK F_HOSTNAME F_IP F_RESUME F_SUSPEND
  %token F_TASKS F_TASK_INFO F_CANCEL F_PAUSE F_REFRESH F_STACK F_STATUS
  %token F_BIND_FUNCTION F_UNBIND_FUNCTION F_ATOMIC
  %token F_METHOD_INFO F_ENCODE F_DECODE F_SIN F_EXP F_LOG F_COS
  %token F_TAN F_SQRT F_ASIN F_ACOS F_ATAN F_POW F_ATAN2 F_CONFIG
+ %token F_FLUSH
  
  /* Reserved for future use. */
  /*%token FORK*/
  
  /*
Common subdirectories: Genesis-1.0p19/src/include and Genesis-1.0p19-new/src/include
Common subdirectories: Genesis-1.0p19/src/modules and Genesis-1.0p19-new/src/modules
diff -C 5 -r Genesis-1.0p19/src/opcodes.c Genesis-1.0p19-new/src/opcodes.c
*** Genesis-1.0p19/src/opcodes.c	Sun Nov 24 07:47:38 1996
--- Genesis-1.0p19-new/src/opcodes.c	Sun Nov 24 07:47:38 1996
***************
*** 219,228 ****
--- 219,229 ----
      { F_FWRITE,         "fwrite",               func_fwrite },
      { F_FILE,           "file",                 func_file },
      { F_FFLUSH,         "fflush",               func_fflush },
  
      /* Miscellaneous functions */
+     { F_FLUSH,  "anticipate_assignment",     func_anticipate_assignment},
      { F_LOCALTIME,        "localtime",       func_localtime },
      { F_TIME,             "time",            func_time },
      { F_MTIME,            "mtime",           func_mtime },
      { F_CTIME,            "ctime",           func_ctime },
      { F_BIND_FUNCTION,    "bind_function",   func_bind_function },
Common subdirectories: Genesis-1.0p19/src/ops and Genesis-1.0p19-new/src/ops
Only in Genesis-1.0p19-new/src/data: .pure
diff -C 5 -r Genesis-1.0p19/src/include/functions.h Genesis-1.0p19-new/src/include/functions.h
*** Genesis-1.0p19/src/include/functions.h	Sun Nov 24 07:47:38 1996
--- Genesis-1.0p19-new/src/include/functions.h	Sun Nov 24 07:47:38 1996
***************
*** 5,14 ****
--- 5,15 ----
  #ifndef cdc_functions_h
  #define cdc_functions_h
  
  #include "macros.h"
  
+ COLDC_FUNC(anticipate_assignment);
  COLDC_FUNC(buflen);
  COLDC_FUNC(bufgraft);
  COLDC_FUNC(buf_replace);
  COLDC_FUNC(subbuf);
  COLDC_FUNC(buf_to_str);
Only in Genesis-1.0p19-new/src/modules: .pure
Only in Genesis-1.0p19-new/src/ops: .pure
diff -C 5 -r Genesis-1.0p19/src/ops/misc.c Genesis-1.0p19-new/src/ops/misc.c
*** Genesis-1.0p19/src/ops/misc.c	Sun Nov 24 07:47:38 1996
--- Genesis-1.0p19-new/src/ops/misc.c	Sun Nov 24 07:47:38 1996
***************
*** 11,20 ****
--- 11,65 ----
  #include "operators.h"
  #include "execute.h"
  #include "util.h"
  #include "opcodes.h"
  
+ void func_anticipate_assignment(void) {
+     Int opcode, ind;
+     Long id;
+     cData *dp, d;
+     Frame *caller_frame = cur_frame->caller_frame;
+     Int pc;
+ 
+     if (!func_init_0())
+ 	return;
+     if (!caller_frame) {
+ 	push_int(1);
+ 	return;
+     }
+ 
+     pc=caller_frame->pc;
+ 
+     /* Most of this is from anticipate_assignment() */
+     
+     // skip error handling
+     while ((opcode = caller_frame->opcodes[pc]) == CRITICAL_END)
+ 	pc++;
+ 
+     switch (opcode) {
+       case SET_LOCAL:
+         /* Zero out local variable value. */
+         dp = &stack[caller_frame->var_start +
+                     caller_frame->opcodes[pc + 1]];
+         data_discard(dp);
+         dp->type = INTEGER;
+         dp->u.val = 0;
+         break;
+       case SET_OBJ_VAR:
+         /* Zero out the object variable, if it exists. */
+         ind = caller_frame->opcodes[pc + 1];
+         id = object_get_ident(caller_frame->method->object, ind);
+         d.type = INTEGER;
+         d.u.val = 0;
+         object_assign_var(caller_frame->object, caller_frame->method->object,
+                           id, &d);
+         break;
+     }
+     push_int(1);
+     return;
+ }
+ 
  void func_time(void) {
      /* Take no arguments. */
      if (!func_init_0())
  	return;