Changeset 3937 for src/perl5

Show
Ignore:
Timestamp:
05/27/05 02:08:48 (4 years ago)
Author:
clkao
svk:copy_cache_prev:
5515
Message:

Apply more ducktapes.

Location:
src/perl5
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/perl5/perl5.c

    r3936 r3937  
    1212static PerlInterpreter *my_perl; 
    1313 
    14 const char eval_file_code[] = 
     14int __init = 0; 
     15 
     16const char pugs_guts_code[] = 
    1517"use strict;" 
    1618"package pugs;" 
     
    1921"sub AUTOLOAD { }" 
    2022"warn 'perl5 glue compiled';" 
    21 //"pugs::guts::test();" 
    22  
    23 "package pugs::code;" 
    24 "sub new { }" 
     23 
     24"package pugs::guts;" 
     25"sub code { my ($class, $val) = @_;" 
     26"          sub { pugs::guts::invoke($val, undef, @_) } }" 
    2527"1;"; 
    2628 
    27 XS(_pugs_guts_test) { 
     29XS(_pugs_guts_invoke) { 
     30    Val *val, *inv, **stack; 
     31    SV *ret; 
     32    int i; 
    2833    dXSARGS; 
    29     if (items != 1) 
     34    if (items < 1) 
    3035        Perl_croak(aTHX_ "hate software"); 
    3136 
     37    val = pugs_SvToVal(ST(0)); 
     38    inv = pugs_SvToVal(ST(1)); 
     39 
     40    stack = (Val **)malloc(sizeof(Val*)*items-2); 
     41    for (i = 2; i < items; ++i) { 
     42        stack[i-2] = pugs_SvToVal(ST(i)); 
     43    } 
     44 
     45    fprintf(stderr, "back to pugs\n"); 
     46    ret = pugs_ValToSv(pugs_Apply (val, inv, stack)); 
     47 
     48    free (stack); 
     49     
    3250    XSRETURN(1); 
    3351} 
     
    117135 
    118136    exitstatus = perl_parse(my_perl, xs_init, argc, argv, (char **)NULL); 
     137    fprintf(stderr, "hello, perl5: %d\n", exitstatus); 
    119138 
    120139    if (exitstatus == 0) 
    121140        exitstatus = perl_run( my_perl ); 
    122     return exitstatus; 
    123  
     141 
     142    __init = 1; 
    124143    fprintf(stderr, "hello, perl5\n"); 
    125144 
    126     newXS((char*) "pugs::guts::test", _pugs_guts_test, (char*)__FILE__); 
    127  
    128     eval_pv(eval_file_code, FALSE); 
     145    newXS((char*) "pugs::guts::invoke", _pugs_guts_invoke, (char*)__FILE__); 
     146 
     147    eval_pv(pugs_guts_code, TRUE); 
    129148 
    130149    if (SvTRUE(ERRSV)) { 
  • src/perl5/pugsembed.c

    r3934 r3937  
    11#include <pugsembed.h> 
     2extern int __init; 
    23 
    34Val * 
     
    1516{ 
    1617    SV *sv = newSV(0); 
     18    Val *isa[2]; 
     19    SV *stack[8]; 
     20 
    1721    fprintf(stderr, "pugs mkvalref: %p\n", val); 
    18     Val *isa[2]; 
     22    sv_setref_pv(sv, "pugs", val); 
     23 
    1924    isa[0] = pugs_PvToVal("Code"); 
    2025    isa[1] = NULL; 
    21     if (pugs_ValToIv(pugs_Apply(pugs_PvToVal("&isa"), val, isa))) { 
     26    if (__init && pugs_ValToIv(pugs_Apply(pugs_PvToVal("&isa"), val, isa))) { 
    2227        fprintf(stderr, "got a code!!\n"); 
     28        stack[0] = newSVpv("pugs::guts", 0); 
     29        stack[1] = sv; 
     30        sv = perl5_call("code", 2, stack, NULL, G_SCALAR); 
    2331    } 
    24     sv_setref_pv(sv, "pugs", val); 
    2532    return (sv); 
    2633}