Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (41 sloc) 1.479 kb
91820ec @fglock Perlito5 - add a simple impl of multi eval($str, :$lang! where "perl5")
authored
1 use v6;
2
3 multi eval($str, :$lang! where 'perl5') {
ec8949c @fglock Perlito5 - perl6-eval.p6: fix for niecza
authored
4 $lang; # workaround for niecza: '$lang is declared but not used'
91820ec @fglock Perlito5 - add a simple impl of multi eval($str, :$lang! where "perl5")
authored
5 my $inp_file = "tmp.p5";
6 my $out_file = "tmp.p6";
7 my $fh = open($inp_file, :w);
8 $fh.print($str);
9 $fh.close;
10 shell "perl perlito5.pl -Isrc5/lib -Cperl6 $inp_file > $out_file";
11 my $p6_str = slurp $out_file;
9ea3cc4 @fglock Perlito5 - simple perl6 eval($str, :$lang<perl5>) works!
authored
12 # say "[[$p6_str]]";
13 $p6_str.eval;
91820ec @fglock Perlito5 - add a simple impl of multi eval($str, :$lang! where "perl5")
authored
14 }
15
9ea3cc4 @fglock Perlito5 - simple perl6 eval($str, :$lang<perl5>) works!
authored
16 my $p5_str = '
17 my @x;
18 $x[1] = 2+2;
19 say "got $x[1]";
20 ';
91820ec @fglock Perlito5 - add a simple impl of multi eval($str, :$lang! where "perl5")
authored
21 eval($p5_str, :lang<perl5>);
22
9ea3cc4 @fglock Perlito5 - simple perl6 eval($str, :$lang<perl5>) works!
authored
23
24 =begin comments
25
1eb7e0c @fglock Perlito5 - perl6 eval-perl5: add comments
authored
26
ec8949c @fglock Perlito5 - perl6-eval.p6: fix for niecza
authored
27 Note: to run niecza in osx you need:
28
29 $ export LD_LIBRARY_PATH=/opt/local/lib
30
31 Missing LD_LIBRARY_PATH gives the error:
32 "Unhandled exception: System.TypeInitializationException"
33
34
ae3f389 @fglock Perlito5 - perl6-eval.p6: add notes
authored
35 Note: fixed in rakudo commit e756635b9e:
36
37 If I define multi eval($str, :$lang! where 'perl5')
38 then rakudo can't find eval :lang<perl6> anymore
39 because eval is declared as an only sub
40
41 This is a workaround (by moritz++):
42
43 proto eval(|$) {*};
44 multi sub eval($str) {
45 $str.eval;
46 }
47
48
49 Note: Accessing perl6 variables inside eval (explained by moritz++):
50
51 sub f { say OUTER::.keys }; { my $x = 3; f() }
52 # $! GLOBALish $=pod EXPORT !UNIT_MARKER $?PACKAGE ::?PACKAGE $_ &f $/
53
54 sub f { say CALLER::.keys }; { my $x = 3; f() }
55 # call_sig $x $_ $*DISPATCHER
56
57 and you might need to walk the CALLER's OUTER
58 this one just gives you the immediate caller's scope
1eb7e0c @fglock Perlito5 - perl6 eval-perl5: add comments
authored
59
60
9ea3cc4 @fglock Perlito5 - simple perl6 eval($str, :$lang<perl5>) works!
authored
61 =end comments
62
Something went wrong with that request. Please try again.