From 56c2c8d672ae2c065c6d46c3e21465012fc98e2d Mon Sep 17 00:00:00 2001 From: "C.Solovev" Date: Mon, 1 Oct 2018 13:39:08 +0400 Subject: [PATCH 1/2] Fix lateinit error with logger for wasm files --- .../main/kotlin/asmble/cli/ScriptCommand.kt | 20 +++++++++++-------- .../src/main/kotlin/asmble/cli/Translate.kt | 2 +- .../src/main/kotlin/asmble/io/BinaryToAst.kt | 3 +-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/src/main/kotlin/asmble/cli/ScriptCommand.kt b/compiler/src/main/kotlin/asmble/cli/ScriptCommand.kt index f30a9a5..22715e5 100644 --- a/compiler/src/main/kotlin/asmble/cli/ScriptCommand.kt +++ b/compiler/src/main/kotlin/asmble/cli/ScriptCommand.kt @@ -56,16 +56,20 @@ abstract class ScriptCommand : Command() { // if input file is class file "class" -> ctx.classLoader.addClass(File(inFile).readBytes()).let { ctx } // if input file is wasm file - else -> Translate.also { it.logger = logger }.inToAst(inFile, inFile.substringAfterLast('.')).let { inAst -> - val (mod, name) = (inAst.commands.singleOrNull() as? Script.Cmd.Module) ?: + else -> { + val translateCmd = Translate + translateCmd.logger = this.logger + translateCmd.inToAst(inFile, inFile.substringAfterLast('.')).let { inAst -> + val (mod, name) = (inAst.commands.singleOrNull() as? Script.Cmd.Module) ?: error("Input file must only contain a single module") - val className = name?.javaIdent?.capitalize() ?: + val className = name?.javaIdent?.capitalize() ?: "Temp" + UUID.randomUUID().toString().replace("-", "") - ctx.withCompiledModule(mod, className, name).let { ctx -> - if (name == null && index != args.inFiles.size - 1) - logger.warn { "File '$inFile' not last and has no name so will be unused" } - if (name == null || args.disableAutoRegister) ctx - else ctx.runCommand(Script.Cmd.Register(name, null)) + ctx.withCompiledModule(mod, className, name).let { ctx -> + if (name == null && index != args.inFiles.size - 1) + logger.warn { "File '$inFile' not last and has no name so will be unused" } + if (name == null || args.disableAutoRegister) ctx + else ctx.runCommand(Script.Cmd.Register(name, null)) + } } } } diff --git a/compiler/src/main/kotlin/asmble/cli/Translate.kt b/compiler/src/main/kotlin/asmble/cli/Translate.kt index 146dfe9..c133f4d 100644 --- a/compiler/src/main/kotlin/asmble/cli/Translate.kt +++ b/compiler/src/main/kotlin/asmble/cli/Translate.kt @@ -70,7 +70,7 @@ open class Translate : Command() { } } "wasm" -> - Script(listOf(Script.Cmd.Module(BinaryToAst(logger = logger).toModule( + Script(listOf(Script.Cmd.Module(BinaryToAst(logger = this.logger).toModule( ByteReader.InputStream(inBytes.inputStream())), null))) else -> error("Unknown in format '$inFormat'") } diff --git a/compiler/src/main/kotlin/asmble/io/BinaryToAst.kt b/compiler/src/main/kotlin/asmble/io/BinaryToAst.kt index 67db443..9c70c9d 100644 --- a/compiler/src/main/kotlin/asmble/io/BinaryToAst.kt +++ b/compiler/src/main/kotlin/asmble/io/BinaryToAst.kt @@ -2,12 +2,11 @@ package asmble.io import asmble.ast.Node import asmble.util.* -import java.io.ByteArrayInputStream import java.nio.ByteBuffer open class BinaryToAst( val version: Long = 1L, - val logger: Logger = Logger.Print(Logger.Level.OFF), + val logger: Logger = Logger.Print(Logger.Level.WARN), val includeNameSection: Boolean = true ) : Logger by logger { From 58cf836b76391cd005eadb98d98255885a8dab28 Mon Sep 17 00:00:00 2001 From: "C.Solovev" Date: Mon, 1 Oct 2018 13:40:38 +0400 Subject: [PATCH 2/2] Disable Go and Rust examples and up project version --- build.gradle | 24 ++++++++++++------------ settings.gradle | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index a137d53..77e200d 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { allprojects { apply plugin: 'java' group 'com.github.cretz.asmble' - version '0.4.0-fl' + version '0.4.0-fl-fix' repositories { mavenCentral() @@ -143,17 +143,17 @@ project(':examples') { } -project(':examples:go-simple') { - apply plugin: 'application' - ext.wasmCompiledClassName = 'asmble.generated.GoSimple' - dependencies { - compile files('build/wasm-classes') - } - compileJava { - dependsOn compileGoWasm - } - mainClassName = 'asmble.examples.gosimple.Main' -} +//project(':examples:go-simple') { +// apply plugin: 'application' +// ext.wasmCompiledClassName = 'asmble.generated.GoSimple' +// dependencies { +// compile files('build/wasm-classes') +// } +// compileJava { +// dependsOn compileGoWasm +// } +// mainClassName = 'asmble.examples.gosimple.Main' +//} // todo temporary disable Rust regex, because some strings in wasm code exceed the size in 65353 bytes. diff --git a/settings.gradle b/settings.gradle index 3b6175d..951750a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ rootProject.name = 'asmble' include 'annotations', 'compiler', 'examples:c-simple', - 'examples:go-simple', - 'examples:rust-regex', +// 'examples:go-simple', +// 'examples:rust-regex', // todo will be enabled when the problem with string max size will be solved 'examples:rust-simple', 'examples:rust-string' \ No newline at end of file