Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (74 sloc) 3.432 kb
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>"Perlito" Perl 6 Compiler</title>
</head>
<body>
<h1><a href="http://www.perlito.org">"Perlito" Perl 6 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="perlito6.js"></script>
<p>Source program:</p>
<textarea id="source" cols="70" rows="10">
my $out = $document.getElementById('print-result');
$out<value> ~= "using the 'document' object\n";
say "hello, World!";
$out<value> ~= "goodbye $_\n" for 1 .. 3;
</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>Syntax tree (AST):</p>
<textarea id="ast-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>
function print(s) {
document.getElementById('print-result').value += s + "\n";
}
function execute() {
var v_document = document;
var source = document.getElementById('source').value;
var pos = 0;
var ast;
var match;
document.getElementById('log-result').value = "";
document.getElementById('ast-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();
document.getElementById('js-result').value += "// Do not edit this file - Generated by Perlito Perl 6\n";
// compilation unit
match = Perlito6$Grammar.exp_stmts(source, pos);
ast = match.scalar();
var tmp = {v_name:"GLOBAL", v_body: ast};
tmp.__proto__ = CompUnit;
ast = tmp;
document.getElementById('ast-result').value += perl(ast) + "\n";
document.getElementById('log-result').value += "Emitting javascript.\n";
document.getElementById('js-result').value += ast.emit_javascript() + ";\n";
pos = match.v_to;
document.getElementById('log-result').value +=
"Finished compilation unit at pos " + pos + " of " + source.length + "\n";
// run
eval(document.getElementById('js-result').value);
// report
var end = new Date().getTime();
var time = end - start;
document.getElementById('log-result').value += "Time: " + (time/1000) + "s\n";
print("Done.\n");
}
catch(err) {
document.getElementById('log-result').value += "Error:\n";
document.getElementById('log-result').value += perl(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.