Skip to content

Commit

Permalink
Merge pull request #129 from fixrtm/use-sai
Browse files Browse the repository at this point in the history
Use sai
  • Loading branch information
anatawa12 authored Nov 30, 2020
2 parents 269ce3a + 85b9208 commit 7fa68df
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 771 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ configurations{
}

repositories {
mavenCentral()
jcenter()
}

dependencies {
Expand All @@ -70,7 +70,7 @@ dependencies {
shade ("io.sigpipe:jbsdiff:1.0") {
exclude group: "org.apache.commons", module: "commons-compress"
}
shade "org.mozilla:rhino:1.7.12"
shade "com.anatawa12.sai:sai:0.0.1"

compileOnly files(file("run/fixrtm-cache/script-compiled-class"))
compileOnly files(sourceSets.main.jasm.outputDir)
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/anatawa12/fixRtm/FixRtm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import com.anatawa12.fixRtm.network.NetworkHandler
import com.anatawa12.fixRtm.rtm.modelpack.modelset.dummies.*
import com.anatawa12.fixRtm.scripting.loadFIXScriptUtil
import com.anatawa12.fixRtm.scripting.nashorn.CompiledImportedScriptCache
import com.anatawa12.fixRtm.scripting.rhino.ExecutedScriptCache
import com.anatawa12.fixRtm.scripting.rhino.PrimitiveJavaHelper
import com.anatawa12.fixRtm.scripting.rhino.RhinoHooks
import com.anatawa12.fixRtm.scripting.sai.ExecutedScriptCache
import jp.ngt.ngtlib.NGTCore
import jp.ngt.rtm.RTMCore
import net.minecraft.block.Block
Expand All @@ -32,7 +30,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.network.NetworkCheckHandler
import net.minecraftforge.fml.relauncher.Side
import org.mozilla.javascript.NativeJavaObject
import java.awt.Color
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
Expand All @@ -46,14 +43,11 @@ object FixRtm {

@Mod.EventHandler
fun construct(e: FMLConstructionEvent) {
NativeJavaObject.canConvert(0, Object::class.java)// load
FIXFileLoader.load() // init
when (MainConfig.scriptingMode) {
MainConfig.ScriptingMode.CacheWithRhino -> {
MainConfig.ScriptingMode.CacheWithSai -> {
loadFIXScriptUtil()// init
ExecutedScriptCache.load()// init
PrimitiveJavaHelper.load()// init
RhinoHooks.load()// load
}
MainConfig.ScriptingMode.BetterWithNashorn -> {
Launch.classLoader.addClassLoaderExclusion("jdk.nashorn.")
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class FixRtmCorePlugin : IFMLLoadingPlugin {

override fun getASMTransformerClass(): Array<String>? = arrayOf(
"com.anatawa12.fixRtm.asm.PreprocessorTransformer",
"com.anatawa12.fixRtm.asm.RhinoTransformer"
)

override fun getSetupClass(): String? = null
Expand Down
369 changes: 0 additions & 369 deletions src/main/java/com/anatawa12/fixRtm/asm/RhinoTransformer.kt

This file was deleted.

10 changes: 6 additions & 4 deletions src/main/java/com/anatawa12/fixRtm/asm/config/MainConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object MainConfig {
"scriptingMode", categoryModelLoading,
"use-default",
"scripting mode. the value is one of the list below:\n" +
"cache-with-rhino : the fastest mode but not stable. some script may make error.\n" +
"cache-with-sai : the fastest mode but not stable. some script may make error.\n" +
"better-with-nashorn : same runtime as RTM but a little faster than RTM.\n" +
"use-rtm-normal : same as RTM. this is the slowest mode.\n" +
"use-default : use default mode. currently use-rtm-normal.\n")
Expand Down Expand Up @@ -95,14 +95,16 @@ object MainConfig {
}
}

enum class ScriptingMode(val configValue: String) {
CacheWithRhino("cache-with-rhino"),
enum class ScriptingMode(vararg val configValues: String) {
CacheWithSai("cache-with-sai", "cache-with-rhino"),
BetterWithNashorn("better-with-nashorn"),
UseRtmNormal("use-rtm-normal"),
;

companion object {
private val byConfigValue = values().associateBy { it.configValue }
private val byConfigValue = values()
.flatMap { it.configValues.map { k -> k to it } }
.toMap()

fun getByConfigValue(value: String) = byConfigValue[value]

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/anatawa12/fixRtm/scripting/ExecutedScript.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.anatawa12.fixRtm.scripting

import com.anatawa12.fixRtm.Loggers
import com.anatawa12.fixRtm.caching.TaggedFileManager
import org.mozilla.javascript.Scriptable
import org.mozilla.javascript.ScriptableObject
import org.mozilla.javascript.serialize.ScriptableInputStream
import org.mozilla.javascript.serialize.ScriptableOutputStream
import com.anatawa12.sai.Scriptable
import com.anatawa12.sai.ScriptableObject
import com.anatawa12.sai.serialize.ScriptableInputStream
import com.anatawa12.sai.serialize.ScriptableOutputStream
import java.io.*

class ExecutedScript private constructor(
Expand All @@ -16,9 +16,9 @@ class ExecutedScript private constructor(
val scopeData: ByteArray?
) {
constructor(
dependencies: Map<String, ByteArray>,
scope: ScriptableObject,
base: Scriptable
dependencies: Map<String, ByteArray>,
scope: ScriptableObject,
base: Scriptable
): this(
dependencies, writeScopeData(scope, base)
) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/anatawa12/fixRtm/scripting/FIXScriptUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package com.anatawa12.fixRtm.scripting
import com.anatawa12.fixRtm.asm.config.MainConfig
import com.anatawa12.fixRtm.io.FIXFileLoader
import com.anatawa12.fixRtm.scripting.nashorn.NashornScriptRuntimeImpl
import com.anatawa12.fixRtm.scripting.rhino.RhinoScriptRuntimeImpl
import com.anatawa12.fixRtm.scripting.sai.SaiScriptRuntimeImpl
import jp.ngt.rtm.modelpack.ModelPackManager
import net.minecraft.util.ResourceLocation
import javax.script.ScriptEngine

val scriptRuntime: IScriptRuntime<*, *> = when (MainConfig.scriptingMode) {
MainConfig.ScriptingMode.CacheWithRhino -> RhinoScriptRuntimeImpl
MainConfig.ScriptingMode.CacheWithSai -> SaiScriptRuntimeImpl
MainConfig.ScriptingMode.BetterWithNashorn -> NashornScriptRuntimeImpl
MainConfig.ScriptingMode.UseRtmNormal -> IScriptRuntime.AssertingRuntime
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.anatawa12.fixRtm.scripting

import com.anatawa12.fixRtm.io.FIXFileLoader
import com.anatawa12.sai.ScriptRuntime
import net.minecraft.util.ResourceLocation
import org.mozilla.javascript.ScriptRuntime
import java.util.concurrent.ConcurrentHashMap


Expand Down
102 changes: 0 additions & 102 deletions src/main/java/com/anatawa12/fixRtm/scripting/rhino/CodeGenHooks.kt

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7fa68df

Please sign in to comment.