Skip to content

Instantly share code, notes, and snippets.

@NotFound
Created December 2, 2011 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NotFound/1421426 to your computer and use it in GitHub Desktop.
Save NotFound/1421426 to your computer and use it in GitHub Desktop.
winxed interactive - test
// interactive.winxed
function parse_line(compiler, storage, string line)
{
string source = "function aux(__storage) {";
for (string name in storage) {
var data = storage[name];
string type = data[0];
if (type == "var")
source += "volatile ";
source += type + " " + name + " = __storage['" + name + "'][1];";
}
source += "var __result = function() { " + line + "; } ();";
for (string name in storage) {
var data = storage[name];
string type = data[0];
source += "__storage['" + name + "'][1] = " + type + "(" + name + ");";
}
source += " return __result; }";
say(source);
var pir = compiler.compile(source, "pir":[named("target")] );
say(pir);
var pircomp = compreg("PIR");
var code = pircomp.compile(pir);
var fun = code.all_subs()[0];
var result = fun(storage);
if (result != null)
say(result);
}
function interact(var compiler)
{
var in = getstdin();
var storage = {
"n" : [ "int", 42 ],
"j" : [ "string", "hi"],
"p" : [ "var", null ]
};
for (;;) {
var line = in.readline_interactive("winxed> ");
if (line == null) {
say();
break;
}
try {
parse_line(compiler, storage, line);
}
catch (e)
{
say(e["message"]);
}
}
}
function main()
{
var compiler = load_language("winxed");
interact(compiler);
}
// End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment