Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Perlito5 - perl6 - create html/perlito5to6.html and "make build-5to6b…
…rowser"
- Loading branch information
Showing
6 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
| <html> | ||
| <head> | ||
| <title>"Perlito" Perl5 to Perl6 Compiler</title> | ||
| </head> | ||
| <body> | ||
| <h1><a href="http://www.perlito.org">"Perlito" Perl5 to Perl6 Compiler</a></h1> | ||
|
|
||
| <p>Perlito is a compiler collection that implements a Perl5 and a Perl6 compiler.</p> | ||
|
|
||
| <p>Main Perlito repository: <a href="http://github.com/fglock/Perlito">http://github.com/fglock/Perlito</a></p> | ||
|
|
||
| <script type="text/javascript" src="perlito5to6.js"></script> | ||
|
|
||
| <p>Source program:</p> | ||
| <textarea id="source" cols="70" rows="10"> | ||
| use v5; | ||
| use strict; | ||
| use feature 'say'; | ||
|
|
||
| package Main; | ||
|
|
||
| say <<"HELLO"; | ||
| "Perlito Perl5" running in $^O | ||
| HELLO | ||
|
|
||
| my @x = qw/ x y z /; | ||
| print $x[1], "\n"; | ||
|
|
||
| </textarea><br/> | ||
| <input type="button" value="Execute" onclick="execute()"/> | ||
|
|
||
| <p>Compiler log:</p> | ||
| <textarea id="log-result" readonly="true" cols="70" rows="5"></textarea><br/> | ||
|
|
||
| <p>Compiled to Perl6:</p> | ||
| <textarea id="js-result" readonly="true" cols="70" rows="5"></textarea><br/> | ||
|
|
||
| <script type="text/javascript"> | ||
|
|
||
| function execute() { | ||
|
|
||
| p5pkg.CORE.print = function(List__) { | ||
| var i; | ||
| for (i = 0; i < List__.length; i++) { | ||
| document.getElementById('log-result').value += p5str(List__[i]); | ||
| } | ||
| return true; | ||
| }; | ||
| p5pkg.CORE.warn = function(List__) { | ||
| var i; | ||
| List__.push("\n"); | ||
| for (i = 0; i < List__.length; i++) { | ||
| document.getElementById('log-result').value += p5str(List__[i]); | ||
| } | ||
| return true; | ||
| }; | ||
| p5pkg["main"]["v_^O"] = "browser"; | ||
| p5pkg["main"]["Hash_INC"]["Perlito5/strict.pm"] = "Perlito5/strict.pm"; | ||
| p5pkg["main"]["Hash_INC"]["Perlito5/warnings.pm"] = "Perlito5/warnings.pm"; | ||
|
|
||
| var source = document.getElementById('source').value; | ||
| var pos = 0; | ||
| var ast; | ||
| var match; | ||
| document.getElementById('log-result').value = ""; | ||
| document.getElementById('js-result').value = ""; | ||
| try { | ||
| // compile | ||
| document.getElementById('log-result').value += "Compiling.\n"; | ||
| var start = new Date().getTime(); | ||
| var js_source = p5pkg["Perlito5"].compile_p5_to_p6([source]); | ||
| var end = new Date().getTime(); | ||
| var time = end - start; | ||
| document.getElementById('log-result').value += "Compilation time: " + time + "ms\n"; | ||
| document.getElementById('js-result').value += js_source + ";\n"; | ||
|
|
||
| p5pkg.CORE.print(["\nDone.\n"]); | ||
| } | ||
| catch(err) { | ||
| document.getElementById('log-result').value += "Error:\n"; | ||
| document.getElementById('log-result').value += err + "\n"; | ||
| document.getElementById('log-result').value += "Compilation aborted.\n"; | ||
| } | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package Perlito5; | ||
|
|
||
| use strict; | ||
| use warnings; | ||
|
|
||
| use Perlito5::Match; | ||
| use Perlito5::Grammar; | ||
| use Perlito5::Grammar::Control; | ||
| use Perlito5::Grammar::Precedence; | ||
| use Perlito5::Grammar::Expression; | ||
| use Perlito5::Macro; | ||
| use Perlito5::Runtime; | ||
|
|
||
| use Perlito5::Perl6::Emitter; | ||
|
|
||
| sub compile_p5_to_p6 { | ||
| my $s = shift; | ||
| $Perlito5::PKG_NAME = 'main'; | ||
| $Perlito5::PROTO = {}; | ||
| my $ast = Perlito5::Grammar->exp_stmts($s, 0); | ||
| Perlito5::AST::CompUnit::emit_perl6_program( | ||
| [ | ||
| Perlito5::AST::CompUnit->new( name => 'main', body => Perlito5::Match::flat($ast) ) | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| 1; | ||
|
|