package org.mozartoz.truffle;

public abstract class Options {

	public static final boolean MEASURE_STARTUP = System.getProperty("oz.measure.startup") != null;

	public static final String SHOW_PROC_AST = System.getProperty("oz.show.ast");

	public static final boolean PROFILER = bool("oz.profiler", false);

	public static final boolean SERIALIZER = !PROFILER && bool("oz.serializer", true);

	public static final boolean TAIL_CALLS = bool("oz.tail.calls", true);

	public static final boolean SELF_TAIL_CALLS = bool("oz.tail.selfcalls", true);
	public static final boolean SELF_TAIL_CALLS_OSR = bool("oz.tail.selfcalls.osr", true);

	public static final boolean STACKTRACE_ON_INTERRUPT = System.getProperty("oz.stacktrace.on_interrupt") != null;

	public static final boolean FREE_LINKS = bool("oz.free.links", true);
	public static final boolean PRINT_NLINKS = bool("oz.print.nlinks", false);

	// Truffle options
	public static final int TruffleInvalidationReprofileCount = integer("graal.TruffleInvalidationReprofileCount", 3);
	public static final int TruffleOSRCompilationThreshold = integer("graal.TruffleOSRCompilationThreshold", 100_000);

	private static boolean bool(String property, boolean defaultValue) {
		String value = System.getProperty(property, Boolean.toString(defaultValue));
		if (value.equalsIgnoreCase("true")) {
			return true;
		} else if (value.equalsIgnoreCase("false")) {
			return false;
		}
		throw new RuntimeException(property + " was expected to be true or false, got " + value);
	}

	private static int integer(String property, int defaultValue) {
		return Integer.valueOf(System.getProperty(property, Integer.toString(defaultValue)));
	}

}

@@ -104,34 +104,20 @@
 ARTUP = 
-System.getProperty
+bool
 (%22oz.mea
@@ -129,25 +129,24 @@
 startup%22
-) != null
+, false)
 ;%0A%0A%09publ
@@ -670,34 +670,20 @@
 RRUPT = 
-System.getProperty
+bool
 (%22oz.sta
@@ -707,17 +707,16 @@
 upt%22
-) != null
+, false)
 ;%0A%0A%09
@@ -1469,16 +1469,17 @@
 se, got 
+'
 %22 + valu
@@ -1479,16 +1479,22 @@
  + value
+ + %22'%22
 );%0A%09%7D%0A%0A%09

Use bool() for most options