minigrace
Version:
A compiler for the Grace programming language
270 lines (261 loc) • 11 kB
JavaScript
let gracecode_timer_sourceFile = "/Users/black/Development/mg/gracelang/minigrace/modules/timer.grace";
let gracecode_timer_sha256 = "185c9965b498538e4b81db6c4b5f94de0d5a198f8bc2107a15e322247c15647f";
let gracecode_timer_minigraceRevision = "b57591d29fc5ee5270d114920bf671367b8c3ecb";
let gracecode_timer_minigraceGeneration = "5171";
if (typeof gctCache !== "undefined")
gctCache["timer"] = "dialect:\n standard\nfreshScopes:\nmethodTypes:$100:\n after(millisec:Unknown)do(codeBlock:Unknown) \u2192 Timer\n every(millisec:Unknown)do(codeBlock:Unknown) \u2192 Timer\n stop(id:Timer) \u2192 Unknown\nmodules:\n standard\npath:\n /Users/black/Development/mg/gracelang/minigrace/modules/timer.grace\nscope:$100:\n Timer type\n after(1)do(1) Timer (mth) $scope_done\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n every(1)do(1) Timer (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n stop(1) Unknown (mth) $scope_done\n stopAll Unknown (mth) $scope_done\nself:\n $100\ntypedec:$100.Timer:\n type Timer = Number\ntypes:\n $100.Timer\n";
if (typeof originalSourceLines !== "undefined") {
originalSourceLines["timer"] = [
"dialect \"standard\"",
"type Timer = Number",
"",
"native \"js\" code ‹",
" this.data.intervalList = [];",
" this.data.timeoutList = [];",
"›",
"",
"method every (millisec) do (codeBlock) -> Timer {",
" native \"js\" code ‹",
" var func = function() {",
" minigrace.trapErrors(function() {",
" callmethod(var_codeBlock, \"apply\", [0]);",
" });",
" }",
" var id = setInterval(func, var_millisec._value);",
" func.id = id;",
" this.data.intervalList.push(id);",
" graceRegisterInterval(id);",
" return new GraceNum(id);",
" ›",
"}",
"method after (millisec) do (codeBlock) -> Timer {",
" native \"js\" code ‹",
" var func = function() {",
" minigrace.trapErrors(function() {",
" callmethod(var_codeBlock, \"apply\", [0]);",
" });",
" }",
" var id = setTimeout(func, var_millisec._value);",
" func.id = id;",
" this.data.timeoutList.push(id);",
" graceRegisterTimeout(id);",
" return new GraceNum(id);",
" ›",
"}",
"method stop(id:Timer) {",
" native \"js\" code ‹",
" var index = this.data.intervalList.indexOf(var_id._value);",
" if(index != -1) {",
" clearInterval(var_id._value);",
" this.data.intervalList.splice(index, 1);",
" }",
" var index = this.data.timeoutList.indexOf(var_id._value);",
" if(index != -1) {",
" clearTimeout(var_id._value);",
" this.data.timeoutList.splice(index, 1);",
" }",
" ›",
"}",
"method stopAll {",
" native \"js\" code ‹",
" var list = this.data.intervalList;",
" for (let i=0; i<list.length; i++)",
" clearInterval(list[i]);",
"",
" this.data.intervalList = [];",
"",
" list = o.methods.timeoutList;",
" var list = o.methods.intervalList;",
" for (let i=0; i<list.length; i++)",
" clearTimeout(list[i]);",
"",
" this.data.timeoutList = [];",
" ›",
"}" ];
}
function gracecode_timer() {
importedModules["timer"] = this;
const var_$module = this;
this.definitionModule = "timer";
this.definitionLine = 1;
setLineNumber(1); // compilenode dialect
// Dialect "standard"
const var_$dialect = do_import("standard", gracecode_standard);
this.outer = var_$dialect;
this.closureKeys = this.closureKeys || [];
this.closureKeys.push("outer_timer_1");
this.outer_timer_1 = var_$dialect;
setLineNumber(2); // compilenode typedec
// Type decl Timer
var func1 = function(argcv) { // method Timer, line 1
var returnTarget = invocationCount;
invocationCount++;
setLineNumber(2); // compilenode member
var call2 = selfRequest(var_$dialect, "Number", [0]);
return call2;
}; // end of method Timer
function memofunc1(argcv) {
if (! this.data["memo$Timer"]) // parameterless memo function
this.data["memo$Timer"] = func1.call(this, argcv);
return this.data["memo$Timer"];
};
this.methods["Timer"] = memofunc1;
memofunc1.methodName = "Timer";
memofunc1.paramCounts = [0];
memofunc1.paramNames = [];
memofunc1.definitionLine = 1;
memofunc1.definitionModule = "timer";
func1.methodName = "Timer";
func1.paramCounts = [0];
func1.paramNames = [];
func1.definitionLine = 1;
func1.definitionModule = "timer";
var func3 = function(argcv, var_millisec, var_codeBlock) { // method every(_)do(_), line 9
var returnTarget = invocationCount;
invocationCount++;
const numArgs = arguments.length - 1;
if ((numArgs > 2) && (numArgs !== 2)) {
raiseTypeArgError("every(_)do(_)", 0, numArgs - 2);
}
setLineNumber(10); // compilenode call
var result = GraceDone; // start native code from line 10
var func = function() {
minigrace.trapErrors(function() {
callmethod(var_codeBlock, "apply", [0]);
});
}
var id = setInterval(func, var_millisec._value);
func.id = id;
this.data.intervalList.push(id);
graceRegisterInterval(id);
return new GraceNum(id);
// end native code insertion
setLineNumber(9); // compilenode member
var call5 = selfRequest(var_$module, "Timer", [0]);
setLineNumber(10); // typecheck
assertTypeOrMsg(result, call5, "result of method every(_)do(_)", "Timer");
return result;
}; // end of method every(_)do(_)
setLineNumber(9); // compilenode member
var call6 = selfRequest(var_$module, "Timer", [0]);
func3.returnType = call6;
this.methods["every(1)do(1)"] = func3;
func3.methodName = "every(1)do(1)";
func3.paramCounts = [1, 1];
func3.paramNames = ["millisec", "codeBlock"];
func3.definitionLine = 9;
func3.definitionModule = "timer";
var func7 = function(argcv, var_millisec, var_codeBlock) { // method after(_)do(_), line 23
var returnTarget = invocationCount;
invocationCount++;
const numArgs = arguments.length - 1;
if ((numArgs > 2) && (numArgs !== 2)) {
raiseTypeArgError("after(_)do(_)", 0, numArgs - 2);
}
setLineNumber(24); // compilenode call
var result = GraceDone; // start native code from line 24
var func = function() {
minigrace.trapErrors(function() {
callmethod(var_codeBlock, "apply", [0]);
});
}
var id = setTimeout(func, var_millisec._value);
func.id = id;
this.data.timeoutList.push(id);
graceRegisterTimeout(id);
return new GraceNum(id);
// end native code insertion
setLineNumber(23); // compilenode member
var call9 = selfRequest(var_$module, "Timer", [0]);
setLineNumber(24); // typecheck
assertTypeOrMsg(result, call9, "result of method after(_)do(_)", "Timer");
return result;
}; // end of method after(_)do(_)
setLineNumber(23); // compilenode member
var call10 = selfRequest(var_$module, "Timer", [0]);
func7.returnType = call10;
this.methods["after(1)do(1)"] = func7;
func7.methodName = "after(1)do(1)";
func7.paramCounts = [1, 1];
func7.paramNames = ["millisec", "codeBlock"];
func7.definitionLine = 23;
func7.definitionModule = "timer";
var func11 = function(argcv, var_id) { // method stop(_), line 37
var returnTarget = invocationCount;
invocationCount++;
const numArgs = arguments.length - 1;
if ((numArgs > 1) && (numArgs !== 1)) {
raiseTypeArgError("stop(_)", 0, numArgs - 1);
}
setLineNumber(37); // compilenode member
var call12 = selfRequest(var_$module, "Timer", [0]);
assertTypeOrMsg(var_id, call12, "argument to request of `stop(_)`", "Timer");
setLineNumber(38); // compilenode call
var result = GraceDone; // start native code from line 38
var index = this.data.intervalList.indexOf(var_id._value);
if(index != -1) {
clearInterval(var_id._value);
this.data.intervalList.splice(index, 1);
}
var index = this.data.timeoutList.indexOf(var_id._value);
if(index != -1) {
clearTimeout(var_id._value);
this.data.timeoutList.splice(index, 1);
}
// end native code insertion
return result;
}; // end of method stop(_)
setLineNumber(37); // compilenode member
var call14 = selfRequest(var_$module, "Timer", [0]);
func11.paramTypes = [call14];
this.methods["stop(1)"] = func11;
func11.methodName = "stop(1)";
func11.paramCounts = [1];
func11.paramNames = ["id"];
func11.definitionLine = 37;
func11.definitionModule = "timer";
var func15 = function(argcv) { // method stopAll, line 51
var returnTarget = invocationCount;
invocationCount++;
const numArgs = arguments.length - 1;
if ((numArgs > 0) && (numArgs !== 0)) {
raiseTypeArgError("stopAll", 0, numArgs - 0);
}
setLineNumber(52); // compilenode call
var result = GraceDone; // start native code from line 52
var list = this.data.intervalList;
for (let i=0; i<list.length; i++)
clearInterval(list[i]);
this.data.intervalList = [];
list = o.methods.timeoutList;
var list = o.methods.intervalList;
for (let i=0; i<list.length; i++)
clearTimeout(list[i]);
this.data.timeoutList = [];
// end native code insertion
return result;
}; // end of method stopAll
this.methods["stopAll"] = func15;
func15.methodName = "stopAll";
func15.paramCounts = [0];
func15.paramNames = [];
func15.definitionLine = 51;
func15.definitionModule = "timer";
setLineNumber(4); // compilenode call
var result = GraceDone; // start native code from line 4
this.data.intervalList = [];
this.data.timeoutList = [];
// end native code insertion
return this;
}
if (typeof global !== "undefined")
global.gracecode_timer = gracecode_timer;
if (typeof window !== "undefined")
window.gracecode_timer = gracecode_timer;
gracecode_timer.definitionModule = "timer";
gracecode_timer.sourceFile = gracecode_timer_sourceFile;
gracecode_timer.sha256 = gracecode_timer_sha256;
gracecode_timer.minigraceRevision = gracecode_timer_minigraceRevision;
gracecode_timer.minigraceGeneration = gracecode_timer_minigraceGeneration;
gracecode_timer.imports = [ ["standard", "5016aa3a5b2e0d35a67289d21c1e41cf8d73bef931ceea7b35f6a8b10a1386cf"] ];
gracecode_timer.definitionLine = 1;