From 3611420a8d6bdffcb0742c5ad3d4250f2c6f6e5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Tue, 20 Feb 2001 16:59:51 +0100
Subject: [PATCH] Made push_type_int{,_backwards}() static. Introduced
 push_int_type() and push_object_type{,_backwards}().

Rev: src/builtin_functions.c:1.344
Rev: src/encode.c:1.82
Rev: src/language.yacc:1.225
Rev: src/operators.c:1.125
Rev: src/pike_types.c:1.148
Rev: src/pike_types.h:1.49
Rev: src/svalue.c:1.94
---
 src/builtin_functions.c | 11 +++++----
 src/encode.c            | 18 ++++++++------
 src/language.yacc       | 41 ++++++++++++-------------------
 src/operators.c         | 54 +++++++++++------------------------------
 src/pike_types.c        | 27 ++++++++++++++++++---
 src/pike_types.h        | 11 +++++----
 src/svalue.c            | 10 +++-----
 7 files changed, 79 insertions(+), 93 deletions(-)

diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index 63a992e0dc..e6d755b179 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: builtin_functions.c,v 1.343 2001/02/20 00:08:19 grubba Exp $");
+RCSID("$Id: builtin_functions.c,v 1.344 2001/02/20 15:59:48 grubba Exp $");
 #include "interpret.h"
 #include "svalue.h"
 #include "pike_macros.h"
@@ -2069,10 +2069,11 @@ node *fix_this_object_type(node *n)
 {
   free_type(n->type);
   type_stack_mark();
-  push_type_int(Pike_compiler->new_program->id);
-  /*  push_type(1);   We are rather sure that we contain ourselves... */
-  push_type(0);		/* But it did not work yet, so... */
-  push_type(T_OBJECT);
+
+  /* We are rather sure that we contain ourselves... */
+  /* push_object_type(1, Pike_compiler->new_program->id); */
+  /* But it did not work yet, so... */
+  push_object_type(0, Pike_compiler->new_program->id);
   n->type = pop_unfinished_type();
   if (n->parent) {
     n->parent->node_info |= OPT_TYPE_NOT_FIXED;
diff --git a/src/encode.c b/src/encode.c
index 11933e632a..a4d4471dbf 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -25,7 +25,7 @@
 #include "version.h"
 #include "bignum.h"
 
-RCSID("$Id: encode.c,v 1.81 2001/02/01 15:54:08 grubba Exp $");
+RCSID("$Id: encode.c,v 1.82 2001/02/20 15:59:49 grubba Exp $");
 
 /* #define ENCODE_DEBUG */
 
@@ -1011,7 +1011,6 @@ static void low_decode_type(struct decode_data *data)
 
 one_more_type:
   tmp = GETC();
-  push_type(tmp);
   switch(tmp)
   {
     default:
@@ -1020,10 +1019,12 @@ one_more_type:
       break;
 
     case T_ASSIGN:
+      push_type(tmp);
       push_type(GETC());
       goto one_more_type;
 
     case T_FUNCTION:
+      push_type(tmp);
       while(GETC()!=T_MANY)
       {
 	data->ptr--;
@@ -1034,6 +1035,7 @@ one_more_type:
     case T_MAPPING:
     case T_OR:
     case T_AND:
+      push_type(tmp);
       low_decode_type(data);
 
     case T_ARRAY:
@@ -1044,6 +1046,7 @@ one_more_type:
     case T_INT:
       {
 	int i;
+	push_type(tmp);
 	/* FIXME: I assume the type is saved in network byte order. Is it?
 	 *	/grubba 1999-03-07
 	 */
@@ -1071,23 +1074,23 @@ one_more_type:
     case T_ZERO:
     case T_VOID:
     case PIKE_T_UNKNOWN:
+      push_type(tmp);
       break;
 
     case T_OBJECT:
     {
       INT32 x;
+      int flag = GETC();
 
-      push_type(GETC());
       decode_value2(data);
-      type_stack_mark();
       switch(Pike_sp[-1].type)
       {
 	case T_INT:
-	  push_type_int(0);
+	  push_object_type_backwards(flag, 0);
 	  break;
 
 	case T_PROGRAM:
-	  push_type_int(Pike_sp[-1].u.program->id);
+	  push_object_type_backwards(flag, Pike_sp[-1].u.program->id);
 	  break;
 
         case T_FUNCTION:
@@ -1100,7 +1103,7 @@ one_more_type:
 	    if (!prog) {
 	      Pike_error("Failed to decode object type.\n");
 	    }
-	    push_type_int(prog->id);
+	    push_object_type_backwards(flag, prog->id);
 	  }
 	  break;
 
@@ -1110,7 +1113,6 @@ one_more_type:
 		get_name_of_type(Pike_sp[-1].type));
       }
       pop_stack();
-      type_stack_reverse();
     }
   }
 
diff --git a/src/language.yacc b/src/language.yacc
index f2d6f43980..9ae5073c0f 100644
--- a/src/language.yacc
+++ b/src/language.yacc
@@ -110,7 +110,7 @@
 /* This is the grammar definition of Pike. */
 
 #include "global.h"
-RCSID("$Id: language.yacc,v 1.224 2001/02/19 23:50:00 grubba Exp $");
+RCSID("$Id: language.yacc,v 1.225 2001/02/20 15:59:49 grubba Exp $");
 #ifdef HAVE_MEMORY_H
 #include <memory.h>
 #endif
@@ -1168,13 +1168,7 @@ identifier_type: idents
 	break;
       }
 
-      if(p) {
-	push_type_int(p->id);
-      }else{
-	push_type_int(0);
-      }
-      push_type(0);
-      push_type(T_OBJECT);
+      push_object_type(0, p?(p->id):0);
     }
     pop_stack();
     free_node($1);
