root/v6/v6-KindaPerl6/docs/FAQ.pod

Revision 19153, 14.4 kB (checked in by dlo, 19 months ago)

[kp6] fixed infix space problem

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1=head1 NAME
2
3KindaPerl6 - Frequent Asked Questions.
4
5=head1 DEVELOPMENT
6
7Development of KindaPerl6 is coordinated almost via the #perl6 IRC channel on
8irc.freenode.net. If you want to contribute join the channel and ask for a
9commit bit (see L<http://dev.pugscode.org/wiki/>).
10
11=head2 Useful links
12
13These are perl6 links, that I believe would be useful for new people to the
14KindaPerl6 project.
15
16L<http://dev.pugscode.org/browser> Trac interface for Perl6 code
17
18L<http://svn.pugscode.org/pugs/> SVN Repository
19
20L<http://feather.perl6.nl/syn/> Official Perl6 Documentation
21
22L<http://sial.org/pbot/perl6> Paste Bot for #perl6
23
24L<http://irclog.perlgeek.de/perl6/today> IRC Chat history for #perl6
25
26L<http://www.cse.unsw.edu.au/~dons/lambdabot/COMMANDS> Commands for lambdabot in #perl6
27
28L<http://dev.pugscode.org/timeline> Recent Commits
29
30L<http://dev.pugscode.org/browser/v6/v6-KindaPerl6/TODO> KP6 TODO
31
32=head2 mp6/kp6 FAQ
33
34=head2 Overview - What is mp6/kp6/v6?
35
36v6 is a perl6-on-perl6 project:  L<http://dev.pugscode.org/browser/v6>
37
38This is not the perl5 v6-alpha, see perl5/Pugs-Compiler-Perl6 for that.
39
40The current plan is to bootstrap full-p6 using kp6.
41
42There are 4 subprojects under v6/:
43
44=over
45
46=item MiniPerl6 aka mp6
47
48v6-MiniPerl6 (mp6) is a subset of Perl 6 used to bootstrap the full Perl 6.
49v6-MiniPerl6 is bootstrapped with perl5.
50
51=item KindaPerl6 aka kp6
52
53v6-KindaPerl6 is a reimplementation of mp6 with a very flexible compiler
54workflow.  kp6 uses plugins in order to implement perl6 semantics over several
55backends.  kp6 is currently being bootstrapped - kp6 is compiled with the mp6
56compiler.
57
58=item Yet Another Perl6 aka yap6
59
60A pure C implementation of KindaPerl6 runtime
61
62=item Onion
63
64Next iteration of the kp6 project
65I<This project was a shortlived experiment.Work on the bootstap is now going inside kp6.The name is reserved for perl6 on parrot>
66
67=item v6.pm
68
69v6.pm is a plain translation of the perl5 v6.pm compiler, such that the modules
70could be interchangeable. This project is currently abandoned.
71I<This project has been removed.>
72
73=item v6-Compiler
74
75v6-Compiler (full-p6) is meant as a more advanced compiler, but the process is
76more  difficult to bootstrap because v6-Compiler needs a more complete Perl 6
77compiler.
78I<This project has been removed.>
79
80=item pugs - the Haskell implementation
81
82PUGS is the root: L<http://dev.pugscode.org/browser> .  There are several
83different perl6 implementations in progress.  PUGS is one of them.
84
85=back
86
87=head2 How can I help?
88
89=head3 Prerequisite reading.
90
91Perl6 is implementing several features I have not heard of before.  Before
92you read the perl6 documentation, these documents are good to read.
93
94- Prototyped based programming: L<http://en.wikipedia.org/wiki/Prototype-based_programming>
95
96The perl5 code that implements Prototyped classes: L<http://search.cpan.org/dist/Class-Prototyped/lib/Class/Prototyped.pm>
97
98- Objects (Autoboxing is interesting): L<http://en.wikipedia.org/wiki/Autoboxing#Autoboxing>
99
100=head3 What do you need?
101
102 - Perl5 (Perl 5.10.RC2 and Perl 5.8.8 worked with the kp6 test cases.)
103 - Coro.pm : L<http://search.cpan.org/~mlehmann/Coro-4.13/Coro.pm>
104   Required for t/kp6/internals/02-gather.t
105 - Subversion client.
106 - Commit bit: Ask on #perl6 irc.freenode.net.
107
108=head3 Customs and Traditions.
109
110- (new comers) When you get your commit bit, Update the AUTHORS file to make sure everything (SVN) is ok.
111
112- Commit code in doubt, revert if wrong.<br>
113
114L<http://irclog.perlgeek.de/perl6/2007-10-31#i_135203>
115
116- Please prefix your kp6 svn commits with [kp6]
117
118L<http://irclog.perlgeek.de/perl6/2007-11-01#i_136077>
119
120Example:
121
122 [kp6] I have refactored subroutine XXX for clarity and updated the documentation.
123
124=head3 Seeing an intermediate step.
125
126Sometimes you want to see how kp6 "saw" the code.  This is seen by running the
127code though AST backend.
128
129 perl script/kp6 -Cast -e ' "a" eq "b" '
130
131=head3 Cannot see the forest for the trees. / Boot strapping
132
133One of the problems I had when I started working on kp6 was I could not see
134how everything worked together.
135
136mp6.pl (miniperl6) is used to compile/translate the AST/Grammar/Visitor perl6
137libraires/code into perl5 code that can be used by kp6 to parse new perl6 code.
138
139AST/Grammar/Visitor code is responsible for converting perl6 code into perl5
140code or some other backend (Parrot/Lisp/Perl5).
141
142Once the kp6 is sufficently working, you can use kp6 to compile the AST/Grammer/Visitor
143perl6 code to produce NEWER, better, libraries.  The new libraries replace the
144existing libraries/code produced by mp6.  Ergo, miniperl6 is no longer needed;
145kp6 has just bootstrapped itself.
146
147The mp6.pl files are:
148
149 src/KindaPerl6/Ast.pm
150                Grammar.pm
151                Traverse.pm
152
153 src/KindaPerl6/Grammer/*
154
155 src/KindaPerl6/Visitor/*
156
157kp6 provides a Runtime enviroment for perl6 code with src/KindaPerl6/Runtime/*
158so that we can execute perl6 code that has been translated to perl5.
159
160=head2 What subset of Perl 6 is covered by mp6?
161
162  (from miniperl6-spec.pod)
163
164=over
165
166=item
167
168A program is organized in compilation units. All statements must be inside a
169'class' declaration: class X { ... }
170
171=item
172
173All statements finish with semicolon.
174
175=item
176
177Only allow one feed of positional arguments.
178
179=item
180
181In Signature, disallow "is slurpy", "is optional", "is named" (*@bad) ($bad?)
182(:$bad)
183
184=item
185
186But we do allow Hash and Array and Tree unpacking:
187
188 sub foo ([$a, $b, $c], {:$x, :$y}, ::Tree $top (:$left, :$right)) { ... }
189
190 foo([1, 2, 3], { x => 1, y => 2 }, ::Tree( left => 1, right => 2 ));
191
192 # This compiles to:
193 sub foo {
194     my perl6::Tree $top;
195     my ($a, $b, $c, $top, $x, $y, $left, $right);
196     ($a, $b, $c)  = @_[0];
197     ($x, $y)      = @_[1]{'x', 'y'};
198     $top          = @_[2];
199     ($left, $right) = ($top.left, $top.right);
200     ...
201 }
202
203 foo([1, 2, 3], { x => 1, y => 2 });
204
205=item
206
207As a consequence, object constructor calls must be written in coercion form:
208
209 ::Foo( x => 1, y => 2 );   # NOT Foo.new
210
211=item
212
213Only allow item context.
214
215=item
216
217No laziness; all List are Sequences.
218
219=item
220
221No subtyping (inheritance) or role mixings.
222
223=item
224
225No first-class Capture and Signature objects, which means no \$x nor :(foo)
226
227=item
228
229No assignment, only bindings, but do not panic:
230
231 $x := $x + 1;   # name = IntOp(named(Int))
232 # $x = $x + 1
233
234The reason is we have to eliminate one of them to avoid dealing with:
235
236 $x := $y;
237 $x = 123;
238
239Because assignment always involve box(unbox()), so emitting the binding to Perl
2405 is much more straightforward as $x is always just a Int in ($x := $x + 1),
241never SomePossiblyTiedScalarContainerType that needs to have special FETCH magic
242associated with $x.
243
244Also it (WHAT IS "IT"?) is inevitable with eliminating list context, because:
245 ($x, $y, $z) := (1, 2); # compile-time error.
246 ($x, $y, $z) = (1, 2);  # list-context-undef-fill that we do not want to deal with.
247
248Because infix:<=> almost always imply slurpiness with LHS is not a simple
249scalar, eliminating it is consistent with eliminating list context.
250
251=item
252
253Annotations are preserved in Perl 5 emitted code using simple Typed vars:
254
255 # MiniPerl6
256 my Int $x;
257 my perl5:CGI $x;
258
259 # Compiled Perl 5
260 my perl6::Int $x;
261 my CGI $x;
262
263The compiler adds no extra assertions, there for using types will not degrade
264performance in MiniPerl6 land.
265
266=item
267
268No coroutines. No continuations
269
270=item
271
272Categories and precedence levels
273
274=item
275
276; no BEGIN blocks!
277
278=back
279
280=head2 Can mp6 be run in perl5?
281
282Yes.  Perl5 is currently the only fully working backend.
283
284=head2 Can mp6 be run in pugs?
285
286We are not aware of anyone who has tried.  Please let us know, if someone has
287tried.
288
289=head2 Can mp6 be run in parrot?
290
291There is an implementation of a parrot emitter, but the emitter cannot run
292full-mp6 yet.
293
294The implementation of the PAST emitter was also under way.
295
296=head2 Can mp6 be run in ruby/javascript/c#/c/d ?
297
298There is some work done for a D implementation.
299
300Ruby and Javascript can probably reuse some work that was done for redsix and pil2js.
301
302=head2 Running mp6
303
304There are control scripts for compiling mp6 to several backends:
305
306Perl 5:
307
308 perl mp6-perl5-boot.pl < source.pl > dest.pl
309
310Parrot:
311
312 perl mp6-parrot.pl < source.pl > dest.pir
313
314Parrot-PAST:
315
316 perl mp6-past.pl < source.pl > dest.past
317
318=over
319
320=item Bootstrapping mp6-perl5:
321
322This script rebuilds the lib5 directory. It creates a directory named lib5-new:
323
324  cd pugs/v6/v6-MiniPerl6
325  perl util/build-perl5.sh
326  mv lib5 lib5-old
327  mv lib5-new lib5
328
329=item What subset of Perl 6 is covered by kp6?
330
331kp6 reuses the mp6 grammar.  The main differences are not visible - kp6 adds an
332extra (Abstract Syntax Tree) AST processing step.
333kp6 adds:
334
335 - lexical subs
336 - metamodel interface
337 - lexical classes (planned, not implemented)
338 - begin blocks
339 - containers
340
341=item Running kp6
342
343kp6 works by creating a parse tree, which is then submitted to a list of AST
344processors called "Visitors" (namespace C<KindaPerl6::Visitor::*>).  Which is
345then handed off to the KindaPerl6/Visitor/Emit/Perl5.pm to be translated into
346perl5.
347
348script/kp6 is one of the possible compiler 'workflows' that can be built with
349kp6.  You can specify other workflows such as lisp by specifying a different
350backend with -B, perldoc script/kp6 for more info.
351
352perl script/kp6 -o dest.pm source.pm
353
354 perl script/kp6 -e 'say 42;'
355 ---
356 42
357
358To execute a Perl 6 script directly type
359
360 perl script/kp6 source.p6
361
362=item Compiling kp6
363
364As of this writing, kp6 is not bootstrapped (in progress though).
365
366The kp6 source files can be compiled with mp6 (whith the exception of the
367KindaPerl6::Runtime::Perl6::* files, which are compiled wih kp6). There
368is a 'mp6.pl' script in kp6 directory:
369
370Please use the make file to compile these.
371
372 make forcerecompile
373 make
374 make test
375
376These will force compilation of various files.
377
378Example:
379
380 perl mp6.pl < lib/KindaPerl6/Visitor/EmitPerl5.pm > lib5/KindaPerl6/Visitor/EmitPerl5.pm
381 -or-
382 perl mp6.pl -o lib5/KindaPerl6/Visitor/EmitPerl5.pm lib/KindaPerl6/Visitor/EmitPerl5.pm
383
384=back
385
386=head2 How much of the test suite passes?
387
388A few tests pass.
389
390In mp6, you can pass t/01-sanity/01-tap.t by preprocess by removing of
391"use v6-alpha;" and wrapping the input in "class Main {...}". See pugs/project_planning/TALK.
392Some tests pass for kp6. See end of file in v6/v6-KindaPerl6/scripts/run_test.pl
393
394=head2 How much of the test suite will eventually pass?
395
396Passing tests depends on improving the grammar and the runtime.
397Instead, kp6 focus is now on bootstraping.
398
399
400=head2 Why does parsing take so much time?
401
402The parser is recursive-descent.
403
404 "Ziggy6" pasted "Total Elapsed Time = 20.53264"
405 Total Elapsed Time = 20.53264 Seconds
406 User+System Time = 19.45264 Seconds
407 Exclusive Times
408 %Time ExclSec CumulS #Calls sec/call Csec/c  Name
409 42.7   8.307  8.446 253776   0.0000 0.0000  MiniPerl6::Perl5::Match::new
410 30.4   5.918  5.876 150690   0.0000 0.0000  MiniPerl6::Perl5::Match::to
411 15.0   2.919 11.171  36356   0.0001 0.0003  MiniPerl6::Grammar::ws
412 8.58   1.669  1.688 253776   0.0000 0.0000  MiniPerl6::Perl5::Match::DESTROY
413 5.58   1.085  1.037 259216   0.0000 0.0000  MiniPerl6::Perl5::Match::__ANON__
414 5.36   1.042 12.035  20975   0.0000 0.0006  MiniPerl6::Grammar::opt_ws
415 4.67   0.909  2.824  36400   0.0000 0.0001  MiniPerl6::Grammar::newline
416 ...
417
418The code generated by the parser makes several method calls on each
419character - this can be optimized with inlining (not planned for mp6).
420A MiniPerl6::Perl5::Match is created for every character.
421
422=head2 Why isn't kp6 self-hosting?
423
424kp6 will be self-hosting. The process depends on a fast enough parse engine and porting
425thing using the mp6 calling conventions.
426
427=head2  What is the plan for kp6?
428
429=over
430
431=item Provide a minimal bootstrapped language implementation for bootstrapping p6-on-p6.
432
433Extra features over mp6 - allow the implementation of BEGIN blocks, flexible grammar.
434
435=item Implement a flexible/pluggable compiler engine.
436
437This is currently done with a Visitor pattern for AST transforms.
438
439=item Lexical subs
440
441Allows operator redefinition:
442
443my multi infix:<+> { ... }
444
445But note that 'multi' is not part of the kp6 spec.
446
447=item Lexical classes / first-class classes.
448
449Better support for grammar mutability:
450
451 $?GRAMMAR   Which grammar am I in? (from S02)
452 @?GRAMMAR   Which nested grammars am I in?
453
454Update: Lexical classes will not be implemented.
455
456=item Metamodel interface
457
458Allow pluggable object models.
459
460=item BEGIN blocks
461
462BEGIN blocks are needed to seperate compile-time from run-time.
463
464=item Containers
465
466This is needed to implement assignment - MP6 only supported binding.
467
468=back
469
470=head2 Is kp6 needed for bootstrapping perl 6 on perl 6?
471
472No. perl 6 on perl 6 can also be bootstrapped with:
473
474 - Parrot
475 - Pugs
476 - v6.pm
477 - Plain mp6
478 - Redsix L<http://dev.pugscode.org/browser/misc/pX/Common/redsix>
479
480=head2 How to use kp6 to compile everything.
481
482TODO: make KP6-BOOT
483
484=head2 How to: make / compile / test  -  kp6
485
486=over
487
488=item Download KindaPerl6.
489
490 svn co http://svn.pugscode.org/pugs/
491
492=item To compile KP6.
493
494 perl Makefile.PL
495 make -j 3 test
496
497I<-j 3 means do 3 jobs at once, great for systems with SMP>
498
499=item To re-compile KP6.
500
501 make clean
502 perl Makefile.PL
503 make -j 3 test
504
505=item Force re-compilation of everything.
506
507 make forcerecompile
508 setenv PERL5LIB "./inc/v6-MiniPerl6-lib5" (XXX can this step be removed?)
509 make
510
511I<WARNING: Do NOT use -j when forcing a recompile!, this will cause the Makefile
512to crash.  The make process will attempt to use code that has not yet been
513compiled.>
514
515=item To execute a script.
516
517 perl scripts/kp6 [perl6 file]
518
519
520=item To compile a perl6 script and view resulting source:
521
522 perl scripts/kp6 -o [outputfile.pl] [source perl6 file]
523
524=item To debug perl6 in perl5 code scripts.
525
526 setenv PERL5LIB compiled/perl5-kp6-mp6/lib
527 perl -d (some script)
528 DB> $DB::deep = 500;
529
530I<Do to the recurisve nature of the code, you're likely to hit 100 pertty fast.>
531
532=back
533
534=head2 Miscellaneous Notes
535
536L<http://irclog.perlgeek.de/perl6/2007-01-22#i_-60765>
537
538fglock: hmm - maybe for mp6; need to find a way to do eval() to
539
540L<http://cataclysm.cx/2006/08/19/closures-in-c/>
541
542 Closures in C
543 By: eaten by a grue
544
545=head2 See Also
546
547A Two-Dimensional Separation of Concerns for Compiler Construction
548
549L<http://www.cis.uab.edu/gray/Pubs/sac-2005-carl.pdf>
550
551- Compares the visitor pattern (used by kp6) with other approaches
552
553=head1 AUTHORS
554
555The Pugs Team E<lt>perl6-compiler@perl.orgE<gt>.
556
557=head1 SEE ALSO
558
559The Perl 6 homepage at L<http://dev.perl.org/perl6>.
560
561The Pugs homepage at L<http://pugscode.org/>.
562
563=head1 COPYRIGHT
564
565Copyright 2007 by Flavio Soibelmann Glock and others.
566
567This program is free software; you can redistribute it and/or modify it
568under the same terms as Perl itself.
569
570See L<http://www.perl.com/perl/misc/Artistic.html>
571
572=cut
Note: See TracBrowser for help on using the browser.