Skip to content

Commit

Permalink
Convert Smalltalk scripts into text blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Sep 21, 2023
1 parent 6104c2a commit 2430b49
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 64 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
@RunWith(Parameterized.class)
public final class SqueakSUnitTest extends AbstractSqueakTestCaseWithImage {

private static final String LOAD_TEMPLATE_FILE_NAME = "LoadTruffleSqueakPackages.st";
private static final String TEST_CLASS_PROPERTY = "squeakTests";

protected static final List<SqueakTest> TESTS = selectTestsToRun().collect(toList());
Expand Down Expand Up @@ -192,11 +191,26 @@ private static boolean inTruffleSqueakPackage(final SqueakTest test) {

private static void loadTruffleSqueakPackages() {
final long start = System.currentTimeMillis();
final String loadTemplate = MiscUtils.getStringResource(SqueakSUnitTest.class, LOAD_TEMPLATE_FILE_NAME);
if (loadTemplate == null) {
println("Unable to find load template for TruffleSqueak packages");
return;
}
final String loadTemplate = """
[[[ | mc |
mc := MCFileTreeRepository path: '%s'.
Installer monticello
mc: mc;
packages: mc allPackageNames;
install ]
on: Warning do: [ :w | w resume ]]
on: Error do: [ :e | e retry ]]
on: ProgressInitiationException do: [ :e |
e isNested
ifTrue: [ e pass ]
ifFalse: [ e rearmHandlerDuring:
[[ e sendNotificationsTo: [ :min :max :current | "silence" ]]
on: ProgressNotification do: [ :notification | notification resume ]]]].
(Smalltalk at: #TruffleSqueakUtilities) setUpAfterLoadingPackages.
Smalltalk snapshot: true andQuit: false.
""";
evaluate(String.format(loadTemplate, getPathToInImageCode()));
truffleSqueakPackagesLoaded = true;
println("TruffleSqueak packages loaded and image saved in " + ((double) System.currentTimeMillis() - start) / 1000 + "s.");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@

public final class SqueakImageContext {
private static final ContextReference<SqueakImageContext> REFERENCE = ContextReference.create(SqueakLanguage.class);
private static final String PREPARE_HEADLESS_IMAGE_SCRIPT = "PrepareHeadlessImage.st";

/* Special objects */
public final ClassObject trueClass = new ClassObject(this);
Expand Down Expand Up @@ -215,11 +214,28 @@ public void ensureLoaded() {
return;
}

final String prepareHeadlessImageScript = MiscUtils.getStringResource(getClass(), PREPARE_HEADLESS_IMAGE_SCRIPT);
if (prepareHeadlessImageScript == null) {
printToStdErr("Unable to find " + PREPARE_HEADLESS_IMAGE_SCRIPT);
return;
}
final String prepareHeadlessImageScript = """
"Remove active context."
Processor activeProcess instVarNamed: #suspendedContext put: nil.
"Modify StartUpList for headless execution."
{EventSensor. Project} do: [:ea | Smalltalk removeFromStartUpList: ea].
"Start up image (see SmalltalkImage>>#snapshot:andQuit:withExitCode:embedded:)."
Smalltalk
clearExternalObjects;
processStartUpList: true;
setPlatformPreferences;
recordStartupStamp.
"Set author information."
Utilities
authorName: 'TruffleSqueak';
setAuthorInitials: 'TruffleSqueak'.
"Initialize fresh MorphicUIManager."
Project current instVarNamed: #uiManager put: MorphicUIManager new.
""";
try {
evaluate(prepareHeadlessImageScript);
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.CompilationMXBean;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
Expand All @@ -28,7 +27,6 @@
import java.util.Calendar;
import java.util.Properties;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
Expand Down Expand Up @@ -173,18 +171,6 @@ public static long getStartTime() {
return ManagementFactory.getRuntimeMXBean().getStartTime();
}

public static String getStringResource(final Class<?> clazz, final String name) {
CompilerAsserts.neverPartOfCompilation();
try (InputStream is = clazz.getResourceAsStream(name)) {
if (is != null) {
return new String(is.readAllBytes());
}
} catch (final IOException e) {
e.printStackTrace();
}
return null;
}

@TruffleBoundary
public static String getSystemProperties() {
final Properties properties = System.getProperties();
Expand Down

0 comments on commit 2430b49

Please sign in to comment.