cvsuser     03/07/03 08:32:28

  Modified:    languages/jako Curses.jako string.jako sys.jako
               languages/jako/examples bench.jako board.jako euclid.jako
                        fact.jako fib.jako hello.jako leibniz.jako
                        life.jako mandelbrot.jako mandelzoom.jako mops.jako
                        nci.jako primes.jako queens.jako queens_array.jako
                        sub.jako
               languages/jako/lib/Jako Lexer.pm
               languages/jako/lib/Jako/Construct/Expression Call.pm
  Log:
    * Added a #line <num> "<filename>" directive
  
    * Added a use <module> directive (which uses the #line stuff internally)
  
    * Made additions and corrections to the Jako Standard Library modules
      (string.jako, sys.jako, Curses.jako, elem.jako, io.jako).
  
    * Changed the examples to use the Jako Standard Library instead of
      having their own op and fn sub declarations.
  
  Revision  Changes    Path
  1.2       +14 -14    parrot/languages/jako/Curses.jako
  
  Index: Curses.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/Curses.jako,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- Curses.jako       3 Jul 2003 03:42:39 -0000       1.1
  +++ Curses.jako       3 Jul 2003 15:32:23 -0000       1.2
  @@ -1,5 +1,5 @@
   #
  -# curses.jako
  +# Curses.jako
   #
   # A Jako module for interfacing with the curses library.
   #
  @@ -7,22 +7,22 @@
   # This program is free software. Its use is subject to the same
   # license as Parrot.
   #
  -# $Id: Curses.jako,v 1.1 2003/07/03 03:42:39 gregor Exp $
  +# $Id: Curses.jako,v 1.2 2003/07/03 15:32:23 gregor Exp $
   #
   
  -module curses : fnlib = "libcurses.so" {
  +module Curses
  +  :fnlib = "libcurses.so"
  +{
  +  sub int initscr  :fn ();
  +  sub int endwin   :fn ();
  +  sub int curs_set :fn (int x);
   
  -  sub int initscr  ();
  -  sub int endwin   ();
  -  sub int curs_set (int x);
  -
  -  sub int addstr   (str s);
  -  sub int refresh  ();
  -  sub int move     (int x, int y);
  -
  -  sub int getch    ();
  -  sub int box      (int screen, int v, int h);
  -  sub int hline    (int ch, int n);
  +  sub int addstr   :fn (str s);
  +  sub int refresh  :fn ();
  +  sub int move     :fn (int x, int y);
   
  +  sub int getch    :fn ();
  +  sub int box      :fn (int screen, int v, int h);
  +  sub int hline    :fn (int ch, int n);
   }
   
  
  
  
  1.3       +4 -1      parrot/languages/jako/string.jako
  
  Index: string.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/string.jako,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- string.jako       3 Jul 2003 03:42:39 -0000       1.2
  +++ string.jako       3 Jul 2003 15:32:23 -0000       1.3
  @@ -5,11 +5,14 @@
   # This program is free software. Its use is subject to the
   # same license as Parrot.
   #
  -# $Id: string.jako,v 1.2 2003/07/03 03:42:39 gregor Exp $
  +# $Id: string.jako,v 1.3 2003/07/03 15:32:23 gregor Exp $
   #
   
   module string
   {
  +  sub     concat :op (str dest, str s);
  +  sub int index  :op (str input, str pattern, int start);
  +  sub int length :op (str dest);
     sub str substr :op (str s, int i, int l);
   }
   
  
  
  
  1.3       +5 -4      parrot/languages/jako/sys.jako
  
  Index: sys.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/sys.jako,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- sys.jako  3 Jul 2003 03:42:39 -0000       1.2
  +++ sys.jako  3 Jul 2003 15:32:23 -0000       1.3
  @@ -7,13 +7,14 @@
   # This program is free software. Its use is subject to the same
   # license as Parrot.
   #
  -# $Id: sys.jako,v 1.2 2003/07/03 03:42:39 gregor Exp $
  +# $Id: sys.jako,v 1.3 2003/07/03 15:32:23 gregor Exp $
   #
   
   module sys
   {
  -  sub     print :op (str a)
  +  sub     print :op        (str a);
     sub int time  :op ();
  -  sub num time  :op ();
  +  sub num timen :op="time" (); # TODO: Really want to allow overloads in Jako
  +  sub     sleep :op        (int n);
   }
   
  
  
  
  1.2       +18 -2     parrot/languages/jako/examples/bench.jako
  
  Index: bench.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/bench.jako,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- bench.jako        8 Dec 2002 18:23:36 -0000       1.1
  +++ bench.jako        3 Jul 2003 15:32:25 -0000       1.2
  @@ -18,12 +18,18 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: bench.jako,v 1.1 2002/12/08 18:23:36 gregor Exp $
  +# $Id: bench.jako,v 1.2 2003/07/03 15:32:25 gregor Exp $
   #
   
  +use sys;
  +
   const int N = 100;
   var   int q = 1;
   
  +var num start_time;
  +
  +start_time = sys::timen();
  +
   while (q < N) {
     var int i, j, w = 1;
   
  @@ -31,9 +37,19 @@
       i++;
       j += i;
       w++;
  -#    print("$q, $w\n");
  +#    sys::print("$q, $w\n");
     }
   
     q++;
   }
  +
  +var num end_time;
  +
  +end_time = sys::timen();
  +
  +var num elapsed;
  +
  +elapsed = end_time - start_time;
  +
  +sys::print("Elapsed: $elapsed\n");
   
  
  
  
  1.3       +10 -9     parrot/languages/jako/examples/board.jako
  
  Index: board.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/board.jako,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- board.jako        3 Jul 2003 03:42:41 -0000       1.2
  +++ board.jako        3 Jul 2003 15:32:25 -0000       1.3
  @@ -7,40 +7,41 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: board.jako,v 1.2 2003/07/03 03:42:41 gregor Exp $
  +# $Id: board.jako,v 1.3 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub print :op (str s);
  +use sys;
   
   var int rank, file;
   var int temp;
   
   rank = 7;
   
  -print("  +---+---+---+---+---+---+---+---+\n");
  +sys::print("  +---+---+---+---+---+---+---+---+\n");
   
   while(rank >= 0) {
     temp = rank + 1;
     file = 0;
   
  -  print("$temp |");
  +  sys::print("$temp |");
   
     while(file < 8) {
       temp = rank + file;
       temp %= 2;
    
       if (temp == 1) {
  -      print("   |");
  +      sys::print("   |");
       } else {
  -      print(" * |");
  +      sys::print(" * |");
       }
   
       file++;
     }
   
  -  print("\n");
  -  print("  +---+---+---+---+---+---+---+---+\n");
  +  sys::print("\n");
  +  sys::print("  +---+---+---+---+---+---+---+---+\n");
     rank--;
   }
   
  -print("    A   B   C   D   E   F   G   H  \n");
  +sys::print("    A   B   C   D   E   F   G   H  \n");
  +
  
  
  
  1.4       +6 -5      parrot/languages/jako/examples/euclid.jako
  
  Index: euclid.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/euclid.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- euclid.jako       3 Jul 2003 03:42:41 -0000       1.3
  +++ euclid.jako       3 Jul 2003 15:32:25 -0000       1.4
  @@ -14,18 +14,18 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: euclid.jako,v 1.3 2003/07/03 03:42:41 gregor Exp $
  +# $Id: euclid.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub print :op (str a);
  +use sys;
   
   var int m, n, r;
   
   m = 96;
   n = 64;
   
  -print("Algorithm E (Euclid's algorithm)\n");
  -print("  Calculating gcd($m, $n) = ...\n");
  +sys::print("Algorithm E (Euclid's algorithm)\n");
  +sys::print("  Calculating gcd($m, $n) = ...\n");
   
   r = m % n;
   while (r != 0) {
  @@ -34,4 +34,5 @@
     r = m % n;
   } 
   
  -print("  ... = $n\n");
  +sys::print("  ... = $n\n");
  +
  
  
  
  1.4       +5 -5      parrot/languages/jako/examples/fact.jako
  
  Index: fact.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/fact.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- fact.jako 3 Jul 2003 03:42:41 -0000       1.3
  +++ fact.jako 3 Jul 2003 15:32:25 -0000       1.4
  @@ -9,10 +9,10 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: fact.jako,v 1.3 2003/07/03 03:42:41 gregor Exp $
  +# $Id: fact.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub print :op (str s);
  +use sys;
   
   const int N = 15;
   
  @@ -40,10 +40,10 @@
   
   var int f;
   
  -print("Algorithm F1 (The factorial function)\n");
  -print("    Calculating fact($N) = ...\n");
  +sys::print("Algorithm F1 (The factorial function)\n");
  +sys::print("    Calculating fact($N) = ...\n");
   
   f = fact(N);
   
  -print("    ... = $f\n");
  +sys::print("    ... = $f\n");
   
  
  
  
  1.4       +6 -5      parrot/languages/jako/examples/fib.jako
  
  Index: fib.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/fib.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- fib.jako  3 Jul 2003 03:42:41 -0000       1.3
  +++ fib.jako  3 Jul 2003 15:32:25 -0000       1.4
  @@ -7,10 +7,10 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: fib.jako,v 1.3 2003/07/03 03:42:41 gregor Exp $
  +# $Id: fib.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub print :op (str s);
  +use sys;
   
   const int n = 24;
   
  @@ -19,8 +19,8 @@
   var   int f =  1; 
   var   int i =  3;
   
  -print("Algorithm F2 (Fibonacci's function)\n");
  -print("  Calculating fib($n) = ...\n");
  +sys::print("Algorithm F2 (Fibonacci's function)\n");
  +sys::print("  Calculating fib($n) = ...\n");
   
   while (i <= n) {
     f = a + b;
  @@ -29,4 +29,5 @@
     i++;
   }
   
  -print("  ... = $f\n");
  +sys::print("  ... = $f\n");
  +
  
  
  
  1.4       +4 -3      parrot/languages/jako/examples/hello.jako
  
  Index: hello.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/hello.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- hello.jako        3 Jul 2003 03:42:41 -0000       1.3
  +++ hello.jako        3 Jul 2003 15:32:25 -0000       1.4
  @@ -7,9 +7,10 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: hello.jako,v 1.3 2003/07/03 03:42:41 gregor Exp $
  +# $Id: hello.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub print :op (str s);
  +use sys;
  +
  +sys::print("Hello, world!\n");
   
  -print("Hello, world!\n");
  
  
  
  1.4       +2 -2      parrot/languages/jako/examples/leibniz.jako
  
  Index: leibniz.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/leibniz.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- leibniz.jako      3 Jul 2003 03:42:41 -0000       1.3
  +++ leibniz.jako      3 Jul 2003 15:32:25 -0000       1.4
  @@ -16,7 +16,7 @@
   # license as the Parrot interpreter.
   #
   
  -sub print :op (str s);
  +use sys;
   
   const num first_den =       1.0;
   const num last_den  = 1000000.0;
  @@ -40,5 +40,5 @@
   var num pi;
   pi = 4.0 * cur_frac;
   
  -print("PI is (very) approximately: $pi\n");
  +sys::print("PI is (very) approximately: $pi\n");
   
  
  
  
  1.4       +53 -59    parrot/languages/jako/examples/life.jako
  
  Index: life.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/life.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- life.jako 3 Jul 2003 03:42:41 -0000       1.3
  +++ life.jako 3 Jul 2003 15:32:25 -0000       1.4
  @@ -10,18 +10,9 @@
   #     http://archive.develooper.com/[EMAIL PROTECTED]/msg13935.html
   #
   
  -sub num time   :op ();
  -sub     sleep  :op (int n);
  -sub     concat :op (str dest, str s);
  -sub int length :op (str dest);
  -sub str substr :op (str s, int i, int l);
  -
  -sub int initscr  :fnlib = "libcurses.so" ();
  -sub int endwin   :fnlib = "libcurses.so" ();
  -sub int curs_set :fnlib = "libcurses.so" (int x);
  -sub int addstr   :fnlib = "libcurses.so" (str s);
  -sub int refresh  :fnlib = "libcurses.so" ();
  -sub int move     :fnlib = "libcurses.so" (int x, int y);
  +use sys;
  +use string;
  +use Curses;
   
   var int foo; # Store result from above functions here.
   
  @@ -68,14 +59,14 @@
     offset += col;
   
     var int len;
  -  len = length(cells);
  -  foo = move(0, 19);
  -  foo = addstr("length(cells) == $len");
  -  foo = move(0, 20);
  -  foo = addstr("substr(cells, $offset, 1)");
  -  foo = move(0, 25);
  -  foo = refresh();
  -  temp = substr(cells, offset, 1);
  +  len = string::length(cells);
  +  foo = Curses::move(0, 19);
  +  foo = Curses::addstr("length(cells) == $len");
  +  foo = Curses::move(0, 20);
  +  foo = Curses::addstr("substr(cells, $offset, 1)");
  +  foo = Curses::move(0, 25);
  +  foo = Curses::refresh();
  +  temp = string::substr(cells, offset, 1);
   
     return 1 if (temp == "*");
     return 0;
  @@ -116,20 +107,23 @@
   
         var str ch;
         if (current != 0) {
  -        foo = move(0, 21);
  -        foo = addstr("substr(\"   *     \", $count, 1)");
  -        foo = move(0, 25);
  -        foo = refresh();
  -        ch = substr("   *     ", count, 1);
  +        foo = Curses::move(0, 21);
  +        foo = Curses::addstr("substr(\"   *     \", $count, 1)");
  +        foo = Curses::move(0, 25);
  +        foo = Curses::refresh();
  +
  +        ch = string::substr("   *     ", count, 1);
         }
         else {
  -        foo = move(0, 21);
  -        foo = addstr("substr(\"  **     \", $count, 1)");
  -        foo = move(0, 25);
  -        foo = refresh();
  -        ch = substr("  **     ", count, 1);
  +        foo = Curses::move(0, 21);
  +        foo = Curses::addstr("substr(\"  **     \", $count, 1)");
  +        foo = Curses::move(0, 25);
  +        foo = Curses::refresh();
  +
  +        ch = string::substr("  **     ", count, 1);
         }
  -      concat(temp, ch);
  +
  +      string::concat(temp, ch);
   
         col++;
       }
  @@ -147,8 +141,8 @@
   
   sub dump(str cells, int g)
   {
  -  foo = move(0, 0);
  -  foo = addstr("Generation $g of $G:");
  +  foo = Curses::move(0, 0);
  +  foo = Curses::addstr("Generation $g of $G:");
   
     var int row = 0;
     while (row < HEIGHT) {
  @@ -158,43 +152,43 @@
         current = at(cells, row, col);
   
         if (current == 1) {
  -        addstr("*");
  +        Curses::addstr("*");
         }
         else {
  -        addstr(" ");
  +        Curses::addstr(" ");
         }
       }
  -    addstr("\n");
  +    Curses::addstr("\n");
     }
   
  -  foo = move(0, 25);
  -  foo = refresh();
  +  foo = Curses::move(0, 25);
  +  foo = Curses::refresh();
   }
   
   
  -foo = initscr();
  -foo = curs_set(0);
  +foo = Curses::initscr();
  +foo = Curses::curs_set(0);
   
   var num start;
  -start = time();
  +start = sys::timen();
   
   var str cells = "";
   
  -concat(cells, r00);
  -concat(cells, r01);
  -concat(cells, r02);
  -concat(cells, r03);
  -concat(cells, r04);
  -concat(cells, r05);
  -concat(cells, r06);
  -concat(cells, r07);
  -concat(cells, r08);
  -concat(cells, r09);
  -concat(cells, r10);
  -concat(cells, r11);
  -concat(cells, r12);
  -concat(cells, r13);
  -concat(cells, r14);
  +string::concat(cells, r00);
  +string::concat(cells, r01);
  +string::concat(cells, r02);
  +string::concat(cells, r03);
  +string::concat(cells, r04);
  +string::concat(cells, r05);
  +string::concat(cells, r06);
  +string::concat(cells, r07);
  +string::concat(cells, r08);
  +string::concat(cells, r09);
  +string::concat(cells, r10);
  +string::concat(cells, r11);
  +string::concat(cells, r12);
  +string::concat(cells, r13);
  +string::concat(cells, r14);
   
   dump(cells, 0);
   
  @@ -203,9 +197,9 @@
   while (g < G) {
     cells = generate(cells);
     dump(cells, g);
  -  sleep(1);
  +  sys::sleep(1);
   }
   
  -foo = curs_set(1);
  -foo = endwin();
  +foo = Curses::curs_set(1);
  +foo = Curses::endwin();
   
  
  
  
  1.4       +5 -5      parrot/languages/jako/examples/mandelbrot.jako
  
  Index: mandelbrot.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/mandelbrot.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- mandelbrot.jako   3 Jul 2003 03:42:41 -0000       1.3
  +++ mandelbrot.jako   3 Jul 2003 15:32:25 -0000       1.4
  @@ -28,8 +28,8 @@
   # license as the Parrot interpreter.
   #
   
  -sub     print  :op (str s);
  -sub str substr :op (str s, int i, int l);
  +use sys;
  +use string;
   
   var str b = " .:,;!/>)|&IH%*#";
   
  @@ -104,8 +104,8 @@
   
   var str ch;
   
  -ch = substr(b, temp_int_4, temp_int_5);
  -print(ch);
  +ch = string::substr(b, temp_int_4, temp_int_5);
  +sys::print(ch);
   
   XLOOP:
   
  @@ -113,7 +113,7 @@
   
   YLOOP:
   
  -print("\n");
  +sys::print("\n");
   goto YREDO;
   
   END:
  
  
  
  1.5       +15 -16    parrot/languages/jako/examples/mandelzoom.jako
  
  Index: mandelzoom.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/mandelzoom.jako,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- mandelzoom.jako   3 Jul 2003 03:42:41 -0000       1.4
  +++ mandelzoom.jako   3 Jul 2003 15:32:25 -0000       1.5
  @@ -28,9 +28,8 @@
   # license as the Parrot interpreter.
   #
   
  -sub     print  :op (str s);
  -sub     sleep  :op (int n);
  -sub str substr :op (str s, int i, int l);
  +use sys;
  +use string;
   
   const str CHARS = " .:,;!/>)|&IH%*#";
   const int DEPTH = 112;
  @@ -132,13 +131,13 @@
   
         var str ch;
   
  -      ch = substr(CHARS, temp_int_4, temp_int_5);
  -      print(ch);
  +      ch = string::substr(CHARS, temp_int_4, temp_int_5);
  +      sys::print(ch);
       } continue {
         x += inc_x;
       }
   
  -    print("\n");
  +    sys::print("\n");
     } continue {
       y -= inc_y;
     }
  @@ -174,22 +173,22 @@
   
   var int i = 1;
   while (i < N) {
  -  print(CLS);
  +  sys::print(CLS);
     
  -  print("ITER:   $i of $N\n");
  -  print("WIDTH:  $WIDTH\n");
  -  print("HEIGHT: $HEIGHT\n");
  -  print("cx:     $cx\n");
  -  print("cy:     $cy\n");
  -  print("sx:     $sx\n");
  -  print("sy:     $sy\n");
  -  print("\n");
  +  sys::print("ITER:   $i of $N\n");
  +  sys::print("WIDTH:  $WIDTH\n");
  +  sys::print("HEIGHT: $HEIGHT\n");
  +  sys::print("cx:     $cx\n");
  +  sys::print("cy:     $cy\n");
  +  sys::print("sx:     $sx\n");
  +  sys::print("sy:     $sy\n");
  +  sys::print("\n");
    
     print_mandel(WIDTH, HEIGHT, cx, cy, sx, sy);
   
     sx  *= RATE;
     sy  *= RATE;
     i++;
  -#  sleep(1);
  +#  sys::sleep(1);
   }
   
  
  
  
  1.4       +12 -13    parrot/languages/jako/examples/mops.jako
  
  Index: mops.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/mops.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- mops.jako 3 Jul 2003 03:42:41 -0000       1.3
  +++ mops.jako 3 Jul 2003 15:32:25 -0000       1.4
  @@ -5,11 +5,10 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: mops.jako,v 1.3 2003/07/03 03:42:41 gregor Exp $
  +# $Id: mops.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub     print :op (str s);
  -sub num time  :op ();
  +use sys;
   
   var num start_time;
   var num end_time;
  @@ -24,23 +23,23 @@
   
   var   int loop_counter   = 0;
   
  -start_time     = time();
  +start_time     = sys::timen();
   while (loop_counter != num_iter) {
     loop_counter += loop_increment;
   }
  -end_time       = time();
  +end_time       = sys::timen();
   
   elapsed_time   = end_time - start_time;
   num_ops        = num_iter * ops_per_iter;
   ops_per_sec    = num_ops / elapsed_time;
   mops           = ops_per_sec / 1000000.0;
   
  -print("Iterations:    $num_iter\n");
  -print("Start time:    $start_time\n");
  -print("End time:      $end_time\n");
  -print("Elapsed time:  $elapsed_time\n");
  -print("Count:         $loop_counter\n");
  -print("Estimated ops: $num_ops\n");
  -print("op/s:          $ops_per_sec\n");
  -print("Mop/s:         $mops\n");
  +sys::print("Iterations:    $num_iter\n");
  +sys::print("Start time:    $start_time\n");
  +sys::print("End time:      $end_time\n");
  +sys::print("Elapsed time:  $elapsed_time\n");
  +sys::print("Count:         $loop_counter\n");
  +sys::print("Estimated ops: $num_ops\n");
  +sys::print("op/s:          $ops_per_sec\n");
  +sys::print("Mop/s:         $mops\n");
   
  
  
  
  1.3       +1 -15     parrot/languages/jako/examples/nci.jako
  
  Index: nci.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/nci.jako,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- nci.jako  3 Jul 2003 03:42:41 -0000       1.2
  +++ nci.jako  3 Jul 2003 15:32:25 -0000       1.3
  @@ -9,21 +9,7 @@
   # license as Parrot.
   #
   
  -module Curses
  -  :fnlib = "libcurses.so"
  -{
  -  sub int initscr  :fn ();
  -  sub int endwin   :fn ();
  -  sub int curs_set :fn (int x);
  -
  -  sub int addstr   :fn (str s);
  -  sub int refresh  :fn ();
  -  sub int move     :fn (int x, int y);
  -
  -  sub int getch    :fn ();
  -  sub int box      :fn (int screen, int v, int h);
  -  sub int hline    :fn (int ch, int n);
  -}
  +use Curses;
   
   var int foo; # Store result from above functions here.
   
  
  
  
  1.4       +6 -6      parrot/languages/jako/examples/primes.jako
  
  Index: primes.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/primes.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- primes.jako       3 Jul 2003 03:42:41 -0000       1.3
  +++ primes.jako       3 Jul 2003 15:32:25 -0000       1.4
  @@ -9,17 +9,17 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: primes.jako,v 1.3 2003/07/03 03:42:41 gregor Exp $
  +# $Id: primes.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub print :op (str s);
  +use sys;
   
   const int n = 100;
   
   var   int i =   2;
   
  -print("Algorithm P (Naiive primality test)\n");
  -print("  Printing primes up to $n...\n");
  +sys::print("Algorithm P (Naiive primality test)\n");
  +sys::print("  Printing primes up to $n...\n");
   
   NUMBER: while (i <= n) {
     var int m;
  @@ -37,10 +37,10 @@
       j++;
     }
   
  -  print("$i  ");
  +  sys::print("$i  ");
   } continue {
     i++;
   }
   
  -print("\n");
  +sys::print("\n");
   
  
  
  
  1.11      +27 -29    parrot/languages/jako/examples/queens.jako
  
  Index: queens.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/queens.jako,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -w -r1.10 -r1.11
  --- queens.jako       3 Jul 2003 03:42:41 -0000       1.10
  +++ queens.jako       3 Jul 2003 15:32:25 -0000       1.11
  @@ -7,13 +7,11 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: queens.jako,v 1.10 2003/07/03 03:42:41 gregor Exp $
  +# $Id: queens.jako,v 1.11 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub     print  :op (str s);
  -sub str substr :op (str s, int i, int l);
  -sub str concat :op (str s, str t);
  -sub int length :op (str s);
  +use sys;
  +use string;
   
   const int NUM_FILES = 8;
   const int NUM_RANKS = 8;
  @@ -37,18 +35,18 @@
     y = i + 1;
   
     var int z;
  -  z = length(board);
  +  z = string::length(board);
     z = z - y;
   
     var str prefix;
  -  prefix = substr(board, 0, x);
  +  prefix = string::substr(board, 0, x);
     var str suffix;
  -  suffix = substr(board, y, z);
  +  suffix = string::substr(board, y, z);
   
     var str temp;
     temp = prefix;
  -  temp = concat(temp, " ");
  -  temp = concat(temp, suffix);
  +  temp = string::concat(temp, " ");
  +  temp = string::concat(temp, suffix);
   
     return temp;
   }
  @@ -96,18 +94,18 @@
     y = i + 1;
   
     var int z;
  -  z = length(board);
  +  z = string::length(board);
     z = z - y;
   
     var str prefix;
  -  prefix = substr(board, 0, x);
  +  prefix = string::substr(board, 0, x);
     var str suffix;
  -  suffix = substr(board, y, z);
  +  suffix = string::substr(board, y, z);
   
     var str temp;
     temp = prefix;
  -  temp = concat(temp, "Q");
  -  temp = concat(temp, suffix);
  +  temp = string::concat(temp, "Q");
  +  temp = string::concat(temp, suffix);
   
     return temp;
   }
  @@ -161,11 +159,11 @@
     i += file;
    
     var int l;
  -  l = length(board);
  +  l = string::length(board);
   
   #  print("Board is $l characters long. Fetching character at index $i.\n");
   
  -  temp = substr(board, i, 1);
  +  temp = string::substr(board, i, 1);
   
     return temp;
   }
  @@ -237,12 +235,12 @@
   
     rank = 7;
   
  -  print("  +---+---+---+---+---+---+---+---+\n");
  +  sys::print("  +---+---+---+---+---+---+---+---+\n");
   
     while(rank >= 0) {
       temp = rank + 1;
   
  -    print("$temp |");
  +    sys::print("$temp |");
   
       file = 0;
       while(file < 8) {
  @@ -251,26 +249,26 @@
         result = queen_at(board, rank, file);
   
         if (result == 1) {
  -        print(" Q |");
  +        sys::print(" Q |");
         } else {
           temp = rank + file;
           temp %= 2;
    
           if (temp == 1) {
  -          print("   |");
  +          sys::print("   |");
           } else {
  -          print(" * |");
  +          sys::print(" * |");
           }
         }
         file++;
       }
   
  -    print("\n");
  -    print("  +---+---+---+---+---+---+---+---+\n");
  +    sys::print("\n");
  +    sys::print("  +---+---+---+---+---+---+---+---+\n");
       rank--;
     }
   
  -  print("    A   B   C   D   E   F   G   H  \n");
  +  sys::print("    A   B   C   D   E   F   G   H  \n");
   }
   
   
  @@ -284,20 +282,20 @@
     var int rank = 0;
     var int file = 0;
   
  -  print("Making new board with $NUM_RANKS ranks and $NUM_FILES files...\n");
  +  sys::print("Making new board with $NUM_RANKS ranks and $NUM_FILES files...\n");
   
     while (rank < NUM_RANKS) {
       file = 0;
       while (file < NUM_FILES) {
  -      board = concat(board, " ");
  +      board = string::concat(board, " ");
         file++;
       }
       rank++;
     }
   
     var int l;
  -  l = length(board);
  -  print("Board length is $l.\n");
  +  l = string::length(board);
  +  sys::print("Board length is $l.\n");
   
     return board;
   }
  
  
  
  1.2       +11 -9     parrot/languages/jako/examples/queens_array.jako
  
  Index: queens_array.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/queens_array.jako,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- queens_array.jako 8 Dec 2002 18:23:36 -0000       1.1
  +++ queens_array.jako 3 Jul 2003 15:32:25 -0000       1.2
  @@ -7,9 +7,11 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: queens_array.jako,v 1.1 2002/12/08 18:23:36 gregor Exp $
  +# $Id: queens_array.jako,v 1.2 2003/07/03 15:32:25 gregor Exp $
   #
   
  +use sys;
  +
   const int NO_QUEEN      = -1;
   
   const int NUM_FILES     = 8;
  @@ -60,36 +62,36 @@
   
     rank = 7;
   
  -  print("  +---+---+---+---+---+---+---+---+\n");
  +  sys::print("  +---+---+---+---+---+---+---+---+\n");
   
     while(rank >= 0) {
       temp = rank + 1;
       file = 0;
   
  -    print("$temp |");
  +    sys::print("$temp |");
   
       while(file < 8) {
         if (board[file] == rank) {
  -        print(" Q |");
  +        sys::print(" Q |");
         } else {
           temp = rank + file;
           temp %= 2;
    
           if (temp == 1) {
  -          print("   |");
  +          sys::print("   |");
           } else {
  -          print(" * |");
  +          sys::print(" * |");
           }
         }
         file++;
       }
   
  -    print("\n");
  -    print("  +---+---+---+---+---+---+---+---+\n");
  +    sys::print("\n");
  +    sys::print("  +---+---+---+---+---+---+---+---+\n");
       rank--;
     }
   
  -  print("    A   B   C   D   E   F   G   H  \n");
  +  sys::print("    A   B   C   D   E   F   G   H  \n");
   }
   
   
  
  
  
  1.4       +3 -3      parrot/languages/jako/examples/sub.jako
  
  Index: sub.jako
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/examples/sub.jako,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- sub.jako  3 Jul 2003 03:42:41 -0000       1.3
  +++ sub.jako  3 Jul 2003 15:32:25 -0000       1.4
  @@ -8,15 +8,15 @@
   # This program is free software. It is subject to the same
   # license as the Parrot interpreter.
   #
  -# $Id: sub.jako,v 1.3 2003/07/03 03:42:41 gregor Exp $
  +# $Id: sub.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
   #
   
  -sub print :op (str s);
  +use sys;
   
   var int x;
   
   sub printit (int x) {
  -  print("$x\n");
  +  sys::print("$x\n");
   }
   
   x = 42;
  
  
  
  1.7       +55 -8     parrot/languages/jako/lib/Jako/Lexer.pm
  
  Index: Lexer.pm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/lib/Jako/Lexer.pm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- Lexer.pm  3 Jul 2003 03:42:45 -0000       1.6
  +++ Lexer.pm  3 Jul 2003 15:32:26 -0000       1.7
  @@ -5,7 +5,7 @@
   # This program is free software. It is subject to the same license
   # as the Parrot interpreter.
   #
  -# $Id: Lexer.pm,v 1.6 2003/07/03 03:42:45 gregor Exp $
  +# $Id: Lexer.pm,v 1.7 2003/07/03 15:32:26 gregor Exp $
   #
   
   use strict;
  @@ -53,10 +53,10 @@
   
     my @tokens;
   
  -  if ($text =~ m{^(\s*([a-zA-Z][a-zA-Z0-9_]*)\s*:)(.*)$}) {
  +  if ($text =~ m{^(\s*([a-zA-Z][a-zA-Z0-9_]*)\s*:(?!:))(.*)$}) {
       push @tokens, Jako::Token->new(
         $file, $line, 'label', 'N', $2);
  -    $text = $3;
  +    $text = $3; # The "(?!:)" is non-capturing!
     }
   
     while (defined $text and $text ne '') {
  @@ -284,6 +284,7 @@
       #
   
       if ($text =~ m{^([a-zA-Z][a-zA-Z0-9_]*(::[a-zA-Z][a-zA-Z0-9_]*)*)(.*)$}) {
  +#printf STDERR "IDENT [%s:%d]: '%s'\n", $file, $line, $1;
         push @tokens, Jako::Token->new(
           $file, $line, 'ident', undef, $1);
         $text = $3;
  @@ -305,6 +306,26 @@
   
   
   #
  +# slurp_file()
  +#
  +
  +sub slurp_file
  +{
  +  my $self = shift;
  +  my ($file) = @_;
  +
  +  my $fh = FileHandle->new($file);
  +
  +  die "$0: IO Error. Unable to open file '$file' for reading.\n"
  +    unless $fh;
  +
  +  my @lines = <$fh>;
  +
  +  return @lines;
  +}
  +
  +
  +#
   # scan_file()
   #
   
  @@ -317,15 +338,41 @@
   
     my $line = 0;
   
  -  my $fh = FileHandle->new($file);
  +  my @lines = $self->slurp_file($file);
  +  unshift @lines, "#line 1 \"$file\"\n";
   
  -  die "$0: IO Error. Unable to open file '$file' for reading.\n"
  -    unless $fh;
  +  while(@lines) {
  +    $_ = shift @lines;
   
  -  while(<$fh>) {
       $line++;
  +
       last if m/^__EOF__\s*$/;
  +
  +    if 
(m/^\s*use\s+([a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*)\s*;\s*(.*?)\s*$/) {
  +
  +      my $use_file = $1;
  +      my $leftover = $3;
  +
  +#print STDERR "use $use_file;\n";
  +
  +      $use_file =~ s{::}{/}g;
  +      $use_file .= ".jako";
  +
  +      my @use_lines = $self->slurp_file($use_file);
  +
  +      unshift @use_lines, "#line 1 \"$use_file\"\n";
  +      push @use_lines, "#line $line \"$file\"\n";
  +      push @use_lines, defined $leftover ? "$leftover\n" : "\n";
  +
  +      unshift @lines, @use_lines;
  +    }
  +    elsif (m/^#line\s+(\d+)(\s+"(.*?)")?\s*$/) {
  +      $line = $1 - 1; # Will be incremented next iteration
  +      $file = $3 if defined $3;
  +    }
  +    else {
       $self->scan_line($_, $file, $line);
  +    }
     }
   
     push @{$self->{TOKENS}}, Jako::Token->new_eof($file, $line);
  
  
  
  1.8       +3 -2      parrot/languages/jako/lib/Jako/Construct/Expression/Call.pm
  
  Index: Call.pm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/jako/lib/Jako/Construct/Expression/Call.pm,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- Call.pm   3 Jul 2003 03:42:51 -0000       1.7
  +++ Call.pm   3 Jul 2003 15:32:27 -0000       1.8
  @@ -5,7 +5,7 @@
   # This program is free software. It is subject to the same license
   # as the Parrot interpreter.
   #
  -# $Id: Call.pm,v 1.7 2003/07/03 03:42:51 gregor Exp $
  +# $Id: Call.pm,v 1.8 2003/07/03 15:32:27 gregor Exp $
   #
   
   use strict;
  @@ -124,7 +124,8 @@
   
   #    $self->DEBUG(0, "Calling %s%s...", $name, ($op ? ' (op $op)' : ' as op'));
   
  -    $name = $op if defined $op;
  +    $name = $op->value if defined $op;
  +    $name =~ s/(^")|("$)//g; # Delete leading and trailing quotes;
   
       $name =~ s/^.*:://; # Delete namespaces from ops
   
  
  
  

Reply via email to