diff options
author | Tom Hughes <tom@compton.nu> | 1999-04-24 19:11:59 +0100 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-05-10 03:48:08 +0000 |
commit | b295d1132eed0f33e5e8fda2cd65ee1297fdabdb (patch) | |
tree | 2cc2bb16f505a1d5c1a468bdce46a301cdf37e84 /ext | |
parent | f2f614a63111e79068118dba78b4ac57891a3382 (diff) | |
download | perl-b295d1132eed0f33e5e8fda2cd65ee1297fdabdb.tar.gz |
applied suggested patch, with win32 and PERL_OBJECT additions
Message-ID: <609bdff748.tom@compton.compton.nu>
Subject: ByteLoader patch
p4raw-id: //depot/perl@3356
Diffstat (limited to 'ext')
-rw-r--r-- | ext/B/B.xs | 5 | ||||
-rw-r--r-- | ext/B/B/Asmdata.pm | 7 | ||||
-rw-r--r-- | ext/B/B/Bytecode.pm | 3 | ||||
-rw-r--r-- | ext/B/B/Debug.pm | 3 | ||||
-rw-r--r-- | ext/ByteLoader/ByteLoader.pm | 45 | ||||
-rw-r--r-- | ext/ByteLoader/ByteLoader.xs | 64 | ||||
-rw-r--r-- | ext/ByteLoader/Makefile.PL | 10 |
7 files changed, 133 insertions, 4 deletions
diff --git a/ext/B/B.xs b/ext/B/B.xs index ccac053da9..dd50d978ac 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -808,6 +808,7 @@ LOOP_lastop(o) #define COP_cop_seq(o) o->cop_seq #define COP_arybase(o) o->cop_arybase #define COP_line(o) o->cop_line +#define COP_warnings(o) o->cop_warnings MODULE = B PACKAGE = B::COP PREFIX = COP_ @@ -835,6 +836,10 @@ U16 COP_line(o) B::COP o +B::SV +COP_warnings(o) + B::COP o + MODULE = B PACKAGE = B::SV PREFIX = Sv U32 diff --git a/ext/B/B/Asmdata.pm b/ext/B/B/Asmdata.pm index f3e57a17d0..ddc391b388 100644 --- a/ext/B/B/Asmdata.pm +++ b/ext/B/B/Asmdata.pm @@ -136,9 +136,10 @@ $insn_data{cop_filegv} = [112, \&PUT_svindex, "GET_svindex"]; $insn_data{cop_seq} = [113, \&PUT_U32, "GET_U32"]; $insn_data{cop_arybase} = [114, \&PUT_I32, "GET_I32"]; $insn_data{cop_line} = [115, \&PUT_U16, "GET_U16"]; -$insn_data{main_start} = [116, \&PUT_opindex, "GET_opindex"]; -$insn_data{main_root} = [117, \&PUT_opindex, "GET_opindex"]; -$insn_data{curpad} = [118, \&PUT_svindex, "GET_svindex"]; +$insn_data{cop_warnings} = [116, \&PUT_svindex, "GET_svindex"]; +$insn_data{main_start} = [117, \&PUT_opindex, "GET_opindex"]; +$insn_data{main_root} = [118, \&PUT_opindex, "GET_opindex"]; +$insn_data{curpad} = [119, \&PUT_svindex, "GET_svindex"]; my ($insn_name, $insn_data); while (($insn_name, $insn_data) = each %insn_data) { diff --git a/ext/B/B/Bytecode.pm b/ext/B/B/Bytecode.pm index de2bf99180..29683b899b 100644 --- a/ext/B/B/Bytecode.pm +++ b/ext/B/B/Bytecode.pm @@ -293,6 +293,8 @@ sub B::COP::bytecode { my $filegv = $op->filegv; my $filegvix = $filegv->objix; my $line = $op->line; + my $warnings = $op->warnings; + my $warningsix = $warnings->objix; if ($debug_bc) { printf "# line %s:%d\n", $filegv->SV->PV, $line; } @@ -305,6 +307,7 @@ cop_seq %d cop_filegv $filegvix cop_arybase %d cop_line $line +cop_warnings $warningsix EOT $filegv->bytecode; $stash->bytecode; diff --git a/ext/B/B/Debug.pm b/ext/B/B/Debug.pm index 7754a5a807..d10db9cb1a 100644 --- a/ext/B/B/Debug.pm +++ b/ext/B/B/Debug.pm @@ -68,13 +68,14 @@ sub B::COP::debug { my ($op) = @_; $op->B::OP::debug(); my ($filegv) = $op->filegv; - printf <<'EOT', $op->label, ${$op->stash}, $$filegv, $op->seq, $op->arybase, $op->line; + printf <<'EOT', $op->label, ${$op->stash}, $$filegv, $op->seq, $op->arybase, $op->line, ${$op->warnings}; cop_label %s cop_stash 0x%x cop_filegv 0x%x cop_seq %d cop_arybase %d cop_line %d + cop_warnings 0x%x EOT $filegv->debug; } diff --git a/ext/ByteLoader/ByteLoader.pm b/ext/ByteLoader/ByteLoader.pm new file mode 100644 index 0000000000..9faec2e08c --- /dev/null +++ b/ext/ByteLoader/ByteLoader.pm @@ -0,0 +1,45 @@ +package ByteLoader; + +use strict; +use vars qw($VERSION @ISA); + +require DynaLoader; + +@ISA = qw(DynaLoader); + +$VERSION = 0.01; + +bootstrap ByteLoader $VERSION; + +# Preloaded methods go here. + +1; +__END__ + +=head1 NAME + +ByteLoader - load byte compiled perl code + +=head1 SYNOPSIS + + use ByteLoader 0.01; + <byte code> + + use ByteLoader 0.01; + <byte code> + +=head1 DESCRIPTION + +This module is used to load byte compiled perl code. It uses the source +filter mechanism to read the byte code and insert it into the compiled +code at the appropriate point. + +=head1 AUTHOR + +Tom Hughes <tom@compton.nu> based on the ideas of Tim Bunce and others. + +=head1 SEE ALSO + +perl(1). + +=cut diff --git a/ext/ByteLoader/ByteLoader.xs b/ext/ByteLoader/ByteLoader.xs new file mode 100644 index 0000000000..98053c7918 --- /dev/null +++ b/ext/ByteLoader/ByteLoader.xs @@ -0,0 +1,64 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include "byterun.c" + +/* defgv must be accessed differently under threaded perl */ +/* DEFSV et al are in 5.004_56 */ +#ifndef DEFSV +#define DEFSV GvSV(defgv) +#endif + +static I32 +#ifdef PERL_OBJECT +byteloader_filter(CPerlObj *pPerl, int idx, SV *buf_sv, int maxlen) +#else +byteloader_filter(int idx, SV *buf_sv, int maxlen) +#endif +{ + OP *saveroot = PL_main_root; + OP *savestart = PL_main_start; + +#ifdef INDIRECT_BGET_MACROS + struct bytesream bs; + + bs.data = PL_rsfp; + bs.fgetc = (int(*) _((void*)))fgetc; + bs.fread = (int(*) _((char*,size_t,size_t,void*)))fread; + bs.freadpv = freadpv; +#else + byterun(PL_rsfp); +#endif + + if (PL_in_eval) { + OP *o; + + PL_eval_start = PL_main_start; + + o = newSVOP(OP_CONST, 0, newSViv(1)); + PL_eval_root = newLISTOP(OP_LINESEQ, 0, PL_main_root, o); + PL_main_root->op_next = o; + PL_eval_root = newUNOP(OP_LEAVEEVAL, 0, PL_eval_root); + o->op_next = PL_eval_root; + + PL_main_root = saveroot; + PL_main_start = savestart; + } + + return 0; +} + +MODULE = ByteLoader PACKAGE = ByteLoader + +PROTOTYPES: ENABLE + +void +import(...) + PPCODE: + filter_add(byteloader_filter, NULL); + +void +unimport(...) + PPCODE: + filter_del(byteloader_filter); diff --git a/ext/ByteLoader/Makefile.PL b/ext/ByteLoader/Makefile.PL new file mode 100644 index 0000000000..4aabe79683 --- /dev/null +++ b/ext/ByteLoader/Makefile.PL @@ -0,0 +1,10 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'ByteLoader', + 'VERSION_FROM' => 'ByteLoader.pm', # finds $VERSION + 'LIBS' => [''], # e.g., '-lm' + 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' + 'INC' => '-I$(PERL_SRC)', # e.g., '-I/usr/include/other' +); |