Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Join new and constructor (#286)
Browse files Browse the repository at this point in the history
* Do not allocate intermediary locals when doing a dup of a local

* Added local ahead trick (disabled)

* Prevent local allocation on stackPopToLocalsCount when not required

* Reverting previous commit

* Try to remove local variable for constructors

* Change order of testNativeClass

* Fixes and tests Js native constructors

* Removed unused AstStm.SET_NEW_WITH_CONSTRUCTOR

* Added AstExpr.CONCAT_STRING (not optimized yet)

* Do not optimize CONCAT_STRING when building async js

* Disable codecov

* Handle CONCAT_STRING in UndeterministicParameterEvaluationFeature

* Just generate CONCAT_STRING for JS

* Fixed D tests on mac

* Inject TargetName in Gradle
  • Loading branch information
soywiz committed Jan 13, 2018
1 parent 7a0b0cf commit 3c3536a
Show file tree
Hide file tree
Showing 32 changed files with 347 additions and 193 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ script:
- mvn package
- node target/jtransc-js/program.js
- popd
after_success:
- bash <(curl -s https://codecov.io/bash)
#after_success:
# - bash <(curl -s https://codecov.io/bash)
notifications:
webhooks:
urls:
Expand Down
Binary file modified benchmark/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
12 changes: 6 additions & 6 deletions benchmark/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 15 15:50:33 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-bin.zip
#Sat Jan 13 10:21:06 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
72 changes: 42 additions & 30 deletions benchmark/gradlew
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,26 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -85,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand Down Expand Up @@ -150,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
14 changes: 4 additions & 10 deletions benchmark/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
15 changes: 6 additions & 9 deletions jtransc-core/src/com/jtransc/ast/AstTransformer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ open class AstTransformer {
is AstStm.SET_ARRAY_LITERALS -> transform(stm)
is AstStm.SET_FIELD_STATIC -> transform(stm)
is AstStm.SET_FIELD_INSTANCE -> transform(stm)
is AstStm.SET_NEW_WITH_CONSTRUCTOR -> transform(stm)
is AstStm.IF -> transform(stm)
is AstStm.IF_ELSE -> transform(stm)
is AstStm.WHILE -> transform(stm)
Expand Down Expand Up @@ -79,6 +78,7 @@ open class AstTransformer {
is AstExpr.BINOP -> transform(expr)
is AstExpr.UNOP -> transform(expr)
is AstExpr.CALL_BASE -> transform(expr)
is AstExpr.CONCAT_STRING -> transform(expr)
is AstExpr.ARRAY_LENGTH -> transform(expr)
is AstExpr.ARRAY_ACCESS -> transform(expr)
is AstExpr.FIELD_INSTANCE_ACCESS -> transform(expr)
Expand All @@ -96,6 +96,11 @@ open class AstTransformer {
}
}

open fun transform(expr: AstExpr.CONCAT_STRING): AstExpr {
for (arg in expr.args) transform(arg)
return expr
}

open fun transform(expr: AstExpr.CALL_BASE): AstExpr {
transform(expr.method)
for (arg in expr.args) transform(arg)
Expand Down Expand Up @@ -267,14 +272,6 @@ open class AstTransformer {
return stm
}

open fun transform(stm: AstStm.SET_NEW_WITH_CONSTRUCTOR): AstStm {
transform(stm.local)
transform(stm.method)
transform(stm.target)
transformExprsBox(stm.args)
return stm
}

open fun transform(stm: AstStm.BREAK): AstStm {
return stm
}
Expand Down
13 changes: 5 additions & 8 deletions jtransc-core/src/com/jtransc/ast/AstVisitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ open class AstVisitor {
is AstStm.SET_ARRAY_LITERALS -> visit(stm)
is AstStm.SET_FIELD_STATIC -> visit(stm)
is AstStm.SET_FIELD_INSTANCE -> visit(stm)
is AstStm.SET_NEW_WITH_CONSTRUCTOR -> visit(stm)
is AstStm.IF -> visit(stm)
is AstStm.IF_ELSE -> visit(stm)
is AstStm.WHILE -> visit(stm)
Expand Down Expand Up @@ -95,6 +94,7 @@ open class AstVisitor {
is AstExpr.BINOP -> visit(expr)
is AstExpr.UNOP -> visit(expr)
is AstExpr.CALL_BASE -> visit(expr)
is AstExpr.CONCAT_STRING -> visit(expr)
is AstExpr.ARRAY_LENGTH -> visit(expr)
is AstExpr.ARRAY_ACCESS -> visit(expr)
is AstExpr.FIELD_INSTANCE_ACCESS -> visit(expr)
Expand All @@ -112,6 +112,10 @@ open class AstVisitor {
}
}

open fun visit(expr: AstExpr.CONCAT_STRING) {
for (arg in expr.args) visit(arg)
}

open fun visit(expr: AstExpr.CALL_BASE) {
visit(expr.method)
for (arg in expr.args) visit(arg)
Expand Down Expand Up @@ -259,13 +263,6 @@ open class AstVisitor {
visit(stm.expr)
}

open fun visit(stm: AstStm.SET_NEW_WITH_CONSTRUCTOR) {
visit(stm.local)
visit(stm.method)
visit(stm.target)
visitExprsBox(stm.args)
}

open fun visit(stm: AstStm.BREAK) {
}

Expand Down
53 changes: 33 additions & 20 deletions jtransc-core/src/com/jtransc/ast/ast_body.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.jtransc.ast
import com.jtransc.ds.cast
import com.jtransc.error.invalidOp
import com.jtransc.error.noImpl
import com.jtransc.gen.TargetName
import kotlin.reflect.KProperty

data class AstBody constructor(
Expand All @@ -15,18 +16,19 @@ data class AstBody constructor(
) {
private var _locals: List<AstLocal>? = null

val locals: List<AstLocal> get() {
if (_locals == null) {
val locals = hashSetOf<AstLocal>()
(object : AstVisitor() {
override fun visit(local: AstLocal) {
locals += local
}
}).visit(stm)
_locals = locals.toList()
val locals: List<AstLocal>
get() {
if (_locals == null) {
val locals = hashSetOf<AstLocal>()
(object : AstVisitor() {
override fun visit(local: AstLocal) {
locals += local
}
}).visit(stm)
_locals = locals.toList()
}
return _locals!!
}
return _locals!!
}

fun invalidateLocals() {
_locals = null
Expand Down Expand Up @@ -101,6 +103,7 @@ data class AstLocal(val index: Int, override val name: String, val type: AstType
val isUsed: Boolean get() = (writesCount != 0) || (readCount != 0)
fun write(set: AstStm.SET_LOCAL) = run { writes += set }
fun read(ref: AstExpr.LOCAL) = run { reads += ref }
var ahead: Boolean = false
}

fun AstType.local(name: String, index: Int = 0) = AstExpr.LOCAL(AstLocal(index, name, this))
Expand Down Expand Up @@ -186,7 +189,7 @@ sealed class AstStm : AstElement, Cloneable<AstStm> {
}

class SET_NEW_WITH_CONSTRUCTOR(val local: AstExpr.LocalExpr, val target: AstType.REF, val method: AstMethodRef, args: List<AstExpr>) : AstStm() {
val args = args.map { it.box }
val args = args.boxes
}

class IF(cond: AstExpr, strue: AstStm) : AstStm() {
Expand Down Expand Up @@ -297,6 +300,8 @@ fun AstStm?.isBreakingFlow() = when (this) {
}

abstract class AstExpr : AstElement, Cloneable<AstExpr> {
companion object

class Box(_value: AstExpr) {
var value: AstExpr = _value
set(value) {
Expand Down Expand Up @@ -355,7 +360,9 @@ abstract class AstExpr : AstElement, Cloneable<AstExpr> {

class TYPED_LOCAL(local: AstLocal, type: AstType) : LOCAL_BASE(local, type)

class LOCAL(local: AstLocal) : LOCAL_BASE(local, local.type)
class LOCAL(local: AstLocal) : LOCAL_BASE(local, local.type) {
//var ahead: Boolean = false
}

class PARAM(val argument: AstArgument) : LocalExpr() {
override val name: String get() = argument.name
Expand Down Expand Up @@ -421,9 +428,13 @@ abstract class AstExpr : AstElement, Cloneable<AstExpr> {
abstract val obj: AstExpr.Box
}

class CONCAT_STRING(val original: AstExpr, val args: List<AstExpr>) : AstExpr() {
override val type: AstType = AstType.STRING
}

class CALL_INSTANCE(obj: AstExpr, override val method: AstMethodRef, args: List<AstExpr>, override val isSpecial: Boolean = false) : CALL_BASE_OBJECT() {
override val obj = obj.box
override val args = args.map { it.box }
override val args = args.boxes

override val type = method.type.ret
}
Expand Down Expand Up @@ -546,6 +557,7 @@ abstract class AstExpr : AstElement, Cloneable<AstExpr> {

val List<AstExpr.Box>.exprs: List<AstExpr> get() = this.map { it.value }
val List<AstExpr>.boxes: List<AstExpr.Box> get() = this.map { it.box }
val List<AstExpr.Box>.unbox: List<AstExpr> get() = this.map { it.value }

fun AstExpr.LOCAL.setTo(value: AstExpr): AstStm.SET_LOCAL {
val stm = AstStm.SET_LOCAL(this, value.castTo(this.type), dummy = true)
Expand Down Expand Up @@ -788,13 +800,14 @@ operator fun AstExpr.get(field: AstFieldRef) = AstExpr.FIELD_INSTANCE_ACCESS(fie
operator fun AstExpr.get(method: MethodRef) = MethodWithRef(this, method.ref)
operator fun AstLocal.get(method: MethodRef) = MethodWithRef(this.expr, method.ref)

val AstStm.stms: List<AstStm> get() {
return if (this is AstStm.STMS) {
this.stms.map { it.value }
} else {
listOf(this)
val AstStm.stms: List<AstStm>
get() {
return if (this is AstStm.STMS) {
this.stms.map { it.value }
} else {
listOf(this)
}
}
}

val Iterable<AstStm>.stms: AstStm get() = this.toList().stm()
fun AstExpr.not() = AstExpr.UNOP(AstUnop.NOT, this)
Expand Down
Loading

0 comments on commit 3c3536a

Please sign in to comment.