I've committed the following patch, which allows vtable
ops to be called for some of the simpler functions. Yes,
I know we don't actually have the vtable methods yet, but
I'm working on it; I'll try and have some of them done by
the end of the day.

The tricky part is making them maintainable.

  Index: Makefile.in
  ===================================================================
  RCS file: /home/perlcvs/parrot/Makefile.in,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -w -r1.34 -r1.35
  --- Makefile.in       2001/10/18 01:15:11     1.34
  +++ Makefile.in       2001/10/18 11:33:47     1.35
  @@ -7,11 +7,12 @@
   $(INC)/register.h $(INC)/string.h $(INC)/events.h $(INC)/interpreter.h \
   $(INC)/memory.h $(INC)/parrot.h $(INC)/stacks.h $(INC)/packfile.h \
   $(INC)/global_setup.h $(INC)/vtable.h $(INC)/oplib/core_ops.h \
  -$(INC)/runops_cores.h $(INC)/trace.h
  +$(INC)/runops_cores.h $(INC)/trace.h $(INC)/oplib/vtable_ops.h
   
   O_FILES = global_setup$(O) interpreter$(O) parrot$(O) register$(O) \
   core_ops$(O) memory$(O) packfile$(O) stacks$(O) string$(O) strnative$(O) \
  -strutf8$(O) strutf16$(O) strutf32$(O) transcode$(O) runops_cores$(O) trace$(O)
  +strutf8$(O) strutf16$(O) strutf32$(O) transcode$(O) runops_cores$(O) \
  +trace$(O) vtable_ops$(O)
   
   #DO NOT ADD C COMPILER FLAGS HERE
   #Add them in Configure.pl--look for the
  @@ -52,6 +53,9 @@
   Parrot/OpLib/core.pm: core.ops ops2pm.pl
        $(PERL) ops2pm.pl core.ops
   
  +Parrot/OpLib/vtable.pm: vtable.ops ops2pm.pl
  +     $(PERL) ops2pm.pl vtabls.ops
  +
   examples/assembly/mops.c: examples/assembly/mops.pbc pbc2c.pl
        $(PERL) pbc2c.pl examples/assembly/mops.pbc > examples/assembly/mops.c
   
  @@ -89,6 +93,12 @@
   core_ops.c $(INC)/oplib/core_ops.h: core.ops ops2c.pl
        $(PERL) ops2c.pl core.ops
   
  +vtable.ops: make_vtable_ops.pl
  +     $(PERL) make_vtable_ops.pl > vtable.ops
  +
  +vtable_ops.c $(INC)/oplib/vtable_ops.h: vtable.ops ops2c.pl
  +     $(PERL) ops2c.pl vtable.ops
  +
   $(INC)/config.h: Configure.pl config_h.in
        $(PERL) Configure.pl
   
  @@ -104,6 +114,7 @@
        $(RM_F) *$(O) *.s core_ops.c $(TEST_PROG) $(PDISASM) $(PDUMP)
        $(RM_F) $(INC)/vtable.h
        $(RM_F) $(INC)/oplib/core_ops.h
  +     $(RM_F) $(INC)/oplib/vtable_ops.h vtable_ops.c vtable.ops
        $(RM_F) $(TEST_PROG) $(PDISASM) $(PDUMP)
        $(RM_F) examples/assembly/mops$(EXE) examples/assembly/mops.c
        $(RM_F) examples/assembly/mops$(O) examples/assembly/mops.pbc
  
  
  
  1.4       +1 -1      parrot/vtable.tbl
  
  Index: vtable.tbl
  ===================================================================
  RCS file: /home/perlcvs/parrot/vtable.tbl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- vtable.tbl        2001/10/10 14:32:56     1.3
  +++ vtable.tbl        2001/10/18 11:33:47     1.4
  @@ -35,7 +35,7 @@
   num  void multiply           PMC* left        PMC* right 
   num  void divide             PMC* left        PMC* right 
   num  void modulus            PMC* left        PMC* right 
  -num  void concatenate        PMC* left        PMC* right 
  +str  void concatenate        PMC* left        PMC* right 
   unique       void is_equal           PMC* left 
   unique       void logical_or         PMC* left        PMC* right 
   unique       void logical_and        PMC* left        PMC* right 
  
  
  
  1.1                  parrot/make_vtable_ops.pl
  
  Index: make_vtable_ops.pl
  ===================================================================
  use Parrot::Vtable;
  my %vtable = parse_vtable();
  
  while (<DATA>) {
      next if /^#/ or /^$/;
      my @params = split;
      my $op = $params[1];
      my $vtable_entry = $params[2] || $op;
      die "Can't find $vtable_entry in vtable, line $.\n"
          unless exists $vtable{$vtable_entry};
      print "AUTO_OP $params[1] (".(join ", ", ("p")x$params[0]).") {\n";
      if ($params[0] == 3) {
          # Three-address function
          print "\t\$2->vtable->vtable_funcs[VTABLE_";
          print uc $vtable_entry;
          print multimethod($vtable_entry);
          print ']($2,$3,$1);';
          print "\n}\n";
      }
  }
  
  sub multimethod {
      my $type = $vtable{$_[0]}{meth_type};
      return ""               if $type eq "unique";
      return ' + $3->vtable->num_type' if $type eq "num";
      return ' + $3->vtable->string_type' if $type eq "str";
      die "Coding error - undefined type $type\n";
  }
  
  
  __DATA__
  # Three-address functions
  3 add
  3 sub subtract
  3 mul multiply
  3 div divide
  3 mod modulus
  3 concat concatenate
  
  
  
-- 
A witty saying means nothing.  -Voltaire

Reply via email to