Skip to content

Commit

Permalink
- Included and declared modules are now executed in reverse order.
Browse files Browse the repository at this point in the history
Example:
	module Foo {
		say "foo";
		module Bar {
			say "bar";
		}
	}

Prints:
	"bar"
	"foo"

This fixes completely the deparsing of modules and the inclusion of modules in other modules.
  • Loading branch information
trizen committed Jul 24, 2015
1 parent 6184111 commit 4bd4f97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/Sidef/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ package Sidef::Parser {
local $parser->{ref_vars}{$name} = $self->{ref_vars}{$name} if exists($self->{ref_vars}{$name});

if ($name ne 'main' and not grep $_ eq $name, @Sidef::Exec::NAMESPACES) {
push @Sidef::Exec::NAMESPACES, $name;
unshift @Sidef::Exec::NAMESPACES, $name;
}

my $code = '{' . substr($_, pos);
Expand Down Expand Up @@ -2360,7 +2360,7 @@ package Sidef::Parser {

local $parser->{class} = $name if defined $name;
if (defined $name and $name ne 'main' and not grep $_ eq $name, @Sidef::Exec::NAMESPACES) {
push @Sidef::Exec::NAMESPACES, $name;
unshift @Sidef::Exec::NAMESPACES, $name;
}
my $struct = $parser->parse_script(code => \$content);

Expand Down
29 changes: 17 additions & 12 deletions scripts/module_order_and_redeclaration.sf
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
C::e();
C::f();
}.capture.lines == [
'a',
'b',
'c',
'C redeclared',
'after first C',
'main module',
'e',
'f',
] || "error".die;
"after first C",
"c",
"C redeclared",
"b",
"a",
"main module",
"e",
"f",
] || die "error";

#
## Redeclaring functions
Expand Down Expand Up @@ -61,9 +61,14 @@
P::f();
};
P::f();
}.capture.lines
== <inO afterP P::f() inP P::f()>
|| "error-3".die;
}.capture.lines == [
"inP",
"inO",
"afterP",
"P::f()",
"P::f()"
] || die "error-3";


#
## Changing module vars
Expand Down
9 changes: 0 additions & 9 deletions scripts/test_all.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
)
} = ();

if (grep { $_ eq '-O2' } @ARGV) {
@ignored{
qw(
module_definition.sf
module_order_and_redeclaration.sf
)
} = ();
}

my $regex_filter;
if (@ARGV and $ARGV[0] =~ m{^/(.+)/$}) {
$regex_filter = qr/$1/i;
Expand Down

0 comments on commit 4bd4f97

Please sign in to comment.