Update of /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries
In directory usw-pr-cvs1:/tmp/cvs-serv24231
Modified Files:
ClassLibrary.pm
Log Message:
* added possibility of recursive function calls
* overall speedup
* fixed minor bugs
Index: ClassLibrary.pm
===================================================================
RCS file: /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries/ClassLibrary.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ClassLibrary.pm 11 Jul 2002 22:03:10 -0000 1.1
--- ClassLibrary.pm 24 Jul 2002 22:46:32 -0000 1.2
***************
*** 64,71 ****
--- 64,93 ----
my $this = $class -> SUPER::new();
my %knownClasses = ();
+ my @callStack = ();
$this -> { m_knownClasses } = \%knownClasses;
+ $this -> { m_callStack } = \@callStack;
$this;
}
+ #/**
+ # Pushes the given node onto the call stack.
+ # @param an instance of XML::DOM2::Node
+ # @private
+ #*/
+ sub pushNode {
+ my ( $this, $node ) = @_;
+ push( @{ $this -> { m_callStack } }, $node );
+ }
+
+ #/**
+ # Pops the topmost node from the call stack.
+ # @return an instance of XML::DOM2::Node
+ # @private
+ #*/
+ sub popNode {
+ my ( $this ) = @_;
+ pop( @{ $this -> { m_callStack } } );
+ }
+
sub init {
***************
*** 216,229 ****
#/**
! # Invokes a method. Method code will be appended
! # to the given element and the dom walker will walk over it.
# @param an instance of NetScript::Engine::Class
# @param an instance of NetScript::Engine::Function
! # @param an instance of XML::DOM2::Element
#*/
sub invokeAMethod {
my ( $this, $classObject, $methodObject, $node, $domWalker ) = @_;
my $se = $this -> interpreter() -> getStatementEvaluator();
! $node -> appendChild( $methodObject -> getCode() ); # append code
my @paramsByVal = @{ $methodObject -> getValueParameters() };
my @paramsByRef = @{ $methodObject -> getReferenceParameters() };
--- 238,251 ----
#/**
! # Invokes a method.
# @param an instance of NetScript::Engine::Class
# @param an instance of NetScript::Engine::Function
! # @param an instance of XML::DOM2::Element - the invoke node
#*/
sub invokeAMethod {
my ( $this, $classObject, $methodObject, $node, $domWalker ) = @_;
my $se = $this -> interpreter() -> getStatementEvaluator();
! # $node -> appendChild( $methodObject -> getCode() ); # append code
!
my @paramsByVal = @{ $methodObject -> getValueParameters() };
my @paramsByRef = @{ $methodObject -> getReferenceParameters() };
***************
*** 260,263 ****
--- 282,287 ----
}
+ $this -> pushNode( $node );
+ $domWalker -> setCurrentSource( $methodObject -> getCode() );
$domWalker -> stepSourceIn();
}
***************
*** 271,297 ****
sub invokeFinished {
my ( $this, $domWalker, $node ) = @_;
- # remove code subtree from node.
- $node -> removeChild( $node -> getFirstChild() );
# restore old state
$this -> interpreter() -> dropStateTree();
}
- #/**
- # Called when object creation is finished.
- # @param an instance of NetScript::Engine::DOMWalker
- # @param an instance of XML::DOM2::Element (the new-node)
- # @callback
- #*/
- sub newFinished {
- my ( $this, $domWalker, $node ) = @_;
-
- # if node has no child nodes there was no ctor invoked
- if ( $node -> hasChildNodes() ) {
- # remove code subtree from node.
- $node -> removeChild( $node -> getFirstChild() );
- # restore old state
- $this -> interpreter() -> dropStateTree();
- }
- }
#/**
--- 295,308 ----
sub invokeFinished {
my ( $this, $domWalker, $node ) = @_;
# restore old state
$this -> interpreter() -> dropStateTree();
+ # get return address
+ my $nextNode = $this -> popNode();
+ # set return node
+ $domWalker -> setCurrentSource( $nextNode );
+ # step to next node
+ $domWalker -> stepSourceNext();
}
#/**
***************
*** 356,367 ****
}
if ( $localName eq "invoke" ) {
- $this -> invokeFinished( $domWalker, $node );
return 0; # consume event
}
if ( $localName eq "new" ) {
- $this -> newFinished( $domWalker, $node );
return 0; # consume event
}
if ( $localName eq "method" ) {
return 0; #consume event
}
--- 367,377 ----
}
if ( $localName eq "invoke" ) {
return 0; # consume event
}
if ( $localName eq "new" ) {
return 0; # consume event
}
if ( $localName eq "method" ) {
+ $this -> invokeFinished( $domWalker, $node );
return 0; #consume event
}
|