cvsuser     02/11/20 17:47:49

  Modified:    .        core.ops interpreter.c method_util.c nci.c string.c
               include/parrot method_util.h nci.h string_funcs.h
               languages/ruby interactive.pl
  Added:       classes  nci.pmc
  Log:
  Added in code to properly do native calls to library routines loaded via
  dlopen or its loval equivalent.
  
  Revision  Changes    Path
  1.229     +6 -5      parrot/core.ops
  
  Index: core.ops
  ===================================================================
  RCS file: /cvs/public/parrot/core.ops,v
  retrieving revision 1.228
  retrieving revision 1.229
  diff -u -w -r1.228 -r1.229
  --- core.ops  15 Nov 2002 05:49:06 -0000      1.228
  +++ core.ops  21 Nov 2002 01:47:44 -0000      1.229
  @@ -4275,10 +4275,11 @@
   
   Load a dynamic link library named $2 and store it in $1.
   
  -=item B<dlfunc>(out PMC, in PMC, in STR)
  +=item B<dlfunc>(out PMC, in PMC, in STR, in STR)
   
  -Look up symbol $3 in library $2, and put the corresponding sub object
  -in $1.
  +Look up symbol $3 in library $2 with signature $3, and put the
  +corresponding sub object in $1. Note that you need the signature so we
  +can build or find an appropriate thunking function.
   
   =item B<invoke>()
   
  @@ -4321,7 +4322,7 @@
     goto NEXT();
   }
   
  -op dlfunc (out PMC, in PMC, in STR) {
  +op dlfunc (out PMC, in PMC, in STR, in STR) {
     const char * name = string_to_cstring(interpreter, ($3));
   
     Parrot_csub_t p = (Parrot_csub_t)D2FPTR(Parrot_dlsym(($2)->data, name));
  @@ -4333,7 +4334,7 @@
        PANIC("Failed to link native method");
     }
   
  -  $1 = Parrot_new_csub(interpreter, p);
  +  $1 = Parrot_new_nci(interpreter, p, $4);
     goto NEXT();
   }
   
  
  
  
  1.118     +2 -2      parrot/interpreter.c
  
  Index: interpreter.c
  ===================================================================
  RCS file: /cvs/public/parrot/interpreter.c,v
  retrieving revision 1.117
  retrieving revision 1.118
  diff -u -w -r1.117 -r1.118
  --- interpreter.c     16 Nov 2002 10:35:58 -0000      1.117
  +++ interpreter.c     21 Nov 2002 01:47:44 -0000      1.118
  @@ -1,7 +1,7 @@
   /* interpreter.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: interpreter.c,v 1.117 2002/11/16 10:35:58 leo Exp $
  + *     $Id: interpreter.c,v 1.118 2002/11/21 01:47:44 dan Exp $
    *  Overview:
    *     The interpreter api handles running the operations
    *  Data Structure and Algorithms:
  @@ -22,7 +22,7 @@
   #  include "parrot/oplib/core_ops_cg.h"
   #endif
   
  -#define ATEXIT_DESTROY
  +/* #define ATEXIT_DESTROY */
   
   extern op_lib_t *PARROT_CORE_PREDEREF_OPLIB_INIT(void);
   
  
  
  
  1.8       +13 -1     parrot/method_util.c
  
  Index: method_util.c
  ===================================================================
  RCS file: /cvs/public/parrot/method_util.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- method_util.c     2 Nov 2002 14:57:47 -0000       1.7
  +++ method_util.c     21 Nov 2002 01:47:44 -0000      1.8
  @@ -1,7 +1,7 @@
   /* method_util.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: method_util.c,v 1.7 2002/11/02 14:57:47 josh Exp $
  + *     $Id: method_util.c,v 1.8 2002/11/21 01:47:44 dan Exp $
    *  Overview:
    *     Utility functions to handle Parrot calling conventions, lookup
    *     methods, etc.
  @@ -14,6 +14,18 @@
   
   #include "parrot/parrot.h"
   #include "parrot/method_util.h"
  +
  +/*
  + * Create a new native sub. (new way)
  + */
  +PMC *
  +Parrot_new_nci(struct Parrot_Interp *interp, Parrot_csub_t func, String *signature)
  +{
  +    PMC *ret = pmc_new(interp, enum_class_NCI);
  +    ret->cache.struct_val = (DPOINTER *)F2DPTR(func);
  +    ret->data = build_call_func(interp, signature);
  +    return ret;
  +}
   
   /*
    * Create a new native sub.
  
  
  
  1.2       +76 -9     parrot/nci.c
  
  Index: nci.c
  ===================================================================
  RCS file: /cvs/public/parrot/nci.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- nci.c     20 Nov 2002 17:46:46 -0000      1.1
  +++ nci.c     21 Nov 2002 01:47:44 -0000      1.2
  @@ -1,7 +1,7 @@
   /* nci.c
    *  Copyright: 2001, 2002 Yet Another Society
    *  CVS Info
  - *     $Id: nci.c,v 1.1 2002/11/20 17:46:46 dan Exp $
  + *     $Id: nci.c,v 1.2 2002/11/21 01:47:44 dan Exp $
    *  Overview:
    *     Native Call Interface routines. The code needed to build a
    *     parrot to C call frame is in here
  @@ -13,10 +13,76 @@
   
   #include "parrot/parrot.h"
   
  +#if !defined(CAN_BUILD_CALL_FRAMES)
  +/* All our static functions that call in various ways. Yes, terribly
  +   hackish, but that's just fine */
  +
  +/* Return void, take nothing */
  +static void pcf_v_v(struct Parrot_Interp *interpreter, PMC *self) {
  +  void (*pointer)();
  +  pointer = self->cache.struct_val;
  +  (void)(*pointer)();
  +  interpreter->ctx.int_reg.registers[0] = 0;
  +  interpreter->ctx.int_reg.registers[1] = 0;
  +  interpreter->ctx.int_reg.registers[2] = 0;
  +  interpreter->ctx.int_reg.registers[3] = 0;
  +  interpreter->ctx.int_reg.registers[4] = 0;
  +  return;
  +}
  +
  +/* Return int, take nothing */
  +static void pcf_i_v(struct Parrot_Interp *interpreter, PMC *self) {
  +  int (*pointer)();
  +  int return_data;
  +  pointer = self->cache.struct_val;
  +  return_data = (int)(*pointer)();
  +  interpreter->ctx.int_reg.registers[5] = return_data;
  +  interpreter->ctx.int_reg.registers[0] = 0;
  +  interpreter->ctx.int_reg.registers[1] = 1;
  +  interpreter->ctx.int_reg.registers[2] = 0;
  +  interpreter->ctx.int_reg.registers[3] = 0;
  +  interpreter->ctx.int_reg.registers[4] = 0;
  +  return;
  +}
  +
  +/* Return double, take nothing */
  +static void pcf_d_v(struct Parrot_Interp *interpreter, PMC *self) {
  +  double (*pointer)();
  +  double return_data;
  +  pointer = self->cache.struct_val;
  +  return_data = (double)(*pointer)();
  +  interpreter->ctx.int_reg.registers[0] = 0;
  +  interpreter->ctx.int_reg.registers[1] = 0;
  +  interpreter->ctx.int_reg.registers[2] = 0;
  +  interpreter->ctx.int_reg.registers[3] = 0;
  +  interpreter->ctx.int_reg.registers[4] = 1;
  +  return;
  +}
  +
  +/* Return double, take double */
  +static void pcf_d_d(struct Parrot_Interp *interpreter, PMC *self) {
  +  double (*pointer)();
  +  double return_data;
  +
  +  pointer = self->cache.struct_val;
  +  return_data = (double)(*pointer)(interpreter->ctx.num_reg.registers[5]);
  +  interpreter->ctx.num_reg.registers[5] = return_data;
  +  interpreter->ctx.int_reg.registers[0] = 0;
  +  interpreter->ctx.int_reg.registers[1] = 0;
  +  interpreter->ctx.int_reg.registers[2] = 0;
  +  interpreter->ctx.int_reg.registers[3] = 0;
  +  interpreter->ctx.int_reg.registers[4] = 1;
  +  return;
  +}
  +
  +#endif
  +
  +
  +
   /* This function serves a single purpose. It takes the function
      signature for a C function we want to call and returns a pointer
      to a function that can call it. */
  -void *build_call_func(Parrot_Interp *interpreter, String *signature) {
  +void *build_call_func(struct Parrot_Interp *interpreter, String *signature) {
   #if defined(CAN_BUILD_CALL_FRAMES)
     /* This would be a good place to put the code that builds the
        frames. Undoubtedly painfully platform-dependent */
  @@ -24,14 +90,15 @@
   #else
     /* And in here is the platform-independent way. Which is to say
        "here there be hacks" */
  +  if (0 == string_length(signature)) return pcf_v_v;
  +  if (!string_compare(interpreter, signature, string_from_c_string(interpreter, 
"i", 1)))
  +    return pcf_i_v;
  +  if (!string_compare(interpreter, signature, string_from_c_string(interpreter, 
"d", 1)))
  +    return pcf_d_v;
  +  if (!string_compare(interpreter, signature, string_from_c_string(interpreter, 
"dd", 2)))
  +    return pcf_d_d;
  +
     return NULL;
   #endif
   }
   
  -#if !defined(CAN_BUILD_CALL_FRAMES)
  -/* Return void, take nothing */
  -static void pcf_v_v(Parrot_Interp *interpreter, void (*pointer)()) {
  -  (void)(*pointer)();
  -  return;
  -}
  -#endif
  
  
  
  1.113     +10 -1     parrot/string.c
  
  Index: string.c
  ===================================================================
  RCS file: /cvs/public/parrot/string.c,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -w -r1.112 -r1.113
  --- string.c  18 Nov 2002 10:12:18 -0000      1.112
  +++ string.c  21 Nov 2002 01:47:44 -0000      1.113
  @@ -1,7 +1,7 @@
   /* string.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: string.c,v 1.112 2002/11/18 10:12:18 leo Exp $
  + *     $Id: string.c,v 1.113 2002/11/21 01:47:44 dan Exp $
    *  Overview:
    *     This is the api definitions for the string subsystem
    *  Data Structure and Algorithms:
  @@ -202,6 +202,15 @@
       return string_copy(interpreter, b);
   }
   
  +/*=for api string string_from_c_string
  + * Make a String from a passed in C string
  + */
  +STRING *
  +string_from_c_string(struct Parrot_Interp *interpreter, const void *buffer,
  +                     UINTVAL buflen) {
  +    return string_make(interpreter, buffer, buflen ? buflen : strlen(buffer),
  +                       NULL, 0, NULL);
  +}
   
   /*=for api string string_make
    * allocate memory for the string, copy information into it
  
  
  
  1.1                  parrot/classes/nci.pmc
  
  Index: nci.pmc
  ===================================================================
  /* NCI.pmc
   *  Copyright: 2002 Yet Another Society
   *  CVS Info
   *     $Id: nci.pmc,v 1.1 2002/11/21 01:47:46 dan Exp $
   *  Overview:
   *     The vtable functions for the native C call functions
   *  Data Structure and Algorithms:
   *  History:
   *     Initial revision by sean 2002/08/04
   *  Notes:
   *  References:
   */
  
  #include "parrot/parrot.h"
  #include "parrot/method_util.h"
  
  pmclass NCI {
  
      void init () {
      }
  
      INTVAL type () {
          return enum_class_NCI;
      }
  
      STRING* name () {
          return whoami;
      }
  
      PMC* clone () {
          return Parrot_new_csub(INTERP, 
(Parrot_csub_t)D2FPTR(SELF->cache.struct_val));
      }
  
      PMC* get_pmc () {
          return SELF;
      }
  
      INTVAL is_same (PMC* value) {
          return SELF == value;
      }
  
      void set_same (PMC* value) {
          SELF->cache.struct_val = value->cache.struct_val;
        SELF->data = value->data;
      }
  
      INTVAL is_equal (PMC* value) {
          return (SELF->vtable == value->vtable
                  && SELF->cache.struct_val == value->cache.struct_val
                && SELF->data == value->data);
      }
  
      INTVAL defined () {
          return SELF->data != NULL;
      }
  
      void* invoke (void * next) {
          Parrot_csub_t func = (Parrot_csub_t)SELF->data;
          func(INTERP, SELF);
          return next;
      }
  }
  
  
  
  1.4       +2 -1      parrot/include/parrot/method_util.h
  
  Index: method_util.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/method_util.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- method_util.h     21 Oct 2002 08:47:14 -0000      1.3
  +++ method_util.h     21 Nov 2002 01:47:47 -0000      1.4
  @@ -1,7 +1,7 @@
   /* method_util.h
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: method_util.h,v 1.3 2002/10/21 08:47:14 sfink Exp $
  + *     $Id: method_util.h,v 1.4 2002/11/21 01:47:47 dan Exp $
    *  Overview:
    *     Utilities to help in writing methods.
    *  Data Structure and Algorithms:
  @@ -27,6 +27,7 @@
   
   typedef INTVAL (*Parrot_csub_t)(struct Parrot_Interp * , PMC * );
   PMC * Parrot_new_csub(struct Parrot_Interp * interp, Parrot_csub_t func);
  +PMC * Parrot_new_nci(struct Parrot_Interp * interp, Parrot_csub_t func, String 
*signature);
   
   struct method_rec_t {
       char * name;
  
  
  
  1.2       +2 -2      parrot/include/parrot/nci.h
  
  Index: nci.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/nci.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- nci.h     20 Nov 2002 17:50:13 -0000      1.1
  +++ nci.h     21 Nov 2002 01:47:47 -0000      1.2
  @@ -1,7 +1,7 @@
   /* nci.h
    *  Copyright: 2002 Yet Another Society
    *  CVS Info
  - *     $Id: nci.h,v 1.1 2002/11/20 17:50:13 dan Exp $
  + *     $Id: nci.h,v 1.2 2002/11/21 01:47:47 dan Exp $
    *  Overview:
    *     The nci api handles building native call frames
    *  Data Structure and Algorithms:
  @@ -15,6 +15,6 @@
   
   #include "parrot/parrot.h"
   
  -void *build_call_func(Parrot_Interp *, String *);
  +void *build_call_func(struct Parrot_Interp *, String *);
   
   #endif
  
  
  
  1.20      +2 -1      parrot/include/parrot/string_funcs.h
  
  Index: string_funcs.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/string_funcs.h,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -w -r1.19 -r1.20
  --- string_funcs.h    7 Nov 2002 15:19:08 -0000       1.19
  +++ string_funcs.h    21 Nov 2002 01:47:47 -0000      1.20
  @@ -1,7 +1,7 @@
   /* string_funcs.h
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: string_funcs.h,v 1.19 2002/11/07 15:19:08 leo Exp $
  + *     $Id: string_funcs.h,v 1.20 2002/11/21 01:47:47 dan Exp $
    *  Overview:
    *     This is the api header for the string subsystem
    *  Data Structure and Algorithms:
  @@ -20,6 +20,7 @@
   INTVAL string_compute_strlen(STRING *);
   STRING *string_concat(struct Parrot_Interp *, STRING *, STRING *, UINTVAL);
   STRING *string_append(struct Parrot_Interp *, STRING *, STRING *, UINTVAL);
  +STRING *string_from_c_string(struct Parrot_Interp *, const void *, UINTVAL);
   STRING *string_repeat(struct Parrot_Interp *, const STRING *, UINTVAL,
                         STRING **);
   STRING *string_chopn(STRING *, INTVAL);
  
  
  
  1.2       +13 -2     parrot/languages/ruby/interactive.pl
  
  Index: interactive.pl
  ===================================================================
  RCS file: /cvs/public/parrot/languages/ruby/interactive.pl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- interactive.pl    12 Aug 2002 05:06:33 -0000      1.1
  +++ interactive.pl    21 Nov 2002 01:47:49 -0000      1.2
  @@ -2,7 +2,7 @@
   
   use strict;
   use lib '.';
  -use YAML;
  +use Data::Dumper;
   use Term::ReadLine;
   use Parse::RecDescent;
   use Ruby;
  @@ -21,8 +21,19 @@
       $::RD_TRACE = 0;
       print "Trace off\n";
     }
  +  elsif($text =~ /^<(.*)/) {
  +      my ($fh, $file_data);
  +      open $fh, $text;
  +      local $/;
  +      $file_data = <$fh>;
  +#      $file_data =~ s/\cJ/ /g;
  +#      $file_data =~ s/\cM/ /g;
  +      print $file_data, "\n";
  +      my $return = Data::Dumper->Dump($grammar->program($file_data));
  +      print $return;
  +  }
     else {
  -    my $return = Dump($grammar->program($text));
  +    my $return = Data::Dumper->Dump($grammar->program($text));
       print $return;
     }
   }
  
  
  


Reply via email to