Skip to content

Commit

Permalink
Perlito5 - misc - minimal repl (js)
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Sep 2, 2013
1 parent d7d8c35 commit 624a3d3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions misc/pad.js
@@ -0,0 +1,43 @@

// this is the algorithm for keeping the compile-time environment
// incrementally set environment; and keep a pad stack

function print (s) { process.stdout.write(s) }

var prog = [

' var x = 3 ',

' print( "x=" + x + "\\n") ',

' var y = 4; ',

' print( "y=" + y + "\\n") ',

' var z = 7; ',

' y++ ',

' print( "y=" + y + "\\n") ',

' var k = y + 1; print( "k="+ k+ "\\n") '

];

var pad;
while (prog.length) {
var line = prog.shift();
cmd = '(function () { ' +
line + '; ' +
'return function (cmd) { ' +
'return( eval(cmd) ) ' +
'} ' +
'}())';
if (pad) {
pad = pad(cmd)
}
else {
pad = eval(cmd);
}
}

0 comments on commit 624a3d3

Please sign in to comment.