On Fri, Nov 02, 2001 at 11:26:37PM -0300, Daniel Grunblatt wrote:
> You forgot the attachment.
Whoops.
       -=- James Mastros
? chr5.diff
? chrord4.diff
? chrord5.diff
? core.ops.mine
? mops.c
? ops.chrord.diff
? ord3.diff
? examples/assembly/chr_table.pasm
? examples/assembly/ord.pasm
? languages/jako/a.out
? languages/jako/benchmarks
? languages/jako/mops.c
? t/Makefile
Index: core.ops
===================================================================
RCS file: /home/perlcvs/parrot/core.ops,v
retrieving revision 1.24
diff -u -r1.24 core.ops
--- core.ops    2001/11/02 12:11:15     1.24
+++ core.ops    2001/11/03 04:39:32
@@ -178,7 +178,7 @@
 
 AUTO_OP print(s|sc) {
   STRING *s = $1;
-  if (s) printf("%.*s",(int)string_length(s),(char *) s->bufstart);
+  if (s) printf("%.*s", (int)string_length(s), (char *) s->bufstart);
 }
 
 
@@ -1133,11 +1133,77 @@
     $1 = string_substr(interpreter, $2, $3, $4, &$1);
 }
 
+########################################
+
+=item B<chr>(s, i)
+=item B<chr>(s, ic)
+
+Set $1 to the single-character string having unicode codepoint $2.
+
+=cut
+
+AUTO_OP chr(s, i|ic) {
+    const ENCODING *enc;
+    const CHARTYPE *type;
+
+    type = chartype_lookup("unicode");
+    enc = encoding_lookup(type->default_encoding);
+    $1 = string_make(interpreter, NULL, 0, enc, 0, type);
+    string_grow($1, 1);
+    $1->bufused = $1->bufstart - enc->encode($1->bufstart, $2);
+}
+
+=back
+
+=cut
+
+########################################
+
+=item B<chr>(s, i,  s)
+=item B<chr>(s, ic, s)
+=item B<chr>(s, i,  sc)
+=item B<chr>(s, ic, sc)
+
+Set $1 to the single-character string having codepoint $2 in the $3 encoding.
 
+=cut
+
+AUTO_OP chr(s, i|ic, s|sc) {
+    const ENCODING *enc;
+    const CHARTYPE *type;
+    void *oldstart;
+
+    /* DANGER WILL ROBINSON: Assumes that bufstart is a native string
+     * (That is, somthing that strcmp will work for) */
+    type = chartype_lookup($3->bufstart);
+    enc = encoding_lookup(type->default_encoding);
+    $1 = string_make(interpreter, NULL, 0, enc, 0, type);
+    string_grow($1, 1);
+    
+    oldstart = $1->bufstart;
+    $1->bufused = enc->encode($1->bufstart, $2) - oldstart;
+}
+
 =back
 
 =cut
 
+########################################
+
+=item B<ord>(i, s)
+=item B<chr>(i, sc)
+
+Set $1 to the codepoint of the first character of $2 (in $2's current chartype).
+
+=cut
+
+AUTO_OP ord(i, s|sc) {
+    $1 = $2->encoding->decode($2->bufstart);
+}
+
+=back
+
+=cut
 
 ###############################################################################
 
Index: string.c
===================================================================
RCS file: /home/perlcvs/parrot/string.c,v
retrieving revision 1.16
diff -u -r1.16 string.c
--- string.c    2001/10/31 22:51:31     1.16
+++ string.c    2001/11/03 04:39:32
@@ -80,6 +80,8 @@
  */
 INTVAL
 string_length(STRING* s) {
+    if (!s->strlen)
+        string_compute_strlen(s);
     return s->strlen;
 }
 
Index: examples/assembly/Makefile
===================================================================
RCS file: /home/perlcvs/parrot/examples/assembly/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- examples/assembly/Makefile  2001/10/17 13:20:39     1.2
+++ examples/assembly/Makefile  2001/11/03 04:39:32
@@ -3,10 +3,13 @@
 
 PERL=perl    # Usually overidden by main Makefile
 
-.SUFFIXES: .pbc .pasm
+.SUFFIXES: .pbc .pasm .c
 
 clean:
        rm -f *.pbc mops.c mops.o mops
 
 .pasm.pbc:
        $(PERL) -I../.. ../../assemble.pl $< > $@
+
+.pbc.c:
+       (cd ../..; pbc2c.pl) < $< > $@


Reply via email to