{eval(readFile("Compiled_NamespaceJS_Compiler"));continuation_lib="\nNS = {\n end_normally : false,\n workinglist : [new Object()],\n current : new Object(),\n destination : {},\n action : \"\",\n propagate : \"\",\n what : \"\",\n parameter : \"\",\n in_progress : false,\n debugMode : true,\n\n // predefined namespaces\n userNs : new Object()\n}\n\n$globals = {\n continuation: {in_progress: false, k: []},\n top_level_continuation: null,\n top_level_namespace: new Object(),\n k_type: {call_cc: new Object(), call_comp: new Object(), normal_stack: new Object()}\n}\n\nfunction enable_delimited_continuations(next){\n $globals.top_level_continuation = new Continuation(); \n var result;\n try [$globals.top_level_namespace] {\n result = next();\n }\n catch (e) {\n result = e;\n }\n return result;\n}\n\nfunction invoke_continuation(k, val){\n if (k.type == $globals.k_type.call_cc){\n $globals.continuation.k = [];\n $globals.continuation.k.push(k);\n }\n else if (k.type == $globals.k_type.call_comp){ \n var restoreK = new Continuation(); \n //if we are not in the process of invoking a continuation\n if (!$globals.continuation.in_progress) { \n restoreK.type = $globals.k_type.normal_stack;\n $globals.continuation.k = [restoreK];\n }\n else {\n //replace the last continuation with the current one\n var last = $globals.continuation.k.length-1;\n restoreK.type = $globals.continuation.k[last].type;\n restoreK.target = $globals.continuation.k[last].target;\n $globals.continuation.k.pop();\n $globals.continuation.k.push(restoreK);\n }\n }\n $globals.continuation.in_progress = true;\n k(val);\n}\n\nfunction call_cc(tag, next){\n var k = new Continuation();\n k.target = tag;\n k.type = $globals.k_type.call_cc;\n return next(k);\n}\n\nfunction call_comp(tag, next){\n var k = new Continuation();\n k.target = tag;\n k.type = $globals.k_type.call_comp;\n return next(k);\n}\n\nfunction prompt(tag, abort_handler, next){\n print(\"entering prompt \" + tag);\n try [tag] {\n var result = next();\n \n //if this has to be delimited\n if ($globals.continuation.in_progress){\n //get the continuation from the end of the list\n var k = $globals.continuation.k[$globals.continuation.k.length-1];\n if (k.target === tag) { \n if (k.type == $globals.k_type.call_cc) {\n $globals.continuation.pop();\n throw [$globals.top_level_namespace] result; \n }\n else if (k.type == $globals.k_type.call_comp){\n //pop and invoke the next continuation from the end of the list\n $globals.continuation.k.pop();\n \n if ($globals.continuation.k[$globals.continuation.k.length-1].type == $globals.k_type.normal_stack) {\n //if this of type normal_stack, then it is the last continuation to invoke, and it will not be delimited by a prompt either\n $globals.continuation.k.pop()(result);\n }\n else {\n //this is either a composable or non-composable continuation\n $globals.continuation.k[$globals.continuation.k.length-1](result);\n }\n }\n else{\n print(\"we should not reach here\");\n }\n }\n }\n }\n catch (e) {\n result = abort_handler(e)\n }\n return result;\n}\n\nfunction abort(tag, val){\n throw [tag] val;\n}\n"}