Your SlideShare is downloading. ×
Personal Perl 6 compiler
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Personal Perl 6 compiler

861
views

Published on

A semi-joke on how to create your own Perl 6 compiler and run the code in production already today.

A semi-joke on how to create your own Perl 6 compiler and run the code in production already today.

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
861
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Perlsonal Perl 6 compiler
  • 2. or
  • 3. How to speed up your Perl 6 app
  • 4. How to speed up your Perl 6 app and make it 10 000 times faster
  • 5. -O fun
  • 6. Let’s take a simple programme
  • 7. Let’s take a simple but CPU consuming programme
  • 8. say
is_prime(@*ARGS[0]); sub
is_prime($n)
{ 



for
2
..
$n
‐
1
‐>
$d
{ 







return
0
unless
$n
%
$d; 



} 



 



return
1; }
  • 9. $
perl6
  • 10. $
perl6
is_prime.p6
  • 11. $
perl6
is_prime.p6
37
  • 12. $
perl6
is_prime.p6
37 1
  • 13. $
perl6
is_prime.p6
38 0
  • 14. $
perl6
is_prime.p6
15511
  • 15. $
perl6
is_prime.p6
15511 1 20 seconds with Rakudo :-(
  • 16. Perl 6 can be fast!
  • 17. Perl 6 can be fast!
  • 18. Perl 6 can be fast!
  • 19. Boost it!
  • 20. Boost it! OK, go to boost.org :-)
  • 21. struct
