Just committed the set Sx, iy op.

Patch at end.

Cheers,

-Melvin




Tested with following:

        # Cola (0.0.1) generated
        #
_START:
        bsr __Main
__END:
        end
        
__Main:
        set I31, -123456789
LBL1:
        ge I31, 123456789, LBL2
         set S0, I31
         print I31
         print "\n "
         print S0
         print "\n"
        add I31, I31, 10000
        branch LBL1
LBL2:
LBL0:
        ret






Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.111
diff -u -r1.111 core.ops
--- core.ops    21 Mar 2002 22:01:50 -0000      1.111
+++ core.ops    22 Mar 2002 04:09:33 -0000
@@ -540,6 +540,11 @@
    goto NEXT();
  }

+inline op set(out STR, in INT) {
+  $1 = string_from_int(interpreter, $2);
+  goto NEXT();
+}
+
  inline op set(out PMC, in INT) {
    $1->vtable->set_integer_native(interpreter, $1, $2);
    goto NEXT();
Index: string.c
===================================================================
RCS file: /cvs/public/parrot/string.c,v
retrieving revision 1.60
diff -u -r1.60 string.c
--- string.c    21 Mar 2002 09:56:41 -0000      1.60
+++ string.c    22 Mar 2002 04:09:34 -0000
@@ -774,6 +774,35 @@
      return f;
  }

+STRING *
+string_from_int(struct Parrot_Interp * interpreter, INTVAL i) {
+    const char * digits = "0123456789";
+    char buf[128];
+    char *ptr = &buf[127];
+    int neg = 0;
+
+    if(i < 0) {
+        neg = 1;
+        i = abs(i);
+    }
+
+    /* Dangerous looking but no 32/64/128/.... bit int
+     * would approach 128 characters in the buffer.
+     */
+    do {
+        *--ptr = digits[i % 10];
+        i /= 10;
+    }
+    while(i);
+
+    if(neg)
+        *--ptr = '-';
+
+    return string_make(interpreter, ptr, (UINTVAL)(127 - (ptr - buf)),
+                            NULL, 0, NULL);
+}
+
+
  /*
   * Local variables:
   * c-indentation-style: bsd
Index: include/parrot/string_funcs.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/string_funcs.h,v
retrieving revision 1.5
diff -u -r1.5 string_funcs.h
--- include/parrot/string_funcs.h       20 Mar 2002 02:08:16 -0000      1.5
+++ include/parrot/string_funcs.h       22 Mar 2002 04:09:35 -0000
@@ -33,7 +33,8 @@
  INTVAL Parrot_string_ord(const STRING *, INTVAL idx);
  FLOATVAL Parrot_string_to_num(const STRING *);
  INTVAL Parrot_string_to_int(const STRING *);
-STRING * Parrot_string_grow(struct Parrot_Interp * interpreter, STRING * 
s, INTVAL addlen);
+STRING * Parrot_string_from_int(struct Parrot_Interp *, INTVAL i);
+STRING * Parrot_string_grow(struct Parrot_Interp *, STRING * s, INTVAL 
addlen);
  void Parrot_string_destroy(STRING *);
  STRING *Parrot_string_make(struct Parrot_Interp *, const void *buffer,
                             UINTVAL buflen, const ENCODING *, UINTVAL flags,
@@ -60,6 +61,7 @@
  #define string_ord              Parrot_string_ord
  #define string_to_num           Parrot_string_to_num
  #define string_to_int           Parrot_string_to_int
+#define string_from_int         Parrot_string_from_int
  #define string_grow             Parrot_string_grow
  #define string_destroy          Parrot_string_destroy
  #define string_make             Parrot_string_make


Reply via email to