Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: b2512a4129
Fetching contributors…

Cannot retrieve contributors at this time

executable file 143 lines (117 sloc) 4.326 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>"Perlito" Perl 5 Compiler</title>
</head>
<body>
<h1><a href="http://www.perlito.org">"Perlito" Perl 5 Compiler</a></h1>
<p>Perlito is a compiler collection that implements a Perl 5 and a Perl 6 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="perlito5.js"></script>
<p>Source program:</p>
<textarea id="source" cols="70" rows="10">
use v5;
use strict;
use feature 'say';
package Main;
JS::inline('document.getElementById("print-result").value') =
"Changing the output box using the document object\n";
say <<"HELLO";
"Perlito Perl5" running in $^O
HELLO
say "hello, $_!"
foreach qw#
World
all
#;
sub fact {
$_[0] <= 1
? $_[0]
: $_[0] * fact( $_[0] - 1 )
}
for my $v ( 1 .. 5 ) {
say "fact $v = ", fact($v);
}
my $time = 'Compile-time';
my $str = ' say("this was compiled at $time") ';
$time = 'Run-time';
eval $str;
package BasePrinter;
sub new {
bless {}, $_[0]
}
package Printer;
our @ISA = qw/ BasePrinter /;
sub out {
JS::inline('document.getElementById("print-result").value') =
JS::inline('document.getElementById("print-result").value') . $_[1];
}
package Main;
my $printer = Printer->new;
$printer->out( "Using my 'Printer' object\n" );
my $s = "the text will be replaced";
$s =~ s {will be} {was};
say $s;
say "oops - it was not" if $s !~ /was/;
say "it was indeed" if $s =~ /was/;
</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 Javascript:</p>
<textarea id="js-result" readonly="true" cols="70" rows="5"></textarea><br/>
<p>Output:</p>
<textarea id="print-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('print-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 = "";
document.getElementById('print-result').value = "";
try {
// compile
document.getElementById('log-result').value += "Compiling.\n";
var start = new Date().getTime();
var js_source = p5pkg["Perlito5"].compile_p5_to_js([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";
// run
start = new Date().getTime();
eval(js_source);
end = new Date().getTime();
time = end - start;
document.getElementById('log-result').value += "Running time: " + time + "ms\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>
Jump to Line
Something went wrong with that request. Please try again.