minigrace
Version:
A compiler for the Grace programming language
906 lines • 222 kB
JavaScript
let gracecode_xmodule_sourceFile = "/Users/black/Development/mg/gracelang/minigrace/xmodule.grace";
let gracecode_xmodule_sha256 = "46a15a75629b375b4b03da9e3e9227e8eb90c02d6f3e161b9a85ba58e671cea2";
let gracecode_xmodule_minigraceRevision = "b57591d29fc5ee5270d114920bf671367b8c3ecb";
let gracecode_xmodule_minigraceGeneration = "5171";
if (typeof gctCache !== "undefined")
gctCache["xmodule"] = "dialect:\n standard\nfreshScopes:\n $103\n $104\n $105\n $107\nmethodTypes:$101:\n filePath(fp:Unknown)sha(sum:Unknown)jsFile(jsf:Unknown)checked(c:Unknown) \u2192 ModuleRecord\n findJsFile(jsFileName:filePath.FilePath)suchThat(p:Predicate1)otherwise(action:Unknown) \u2192 Unknown\nmodules:\n basic\n buildinfo\n errormessages\n intrinsic\n io\n mirror\n regularExpression\n shasum\n standard\n sys\n unixFilePath\n util\npath:\n /Users/black/Development/mg/gracelang/minigrace/xmodule.grace\nscope:$101:\n AstNode type\n CompilerError Unknown (mth) $scope_done\n DialectError Unknown (def) $scope_done public\n GatheringError Unknown (mth) $scope_done\n ModuleRecord type\n Position type\n Range type\n RangeSuggestions type\n Scope type\n Variable type\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n canonicalName(1) Unknown (mth) $scope_done\n checkDialect(1) Unknown (mth) $scope_done\n checkExternalModule(1) Unknown (mth) $scope_done\n checkTransitiveImports(2) Unknown (mth) $scope_done\n compileModule(1)inFile(1)atRange(1) Unknown (mth) $scope_done confidential\n compiledModuleExistsInBrowser(1) Unknown (mth) $scope_done\n currentDialect Unknown (def) $102 public\n doAstCheck(1) Unknown (mth) $scope_done\n doParseCheck(1) Unknown (mth) $scope_done\n emptyRange Unknown (mth) $scope_done\n externalModules Unknown (def) $scopeUniv public\n extract(1)from(1) Unknown (mth) $scope_done\n extractGctFor(1) Unknown (mth) $scope_done confidential\n extractGctFor(1)fromJsFile(1) Unknown (mth) $scope_done confidential\n extractGctFromCache(1) Unknown (mth) $scope_done\n fakeSymbolTable Unknown (mth) $104\n file(1)createdBy(1)withSHA(1) Unknown (mth) $scope_done\n filePath(1)sha(1)jsFile(1)checked(1) ModuleRecord (mth) $103\n findGraceFile(1)otherwise(1) FilePath (mth) $scope_done confidential\n findJsFile(1)suchThat(1)otherwise(1) Unknown (mth) $scope_done\n findOrBuildCompiledModule(3) ModuleRecord (mth) $scope_done confidential\n gctAsString(1) Unknown (mth) $scope_done\n gctDictionaryFor(1) Unknown (mth) $scope_done\n gctDictionaryFrom(1)for(1) Unknown (mth) $scope_done confidential\n isMe(1) Boolean (go) $scope_boolean\n line(1)column(1) Position (mth) $105\n myIdentityHash Number (go) $scope_number\n noPosition Unknown (mth) $scope_done\n nullNode AstNode (mth) $106\n numericName(1) Unknown (mth) $scope_done\n printBacktrace(1)asFarAs(1) Unknown (mth) $scope_done\n reportDialectError(1) Unknown (mth) $scope_done\n splitJsString(1) Unknown (mth) $scope_done confidential\n start(1)end(1) Range (mth) $107\n writeGCT(2) Unknown (mth) $scope_done\nscope:$102:\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n hasAstChecker Unknown (var) $scopeEmpty public\n hasAstChecker:=(1) Unknown (var) $scopeEmpty public\n hasAtEnd Unknown (var) $scopeEmpty public\n hasAtEnd:=(1) Unknown (var) $scopeEmpty public\n hasAtStart Unknown (var) $scopeEmpty public\n hasAtStart:=(1) Unknown (var) $scopeEmpty public\n hasParseChecker Unknown (var) $scopeEmpty public\n hasParseChecker:=(1) Unknown (var) $scopeEmpty public\n isMe(1) Boolean (go) $scope_boolean\n moduleObject Unknown (var) $scopeEmpty public\n moduleObject:=(1) Unknown (var) $scopeEmpty public\n myIdentityHash Number (go) $scope_number\n name Unknown (var) $scopeEmpty public\n name:=(1) Unknown (var) $scopeEmpty public\nscope:$103:\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n checked Unknown (mth) $scope_done\n importsChecked Unknown (var) $scopeEmpty readable\n importsChecked:=(1) Unknown (var) $scopeEmpty readable\n isMe(1) Boolean (go) $scope_boolean\n jsFile Unknown (def) $scopeEmpty public\n myIdentityHash Number (go) $scope_number\n path Unknown (def) $scopeEmpty public\n sha Unknown (def) $scopeEmpty public\nscope:$104:\n ::(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n areReusedNamesCompleted Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n hash Unknown (mth) $scope_done\n isFresh Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n localNames Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n node Unknown (var) $scopeEmpty\n node:=(1) Unknown (var) $scopeEmpty\n prefix== Unknown (mth) $scope_done\n prefix\u2260 Unknown (mth) $scope_done\n variety Unknown (mth) $scope_done\n varsAreMethods Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$105:\n ::(1) Unknown (mth) $scope_done\n <(1) Boolean (mth) $scope_done\n ==(1) Boolean (mth) $scope_done\n >(1) Boolean (mth) $scope_done\n addColumn(1) Unknown (mth) $scope_done\n addLine(1) Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n column Unknown (def) $scopeEmpty\n hash Number (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n line Unknown (def) $scopeEmpty\n myIdentityHash Number (go) $scope_number\n prefix== Unknown (mth) $scope_done\n prefix\u2260 Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\n \u2264(1) Boolean (mth) $scope_done\n \u2265(1) Boolean (mth) $scope_done\nscope:$106:\n ::(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n accept(1)from(1) Unknown (mth) $scope_done\n annotations Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n childrenDo(1) Unknown (mth) $scope_done\n childrenMap(1) Unknown (mth) $scope_done\n column Unknown (def) $scope_number\n column:=(1) Unknown (mth) $scope_done\n comments Unknown (mth) $scope_done\n decType Unknown (mth) $scope_done\n end Position (mth) $scope_done\n endCol Unknown (mth) $scope_done\n hasAnnotation(1) Unknown (mth) $scope_done\n hash Unknown (mth) $scope_done\n inClass Unknown (mth) $scope_done\n inTrait Unknown (mth) $scope_done\n isAssignment Unknown (mth) $scope_done\n isBlock Unknown (mth) $scope_done\n isBuiltIn Unknown (mth) $scope_done\n isCall Unknown (mth) $scope_done\n isClass Unknown (mth) $scope_done\n isComment Unknown (mth) $scope_done\n isConstant Unknown (mth) $scope_done\n isDeclaredByParent Unknown (mth) $scope_done\n isDialect Unknown (mth) $scope_done\n isExecutable Unknown (mth) $scope_done\n isExternal Unknown (mth) $scope_done\n isFresh Unknown (mth) $scope_done\n isIdentifier Unknown (mth) $scope_done\n isImport Unknown (mth) $scope_done\n isMarkerDeclaration Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n isMember Unknown (mth) $scope_done\n isMethod Unknown (mth) $scope_done\n isModule Unknown (mth) $scope_done\n isNull Unknown (mth) $scope_done\n isObject Unknown (mth) $scope_done\n isOuter Unknown (mth) $scope_done\n isReturn Unknown (mth) $scope_done\n isSelf Unknown (mth) $scope_done\n isSelfOrOuter Unknown (mth) $scope_done\n isSequenceConstructor Unknown (mth) $scope_done\n isSuper Unknown (mth) $scope_done\n isTrait Unknown (mth) $scope_done\n isTypeDec Unknown (mth) $scope_done\n kind Unknown (def) $scope_string\n line Unknown (def) $scope_number\n line:=(1) Unknown (mth) $scope_done\n map(1)ancestors(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n nameString Unknown (mth) $scope_done\n newAccept(1) Unknown (mth) $scope_done\n prefix== Unknown (mth) $scope_done\n prefix\u2260 Unknown (mth) $scope_done\n pretty(1) Unknown (mth) $scope_done\n range Unknown (mth) $scope_done\n register Unknown (def) $scope_string\n scope Unknown (def) $104\n shallowCopy Unknown (mth) $scope_done\n start Unknown (mth) $scope_done\n toGrace(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$107:\n ::(1) Unknown (mth) $scope_done\n <(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >(1) Unknown (mth) $scope_done\n arrow Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n column Unknown (mth) $scope_done\n end Unknown (def) $scopeEmpty\n hash Number (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n line Unknown (mth) $scope_done\n lineRangeString Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n prefix== Unknown (mth) $scope_done\n prefix\u2260 Unknown (mth) $scope_done\n rangeLongString Unknown (mth) $scope_done\n rangeString Unknown (mth) $scope_done\n start Unknown (def) $scopeEmpty\n sugg Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\n \u2264(1) Unknown (mth) $scope_done\n \u2265(1) Unknown (mth) $scope_done\nself:\n $101\ntypedec:$101.ModuleRecord:\n type ModuleRecord = interface {\n path \u2192 filePath.FilePath\n sha \u2192 String\n jsFile \u2192 filePath.FilePath\n importsChecked \u2192 Boolean\n checked}\ntypedec:$101.RangeSuggestions:\n type RangeSuggestions = interface {\n line \u2192 Number\n posStart \u2192 Number\n posEnd \u2192 Number\n suggestions}\ntypes:\n $101.ModuleRecord\n $101.RangeSuggestions\n";
if (typeof originalSourceLines !== "undefined") {
originalSourceLines["xmodule"] = [
"dialect \"standard\"",
"import \"io\" as io",
"import \"sys\" as sys",
"import \"util\" as util",
"import \"mirror\" as mirror",
"import \"errormessages\" as errormessages",
"import \"unixFilePath\" as filePath",
"import \"shasum\" as shasum",
"import \"regularExpression\" as regex",
"import \"intrinsic\" as intrinsic",
"import \"basic\" as basic",
"import \"buildinfo\" as buildinfo",
"",
"use basic.open",
"",
"def CheckerFailure = Exception.refine \"CheckerFailure\"",
"def DialectError is public = Exception.refine \"DialectError\"",
" //must correspond to what is defined in \"dialect\"",
"",
"def gctCache = dictionary.empty",
"def keyCompare = { a, b -> a.key.compare(b.key) }",
"",
"def currentDialect is public = object {",
" var name is public := \"standard\"",
" var moduleObject is public // will be assigned if the dialect is loaded",
" var hasParseChecker is public := false",
" var hasAstChecker is public := false",
" var hasAtStart is public := false",
" var hasAtEnd is public := false",
"}",
"// TODO: this partially duplicates information in the moduleNode; integrate",
"",
"type RangeSuggestions = interface {",
" line -> Number",
" posStart -> Number",
" posEnd -> Number",
" suggestions",
"}",
"",
"def externalModules is public = dictionary.empty // dialect, & direct imports",
"def allModules = dictionary.empty // includes above and transitive imports",
"",
"type ModuleRecord = interface { // a record describing an external module",
" path -> filePath.FilePath // the path to the source file",
" sha -> String // the SHA256 checksum of the source",
" jsFile -> filePath.FilePath // the corresponding .js object file",
" importsChecked -> Boolean // have transitive imports been checked?",
" checked // sets importsChecked",
"}",
"",
"class filePath (fp) sha (sum) jsFile (jsf) checked (c) -> ModuleRecord {",
" def path is public = fp // the path to the source file",
" def sha is public = sum // the SHA256 checksum of the source",
" def jsFile is public = jsf // the corresponding .js object file",
" var importsChecked is readable := c",
" // have transitive imports been checked?",
" method checked { importsChecked := true }",
"}",
"",
"method checkDialect(moduleObject) {",
" def dialectNode = moduleObject.theDialect",
" def dmn = dialectNode.moduleName",
" currentDialect.name := dmn",
" if (dmn == \"none\") then { return }",
" util.log 50 verbose \"checking dialect \\\"{dmn}\\\" used by module {moduleObject.name}\"",
" checkExternalModule(dialectNode)",
" def dialectGct = gctDictionaryFor(dialectNode.moduleName)",
" def dialectScope = dialectGct.at \"self\" ifAbsent {",
" EnvironmentException.raise \"dialect \\\"{dmn}\\\"'s gct does not have a 'self' entry\"",
" }.first",
" def dAttributes = dialectGct.at \"scope:{dialectScope}\"",
" if (dAttributes.anySatisfy { each -> each.startsWith \"thisDialect\" }) then {",
" util.log 45 verbose \"loading dialect \\\"{dmn}\\\" for checkers.\"",
" try {",
" def dobj = mirror.loadModule(dialectNode.path)",
" currentDialect.moduleObject := dobj",
" if (mirror.reflect(dobj).methodNames.contains \"thisDialect\") then {",
" def mths = mirror.reflect(dobj.thisDialect).methods",
" for (mths) do { m ->",
" if (m.name == \"parseChecker(_)\") then {",
" currentDialect.hasParseChecker := true",
" }",
" if (m.name == \"astChecker(_)\") then {",
" currentDialect.hasAstChecker := true",
" }",
" if (m.name == \"atEnd(_)\") then {",
" currentDialect.hasAtEnd := true",
" }",
" if (m.name == \"atStart(_)\") then {",
" currentDialect.hasAtStart := true",
" }",
" }",
" }",
" } catch { e:Exception ->",
" util.setPosition(dialectNode.line, 1)",
" e.printBacktrace",
" errormessages.error \"Dialect error: dialect \\\"{dmn}\\\" failed to load.\\n{e}.\"",
" atRange(dialectNode)",
" }",
" } else {",
" util.log 45 verbose \"not loading dialect \\\"{dmn}\\\" because it does not define 'thisDialect'\"",
" }",
"}",
"",
"method doParseCheck(moduleNode) {",
" if (currentDialect.hasParseChecker.not) then { return }",
" try {",
" currentDialect.moduleObject.thisDialect.parseChecker(moduleNode)",
" } catch { e:CheckerFailure | DialectError | errormessages.SyntaxError ->",
" reportDialectError(e)",
" } catch { e:Exception -> // some unknown Grace exception",
" printBacktrace (e) asFarAs \"thisDialect.parseChecker\"",
" errormessages.error(\"Unexpected exception raised by parse checker for \" ++",
" \"dialect '{currentDialect.name}'.\\n{e.exception}: {e.message}\")",
" }",
"}",
"",
"method doAstCheck(moduleNode) {",
" if (currentDialect.hasAstChecker.not) then { return }",
" try {",
" currentDialect.moduleObject.thisDialect.astChecker(moduleNode)",
" } catch { e:CheckerFailure | DialectError | errormessages.SyntaxError ->",
" reportDialectError(e)",
" } catch { e:Exception -> // some unknown Grace exception",
" printBacktrace (e) asFarAs \"thisDialect.astChecker\"",
" errormessages.error(\"Unexpected exception raised by AST checker for \" ++",
" \"dialect '{currentDialect.name}'.\\n{e.exception}: {e.message}\")",
" }",
"}",
"",
"method reportDialectError(ex) {",
" match (ex.data)",
" case { rs:RangeSuggestions ->",
" errormessages.error \"Dialect {currentDialect.name}: {ex.message}.\"",
" atRange(rs)",
" withSuggestions(rs.suggestions)",
" } case { r:Range -> // inlcudes AstNode",
" errormessages.error \"Dialect {currentDialect.name}: {ex.message}.\"",
" atRange(r)",
" } case { p:Position ->",
" errormessages.error \"Dialect {currentDialect.name}: {ex.message}.\"",
" atPosition(p.line, p.column)",
" } else {",
" errormessages.error \"Dialect {currentDialect.name}: {ex.message}.\"",
" atLine(util.linenum)",
" }",
"}",
"",
"method printBacktrace(exceptionPacket) asFarAs (methodName) {",
" def ex = exceptionPacket.exception",
" def msg = exceptionPacket.message",
" def lineNr = exceptionPacket.line",
" def mod = exceptionPacket.moduleName",
" io.error.write \"{ex}: {msg}\\n\"",
" def bt = exceptionPacket.backtrace",
" bt.reversed.do { frameDescription ->",
" io.error.write \" requested from {frameDescription}\\n\"",
" if (frameDescription.contains(methodName)) then { return }",
" }",
"}",
"",
"method checkExternalModule(node) {",
" // Used by identifierresolution to check that node, representing a",
" // dialect or import statement, refers to a module that exisits.",
"",
" // Checks that node.moduleName can be found on node.path, and that a",
" // compiled version exists; creates the compiled version if necessary.",
" // If an existing, up-to-date, compiled version was found, then check",
" // its imports; if we had to compile it, then the recursive compile has",
" // already checked its imports.",
"",
" def moduleName = node.moduleName",
" if (externalModules.containsKey(moduleName)) then {",
" errormessages.syntaxError \"multiple imports of {moduleName}\"",
" atRange (node.range)",
" }",
" if (intrinsic.inBrowser) then {",
" if (compiledModuleExistsInBrowser(moduleName)) then {",
" return",
" } else {",
" errormessages.error \"Please \\\"Run\\\" module {moduleName} before importing it.\"",
" atRange(node.range)",
" }",
" }",
" util.log 50 verbose \"checking module \\\"{moduleName}\\\" used by {util.modname}\"",
" def moduleInfo = findOrBuildCompiledModule(moduleName, node.path, node.range)",
" externalModules.at (moduleName) put (moduleInfo)",
" allModules.at(moduleName) put (moduleInfo)",
" checkTransitiveImports(moduleInfo, node)",
"}",
"",
"method compiledModuleExistsInBrowser(name) {",
" native \"js\" code ‹",
" if (typeof window[graceModuleName(var_name._value)] === \"function\") {",
" return GraceTrue;",
" } else {",
" return GraceFalse;",
" }›",
"}",
"",
"method findOrBuildCompiledModule(moduleName, modulePath, sourceRange) -> ModuleRecord",
" is confidential {",
" // Returns a record desribing the compiled module for moduleName.",
" // Creates the .js file if necessary.",
" // modulePath is the whole string from the dialect or import, potentially",
" // containing \"/\" characters; moduleName is the name after the final \"/\"",
"",
" allModules.at(moduleName) ifAbsent {",
" def graceFile = findGraceFile(modulePath) otherwise { m ->",
" def rm = errormessages.readableStringFrom(m)",
" errormessages.error \"I can't find {modulePath}; tried {rm}.\"",
" atRange (sourceRange)",
" }",
" def sourceSHA = shasum.sha256OfFile(graceFile)",
" def thisCompiler = buildinfo.gitgeneration",
" def jsFileName = filePath.withBase(graceFile.base).setExtension \".js\"",
" def jsFile = findJsFile(jsFileName) suchThat { f ->",
" file(f) createdBy(thisCompiler) withSHA(sourceSHA)",
" } otherwise { m ->",
" def rm = errormessages.readableStringFrom(m)",
" util.log 50 verbose(\"I can't find {jsFileName} with SHA {sourceSHA} \" ++",
" \"compiled by {thisCompiler}; tried {rm}\")",
" def objectFile = compileModule (moduleName) inFile (graceFile)",
" atRange (sourceRange)",
" if (objectFile.exists.not) then {",
" errormessages.error(\"I just compiled {graceFile}, \" ++",
" \"but {objectFile} does not exist\") atRange (sourceRange)",
" }",
" def newModuleRecord = filePath (graceFile) sha (sourceSHA) jsFile (objectFile) checked (true)",
" allModules.at(moduleName) put (newModuleRecord)",
" return newModuleRecord",
" }",
" util.log 55 verbose \"found compiled module \\\"{moduleName}\\\" in {jsFile}\"",
" def newModuleRecord = filePath (graceFile) sha (sourceSHA) jsFile (jsFile) checked (false)",
" allModules.at(moduleName) put (newModuleRecord)",
" newModuleRecord",
" }",
"}",
"",
"method findGraceFile (modulePath) otherwise (action) -> filePath.FilePath",
" is confidential {",
" var candidate := filePath.fromString(modulePath).setExtension \".grace\"",
" def directoryPrefix = candidate.directory",
" if (directoryPrefix.startsWith \"/\") then {",
" if (candidate.exists) then { return candidate }",
" action.apply([candidate])",
" }",
" candidate.setDirectory(util.sourceDir ++ directoryPrefix)",
" if (candidate.exists) then { return candidate }",
" def rejects = list [ candidate ]",
" def locations = filePath.split(sys.environ.at \"GRACE_MODULE_PATH\")",
" locations.do { each ->",
" candidate := candidate.copy.setDirectory(each ++ directoryPrefix)",
" if (candidate.exists) then { return candidate }",
" rejects.add(candidate)",
" }",
" action.apply(rejects)",
"}",
"",
"method findJsFile (jsFileName:filePath.FilePath) suchThat (p:Predicate1) otherwise (action) {",
" // returns a file with the same base as jsFileName, on a directory in",
" // util.sourceDir, util.outDir, or GRACE_MODULE_PATH",
"",
" if ((jsFileName.exists) && {p.apply(jsFileName)}) then { return jsFileName }",
" var candidate := jsFileName.copy",
" def directoryPrefix = candidate.directory",
"",
" candidate.setDirectory(util.outDir)",
" if ((candidate.exists) && {p.apply(candidate)}) then { return candidate }",
" def rejects = list [ candidate ]",
"",
" candidate := candidate.copy.setDirectory(util.outDir ++ directoryPrefix)",
" if ((candidate.exists) && {p.apply(candidate)}) then { return candidate }",
" rejects.add(candidate)",
"",
" if (util.sourceDir ≠ util.outDir) then {",
" candidate := candidate.copy.setDirectory(util.sourceDir ++ directoryPrefix)",
" if ((candidate.exists) && {p.apply(candidate)}) then { return candidate }",
" rejects.add(candidate)",
" }",
" def locations = filePath.split(sys.environ.at \"GRACE_MODULE_PATH\")",
" def od = util.outDir",
" if (locations.contains(od).not) then {",
" locations.add(od)",
" }",
" locations.do { each ->",
" if (directoryPrefix ≠ \"./\") then {",
" candidate := candidate.copy.setDirectory(each ++ directoryPrefix)",
" if ((candidate.exists) && {p.apply(candidate)}) then { return candidate }",
" rejects.add(candidate)",
" }",
" candidate := candidate.copy.setDirectory(each)",
" if ((candidate.exists) && {p.apply(candidate)}) then { return candidate }",
" rejects.add(candidate)",
" }",
" action.apply(rejects)",
"}",
"",
"method file(f) createdBy(thisCompiler) withSHA(sourceSHA) {",
" // was f created by thisCompiler from a Grace file with sourceSHA?",
" ",
" def jsStream = io.open(f, \"r\")",
" try {",
" def originalSHA = extract \"sha256\" from (jsStream)",
" if (originalSHA ≠ sourceSHA) then { return false }",
" def usedCompiler = extract \"minigraceGeneration\" from (jsStream)",
" if (usedCompiler ≠ thisCompiler) then { return false }",
" return true",
" } catch { ex:EnvironmentException ->",
" util.log (util.defaultVerbosity) verbose (ex.message)",
" return false",
" } finally {",
" jsStream.close",
" }",
"}",
"",
"method extract (item) from (stream) {",
" var maxLines := 10 // look in first 10 lines of js file",
" def sought = regex.fromString \"gracecode_.*_{item} = \\\"(\\\\w+)\\\"\"",
" while { stream.eof.not && (maxLines > 0) } do {",
" def line = stream.getline",
" def matches = sought.allMatches(line)",
" if (matches.isEmpty.not) then {",
" return matches.first.group 1",
" }",
" maxLines := maxLines - 1",
" }",
" EnvironmentException.raise \"Can't find {item} in JS file {stream.pathname}\"",
"}",
"",
"method checkTransitiveImports(moduleRecord, node) {",
" if (moduleRecord.importsChecked) then { return }",
" moduleRecord.checked",
" def modulePath = moduleRecord.path",
" def moduleName = modulePath.base",
" def gctDict = gctDictionaryFor(moduleName)",
" util.log 50 verbose \"checking modules imported by \\\"{moduleName}\\\"\"",
" def importedModules = gctDict.at \"modules\" // includes the dialect",
" def m = util.modname",
" importedModules.do { eachImport ->",
" if (m == eachImport) then {",
" errormessages.error(\"cyclic import detected — '{m}' is imported \"",
" ++ \"by '{moduleName}', which is imported by '{m}'\")",
" atRange(node.range)",
" }",
" if (intrinsic.inBrowser) then {",
" if (compiledModuleExistsInBrowser(eachImport)) then {",
" return",
" } else {",
" errormessages.error \"Please \\\"Run\\\" module {eachImport} before importing it.\"",
" atRange(node.range)",
" }",
" }",
" def moduleInfo = findOrBuildCompiledModule(eachImport, eachImport, node.range)",
" checkTransitiveImports(moduleInfo, node)",
" }",
"}",
"",
"method compileModule (nm) inFile (sourceFile) atRange (sourceRange) is confidential {",
" // Compiles module with name nm located in sourceFile.",
" // Returns the filePath containing the compiled code.",
"",
" if (util.recurse.not) then {",
" errormessages.error \"Please compile module {nm} before using it.\"",
" atRange (sourceRange)",
" }",
" if (intrinsic.inBrowser) then {",
" errormessages.error \"Please \\\"Run\\\" module {nm} before using it.\"",
" atRange (sourceRange)",
" }",
" var cmd",
" if (sys.argv.first.contains \"/\") then {",
" cmd := io.realpath(sys.argv.first)",
" } else {",
" cmd := io.realpath \"{sys.execPath}/{sys.argv.first}\"",
" }",
" cmd := \"\\\"{cmd}\\\"\"",
" cmd := cmd.replace \"compiler-js\" with \"minigrace-js\"",
" if (util.verbosity != util.defaultVerbosity) then {",
" cmd := cmd ++ \" --verbose {util.verbosity}\"",
" }",
" var outputDirectory",
" if (util.dirFlag) then {",
" cmd := cmd ++ \" --dir \" ++ util.outDir",
" outputDirectory := util.outDir",
" } else {",
" outputDirectory := sourceFile.directory",
" }",
" if (false != util.vtag) then {",
" cmd := cmd ++ \" --vtag \" ++ util.vtag",
" }",
" if (false != util.gracelibPath) then {",
" cmd := cmd ++ \" --gracelib \" ++ util.gracelibPath",
" }",
" cmd := cmd ++ util.commandLineExtensions",
" if (util.defaultTarget ≠ util.target) then {",
" cmd := cmd ++ \" --target {util.target}\"",
" }",
" cmd := cmd ++ \" --make \\\"{sourceFile}\\\"\"",
" util.log (util.defaultVerbosity - 1) verbose \"executing sub-compile of {sourceFile}\"",
" def exitCode = io.spawn(\"bash\", [\"-c\", cmd]).status",
" if (exitCode != 0) then {",
" errormessages.error \"Failed to compile imported module {nm} ({exitCode}).\"",
" atRange (sourceRange)",
" }",
" filePath.withDirectory(outputDirectory) base(sourceFile.base) extension \".js\"",
"}",
"",
"method gctDictionaryFor(moduleName) {",
" // used by identifierresolution to discover the names defined by moduleName,",
" // as well as here (in xmodule) to find transitive imports of moduleName",
"",
" gctCache.at(moduleName) ifAbsent {",
" gctDictionaryFrom(extractGctFor(moduleName)) for(moduleName)",
" }",
"}",
"",
"method gctDictionaryFrom(gctList) for(moduleName) is confidential {",
" def gctDict = dictionary.empty",
" var key := \"\"",
" for (gctList) do { line ->",
" if (line.size > 0) then {",
" if (line.first ≠ \" \") then {",
" key := line.substringFrom 1 to (line.size-1) // dropping the \":\"",
" gctDict.at(key) put(list [ ])",
" } else {",
" gctDict.at(key).addLast(line.substringFrom 2)",
" }",
" }",
" }",
" gctCache.at(moduleName) put(gctDict)",
" gctDict",
"}",
"",
"method extractGctFor(moduleName) is confidential {",
" // Extracts the gct information for moduleName from an external resource",
" // Returns the gct information as a collection of Strings.",
"",
" if (intrinsic.inBrowser) then { return extractGctFromCache(moduleName) }",
" def jsFile = allModules.at(moduleName).jsFile",
" try {",
" extractGctFor(moduleName) fromJsFile(jsFile)",
" } catch {ex:EnvironmentException ->",
" EnvironmentException.raise (\"failed to find gct for {moduleName} \" ++",
" \"in {jsFile}\")",
" }",
"}",
"",
"method extractGctFor(moduleName) fromJsFile(filepath) is confidential {",
" // Looks in filepath, containing the compiled code for moduleName.",
" // Returns the gct information as a collection of Strings.",
"",
" def jsStream = io.open(filepath, \"r\")",
" var maxLines := 10 // look in first 10 lines of js file",
" while { jsStream.eof.not && (maxLines > 0) } do {",
" def line = jsStream.getline",
" if (line.startsWith \" gctCache[\") then {",
" jsStream.close",
" return splitJsString(line)",
" }",
" maxLines := maxLines - 1",
" }",
" jsStream.close",
" EnvironmentException.raise \"Can't find gct string in JS file {filepath}\"",
"}",
"",
"method splitJsString(jsLine:String) is confidential {",
" // jsLine is a line of javascript like",
" // gctCache[\"xmodule\"] = \"objects:\\nconfidential:\\n CheckerFailure\\n ...\"",
" // Evaluates the string on the rhs of the = sign, splits into lines,",
" // and returns a (Grace) list containing those lines as (Grace) strings.",
" native \"js\" code ‹",
" var arg = var_jsLine._value;",
" var keyStr = \"\\\"] = \";",
" var keyStart = arg.indexOf(keyStr);",
" var stringLit = arg.substr(keyStart + keyStr.length);",
" var gctString = eval(stringLit);",
" var jsStringArray = gctString.split(\"\\n\");",
" result = GraceList([]);",
" for (var ix = 0, len = jsStringArray.length ; ix < len; ix++) {",
" callmethod(result, \"add(1)\", [1],",
" new GraceString (jsStringArray[ix]));",
" }›",
"}",
"",
"method extractGctFromCache(module) {",
" // When running in the browser, returns a Grace list containing",
" // the contents of the cached gct information for module",
"",
" native \"js\" code ‹var gctString = gctCache[var_module._value];",
" var jsStringArray = gctString.split(\"\\n\");",
" result = GraceList([]);",
" for (var ix = 0, len = jsStringArray.length ; ix < len; ix++) {",
" callmethod(result, \"add(1)\", [1],",
" new GraceString (jsStringArray[ix]));",
" }›",
"}",
"",
"method writeGCT(modname, dict) {",
" if (util.extensions.containsKey \"gctfile\") then {",
" def fp = io.open(\"{util.outDir}{modname}.gct\", \"w\")",
" dict.bindings.sortedBy(keyCompare).do { b ->",
" fp.write \"{b.key}:\\n\"",
" b.value.do { v -> fp.write \" {v}\\n\" }",
" }",
" fp.close",
" }",
" gctCache.at(modname) put(dict)",
"}",
"",
"method gctAsString(gctDict) {",
" var ret := \"\"",
" gctDict.bindings.sortedBy(keyCompare).do { b ->",
" ret := ret ++ \"{b.key}:\\n\"",
" b.value.do { v -> ret := ret ++ \" {v}\\n\" }",
" }",
" ret",
"}" ];
}
function gracecode_xmodule() {
importedModules["xmodule"] = this;
const var_$module = this;
this.definitionModule = "xmodule";
this.definitionLine = 1;
setLineNumber(1); // compilenode dialect
// Dialect "standard"
const var_$dialect = do_import("standard", gracecode_standard);
this.outer = var_$dialect;
setLineNumber(2); // compilenode import
// Import of "io" as io
if (typeof gracecode_io == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module io"));
var var_io = do_import("io", gracecode_io);
var func0 = function(argcv) { // accessor method io, line 2
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("io", 0, numArgs - 0);
return var_io;
}; // end of method io
this.methods["io"] = func0;
func0.methodName = "io";
func0.paramCounts = [0];
func0.paramNames = [];
func0.definitionLine = 2;
func0.definitionModule = "xmodule";
func0.debug = "import";
func0.confidential = true;
setLineNumber(3); // compilenode import
// Import of "sys" as sys
if (typeof gracecode_sys == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module sys"));
var var_sys = do_import("sys", gracecode_sys);
var func1 = function(argcv) { // accessor method sys, line 3
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("sys", 0, numArgs - 0);
return var_sys;
}; // end of method sys
this.methods["sys"] = func1;
func1.methodName = "sys";
func1.paramCounts = [0];
func1.paramNames = [];
func1.definitionLine = 3;
func1.definitionModule = "xmodule";
func1.debug = "import";
func1.confidential = true;
setLineNumber(4); // compilenode import
// Import of "util" as util
if (typeof gracecode_util == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module util"));
var var_util = do_import("util", gracecode_util);
var func2 = function(argcv) { // accessor method util, line 4
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("util", 0, numArgs - 0);
return var_util;
}; // end of method util
this.methods["util"] = func2;
func2.methodName = "util";
func2.paramCounts = [0];
func2.paramNames = [];
func2.definitionLine = 4;
func2.definitionModule = "xmodule";
func2.debug = "import";
func2.confidential = true;
setLineNumber(5); // compilenode import
// Import of "mirror" as mirror
if (typeof gracecode_mirror == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module mirror"));
var var_mirror = do_import("mirror", gracecode_mirror);
var func3 = function(argcv) { // accessor method mirror, line 5
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("mirror", 0, numArgs - 0);
return var_mirror;
}; // end of method mirror
this.methods["mirror"] = func3;
func3.methodName = "mirror";
func3.paramCounts = [0];
func3.paramNames = [];
func3.definitionLine = 5;
func3.definitionModule = "xmodule";
func3.debug = "import";
func3.confidential = true;
setLineNumber(6); // compilenode import
// Import of "errormessages" as errormessages
if (typeof gracecode_errormessages == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module errormessages"));
var var_errormessages = do_import("errormessages", gracecode_errormessages);
var func4 = function(argcv) { // accessor method errormessages, line 6
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("errormessages", 0, numArgs - 0);
return var_errormessages;
}; // end of method errormessages
this.methods["errormessages"] = func4;
func4.methodName = "errormessages";
func4.paramCounts = [0];
func4.paramNames = [];
func4.definitionLine = 6;
func4.definitionModule = "xmodule";
func4.debug = "import";
func4.confidential = true;
setLineNumber(7); // compilenode import
// Import of "unixFilePath" as filePath
if (typeof gracecode_unixFilePath == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module unixFilePath"));
var var_filePath = do_import("unixFilePath", gracecode_unixFilePath);
var func5 = function(argcv) { // accessor method filePath, line 7
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("filePath", 0, numArgs - 0);
return var_filePath;
}; // end of method filePath
this.methods["filePath"] = func5;
func5.methodName = "filePath";
func5.paramCounts = [0];
func5.paramNames = [];
func5.definitionLine = 7;
func5.definitionModule = "xmodule";
func5.debug = "import";
func5.confidential = true;
setLineNumber(8); // compilenode import
// Import of "shasum" as shasum
if (typeof gracecode_shasum == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module shasum"));
var var_shasum = do_import("shasum", gracecode_shasum);
var func6 = function(argcv) { // accessor method shasum, line 8
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("shasum", 0, numArgs - 0);
return var_shasum;
}; // end of method shasum
this.methods["shasum"] = func6;
func6.methodName = "shasum";
func6.paramCounts = [0];
func6.paramNames = [];
func6.definitionLine = 8;
func6.definitionModule = "xmodule";
func6.debug = "import";
func6.confidential = true;
setLineNumber(9); // compilenode import
// Import of "regularExpression" as regex
if (typeof gracecode_regularExpression == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module regularExpression"));
var var_regex = do_import("regularExpression", gracecode_regularExpression);
var func7 = function(argcv) { // accessor method regex, line 9
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("regex", 0, numArgs - 0);
return var_regex;
}; // end of method regex
this.methods["regex"] = func7;
func7.methodName = "regex";
func7.paramCounts = [0];
func7.paramNames = [];
func7.definitionLine = 9;
func7.definitionModule = "xmodule";
func7.debug = "import";
func7.confidential = true;
setLineNumber(10); // compilenode import
// Import of "intrinsic" as intrinsic
if (typeof gracecode_intrinsic == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module intrinsic"));
var var_intrinsic = do_import("intrinsic", gracecode_intrinsic);
var func8 = function(argcv) { // accessor method intrinsic, line 10
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("intrinsic", 0, numArgs - 0);
return var_intrinsic;
}; // end of method intrinsic
this.methods["intrinsic"] = func8;
func8.methodName = "intrinsic";
func8.paramCounts = [0];
func8.paramNames = [];
func8.definitionLine = 10;
func8.definitionModule = "xmodule";
func8.debug = "import";
func8.confidential = true;
setLineNumber(11); // compilenode import
// Import of "basic" as basic
if (typeof gracecode_basic == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module basic"));
var var_basic = do_import("basic", gracecode_basic);
var func9 = function(argcv) { // accessor method basic, line 11
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("basic", 0, numArgs - 0);
return var_basic;
}; // end of method basic
this.methods["basic"] = func9;
func9.methodName = "basic";
func9.paramCounts = [0];
func9.paramNames = [];
func9.definitionLine = 11;
func9.definitionModule = "xmodule";
func9.debug = "import";
func9.confidential = true;
setLineNumber(12); // compilenode import
// Import of "buildinfo" as buildinfo
if (typeof gracecode_buildinfo == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module buildinfo"));
var var_buildinfo = do_import("buildinfo", gracecode_buildinfo);
var func10 = function(argcv) { // accessor method buildinfo, line 12
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("buildinfo", 0, numArgs - 0);
return var_buildinfo;
}; // end of method buildinfo
this.methods["buildinfo"] = func10;
func10.methodName = "buildinfo";
func10.paramCounts = [0];
func10.paramNames = [];
func10.definitionLine = 12;
func10.definitionModule = "xmodule";
func10.debug = "import";
func10.confidential = true;
this.closureKeys = this.closureKeys || [];
this.closureKeys.push("outer_xmodule_1");
this.outer_xmodule_1 = var_$dialect;
setLineNumber(14); // reuse call
var initFun11 = request(var_basic, "open$build(3)", [null], this, [], []); // compileReuseCall
setLineNumber(33); // compilenode typedec
// Type decl RangeSuggestions
var func13 = function(argcv) { // method RangeSuggestions, line 1
var returnTarget = invocationCount;
invocationCount++;
setLineNumber(33); // compilenode interfaceliteral
// interface literal
var iface14 = new GraceInterface("RangeSuggestions");
sig15 = () => {
setLineNumber(34); // compilenode member
var call16 = selfRequest(var_$dialect, "Number", [0]);
return new GraceSignature("line", [], [], [], call16);
}
sig17 = () => {
setLineNumber(35); // compilenode member
var call18 = selfRequest(var_$dialect, "Number", [0]);
return new GraceSignature("posStart", [], [], [], call18);
}
sig19 = () => {
setLineNumber(36); // compilenode member
var call20 = selfRequest(var_$dialect, "Number", [0]);
return new GraceSignature("posEnd", [], [], [], call20);
}
sig21 = () => {
return new GraceSignature("suggestions", [], [], [], type_Unknown);
}
iface14.typeMethods = {
"line": sig15
, "posStart": sig17
, "posEnd": sig19
, "suggestions": sig21
};
return iface14;
}; // end of method RangeSuggestions
function memofunc13(argcv) {
if (! this.data["memo$RangeSuggestions"]) // parameterless memo function
this.data["memo$RangeSuggestions"] = func13.call(this, argcv);
return this.data["memo$RangeSuggestions"];
};
this.methods["RangeSuggestions"] = memofunc13;
memofunc13.methodName = "RangeSuggestions";
memofunc13.paramCounts = [0];
memofunc13.paramNames = [];
memofunc13.definitionLine = 1;
memofunc13.definitionModule = "xmodule";
func13.methodName = "RangeSuggestions";
func13.paramCounts = [0];
func13.paramNames = [];
func13.definitionLine = 1;
func13.definitionModule = "xmodule";
setLineNumber(43); // compilenode typedec
// Type decl ModuleRecord
var func23 = function(argcv) { // method ModuleRecord, line 1
var returnTarget = invocationCount;
invocationCount++;
setLineNumber(43); // compilenode interfaceliteral
// interface literal
var iface24 = new GraceInterface("ModuleRecord");
sig25 = () => {
setLineNumber(44); // compilenode member
// call case 4: other requests
var call26 = request(var_filePath, "FilePath", [0]);
return new GraceSignature("path", [], [], [], call26);
}
sig27 = () => {
setLineNumber(45); // compilenode member
var call28 = selfRequest(var_$dialect, "String", [0]);
return new GraceSignature("sha", [], [], [], call28);
}
sig29 = () => {
setLineNumber(46); // compilenode member
// call case 4: other requests
var call30 = request(var_filePath, "FilePath", [0]);
return new GraceSignature("jsFile", [], [], [], call30);
}
sig31 = () => {
setLineNumber(47); // compilenode member
var call32 = selfRequest(var_$dialect, "Boolean", [0]);
return new GraceSignature("importsChecked", [], [], [], call32);
}
sig33 = () => {
return new GraceSignature("checked", [], [], [], type_Unknown);
}
iface24.typeMethods = {
"path": sig25
, "sha": sig27
, "jsFile": sig29
, "importsChecked": sig31
, "checked": sig33
};
return iface24;
}; // end of method ModuleRecord
function memofunc23(argcv) {
if (! this.data["memo$ModuleRecord"]) // parameterless memo function
this.data["memo$ModuleRecord"] = func23.call(this, argcv);
return this.data["memo$ModuleRecord"];
};
this.methods["ModuleRecord"] = memofunc23;
memofunc23.methodName = "ModuleRecord";
memofunc23.paramCounts = [0];
memofunc23.paramNames = [];
memofunc23.definitionLine = 1;
memofunc23.definitionModule = "xmodule";
func23.methodName = "ModuleRecord";
func23.paramCounts = [0];
func23.paramNames = [];
func23.definitionLine = 1;
func23.definitionModule = "xmodule";
var func34 = function(argcv, var_fp, var_sum, var_jsf, var_c) { // method filePath(_)sha(_)jsFile(_)checked(_), line 51
var returnTarget = invocationCount;
invocationCount++;
const numArgs = arguments.length - 1;
if ((numArgs > 4) && (numArgs !== 4)) {
raiseTypeArgError("filePath(_)sha(_)jsFile(_)checked(_)", 0, numArgs - 4);
}
var ouc = emptyGraceObject("filePath(_)sha(_)jsFile(_)checked(_)", "xmodule", 51);
var ouc_init = this.methods["filePath(1)sha(1)jsFile(1)checked(1)$build(3)"].call(this, null, var_fp, var_sum, var_jsf, var_c, ouc, [], []);
ouc_init.call(ouc);
setLineNumber(51); // compilenode member
var call35 = selfRequest(var_$module, "ModuleRecord", [0]);
assertTypeOrMsg(ouc, call35, "object returned from filePath(_)sha(_)jsFile(_)checked(_)", "ModuleRecord");
return ouc;
}; // end of method filePath(_)sha(_)jsFile(_)checked(_)
var call36 = selfRequest(var_$module, "ModuleRecord", [0]);
func34.returnType = call36;
this.methods["filePath(1)sha(1)jsFile(1)checked(1)"] = func34;
func34.methodName = "filePath(1)sha(1)jsFile(1)checked(1)";
func34.paramCounts = [1, 1, 1, 1];
func34.paramNames = ["fp", "sum", "jsf", "c"];
func34.definitionLine = 51;
func34.definitionModule = "xmodule";
var func37 = function(argcv, var_fp, var_sum, var_jsf, var_c, inheritingObject, aliases, exclusions) { // method filePath(_)sha(_)jsFile(_)checked(_)$build(_,_,_), line 51
var returnTarget = invocationCount;
invocationCount++;
const numArgs = arguments.length - 4;
if ((numArgs > 4) && (numArgs !== 4)) {
raiseTypeArgError("filePath(_)sha(_)jsFile(_)checked(_)", 0, numArgs - 4);
}
var obj38_build = function(ignore, var_fp, var_sum, var_jsf, var_c, outerObj, aliases, exclusions) {
this.closureKeys = this.closureKeys || [];
this.closureKeys.push("outer_xmodule_51");
this.outer_xmodule_51 = outerObj;
const inheritedExclusions = { };
for (var eix = 0, eLen = exclusions.length; eix < eLen; eix ++) {
const exMeth = exclusions[eix];
inheritedExclusions[exMeth] = this.methods[exMeth]; };
this.data.path = undefined;
var reader39_path = function() { // reader method path
if (this.data.path === undefined) raiseUninitializedVariable("path");
return this.data.path;
};
reader39_path.isDef = true;
this.methods["path"] = reader39_path;
this.data.sha = undefined;
var reader40_sha = function() { // reader method sha
if (this.data.sha === undefined