Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
dist: precise
dist: trusty
node_js:
- '4'
jdk:
Expand All @@ -14,14 +14,17 @@ before_install:
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
- sudo update-alternatives --config gcc
- sudo update-alternatives --config g++
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
- echo "deb http://download.mono-project.com/repo/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/mono-official.list
- sudo apt-get update
- mkdir $HOME/usr
- export PATH="$HOME/usr/bin:$PATH"
- wget https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.sh
- chmod +x cmake-3.7.2-Linux-x86_64.sh
- "./cmake-3.7.2-Linux-x86_64.sh --prefix=$HOME/usr --exclude-subdir --skip-license"
install:
- sudo apt-get -y update
- sudo apt-get -y install mono-runtime mono-mcs
- sudo apt-get -y install mono-runtime mono-mcs mono-devel
- sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
- sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key
add -'
Expand Down Expand Up @@ -59,6 +62,12 @@ before_script:
- which node || true
- node --version || true
- dmd --version || true
- mono --version || true
- csc -version || true
- mcs --version || true
- mono --version || true
- mono-csc --version || true
- mono-mcs --version || true
- "./gradlew --version"
script:
- jdk_switcher use oraclejdk8
Expand Down
2 changes: 1 addition & 1 deletion deploy.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SET JTRANCS_DEPLOY=1
gradle install uploadArchives publishPlugins -xtest
gradlew install uploadArchives publishPlugins -xtest %*
2 changes: 1 addition & 1 deletion jtransc-core/src/com/jtransc/gen/common/CommonGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ abstract class CommonGenerator(val injector: Injector) : IProgramTemplate {
fun genExprLocal(e: AstExpr.LOCAL) = if (localVarPrefix.isEmpty()) e.local.targetName else localVarPrefix + e.local.targetName
fun genExprTypedLocal(e: AstExpr.TYPED_LOCAL) = genExprCast(genExprLocal(e.local), e.local.type, e.type)

fun genStmLine(stm: AstStm.LINE) = indent {
open fun genStmLine(stm: AstStm.LINE) = indent {
mark(stm)
if (GENERATE_LINE_NUMBERS) line("// ${stm.line}")
}
Expand Down
7 changes: 7 additions & 0 deletions jtransc-gen-cs/src/com/jtransc/gen/cs/CSharpCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ class CSharpCompiler(

data class Compiler(val path: String, val isMono: Boolean)

val isMonoWithGotoBug get() = !OS.isWindows

fun getCompiler(extraParams: Map<String?, String?>): Compiler {
val forceMono = "CSHARP_USE_MONO" in extraParams
val csharpCommand = extraParams["CSHARP_CMD"]
val csharpCommandWin = extraParams["CSHARP_CMD_WIN"] ?: csharpCommand
val csharpCommandUnix = extraParams["CSHARP_CMD_UNIX"] ?: csharpCommand
val actualCsharpCommand = if (OS.isWindows) csharpCommandWin else csharpCommandUnix

val hasCsc = processUtils.locateCommand("mono-csc") ?: processUtils.locateCommand("csc")

return when {
actualCsharpCommand != null -> Compiler(actualCsharpCommand, isMono = false)
!forceMono && (hasCsc != null) -> Compiler(hasCsc, isMono = false)
forceMono || !OS.isWindows -> Compiler(csharpCommandWin ?: MCS, isMono = true)
else -> Compiler(csharpCommandUnix ?: CSC, isMono = false)
}
Expand Down
20 changes: 17 additions & 3 deletions jtransc-gen-cs/src/com/jtransc/gen/cs/CSharpTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.jtransc.injector.Injector
import com.jtransc.injector.Singleton
import com.jtransc.io.ProcessResult2
import com.jtransc.text.Indenter
import com.jtransc.text.quote
import com.jtransc.vfs.*
import java.io.File

Expand Down Expand Up @@ -60,13 +61,21 @@ class CSharpTarget : GenTargetDescriptor() {
class CSharpGenerator(injector: Injector) : CommonGenerator(injector) {
override val SINGLE_FILE: Boolean = true

val csharpCompiler = CSharpCompiler()

//class DGenerator(injector: Injector) : FilePerClassCommonGenerator(injector) {
override val methodFeatures = setOf(SwitchFeature::class.java, GotosFeature::class.java)
override val methodFeatures = if (csharpCompiler.isMonoWithGotoBug) {
setOf(SwitchFeature::class.java)
} else {
setOf(SwitchFeature::class.java, GotosFeature::class.java)
}
override val methodFeaturesWithTraps = setOf(SwitchFeature::class.java)
override val stringPoolType: StringPool.Type = StringPool.Type.GLOBAL
override val interfacesSupportStaticMembers: Boolean = false
override val floatHasFSuffix = true

override val GENERATE_LINE_NUMBERS = true

override val keywords = setOf(
"abstract", "alias", "align", "asm", "assert", "auto",
"body", "bool", "break", "byte",
Expand Down Expand Up @@ -99,12 +108,15 @@ class CSharpGenerator(injector: Injector) : CommonGenerator(injector) {

override val fixencoding = false

val csharpCompiler = CSharpCompiler()

override fun genCompilerCommand(programFile: File, debug: Boolean, libs: List<String>): List<String> {
return csharpCompiler.genCommand(programFile, debug, libs, extraParams)
}

override fun genStmLine(stm: AstStm.LINE) = indent {
mark(stm)
if (GENERATE_LINE_NUMBERS) line("#line ${stm.line} ${stm.file.quote()}")
}

override fun run(redirect: Boolean): ProcessResult2 {
val names = if (JTranscSystem.isWindows()) {
listOf("program.exe", "a.exe")
Expand Down Expand Up @@ -138,6 +150,8 @@ class CSharpGenerator(injector: Injector) : CommonGenerator(injector) {

override fun quoteString(str: String) = str.dquote()



override fun genSingleFileClasses(output: SyncVfsFile): Indenter = Indenter {
val StringFqName = buildTemplateClass("java.lang.String".fqname)
val classesStr = super.genSingleFileClasses(output)
Expand Down
6 changes: 0 additions & 6 deletions jtransc-main/test/CSharpTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ import testservice.test.ServiceLoaderTest
class CSharpTest : _Base() {
override val DEFAULT_TARGET = CSharpTarget()

@Ignore("Disabled until it works on travis")
@Test fun testHelloWorld() = testClass(Params(clazz = HelloWorldTest::class.java, minimize = false, log = false))

//@Test fun testMicroHelloWorldAsm2() = testClass<MicroHelloWorld>(minimize = false, target = CSharpTarget(), log = false, treeShaking = true, backend = BuildBackend.ASM2)
@Ignore("Disabled until it works on travis")
@Test fun testMicroHelloWorldAsm() = testClass(Params(clazz = MicroHelloWorld::class.java, minimize = false, log = false, treeShaking = true, backend = BuildBackend.ASM))

@Ignore("Disabled until it works on travis")
@Test fun testServiceLoaderTest() = testNativeClass("""
TestServiceImpl1.test:ss
TestServiceCS
""", Params(clazz = ServiceLoaderTest::class.java, minimize = false))

@Ignore("Disabled until it works on travis")
@Test fun testBig() = testClass(Params(clazz = BigTest::class.java, minimize = false, debug = false, log = false))

@Ignore("Already included in BigTest")
Expand All @@ -55,7 +51,6 @@ class CSharpTest : _Base() {
@Test fun testJTranscBug127() = testClass(Params(clazz = JTranscBug127::class.java, minimize = false, log = false, debug = true))

//@Test fun testMicroStaticInitTestAsm2() = testClass<StaticInitTest>(minimize = false, target = CSharpTarget(), log = false, backend = BuildBackend.ASM2, treeShaking = true)
@Ignore("Disabled until it works on travis")
@Test fun testMicroStaticInitTestAsm1() = testClass(Params(clazz = StaticInitTest::class.java, minimize = false, target = CSharpTarget(), log = false, backend = BuildBackend.ASM, treeShaking = true))

@Ignore("Not working fine yet")
Expand All @@ -64,6 +59,5 @@ class CSharpTest : _Base() {
@Ignore("Not working fine yet")
@Test fun testProcess() = testClass(Params(clazz = ProcessTest::class.java, minimize = false, log = false))

@Ignore("Disabled until it works on travis")
@Test fun testAsyncIO() = testClass(Params(clazz = AsyncIOTest::class.java, minimize = false, log = false, treeShaking = true))
}
7 changes: 7 additions & 0 deletions jtransc-utils/src/com/jtransc/lang/nullable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ package com.jtransc.lang

fun <T, T2> T?.nullMap(notNull:T2, isNull:T2) = if (this != null) notNull else isNull

fun <T, R> T?.nonNullMap(gen: (T) -> R): R? {
if (this == null) {
return null
} else {
return gen(this)
}
}