minigrace
Version:
A compiler for the Grace programming language
131 lines (128 loc) • 5.88 kB
JavaScript
let gracecode_shasum_sourceFile = "/Users/black/Development/mg/gracelang/minigrace/shasum.grace";
let gracecode_shasum_sha256 = "07b15f911574781f29203439814e6670bcb6015443837ddba0913468e44284b2";
let gracecode_shasum_minigraceRevision = "b57591d29fc5ee5270d114920bf671367b8c3ecb";
let gracecode_shasum_minigraceGeneration = "5171";
if (typeof gctCache !== "undefined")
gctCache["shasum"] = "dialect:\n standard\nfreshScopes:\nmethodTypes:$100:\n sha256OfFile(f:Unknown) \u2192 String\nmodules:\n standard\npath:\n /Users/black/Development/mg/gracelang/minigrace/shasum.grace\nscope:$100:\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n sha256OfFile(1) String (mth) $scope_done\nself:\n $100\ntypes:\n";
if (typeof originalSourceLines !== "undefined") {
originalSourceLines["shasum"] = [
"dialect \"standard\"",
"// this module provides a function to compute the sha256 checksum",
"// of a file. It depends on the sha node package, which must be installed.",
"",
"native \"js\" code ‹",
" var shaModule;",
" const sha_options = {algorithm: 'sha256'};",
" function sha() {",
" if (!shaModule) {",
" try {",
" shaModule = require('sha');",
" } catch (ex) {",
" throw new GraceExceptionPacket(EnvironmentExceptionObject,",
" new GraceString(\"Can't load JavaScript module 'sha': is it installed?\"));",
" }",
" }",
" return shaModule;",
" }",
"›",
"",
"method sha256OfFile(f) -> String {",
" def fileName = f.asString // in case f is a file path",
" native \"js\" code ‹",
" try {",
" var h = sha().getSync(var_fileName._value, sha_options);",
" } catch (ex) {",
" if ((typeof ex.message.startsWith === \"function\") && (ex.message.startsWith(\"ENOENT:\"))) {",
" setLineNumber(14);",
" throw new GraceExceptionPacket(EnvironmentExceptionObject,",
" new GraceString(\"File '\" + var_fileName._value + \"' does not exist\"));",
" } else {",
" throw ex;",
" }",
" }",
" return new GraceString(h);",
" ›",
"}" ];
}
function gracecode_shasum() {
importedModules["shasum"] = this;
const var_$module = this;
this.definitionModule = "shasum";
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_shasum_1");
this.outer_shasum_1 = var_$dialect;
var func0 = function(argcv, var_f) { // method sha256OfFile(_), line 21
var returnTarget = invocationCount;
invocationCount++;
const numArgs = arguments.length - 1;
if ((numArgs > 1) && (numArgs !== 1)) {
raiseTypeArgError("sha256OfFile(_)", 0, numArgs - 1);
}
setLineNumber(22); // compilenode member
// call case 4: other requests
var call1 = request(var_f, "asString", [0]);
var var_fileName = call1;
setLineNumber(23); // compilenode call
var result = GraceDone; // start native code from line 23
try {
var h = sha().getSync(var_fileName._value, sha_options);
} catch (ex) {
if ((typeof ex.message.startsWith === "function") && (ex.message.startsWith("ENOENT:"))) {
setLineNumber(14);
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("File '" + var_fileName._value + "' does not exist"));
} else {
throw ex;
}
}
return new GraceString(h);
// end native code insertion
setLineNumber(21); // compilenode member
var call3 = selfRequest(var_$dialect, "String", [0]);
setLineNumber(23); // typecheck
assertTypeOrMsg(result, call3, "result of method sha256OfFile(_)", "String");
return result;
}; // end of method sha256OfFile(_)
setLineNumber(21); // compilenode member
var call4 = selfRequest(var_$dialect, "String", [0]);
func0.returnType = call4;
this.methods["sha256OfFile(1)"] = func0;
func0.methodName = "sha256OfFile(1)";
func0.paramCounts = [1];
func0.paramNames = ["f"];
func0.definitionLine = 21;
func0.definitionModule = "shasum";
setLineNumber(5); // compilenode call
var result = GraceDone; // start native code from line 5
var shaModule;
const sha_options = {algorithm: 'sha256'};
function sha() {
if (!shaModule) {
try {
shaModule = require('sha');
} catch (ex) {
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("Can't load JavaScript module 'sha': is it installed?"));
}
}
return shaModule;
}
// end native code insertion
return this;
}
if (typeof global !== "undefined")
global.gracecode_shasum = gracecode_shasum;
if (typeof window !== "undefined")
window.gracecode_shasum = gracecode_shasum;
gracecode_shasum.definitionModule = "shasum";
gracecode_shasum.sourceFile = gracecode_shasum_sourceFile;
gracecode_shasum.sha256 = gracecode_shasum_sha256;
gracecode_shasum.minigraceRevision = gracecode_shasum_minigraceRevision;
gracecode_shasum.minigraceGeneration = gracecode_shasum_minigraceGeneration;
gracecode_shasum.imports = [ ["standard", "5016aa3a5b2e0d35a67289d21c1e41cf8d73bef931ceea7b35f6a8b10a1386cf"] ];
gracecode_shasum.definitionLine = 1;