@@ -1189,13 +1183,13 @@ type2: type2 '|' type3 { push_type(T_OR); }
   | type3 
   ;
 
-type3: TOK_INT_ID  opt_int_range    { push_type(T_INT); }
+type3: TOK_INT_ID  opt_int_range    {}
   | TOK_FLOAT_ID    { push_type(T_FLOAT); }
   | TOK_PROGRAM_ID  { push_type(T_PROGRAM); }
   | TOK_VOID_ID     { push_type(T_VOID); }
   | TOK_MIXED_ID    { push_type(T_MIXED); }
   | TOK_STRING_ID { push_type(T_STRING); }
-  | TOK_OBJECT_ID   opt_object_type { push_type(T_OBJECT); }
+  | TOK_OBJECT_ID   opt_object_type {}
   | TOK_MAPPING_ID opt_mapping_type { push_type(T_MAPPING); }
   | TOK_ARRAY_ID opt_array_type { push_type(T_ARRAY); }
   | TOK_MULTISET_ID opt_array_type { push_type(T_MULTISET); }
@@ -1247,32 +1241,32 @@ expected_dot_dot: TOK_DOT_DOT
 
 opt_int_range: /* Empty */
   {
-    push_type_int(MAX_INT32);
-    push_type_int(MIN_INT32);
+    push_int_type(MIN_INT32, MAX_INT32);
   }
   | '(' number_or_minint expected_dot_dot number_or_maxint ')'
   {
+    INT32 min = MIN_INT32;
+    INT32 max = MAX_INT32;
+
     /* FIXME: Check that $4 is >= $2. */
     if($4->token == F_CONSTANT && $4->u.sval.type == T_INT)
     {
-      push_type_int($4->u.sval.u.integer);
-    }else{
-      push_type_int(MAX_INT32);
+      max = $4->u.sval.u.integer;
     }
 
     if($2->token == F_CONSTANT && $2->u.sval.type == T_INT)
     {
-      push_type_int($2->u.sval.u.integer);
-    }else{
-      push_type_int(MIN_INT32);
+      min = $2->u.sval.u.integer;
     }
 
+    push_int_type(min, max);
+
     free_node($2);
     free_node($4);
   }
   ;
 
