cvsuser     03/03/18 01:28:18

  Modified:    languages/imcc/docs calling_conventions.pod running.pod
               languages/imcc imcc.l imcc.y
               languages/imcc/t/syn bsr.t
  Log:
  imcc-syntax: nameclash with call; stack calling conventions
  
  Revision  Changes    Path
  1.2       +13 -7     parrot/languages/imcc/docs/calling_conventions.pod
  
  Index: calling_conventions.pod
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/docs/calling_conventions.pod,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- calling_conventions.pod   5 Mar 2003 16:08:52 -0000       1.1
  +++ calling_conventions.pod   18 Mar 2003 09:28:14 -0000      1.2
  @@ -31,26 +31,32 @@
      call _foo #(r, s) = _foo(x,y)
      .local int r
      .local int s
  -   .result s # restore results in reversed order
  -   .result r # [1]
  +   .result r # restore results in order
  +   .result s #
   
  -and return values are B<restore>d in reversed order from there.
  +and return values are B<restore>d in argument order from there.
   
   The subroutine is responsible for preserving registers.
   
    .sub _foo           # sub foo(int a, int b)
      saveall
  -   .param int a
  +   .param int a         # receive arguments from left to right
      .param int b
      ...
   
  -   .return pl                # return (pl, mi)
  -   .return mi                # [1]
  +   .return mi                # return (pl, mi), push results
  +   .return pl                # in reverse order
      restoreall
      ret
    .end
   
  -[1] or vice versa?
  +=head2 Rational
  +
  +Pushing arguments in reversed order on the user stack makes the left
  +most argument the top of stack entry. This allows for a variable
  +amount of function arguments (and return values), where the left most
  +argument before a variable amount of following arguments is the
  +argument count.
   
   =head2 Status
   
  
  
  
  1.8       +3 -1      parrot/languages/imcc/docs/running.pod
  
  Index: running.pod
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/docs/running.pod,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- running.pod       20 Feb 2003 08:04:20 -0000      1.7
  +++ running.pod       18 Mar 2003 09:28:14 -0000      1.8
  @@ -69,8 +69,10 @@
   
   =item -v, --verbose
   
  -One I<-v> shows, which files are worked on, two give you a summary
  +One B<-v> shows, which files are worked on and prints a summary
   over register usage and optimization stats perl I<compilation unit>.
  +With two B<-v> switches IMCC prints a line per individual processing
  +step too.
   
   =item -y, --yydebug
   
  
  
  
  1.33      +4 -4      parrot/languages/imcc/imcc.l
  
  Index: imcc.l
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/imcc.l,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -w -r1.32 -r1.33
  --- imcc.l    4 Mar 2003 15:45:34 -0000       1.32
  +++ imcc.l    18 Mar 2003 09:28:15 -0000      1.33
  @@ -301,10 +301,10 @@
           return(STRINGC);
       }
   
  -<*>\$I[0-9]+          DUP_AND_RET(valp, IREG);
  -<*>\$N[0-9]+          DUP_AND_RET(valp, NREG);
  -<*>\$S[0-9]+          DUP_AND_RET(valp, SREG);
  -<*>\$P[0-9]+          DUP_AND_RET(valp, PREG);
  +<INITIAL>\$I[0-9]+          DUP_AND_RET(valp, IREG);
  +<INITIAL>\$N[0-9]+          DUP_AND_RET(valp, NREG);
  +<INITIAL>\$S[0-9]+          DUP_AND_RET(valp, SREG);
  +<INITIAL>\$P[0-9]+          DUP_AND_RET(valp, PREG);
   
   <emit,INITIAL>{WS}+ /* skip */;
   
  
  
  
  1.54      +2 -4      parrot/languages/imcc/imcc.y
  
  Index: imcc.y
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/imcc.y,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -w -r1.53 -r1.54
  --- imcc.y    5 Mar 2003 16:08:50 -0000       1.53
  +++ imcc.y    18 Mar 2003 09:28:15 -0000      1.54
  @@ -524,10 +524,8 @@
       |   RESULT var                   { $$ = MK_I(interp, "restore", R1($2)); }
       |   ARG var                              { $$ = MK_I(interp, "save", R1($2)); }
       |   RETURN var                   { $$ = MK_I(interp, "save", R1($2)); }
  -    |   CALL IDENTIFIER                      { $$ = MK_I(interp, "bsr",
  -                                              R1(mk_address($2, U_add_once)));}
  -    |   GOTO IDENTIFIER                      { $$ = MK_I(interp, "branch",
  -                                              R1(mk_address($2, U_add_once)));}
  +    |   CALL var_or_i                        { $$ = MK_I(interp, "bsr",  R1($2)); }
  +    |   GOTO var_or_i                        { $$ = MK_I(interp, "branch",R1($2)); }
       |   INC var                              { $$ = MK_I(interp, "inc",R1($2)); }
       |   DEC var                              { $$ = MK_I(interp, "dec",R1($2)); }
       |   SAVEALL                              { $$ = MK_I(interp, "saveall" ,R0()); }
  
  
  
  1.5       +218 -39   parrot/languages/imcc/t/syn/bsr.t
  
  Index: bsr.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/t/syn/bsr.t,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- bsr.t     4 Mar 2003 15:45:36 -0000       1.4
  +++ bsr.t     18 Mar 2003 09:28:17 -0000      1.5
  @@ -1,6 +1,6 @@
   #!perl
   use strict;
  -use TestCompiler tests => 4;
  +use TestCompiler tests => 10;
   use Test::More qw(skip);
   
   ##############################
  @@ -25,39 +25,6 @@
   OUT
   
   ##############################
  -# this is considered a non local bsr
  -#
  -output_is(<<'CODE', <<'OUT', "recursive bsr with saveall");
  -.sub _test
  -   $I0 = 5
  -   $I1 = $I0
  -   bsr _fact
  -   print $I1
  -   print "\n"
  -   end
  -_fact:
  -   save $I0
  -   save $I1
  -   saveall
  -   restore $I1
  -   restore $I0
  -   if $I0 <= 1 goto fin
  -   dec $I0
  -   $I1 = $I1 * $I0
  -   bsr _fact
  -fin:
  -   save $I1
  -   restoreall
  -   restore $I1
  -   ret
  -.end
  -
  -CODE
  -120
  -OUT
  -
  -
  -##############################
   output_is(<<'CODE', <<'OUT', "stack calling conventions");
   .sub _main
      .local int x
  @@ -69,8 +36,8 @@
      call _foo #(r, s) = _foo(x,y)
      .local int r
      .local int s
  -   .result s # restore results in reversed order
  -   .result r
  +   .result r # restore results in order
  +   .result s
   
      print "r = "
      print r
  @@ -95,8 +62,8 @@
      .local int mi
      pl = a + b
      mi = a - b
  +   .return mi                # from right to left
      .return pl                # return (pl, mi)
  -   .return mi
      restoreall
      ret
   .end
  @@ -126,8 +93,8 @@
      .local int mi
      pl = a + b
      mi = a - b
  +   .return mi                # from right to left
      .return pl                # return (pl, mi)
  -   .return mi
      restoreall
      ret
   .end
  @@ -144,8 +111,8 @@
      call _foo #(r, s) = _foo(x,y)
      .local int r
      .local int s
  -   .result s # restore results in reversed order
      .result r
  +   .result s # restore results in order
   
      print "r = "
      print r
  @@ -161,6 +128,218 @@
   b = 20
   r = 30
   s = -10
  +OUT
  +
  +##############################
  +#
  +output_is(<<'CODE', <<'OUT', "fact with stack calling conventions");
  +.sub _main
  +    .local int counter
  +    counter = 5
  +    .arg counter
  +    call _fact
  +    .local int product
  +    .result product
  +    print product
  +    print "\n"
  +    end
  +.end
  +
  +.sub _fact
  +    saveall
  +    .param int N
  +    .local int prod
  +    prod = 1
  +L1:
  +    prod = prod * N
  +    dec N
  +    if N > 0 goto L1
  +    .return prod
  +    restoreall
  +    ret
  +.end
  +CODE
  +120
  +OUT
  +
  +
  +##############################
  +# this is considered a non local bsr
  +#
  +output_is(<<'CODE', <<'OUT', "recursive bsr with saveall");
  +.sub _test
  +   $I0 = 5   # count
  +   $I1 = 1   # product
  +   save $I0
  +   save $I1
  +   bsr _fact
  +   restore $I1
  +   print $I1
  +   print "\n"
  +   end
  +_fact:
  +   saveall
  +   restore $I1
  +   restore $I0
  +   if $I0 <= 1 goto fin
  +   $I1 = $I1 * $I0
  +   dec $I0
  +   save $I0
  +   save $I1
  +   bsr _fact
  +   restore $I1
  +fin:
  +   save $I1
  +   restoreall
  +   ret
  +.end
  +
  +CODE
  +120
  +OUT
  +
  +##############################
  +# tail recursion - caller saves
  +output_is(<<'CODE', <<'OUT', "tail recursive bsr");
  +.sub _test
  +   $I0 = 5   # count
  +   $I1 = 1   # product
  +   saveall
  +   bsr _fact
  +   save $I1
  +   restoreall
  +   restore $I1
  +   print $I1
  +   print "\n"
  +   end
  +_fact:
  +   if $I0 <= 1 goto fin
  +   $I1 = $I1 * $I0
  +   dec $I0
  +   saveall
  +   bsr _fact
  +   save $I1
  +   restoreall
  +   restore $I1
  +fin:
  +   ret
  +.end
  +
  +CODE
  +120
  +OUT
  +
  +##############################
  +# tail recursion - caller saves
  +output_is(<<'CODE', <<'OUT', "tail recursive bsr 2");
  +.sub _test
  +   $I0 = 5   # count
  +   $I1 = 1   # product
  +   saveall
  +   bsr _fact
  +   save $I1
  +   restoreall
  +   restore $I1
  +   print $I1
  +   print "\n"
  +   end
  +_fact:
  +   if $I0 <= 1 goto fin
  +   $I1 = $I1 * $I0
  +   dec $I0
  +   bsr _fact
  +fin:
  +   ret
  +.end
  +
  +CODE
  +120
  +OUT
  +
  +##############################
  +# tail recursion - caller saves
  +output_is(<<'CODE', <<'OUT', "tail recursive bsr - opt");
  +.sub _test
  +   $I0 = 5   # count
  +   $I1 = 1   # product
  +   saveall
  +   bsr _fact
  +   save $I1
  +   restoreall
  +   restore $I1
  +   print $I1
  +   print "\n"
  +   end
  +_fact:
  +   if $I0 <= 1 goto fin
  +   $I1 = $I1 * $I0
  +   dec $I0
  +   branch _fact
  +fin:
  +   ret
  +.end
  +
  +CODE
  +120
  +OUT
  +
  +##############################
  +# tail recursion - caller saves - parrot calling convention
  +output_is(<<'CODE', <<'OUT', "tail recursive bsr, parrot cc");
  +.sub _test
  +   I6 = 5    # count
  +   I5 = 1    # product
  +   P0 = new Sub
  +   $I0 = addr _fact
  +   set P0, $I0
  +   saveall
  +   invoke
  +   save I5
  +   restoreall
  +   restore $I0
  +   print $I0
  +   print "\n"
  +   end
  +# the callers args I5, I6 are used to do the calculation and have
  +# the same state after, so instead of calling again the sub, just
  +# a branch to the entry is done
  +_fact:
  +   if I6 <= 1 goto fin
  +   I5 = I5 * I6
  +   dec I6
  +   branch _fact
  +fin:
  +   ret
  +.end
  +
  +CODE
  +120
  +OUT
  +
  +##############################
  +# coroutine
  +output_is(<<'CODE', <<'OUT', "coroutine");
  +.sub _main
  +    .local Coroutine co
  +    co = new Coroutine
  +    $I0 = addr _routine
  +    co = $I0
  +    print "Hello"
  +    invoke co
  +    print "perl6"
  +    invoke co
  +    print "\n"
  +    end
  +
  +_routine:
  +    print " "
  +    invoke co
  +    print "."
  +    invoke co
  +
  +.end
  +CODE
  +Hello perl6.
   OUT
   
   END {
  
  
  

Reply via email to