p6grammar:
public
grammar<p6grammar>
{ 



template<typename
ScannerT> 



struct
definition
{ 







definition(p6grammar
const&
self)
{
  • 22. struct
p6grammar:
public
grammar<p6grammar>
{ 



template<typename
ScannerT> 



struct
definition
{ 







definition(p6grammar
const&
self)
{ 











program 















=
statement_list
>>
end_p;
  • 23. struct
p6grammar:
public
grammar<p6grammar>
{ 



template<typename
ScannerT> 



struct
definition
{ 







definition(p6grammar
const&
self)
{ 











program 















=
statement_list
>>
end_p; 











statement_list
 















=
*statement;
  • 24. struct
p6grammar:
public
grammar<p6grammar>
{ 



template<typename
ScannerT> 



struct
definition
{ 







definition(p6grammar
const&
self)
{ 











program 















=
statement_list
>>
end_p; 











statement_list
 















=
*statement; 











statement 















=
statement_code
 

















>>
!statement_separator;
  • 25. 











statement_code 















=
comment 















|
statement_control
 















|
sub_def 















|
sub_call 















|
expression;
  • 26. 











statement_code 















=
comment 















|
statement_control
 















|
sub_def 















|
sub_call 















|
expression; 











comment 















=
ch_p('#')
 

















>>
lexeme_d[*~ch_p('n')]; 









  • 27. 











statement_code 















=
comment 















|
statement_control
 















|
sub_def 















|
sub_call 















|
expression; 











comment 















=
ch_p('#')
 

















>>
lexeme_d[*~ch_p('n')]; 











sub_call 















=
sub_name
 

















>>
!sub_arguments;
  • 28. 












sub_body struct
p6grammar:
public
grammar<p6grammar>
{ 











argument 















=
ch_p('{')[&a_sub_def_body_start]
 



template<typename
ScannerT>
struct
definition
{ 















=
expression >>
!statement_list
>>
ch_p('}'); 







definition(p6grammar
const&
self)
{ 















|
variable; 















 











program 











 











statement_control 















=
statement_list
>>
end_p; 











variable 















=
for_cycle 











 















=
array 















|
conditional_block; 











statement_list
 















|
scalar; 















 















=
*statement; 















 











conditional_block 















 











scalar 















=
(str_p("if")
|
str_p("unless")) 











statement 















=
constant [&a_condition_start]
>>
expression[&a_condition_end]
 















=
statement_code
>>
! 















|
ch_p('$')
>>
identifier[&a_scalar] >>
code_block[&a_conditional_block_end]; statement_separator[&a_statement]; 















|
array_element; 















 















 











 











code_block 











statement_code 











array 















=
ch_p('{')
>>
statement_list
>>
 















=
comment 















=
simple_array ch_p('}'); 















|
statement_control
 















|
global_array; 















 















|
sub_def 















 











for_cycle 















//|
(sub_call[&a_sub_call_start]
 











simple_array 















=
str_p("for")[&a_for_cycle_start] >>
!statement_modifier)[&a_sub_call_end] 















=
ch_p('@')
>>
(identifier
>>
 















>>
(range
>>
!(str_p("‐>")
>>
 















|
sub_call ~eps_p('['))[&a_array]; ch_p('$')
>>
identifier[&a_for_cycle_variable])) 















|
expression; [&a_for_cycle_range] 











 











global_array 















>>
 











comment 















=
str_p("@*")
>>
(identifier
>>
 for_cycle_body[&a_for_cycle_body]; 















=
ch_p('#')
>>
 ~eps_p('['))[&a_global_array]; 















 lexeme_d[*~ch_p('n')]; 











 











range 















 











array_element 















=
ch_p('(')
>>
range_content
>>
 











statement_separator 















=
simple_array_element ch_p(')') 















=
ch_p(';'); 















|
global_array_element; 















|
range_content; 











 















 















 











sub_call 











simple_array_element 











range_content 















=
(sub_name
>>
!sub_arguments) 















=
(ch_p('@')
>>
 















=
expression
>>
str_p("..") [&a_sub_called]; array_element_name_and_index)[&a_array_element]; [&a_range_sep]
>>
expression; 















 











 











sub_name 











global_array_element 











expression 















=
builtin_sub_name 















=
(str_p("@*")
>>
 















=
ch_p('(')[&a_paren]
>>
 















|
identifier[&a_sub_name] array_element_name_and_index) expression_content

>>
ch_p(')')[&a_paren] [&a_sub_calling]; [&a_global_array_element]; 















|
expression_content; 















 











 















 











builtin_sub_name 











array_element_name_and_index 











expression_content 















=
str_p("say")[&a_builtin_say] 















=
 















=
scalar
>>
*(math_op[&a_math_op]
>>
 















|
str_p("print")[&a_builtin_print] identifier[assign_a(array_element_name)] expression) 















|
str_p("return") 

















>>
ch_p('[')
>>
array_index 















|
sub_call; [&a_builtin_return]; 

















>>
ch_p(']'); 















 















 



















 











math_op 











identifier 











array_index 















=
ch_p('+') 















=
lexeme_d[+(alpha_p
|
'_')
>>
 















=
 















|
ch_p('‐')
>>
eps_p(~ch_p('>')) *(alnum_p
|
'_')]; int_p[assign_a(array_element_index)]; 















|
ch_p('*') 















 















 















|
ch_p('/') 











sub_arguments 











constant 















|
ch_p('%'); 















=
ch_p('(')
>>
!argument_list
>>
 















=
real_p[&a_constant]; 











 ch_p(')') 















 











for_cycle_body 















|
argument_list; 











sub_def 















=
sub_body; 















 















=
str_p("sub")[&a_sub_def_start] 















 











argument_list 















>>
sub_name 











statement_modifier 















=
list_p(argument,
ch_p(',') 















>>
! 















=
(str_p("unless")
|
str_p("if"))
>>
 [&a_argument_list_sep]); sub_arguments[&a_sub_def_arguments_end] expression; 















 















>>
sub_body[&a_sub_def_end];
  • 29. say
is_prime(@*ARGS[0]); sub
is_prime($n)
{ 



for
2
..
$n
‐
1
‐>
$d
{ 







 







return
0
unless
$n
%
$d; 







 



} 



 



return
1; }
  • 30. say
is_prime(@*ARGS[0]); sub
is_prime($n)
{ 



for
2
..
$n
‐
1
‐>
$d
{ 







 







return
0
unless
$n
%
$d; 







 



} 



 



return
1; }
  • 31. say
is_prime(@*ARGS[0]); sub
is_prime($n)
{ 



for
2
..
$n
‐
1
‐>
$d
{ 







unless
$n
%
$d
{ 











return
0; 







} 



} 



 



return
1; }
  • 32. Programme 1 Checks if the argument is a prime
  • 33. say
is_prime(@*ARGS[0]); sub
is_prime($n)
{ 



for
2
..
$n
‐
1
‐>
$d
{ 







unless
$n
%
$d
{ 











return
0; 







} 



} 



 



return
1; }
  • 34. ./p++
<
t/is_prime.p6
  • 35. #include<iostream> #include<string> using
namespace
std; typedef
int
variable_t; typedef
int
scalar_t; typedef
int
range_boundary_t; variable_t
sub_is_prime(scalar_t
var_scalar_n)
{ 



for
(range_boundary_t
var_scalar_d
=
2;
var_scalar_d
<=
var_scalar_n
‐
1 var_scalar_d++)
{ 



if(!(var_scalar_n
%
var_scalar_d))
{ 



return
0; } 



} 



return
1; } int
main(int
argn,
char**
var_global_array_ARGS)
{ 



cout
<<
sub_is_prime(atoi(var_global_array_ARGS[1
+
0]))
<<
"n"; 



return
0; }
  • 36. say
is_prime(@*ARGS[0]); cout
<<
sub_is_prime( 






atoi(var_global_array_ARGS[1
+
0]) 


)
 



<<
"n";
  • 37. sub
is_prime($n)
{ variable_t
sub_is_prime(scalar_t
var_scalar_n)
{
  • 38. for
2
..
$n
‐
1
‐>
$d
{
 for
(range_boundary_t
var_scalar_d
=
2;

 




var_scalar_d
<=
var_scalar_n
‐
1;
 




var_scalar_d++)
{
  • 39. $
time
./is_prime
15511 1
  • 40. $
time
./is_prime
15511 1 real
 0m0.002s
  • 41. Programme 2 Checks if the argument is a prime and displays the first denominator
  • 42. say
is_prime(@*ARGS[0]); sub
is_prime($n)
{ 



for
2
..
$n
‐
1
‐>
$d
{ 







unless
$n
%
$d 











say
$d; 











return
0; 







} 



} 



 



return
1; }
  • 43. Programme 3 Generates prime numbers below 1 000 000
  • 44. S2 recommends @primes
=
 



grep
*.prime,
2..*;
  • 45. for
2
..
1000000
‐>
$n
{ 



if
is_prime($n)
{ 







say
$n; 



} } sub
is_prime($n)
{ 



for
2
..
$n
‐
1
‐>
$d
{ 







unless
$n
%
$d
{ 










return
0; 







} 



} 



return
1; }
  • 46. Sparse ideas behind p6c
  • 47. 1. C++‘s type casts
  • 48. my
$var
=
100; say
$var; $var
=
"string"; say
$var;

  • 49. my
$var
=
100; say
$var; $var
=
"string"; say
$var;
 variable_var.set(100); cout
<<
variable_var; variable_var.set("string"); cout
<<
variable_var;
  • 50. class
PerlVariable
{ 


.
.
. public: 


operator
int(); 


operator
string(); }
  • 51. 2. Intensive use of C++ compiler
  • 52. class
MyClass
{ 


has
$member; 


method
meth()
{...} }
  • 53. class
MyClass
{ 


has
$member; 


method
meth()
{...} } class
MyClass
{ public: 



PerlVariable
member_member; 



void
meth_method(); }
  • 54. 3. What to implement (base principle)
  • 55. a) Write Perl 6 programme I’d like to have in production
  • 56. a) Write Perl 6 programme I’d like to have in production b) Implement that part of the compiler
  • 57. a) Write Perl 6 programme I’d like to have in production b) Implement that part of the compiler (following STD.pm)
  • 58. svn://svn.shitov.ru/p6c http://perl6.ru/p6c
  • 59. svn://svn.shitov.ru/p6c http://perl6.ru/p6c __END__ Andrew Shitov | mail@andy.sh