-opt_object_type:  /* Empty */ { push_type_int(0); push_type(0); }
+opt_object_type:  /* Empty */ { push_object_type(0, 0); }
   | '(' program_ref ')'
   {
     /* NOTE: On entry, there are two items on the stack:
@@ -1280,10 +1274,8 @@ opt_object_type:  /* Empty */ { push_type_int(0); push_type(0); }
      *   Pike_sp-1:	The resolved program (program|function|zero).
      */
     struct program *p=program_from_svalue(Pike_sp-1);
-    if(p)
-    {
-      push_type_int(p->id);
-    }else{
+
+    if(!p) {
       if (Pike_compiler->compiler_pass!=1) {
 	if ((Pike_sp[-2].type == T_STRING) && (Pike_sp[-2].u.string->len > 0) &&
 	    (Pike_sp[-2].u.string->len < 256)) {
@@ -1293,10 +1285,9 @@ opt_object_type:  /* Empty */ { push_type_int(0); push_type(0); }
 	  yyerror("Not a valid program specifier.");
 	}
       }
-      push_type_int(0);
     }
+    push_object_type(0, p?(p->id):0);
     pop_n_elems(2);
-    push_type(0);
   }
   ;
 
diff --git a/src/operators.c b/src/operators.c
index 332685b386..ceec25d77a 100644
--- a/src/operators.c
+++ b/src/operators.c
@@ -6,7 +6,7 @@
 /**/
 #include "global.h"
 #include <math.h>
-RCSID("$Id: operators.c,v 1.124 2001/02/20 13:02:12 grubba Exp $");
+RCSID("$Id: operators.c,v 1.125 2001/02/20 15:59:49 grubba Exp $");
 #include "interpret.h"
 #include "svalue.h"
 #include "multiset.h"
@@ -1091,9 +1091,7 @@ PMOD_EXPORT void o_and(void)
 	      SIMPLE_BAD_ARG_ERROR("`&", 1, "type");
 	   }
 	   type_stack_mark();
-	   push_type_int(p->id);
-	   push_type(0);
-	   push_type(T_OBJECT);
+	   push_object_type(0, p->id);
 	   free_svalue(sp - 2);
 	   sp[-2].u.string = pop_unfinished_type();
 	   sp[-2].type = T_TYPE;
@@ -1107,9 +1105,7 @@ PMOD_EXPORT void o_and(void)
 	      SIMPLE_BAD_ARG_ERROR("`&", 2, "type");
 	   }
 	   type_stack_mark();
-	   push_type_int(p->id);
-	   push_type(0);
-	   push_type(T_OBJECT);
+	   push_object_type(0, p->id);
 	   free_svalue(sp - 1);
 	   sp[-1].u.string = pop_unfinished_type();
 	   sp[-1].type = T_TYPE;
@@ -1210,9 +1206,7 @@ PMOD_EXPORT void o_and(void)
       SIMPLE_BAD_ARG_ERROR("`&", 1, "type");
     }    
     type_stack_mark();
-    push_type_int(p->id);
-    push_type(0);
-    push_type(T_OBJECT);
+    push_object_type(0, p->id);
     a = pop_unfinished_type();
 
     p = program_from_svalue(sp - 1);
@@ -1221,9 +1215,7 @@ PMOD_EXPORT void o_and(void)
       SIMPLE_BAD_ARG_ERROR("`&", 2, "type");
     }    
     type_stack_mark();
-    push_type_int(p->id);
-    push_type(0);
-    push_type(T_OBJECT);
+    push_object_type(0, p->id);
     b = pop_unfinished_type();
 
     t = and_pike_types(a, b);
@@ -1438,9 +1430,7 @@ PMOD_EXPORT void o_or(void)
 	  SIMPLE_BAD_ARG_ERROR("`|", 1, "type");
 	}
 	type_stack_mark();
-	push_type_int(p->id);
-	push_type(0);
-	push_type(T_OBJECT);
+	push_object_type(0, p->id);
 	free_svalue(sp - 2);
 	sp[-2].u.string = pop_unfinished_type();
 	sp[-2].type = T_TYPE;
@@ -1452,9 +1442,7 @@ PMOD_EXPORT void o_or(void)
 	  SIMPLE_BAD_ARG_ERROR("`|", 2, "type");
 	}
 	type_stack_mark();
-	push_type_int(p->id);
-	push_type(0);
-	push_type(T_OBJECT);
+	push_object_type(0, p->id);
 	free_svalue(sp - 1);
 	sp[-1].u.string = pop_unfinished_type();
 	sp[-1].type = T_TYPE;
@@ -1527,9 +1515,7 @@ PMOD_EXPORT void o_or(void)
       SIMPLE_BAD_ARG_ERROR("`|", 1, "type");
     }
     type_stack_mark();
