def loadPrelude(config, recorder, vat): scope = safeScope() # For the prelude (and only the prelude), permit the boot scope. scope.update(bootScope(config.libraryPaths, recorder)) registerGlobals({u"Bool": scope[u"Bool"], u"Bytes": scope[u"Bytes"], u"Char": scope[u"Char"], u"Double": scope[u"Double"], u"Int": scope[u"Int"], u"Str": scope[u"Str"], u"Void": scope[u"Void"]}) module = obtainModule(config.libraryPaths, recorder, "prelude") with recorder.context("Time spent in prelude"): result = module.eval(scope)[0] assert result is not None, "Prelude returned None" assert isinstance(result, ConstMap), "Prelude returned non-Map" prelude = {} for key, value in unwrapMap(result).items(): s = unwrapStr(key) assert s.startswith(u"&&"), "Prelude key doesn't start with &&" prelude[s[2:]] = value log(["info", "prelude"], u"Loaded the prelude") return prelude
def loadPrelude(config, recorder, vat): scope = safeScope() # For the prelude (and only the prelude), permit the boot scope. scope.update(bootScope(config.libraryPaths, recorder)) registerGlobals({ u"Bool": scope[u"Bool"], u"Bytes": scope[u"Bytes"], u"Char": scope[u"Char"], u"Double": scope[u"Double"], u"Int": scope[u"Int"], u"Str": scope[u"Str"], u"Void": scope[u"Void"] }) code = obtainModule(config.libraryPaths, "prelude", recorder) with recorder.context("Time spent in prelude"): result = evaluateTerms([code], scope) if result is None: print "Prelude returned None!?" return {} # debug_print("Prelude result:", result.toQuote()) if isinstance(result, ConstMap): prelude = {} for key, value in unwrapMap(result).items(): if isinstance(key, StrObject): s = unwrapStr(key) if not s.startswith(u"&&"): print "Prelude map key", s, "doesn't start with '&&'" else: prelude[s[2:]] = value else: print "Prelude map key", key, "isn't a string" return prelude print "Prelude didn't return map!?" return {}
def loadPrelude(config, recorder, vat): scope = safeScope() # For the prelude (and only the prelude), permit the boot scope. scope.update(bootScope(config.libraryPaths, recorder)) registerGlobals({u"Bool": scope[u"Bool"], u"Bytes": scope[u"Bytes"], u"Char": scope[u"Char"], u"Double": scope[u"Double"], u"Int": scope[u"Int"], u"Str": scope[u"Str"], u"Void": scope[u"Void"]}) code = obtainModule(config.libraryPaths, "prelude", recorder) with recorder.context("Time spent in prelude"): result = evaluateTerms([code], scope) if result is None: print "Prelude returned None!?" return {} # debug_print("Prelude result:", result.toQuote()) if isinstance(result, ConstMap): prelude = {} for key, value in unwrapMap(result).items(): if isinstance(key, StrObject): s = unwrapStr(key) if not s.startswith(u"&&"): print "Prelude map key", s, "doesn't start with '&&'" else: prelude[s[2:]] = value else: print "Prelude map key", key, "isn't a string" return prelude print "Prelude didn't return map!?" return {}
def runTyphon(argv): # Start metrics. recorder = globalRecorder() recorder.start() # Initialize libsodium. if rsodium.init() < 0: print "Couldn't initialize libsodium!" return 1 config = Configuration(argv) if config.verbose: enableDebugPrint() config.enableLogging() if len(config.argv) < 2: print "No file provided?" return 1 # Pass user configuration to the JIT. set_user_param(None, config.jit) # Intialize our loop. uv_loop = ruv.alloc_loop() # Usurp SIGPIPE, as libuv does not handle it. rsignal.pypysig_ignore(rsignal.SIGPIPE) # Initialize our first vat. It shall be immortal. vatManager = VatManager() vat = Vat(vatManager, uv_loop, checkpoints=-1) vatManager.vats.append(vat) # Update loop timing information. Until the loop really gets going, we # have to do this ourselves in order to get the timing correct for early # timers. ruv.update_time(uv_loop) try: with scopedVat(vat) as vat: prelude = loadPrelude(config, recorder, vat) except LoadFailed as lf: print lf return 1 except CompilerFailed as cf: debug_print("Caught exception while importing prelude:", cf.formatError()) return 1 except UserException as ue: debug_print("Caught exception while importing prelude:", ue.formatError()) return 1 registerGlobals(prelude) scope = safeScope() scope.update(prelude) ss = scope.copy() reflectedSS = monteMap() for k, b in ss.iteritems(): reflectedSS[StrObject(u"&&" + k)] = b ss[u"safeScope"] = finalBinding(ConstMap(reflectedSS), deepFrozenGuard) reflectedSS[StrObject(u"&&safeScope")] = ss[u"safeScope"] scope[u"safeScope"] = ss[u"safeScope"] scope.update(unsafeScope(config)) # The initial vat is included as `currentVat` to the first level of # loading and such. scope[u"currentVat"] = finalBinding(vat, anyGuard) reflectedUnsafeScope = monteMap() unsafeScopeDict = {} for k, b in scope.iteritems(): reflectedUnsafeScope[StrObject(u"&&" + k)] = b unsafeScopeDict[k] = b rus = finalBinding(ConstMap(reflectedUnsafeScope), anyGuard) reflectedUnsafeScope[StrObject(u"&&unsafeScope")] = rus unsafeScopeDict[u"unsafeScope"] = rus try: module = obtainModule([""], recorder, config.argv[1]) except LoadFailed as lf: print lf return 1 if config.loadOnly: # We are finished. return 0 if not config.benchmark: benchmarkSettings.disable() with profiling("vmprof.log", config.profile): # Update loop timing information. ruv.update_time(uv_loop) debug_print("Taking initial turn in script...") result = NullObject try: with recorder.context("Time spent in vats"): with scopedVat(vat): result = module.eval(unsafeScopeDict)[0] if result is None: return 1 except UserException as ue: debug_print("Caught exception while taking initial turn:", ue.formatError()) return 1 # Exit status code. exitStatus = 0 # Update loop timing information. ruv.update_time(uv_loop) try: runUntilDone(vatManager, uv_loop, recorder) rv = resolution(result) if result is not None else NullObject if isinstance(rv, IntObject): exitStatus = rv.getInt() except SystemExit: pass # Huh, apparently this doesn't work. Wonder why/why not. # exitStatus = se.code finally: recorder.stop() recorder.printResults() # Clean up and exit. cleanUpEverything() return exitStatus
def runTyphon(argv): recorder = Recorder() recorder.start() # Initialize libsodium. if rsodium.init() < 0: print "Couldn't initialize libsodium!" return 1 config = Configuration(argv) if config.verbose: enableDebugPrint() config.enableLogging() if len(config.argv) < 2: print "No file provided?" return 1 # Pass user configuration to the JIT. set_user_param(None, config.jit) # Intialize our loop. uv_loop = ruv.alloc_loop() # Usurp SIGPIPE, as libuv does not handle it. rsignal.pypysig_ignore(rsignal.SIGPIPE) # Initialize our first vat. It shall be immortal. vatManager = VatManager() vat = Vat(vatManager, uv_loop, checkpoints=-1) vatManager.vats.append(vat) # Update loop timing information. Until the loop really gets going, we # have to do this ourselves in order to get the timing correct for early # timers. ruv.update_time(uv_loop) try: with scopedVat(vat) as vat: prelude = loadPrelude(config, recorder, vat) except LoadFailed as lf: print lf return 1 registerGlobals(prelude) scope = safeScope() scope.update(prelude) ss = scope.copy() reflectedSS = monteMap() for k, b in ss.iteritems(): reflectedSS[StrObject(u"&&" + k)] = b ss[u"safeScope"] = finalBinding(ConstMap(reflectedSS), deepFrozenGuard) reflectedSS[StrObject(u"&&safeScope")] = ss[u"safeScope"] scope[u"safeScope"] = ss[u"safeScope"] scope.update(unsafeScope(config)) reflectedUnsafeScope = monteMap() unsafeScopeDict = {} for k, b in scope.iteritems(): reflectedUnsafeScope[StrObject(u"&&" + k)] = b unsafeScopeDict[k] = b rus = finalBinding(ConstMap(reflectedUnsafeScope), anyGuard) reflectedUnsafeScope[StrObject(u"&&unsafeScope")] = rus unsafeScopeDict[u"unsafeScope"] = rus try: code = obtainModule([""], config.argv[1], recorder) except LoadFailed as lf: print lf return 1 if config.loadOnly: # We are finished. return 0 if not config.benchmark: benchmarkSettings.disable() with profiling("vmprof.log", config.profile): # Update loop timing information. ruv.update_time(uv_loop) debug_print("Taking initial turn in script...") result = NullObject with recorder.context("Time spent in vats"): with scopedVat(vat): result = evaluateTerms([code], unsafeScopeDict) if result is None: return 1 # Exit status code. exitStatus = 0 # Update loop timing information. ruv.update_time(uv_loop) try: runUntilDone(vatManager, uv_loop, recorder) rv = resolution(result) if result is not None else NullObject if isinstance(rv, IntObject): exitStatus = rv.getInt() except SystemExit: pass # Huh, apparently this doesn't work. Wonder why/why not. # exitStatus = se.code finally: recorder.stop() recorder.printResults() # Clean up and exit. cleanUpEverything() return exitStatus