Skip to content

Commit 0f008b0

Browse files
committed
Perlito5 - js - fix caller(), typeglob-reference assignment, grep; added minimal Carp module
1 parent 1f23d35 commit 0f008b0

File tree

6 files changed

+83
-8
lines changed

6 files changed

+83
-8
lines changed

html/perlito5.js

Lines changed: 32 additions & 3 deletions
Large diffs are not rendered by default.

perlito5.pl

Lines changed: 13 additions & 4 deletions
Large diffs are not rendered by default.

src5/lib/Perlito5/Grammar/Use.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ my %Perlito_internal_module = (
1515
utf8 => 'Perlito5::utf8',
1616
bytes => 'Perlito5::bytes',
1717
encoding => 'Perlito5::encoding',
18+
Carp => 'Perlito5::Carp',
1819
);
1920

2021

src5/lib/Perlito5/Javascript2/CORE.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ CORE.bless = function(List__) {
4343
return o;
4444
};
4545
46+
CORE.caller = function(List__, want) {
47+
return p5pkg["Perlito5"].v_CALLER._array_ ?
48+
p5pkg["Perlito5"].v_CALLER._array_[0]._array_ :
49+
p5context([], want);
50+
};
51+
4652
CORE.chr = function(List__) {
4753
var v = p5num(List__[0]);
4854
return String.fromCharCode(v >= 0 ? v : 65533);

src5/lib/Perlito5/Javascript2/Emitter.pm

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,12 @@ package Perlito5::AST::Apply;
15571557
. Perlito5::Javascript2::to_scalar([$arguments], $level+1)
15581558
. ')';
15591559
}
1560+
if ($code eq 'prefix:<*>') {
1561+
return 'p5typeglob_deref_set('
1562+
. Perlito5::Javascript2::to_scalar($self->{arguments}, $level+1) . ', '
1563+
. Perlito5::Javascript2::to_scalar([$arguments], $level+1)
1564+
. ')';
1565+
}
15601566

15611567
'(' . $self->emit_javascript2( $level+1 ) . ' = ' . $arguments->emit_javascript2( $level+1 ) . ')';
15621568
}
@@ -2232,7 +2238,16 @@ package Perlito5::AST::Apply;
22322238
my $level = shift;
22332239
my $wantarray = shift;
22342240
my @in = @{$self->{arguments}};
2235-
my $fun = shift @in;
2241+
2242+
my $fun;
2243+
2244+
if ( $self->{special_arg} ) {
2245+
# TODO - test 'special_arg' type (scalar, block, ...)
2246+
$fun = $self->{special_arg};
2247+
}
2248+
else {
2249+
$fun = shift @in;
2250+
}
22362251
my $list = Perlito5::Javascript2::to_list(\@in);
22372252

22382253
if (ref($fun) eq 'Perlito5::AST::Lit::Block') {

src5/lib/Perlito5/Javascript2/Runtime.pm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@ function p5typeglob_set(namespace, name, obj) {
328328
return p5pkg[namespace][name]; // TODO - return GLOB
329329
}
330330
331+
function p5typeglob_deref_set(v, obj) {
332+
if (typeof v === "string") {
333+
var pkg_name = v.split(/::/);
334+
if (pkg_name.length > 1) {
335+
v = pkg_name.pop();
336+
pkg_name = pkg_name.join("::");
337+
}
338+
else {
339+
pkg_name = p5pkg["Perlito5"].v_PKG_NAME;
340+
}
341+
return p5typeglob_set(pkg_name, v, obj);
342+
}
343+
CORE.die(["TODO: can't p5typeglob_deref_set()"]);
344+
}
345+
331346
function p5set_local(namespace, name, sigil) {
332347
var vname = sigils[sigil] + name;
333348
p5LOCAL.push([namespace, vname, namespace[vname]]);

0 commit comments

Comments
 (0)