Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - javascript: implement "our" (fix "local" scope after "our"…

… os set)
  • Loading branch information...
commit 4fe66e382afc583474310d65cb1871d13d0aa8a6 1 parent 64b8b8a
@fglock authored
View
2  ChangeLog
@@ -13,7 +13,7 @@ Dev 2012-02-29
- javascript backend:
-- symbol tables; typeglobs
-- references
--- "local"; goto &sub
+-- "local", "our"; goto &sub
-- perlito5 calling convention is incompatible with native javascript
The last commit using native javascript data is "e1e3316b"
-- native javascript can be accessed with JS::inline('string')
View
33 html/perlito5.js
@@ -1498,8 +1498,17 @@ CORE.ref = function(List__) {
(v_level = NAMESPACE["Perlito5::AST::Decl"].shift([List__]));
if ( ((v_self || (v_self = new HashRef({})))._hash_[('decl')] == 'local') ) {
(function () {
+ var v_perl5_name = null;
+ (v_perl5_name = (v_self || (v_self = new HashRef({})))._hash_[('var')]._class_.perl5_name([(v_self || (v_self = new HashRef({})))._hash_[('var')]]));
+ var v_decl_namespace = null;
+ (v_decl_namespace = '');
+ var v_decl = null;
+ (v_decl = (v_self || (v_self = new HashRef({})))._hash_[('var')]._class_.perl5_get_decl([(v_self || (v_self = new HashRef({})))._hash_[('var')],v_perl5_name]));
+ if ( (bool(v_decl) && (((v_decl || (v_decl = new HashRef({})))._hash_[('decl')] == 'our') || ((v_decl || (v_decl = new HashRef({})))._hash_[('decl')] == 'local'))) ) {
+ (v_decl_namespace = (v_decl || (v_decl = new HashRef({})))._hash_[('namespace')]);
+ };
var v_ns = null;
- (v_ns = ('NAMESPACE["' + string(or(((v_self || (v_self = new HashRef({})))._hash_[('var')] || ((v_self || (v_self = new HashRef({})))._hash_[('var')] = new HashRef({})))._hash_[('namespace')], function () { return NAMESPACE["Perlito5::Javascript"].v_PKG_NAME; })) + '"]'));
+ (v_ns = ('NAMESPACE["' + string(or(or(((v_self || (v_self = new HashRef({})))._hash_[('var')] || ((v_self || (v_self = new HashRef({})))._hash_[('var')] = new HashRef({})))._hash_[('namespace')], function () { return v_decl_namespace; }), function () { return NAMESPACE["Perlito5::Javascript"].v_PKG_NAME; })) + '"]'));
throw(('set_local(' + string(v_ns) + ',' + string(NAMESPACE["Perlito5::Javascript"].escape_string([((v_self || (v_self = new HashRef({})))._hash_[('var')] || ((v_self || (v_self = new HashRef({})))._hash_[('var')] = new HashRef({})))._hash_[('name')]])) + ',' + string(NAMESPACE["Perlito5::Javascript"].escape_string([((v_self || (v_self = new HashRef({})))._hash_[('var')] || ((v_self || (v_self = new HashRef({})))._hash_[('var')] = new HashRef({})))._hash_[('sigil')]])) + '); ' + string((v_self || (v_self = new HashRef({})))._hash_[('var')]._class_.emit_javascript_indented([(v_self || (v_self = new HashRef({})))._hash_[('var')],v_level]))));
})();
};
@@ -1520,10 +1529,26 @@ CORE.ref = function(List__) {
(v_self = NAMESPACE["Perlito5::AST::Decl"].shift([List__]));
var v_env = null;
(v_env = (new HashRef(array_to_hash(interpolate_array('decl', (v_self || (v_self = new HashRef({})))._hash_[('decl')])))));
- if ( (((v_self || (v_self = new HashRef({})))._hash_[('decl')] != 'my') && (((v_self || (v_self = new HashRef({})))._hash_[('var')] || ((v_self || (v_self = new HashRef({})))._hash_[('var')] = new HashRef({})))._hash_[('namespace')] == '')) ) {
- ((v_env || (v_env = new HashRef({})))._hash_[('namespace')] = NAMESPACE["Perlito5::Javascript"].v_PKG_NAME);
+ var v_perl5_name = null;
+ (v_perl5_name = (v_self || (v_self = new HashRef({})))._hash_[('var')]._class_.perl5_name([(v_self || (v_self = new HashRef({})))._hash_[('var')]]));
+ if ( ((v_self || (v_self = new HashRef({})))._hash_[('decl')] != 'my') ) {
+ if ( (((v_self || (v_self = new HashRef({})))._hash_[('decl')] == 'our') && bool(((v_self || (v_self = new HashRef({})))._hash_[('var')] || ((v_self || (v_self = new HashRef({})))._hash_[('var')] = new HashRef({})))._hash_[('namespace')])) ) {
+ NAMESPACE["Perlito5::AST::Decl"].die([('No package name allowed for variable ' + string(v_perl5_name) + ' in ' + '"' + 'our' + '"')]);
+ };
+ if ( (((v_self || (v_self = new HashRef({})))._hash_[('var')] || ((v_self || (v_self = new HashRef({})))._hash_[('var')] = new HashRef({})))._hash_[('namespace')] == '') ) {
+ (function () {
+ var v_decl_namespace = null;
+ (v_decl_namespace = '');
+ var v_decl = null;
+ (v_decl = (v_self || (v_self = new HashRef({})))._hash_[('var')]._class_.perl5_get_decl([(v_self || (v_self = new HashRef({})))._hash_[('var')],v_perl5_name]));
+ if ( ((((v_self || (v_self = new HashRef({})))._hash_[('decl')] == 'local') && bool(v_decl)) && (((v_decl || (v_decl = new HashRef({})))._hash_[('decl')] == 'our') || ((v_decl || (v_decl = new HashRef({})))._hash_[('decl')] == 'local'))) ) {
+ (v_decl_namespace = (v_decl || (v_decl = new HashRef({})))._hash_[('namespace')]);
+ };
+ ((v_env || (v_env = new HashRef({})))._hash_[('namespace')] = or(v_decl_namespace, function () { return NAMESPACE["Perlito5::Javascript"].v_PKG_NAME; }));
+ })();
+ };
};
- (((NAMESPACE["Perlito5::Javascript"].v_VAR || (NAMESPACE["Perlito5::Javascript"].v_VAR = new ArrayRef([])))._array_[0] || ((NAMESPACE["Perlito5::Javascript"].v_VAR || (NAMESPACE["Perlito5::Javascript"].v_VAR = new ArrayRef([])))._array_[0] = new HashRef({})))._hash_[(v_self || (v_self = new HashRef({})))._hash_[('var')]._class_.perl5_name([(v_self || (v_self = new HashRef({})))._hash_[('var')]])] = v_env);
+ (((NAMESPACE["Perlito5::Javascript"].v_VAR || (NAMESPACE["Perlito5::Javascript"].v_VAR = new ArrayRef([])))._array_[0] || ((NAMESPACE["Perlito5::Javascript"].v_VAR || (NAMESPACE["Perlito5::Javascript"].v_VAR = new ArrayRef([])))._array_[0] = new HashRef({})))._hash_[v_perl5_name] = v_env);
if ( ((v_self || (v_self = new HashRef({})))._hash_[('decl')] == 'my') ) {
var v_str = null;
(v_str = '');
View
25 lib5/Perlito5/Javascript/Emitter.pm
@@ -403,7 +403,13 @@ package Perlito5::AST::Decl;
((my $self) = shift());
((my $level) = shift());
if ((($self->{('decl')} eq 'local'))) {
- ((my $ns) = ('NAMESPACE[' . chr(34) . (($self->{('var')}->{('namespace')} || $Perlito5::Javascript::PKG_NAME)) . chr(34) . ']'));
+ ((my $perl5_name) = $self->{('var')}->perl5_name());
+ ((my $decl_namespace) = '');
+ ((my $decl) = $self->{('var')}->perl5_get_decl($perl5_name));
+ if ((($decl && ((($decl->{('decl')} eq 'our') || ($decl->{('decl')} eq 'local')))))) {
+ ($decl_namespace = $decl->{('namespace')})
+ };
+ ((my $ns) = ('NAMESPACE[' . chr(34) . ((($self->{('var')}->{('namespace')} || $decl_namespace) || $Perlito5::Javascript::PKG_NAME)) . chr(34) . ']'));
return (('set_local(' . $ns . ',' . Perlito5::Javascript::escape_string($self->{('var')}->{('name')}) . ',' . Perlito5::Javascript::escape_string($self->{('var')}->{('sigil')}) . ')' . chr(59) . ' ' . $self->{('var')}->emit_javascript_indented($level)))
};
$self->{('var')}->emit_javascript_indented($level)
@@ -411,10 +417,21 @@ package Perlito5::AST::Decl;
sub emit_javascript_init {
((my $self) = shift());
((my $env) = {('decl' => $self->{('decl')})});
- if ((($self->{('decl')} ne 'my') && ($self->{('var')}->{('namespace')} eq ''))) {
- ($env->{('namespace')} = $Perlito5::Javascript::PKG_NAME)
+ ((my $perl5_name) = $self->{('var')}->perl5_name());
+ if ((($self->{('decl')} ne 'my'))) {
+ if ((($self->{('decl')} eq 'our') && $self->{('var')}->{('namespace')})) {
+ die(('No package name allowed for variable ' . $perl5_name . ' in ' . chr(34) . 'our' . chr(34)))
+ };
+ if ((($self->{('var')}->{('namespace')} eq ''))) {
+ ((my $decl_namespace) = '');
+ ((my $decl) = $self->{('var')}->perl5_get_decl($perl5_name));
+ if ((((($self->{('decl')} eq 'local') && $decl) && ((($decl->{('decl')} eq 'our') || ($decl->{('decl')} eq 'local')))))) {
+ ($decl_namespace = $decl->{('namespace')})
+ };
+ ($env->{('namespace')} = ($decl_namespace || $Perlito5::Javascript::PKG_NAME))
+ }
};
- ($Perlito5::Javascript::VAR->[0]->{$self->{('var')}->perl5_name()} = $env);
+ ($Perlito5::Javascript::VAR->[0]->{$perl5_name} = $env);
if ((($self->{('decl')} eq 'my'))) {
((my $str) = '');
($str = ($str . 'var ' . $self->{('var')}->emit_javascript() . ' ' . chr(61) . ' '));
View
43 src5/lib/Perlito5/Javascript/Emitter.pm
@@ -251,16 +251,6 @@ package Perlito5::Javascript::LexicalBlock;
}
my $tab = Perlito5::Javascript::tab($level);
- # for my $decl ( @block ) {
- # if ($decl->isa( 'Perlito5::AST::Decl' )) {
- # push @str, $decl->emit_javascript_init;
- # }
- # if ($decl->isa( 'Perlito5::AST::Apply' ) && $decl->code eq 'infix:<=>') {
- # if ($decl->{"arguments"}[0]->isa( 'Perlito5::AST::Decl' )) {
- # push @str, $decl->{"arguments"}[0]->emit_javascript_init;
- # }
- # }
- # }
my $last_statement;
if ($self->{"needs_return"}) {
$last_statement = pop @block;
@@ -564,7 +554,16 @@ package Perlito5::AST::Decl;
# . $self->{"var"}->emit_javascript_indented( $level );
# }
- my $ns = 'NAMESPACE["' . ($self->{"var"}{"namespace"} || $Perlito5::Javascript::PKG_NAME) . '"]';
+ my $perl5_name = $self->{"var"}->perl5_name;
+ # say "looking up $perl5_name";
+ my $decl_namespace = '';
+ my $decl = $self->{"var"}->perl5_get_decl( $perl5_name );
+ if ( $decl && ($decl->{"decl"} eq 'our' || $decl->{"decl"} eq 'local')) {
+ # say "found ", $decl->{"decl"}, " namespace: ", $decl->{"namespace"};
+ $decl_namespace = $decl->{"namespace"};
+ }
+
+ my $ns = 'NAMESPACE["' . ($self->{"var"}{"namespace"} || $decl_namespace || $Perlito5::Javascript::PKG_NAME) . '"]';
return
'set_local(' . $ns . ','
@@ -578,9 +577,25 @@ package Perlito5::AST::Decl;
my $self = shift;
my $env = { decl => $self->{"decl"} };
- $env->{"namespace"} = $Perlito5::Javascript::PKG_NAME
- if $self->{"decl"} ne 'my' && $self->{"var"}{"namespace"} eq '';
- $Perlito5::Javascript::VAR->[0]{ $self->{"var"}->perl5_name } = $env;
+ my $perl5_name = $self->{"var"}->perl5_name;
+ if ( $self->{"decl"} ne 'my' ) {
+
+ die "No package name allowed for variable $perl5_name in \"our\""
+ if $self->{"decl"} eq 'our' && $self->{"var"}{"namespace"};
+
+ if ( $self->{"var"}{"namespace"} eq '' ) {
+ # say "looking up $perl5_name";
+ my $decl_namespace = '';
+ my $decl = $self->{"var"}->perl5_get_decl( $perl5_name );
+ if ( $self->{"decl"} eq 'local' && $decl && ($decl->{"decl"} eq 'our' || $decl->{"decl"} eq 'local')) {
+ # say "found ", $decl->{"decl"}, " namespace: ", $decl->{"namespace"};
+ $decl_namespace = $decl->{"namespace"};
+ }
+ $env->{"namespace"} = $decl_namespace || $Perlito5::Javascript::PKG_NAME;
+ }
+ }
+
+ $Perlito5::Javascript::VAR->[0]{ $perl5_name } = $env;
if ($self->{"decl"} eq 'my') {
my $str = "";
Please sign in to comment.
Something went wrong with that request. Please try again.