-    push_type_int(p->id);
-    push_type(0);
-    push_type(T_OBJECT);
+    push_object_type(0, p->id);
     a = pop_unfinished_type();
 
     p = program_from_svalue(sp - 1);
@@ -1538,9 +1524,7 @@ PMOD_EXPORT void o_or(void)
       SIMPLE_BAD_ARG_ERROR("`|", 2, "type");
     }
     type_stack_mark();
-    push_type_int(p->id);
-    push_type(0);
-    push_type(T_OBJECT);
+    push_object_type(0, p->id);
     b = pop_unfinished_type();
 
     t = or_pike_types(a, b, 0);
@@ -1656,9 +1640,7 @@ PMOD_EXPORT void o_xor(void)
 	  SIMPLE_BAD_ARG_ERROR("`^", 1, "type");
 	}
 	type_stack_mark();
-	push_type_int(p->id);
-	push_type(0);
-	push_type(T_OBJECT);
+	push_object_type(0, p->id);
 	free_svalue(sp - 2);
 	sp[-2].u.string = pop_unfinished_type();
 	sp[-2].type = T_TYPE;
@@ -1670,9 +1652,7 @@ PMOD_EXPORT void o_xor(void)
 	  SIMPLE_BAD_ARG_ERROR("`^", 2, "type");
 	}
 	type_stack_mark();
-	push_type_int(p->id);
-	push_type(0);
-	push_type(T_OBJECT);
+	push_object_type(0, p->id);
 	free_svalue(sp - 1);
 	sp[-1].u.string = pop_unfinished_type();
 	sp[-1].type = T_TYPE;
@@ -1732,9 +1712,7 @@ PMOD_EXPORT void o_xor(void)
       SIMPLE_BAD_ARG_ERROR("`^", 2, "type");
     }
     type_stack_mark();
-    push_type_int(p->id);
-    push_type(0);
-    push_type(T_OBJECT);
+    push_object_type(0, p->id);
     pop_stack();
     push_string(pop_unfinished_type());
     sp[-1].type = T_TYPE;
@@ -1748,9 +1726,7 @@ PMOD_EXPORT void o_xor(void)
       SIMPLE_BAD_ARG_ERROR("`^", 1, "type");
     }
     type_stack_mark();
-    push_type_int(p->id);
-    push_type(0);
-    push_type(T_OBJECT);
+    push_object_type(0, p->id);
     pop_stack();
     push_string(pop_unfinished_type());
     sp[-1].type = T_TYPE;
@@ -2872,9 +2848,7 @@ PMOD_EXPORT void o_compl(void)
 	PIKE_ERROR("`~", "Bad argument.\n", sp, 1);
       }
       type_stack_mark();
-      push_type_int(p->id);
-      push_type(0);
-      push_type(T_OBJECT);
+      push_object_type(0, p->id);
       push_type(T_NOT);
       pop_stack();
       push_string(pop_unfinished_type());
diff --git a/src/pike_types.c b/src/pike_types.c
index 2fb4614538..45ab7ff294 100644
--- a/src/pike_types.c
+++ b/src/pike_types.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: pike_types.c,v 1.147 2001/02/19 23:50:02 grubba Exp $");
+RCSID("$Id: pike_types.c,v 1.148 2001/02/20 15:59:50 grubba Exp $");
 #include <ctype.h>
 #include "svalue.h"
 #include "pike_types.h"
@@ -244,20 +244,41 @@ void type_stack_reverse(void)
   reverse((char *)(Pike_compiler->type_stackp-a),a,1);
 }
 
-void push_type_int(INT32 i)
+static void push_type_int(INT32 i)
 {
   ptrdiff_t e;
   for(e = 0; e < (ptrdiff_t)sizeof(i); e++)
     push_type(DO_NOT_WARN((unsigned char)((i>>(e*8)) & 0xff)));
 }
 
-void push_type_int_backwards(INT32 i)
+static void push_type_int_backwards(INT32 i)
 {
   int e;
   for(e=(int)sizeof(i);e-->0;)
     push_type( (i>>(e*8)) & 0xff );
 }
 
