Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - javascript: fix \&

  • Loading branch information...
commit f3c54e424c8b14fea0dd40d9a062e48fdaf26ce7 1 parent ad2273d
@fglock authored
View
2  ChangeLog
@@ -11,7 +11,7 @@ Perlito Perl 5:
- javascript backend:
-- symbol tables; typeglobs
--- scalar references; hash references
+-- references
-- 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
8 README-perlito5-js
@@ -16,7 +16,7 @@ Array
- native []
Scalar
-- native values
+- native value
HashRef
- native {} wrapped in a "HashRef" object
@@ -27,6 +27,9 @@ ArrayRef
ScalarRef
- native value wrapped in a "ScalarRef" object
+CodeRef
+- native value
+
Object
- one of the reference types, with a _class_ attribute
@@ -47,10 +50,9 @@ Calling context ("wantarray", caller)
Alias
- TODO
-- We could probably use String/Boolean/Number (boxed types) as SCALARs
+- using String/Boolean/Number (boxed types) as SCALARs doesn't seem to work
List (eg. subroutine return value)
-- TODO
- native []
AUTOLOAD
View
8 html/perlito5.js
@@ -2896,6 +2896,14 @@ make_sub(__PACKAGE__, "emit_javascript_indented", function () {
})(); };
if ( bool(((v_arg._class_.sigil(v_arg) == '%'))) ) { (function () {
throw(('(new HashRef(' + string(v_arg._class_.emit_javascript(v_arg)) + '))'));;
+ })(); };
+ if ( bool(((v_arg._class_.sigil(v_arg) == '&'))) ) { (function () {
+ if ( bool(((v_arg ? v_arg : v_arg = new HashRef({}))._hash_[('namespace')])) ) { (function () {
+ throw(('NAMESPACE[' + String.fromCharCode(34) + string((v_arg ? v_arg : v_arg = new HashRef({}))._hash_[('namespace')]) + String.fromCharCode(34) + '].' + string((v_arg ? v_arg : v_arg = new HashRef({}))._hash_[('name')])));;
+ })(); }
+ else { (function () {
+ throw(('PKG.' + string((v_arg ? v_arg : v_arg = new HashRef({}))._hash_[('name')])));;
+ })(); };;
})(); };;
})(); };
throw(('(new ScalarRef(' + string(v_arg._class_.emit_javascript(v_arg)) + '))'));;
View
8 lib5/Perlito5/Javascript/Emitter.pm
@@ -507,6 +507,14 @@ package Apply;
};
if ((($arg->sigil() eq chr(37)))) {
return (('(new HashRef(' . $arg->emit_javascript() . '))'))
+ };
+ if ((($arg->sigil() eq chr(38)))) {
+ if (($arg->{('namespace')})) {
+ return (('NAMESPACE[' . chr(34) . $arg->{('namespace')} . chr(34) . '].' . $arg->{('name')}))
+ }
+ else {
+ return (('PKG.' . $arg->{('name')}))
+ }
}
};
return (('(new ScalarRef(' . $arg->emit_javascript() . '))'))
View
9 src5/lib/Perlito5/Javascript/Emitter.pm
@@ -615,8 +615,15 @@ package Apply;
if ( $arg->sigil eq '%' ) {
return '(new HashRef(' . $arg->emit_javascript . '))';
}
+ if ( $arg->sigil eq '&' ) {
+ if ($arg->{"namespace"}) {
+ return 'NAMESPACE["' . $arg->{"namespace"} . '"].' . $arg->{"name"};
+ }
+ else {
+ return 'PKG.' . $arg->{"name"};
+ }
+ }
}
- # XXX \&x should return a CODE ref
return '(new ScalarRef(' . $arg->emit_javascript . '))';
}
Please sign in to comment.
Something went wrong with that request. Please try again.