+void push_int_type(INT32 min, INT32 max)
+{
+  push_type_int(max);
+  push_type_int(min);
+  push_type(T_INT);
+}
+
+void push_object_type(int flag, INT32 id)
+{
+  push_type_int(id);
+  push_type(flag);
+  push_type(T_OBJECT);
+}
+
+void push_object_type_backwards(int flag, INT32 id)
+{
+  unsafe_push_type(T_OBJECT);
+  unsafe_push_type(flag);
+  push_type_int_backwards(id);
+}
+
 INT32 extract_type_int(char *p)
 {
   int e;
diff --git a/src/pike_types.h b/src/pike_types.h
index 03a8bd397f..e5882f979d 100644
--- a/src/pike_types.h
+++ b/src/pike_types.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: pike_types.h,v 1.48 2001/02/19 23:50:02 grubba Exp $
+ * $Id: pike_types.h,v 1.49 2001/02/20 15:59:50 grubba Exp $
  */
 #ifndef PIKE_TYPES_H
 #define PIKE_TYPES_H
@@ -179,8 +179,9 @@ ptrdiff_t pop_stack_mark(void);
 void pop_type_stack(void);
 void type_stack_pop_to_mark(void);
 void type_stack_reverse(void);
-void push_type_int(INT32 i);
-void push_type_int_backwards(INT32 i);
+void push_int_type(INT32 min, INT32 max);
+void push_object_type(int flag, INT32 id);
+void push_object_type_backwards(int flag, INT32 id);
 INT32 extract_type_int(char *p);
 void push_unfinished_type(char *s);
 void push_finished_type(struct pike_type *type);
@@ -238,8 +239,8 @@ int pike_type_allow_premature_toss(char *type);
 #define dtMapping dtMap(dtMix,dtMix)
 #define dtSet(IND) {unsafe_push_type(PIKE_T_MULTISET); {IND}}
 #define dtMultiset dtSet(dtMix)
-#define dtObjImpl(PROGRAM) {unsafe_push_type(PIKE_T_OBJECT); unsafe_push_type(0); push_type_int_backwards((PROGRAM)->id);}
-#define dtObjIs(PROGRAM) {unsafe_push_type(PIKE_T_OBJECT); unsafe_push_type(1); push_type_int_backwards((PROGRAM)->id);}
+#define dtObjImpl(PROGRAM) {push_object_type_backwards(0, (PROGRAM)->id);}
+#define dtObjIs(PROGRAM) {push_object_type_backwards(1, (PROGRAM)->id);}
 #define dtObj dtStore(tObj)
 #define dtFuncV(ARGS,REST,RET) MagicdtFuncV(RET,REST,ARGS)
 #define dtFunc(ARGS,RET) MagicdtFunc(RET,ARGS)
diff --git a/src/svalue.c b/src/svalue.c
index a0764b0a7a..7218b7613e 100644
--- a/src/svalue.c
+++ b/src/svalue.c
@@ -32,7 +32,7 @@
 #include <ieeefp.h>
 #endif
 
-RCSID("$Id: svalue.c,v 1.93 2001/01/24 22:37:52 marcus Exp $");
+RCSID("$Id: svalue.c,v 1.94 2001/02/20 15:59:51 grubba Exp $");
 
 struct svalue dest_ob_zero = { T_INT, 0 };
 
@@ -785,9 +785,7 @@ PMOD_EXPORT int is_lt(struct svalue *a,struct svalue *b)
 	Pike_error("Bad argument to comparison.");
       }
       type_stack_mark();
-      push_type_int(aa.u.program->id);
-      push_type(0);
-      push_type(T_OBJECT);
+      push_object_type(0, aa.u.program->id);
       aa.u.string = pop_unfinished_type();
       aa.type = T_TYPE;
       res = is_lt(&aa, b);
@@ -803,9 +801,7 @@ PMOD_EXPORT int is_lt(struct svalue *a,struct svalue *b)
 	Pike_error("Bad argument to comparison.");
       }
       type_stack_mark();
-      push_type_int(bb.u.program->id);
-      push_type(0);
-      push_type(T_OBJECT);
+      push_object_type(0, bb.u.program->id);
       bb.u.string = pop_unfinished_type();
       bb.type = T_TYPE;
       res = is_lt(a, &bb);
-- 
GitLab