Implemented Support of Java 21 VirtualThread
This commit is contained in:
19
.classpath
19
.classpath
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" path="src/core"/>
|
|
||||||
<classpathentry excluding="org/luaj/vm2/luajc/antlr/|org/luaj/vm2/luajc/lst/|org/luaj/vm2/luajc/JavaCodeGenerator.java" kind="src" path="src/jse"/>
|
|
||||||
<classpathentry kind="src" path="src/jme"/>
|
|
||||||
<classpathentry kind="src" path="test/java"/>
|
|
||||||
<classpathentry kind="src" path="test/junit"/>
|
|
||||||
<classpathentry kind="src" path="test/lua"/>
|
|
||||||
<classpathentry kind="src" path="examples/jse"/>
|
|
||||||
<classpathentry kind="src" path="examples/jme"/>
|
|
||||||
<classpathentry kind="src" path="examples/lua"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
|
||||||
<classpathentry kind="lib" path="lib/midpapi20.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/cldcapi11.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/bcel-5.2.jar"/>
|
|
||||||
<classpathentry kind="var" path="JRE_LIB"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
||||||
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
16
.idea/compiler.xml
generated
Normal file
16
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="core" />
|
||||||
|
<module name="jme" />
|
||||||
|
<module name="jse" />
|
||||||
|
<module name="maven-example" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/discord.xml
generated
Normal file
7
.idea/discord.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="PROJECT_FILES" />
|
||||||
|
<option name="description" value="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
13
.idea/encodings.xml
generated
Normal file
13
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/core/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/jme/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/jme/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/jse/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/jse/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
25
.idea/jarRepositories.xml
generated
Normal file
25
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="oac" />
|
||||||
|
<option name="name" value="oac" />
|
||||||
|
<option name="url" value="https://repo.open-autonomous-connection.org/api/packages/open-autonomous-connection/maven" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
9
.idea/luaj.iml
generated
Normal file
9
.idea/luaj.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
18
.idea/misc.xml
generated
Normal file
18
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/examples/maven/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/core/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/jme/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/jse/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
17
.project
17
.project
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>luaj-vm</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
11
README.md
11
README.md
@@ -317,10 +317,6 @@ A simple example may be found in
|
|||||||
You must include the library <b>luaj-jme-3.0.2.jar</b> in your midlet jar.
|
You must include the library <b>luaj-jme-3.0.2.jar</b> in your midlet jar.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
An ant script to build and run the midlet is in
|
|
||||||
<pre>
|
|
||||||
<a href="build-midlet.xml">build-midlet.xml</a>
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
You must install the wireless toolkit and define <em>WTK_HOME</em> for this script to work.
|
You must install the wireless toolkit and define <em>WTK_HOME</em> for this script to work.
|
||||||
@@ -428,7 +424,6 @@ Applets in browsers should use the JsePlatform. The permissions model in applet
|
|||||||
highly restrictive, so a specialization of the <a href="#luajava">Luajava</a> library must be used that
|
highly restrictive, so a specialization of the <a href="#luajava">Luajava</a> library must be used that
|
||||||
uses default class loading. This is illustrated in the sample Applet
|
uses default class loading. This is illustrated in the sample Applet
|
||||||
<a href="examples/jse/SampleApplet.java">examples/jse/SampleApplet.java</a>,
|
<a href="examples/jse/SampleApplet.java">examples/jse/SampleApplet.java</a>,
|
||||||
which can be built using <a href="build-applet.xml">build-applet.xml</a>.
|
|
||||||
|
|
||||||
|
|
||||||
<h3>JmePlatform</h3>
|
<h3>JmePlatform</h3>
|
||||||
@@ -447,7 +442,6 @@ In particular Globals.finder is overridden to load as resources, so scripts shou
|
|||||||
colocated with class files in the MIDlet jar file. <a href="#luajava">Luajava</a> cannot be used.
|
colocated with class files in the MIDlet jar file. <a href="#luajava">Luajava</a> cannot be used.
|
||||||
Camples code is in
|
Camples code is in
|
||||||
<a href="examples/jme/SampleMIDlet.java">examples/jme/SampleMIDlet.java</a>,
|
<a href="examples/jme/SampleMIDlet.java">examples/jme/SampleMIDlet.java</a>,
|
||||||
which can be built using <a href="build-midlet.xml">build-midlet.xml</a>.
|
|
||||||
|
|
||||||
|
|
||||||
<h2>Thread Safety</h2>
|
<h2>Thread Safety</h2>
|
||||||
@@ -889,10 +883,6 @@ Unit test scripts can be found in these locations
|
|||||||
<h2>Code coverage</h2>
|
<h2>Code coverage</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
A build script for running unit tests and producing code coverage statistics is in
|
|
||||||
<pre>
|
|
||||||
<a href="build-coverage.xml">build-coverage.xml</a>
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
It relies on the cobertura code coverage library.
|
It relies on the cobertura code coverage library.
|
||||||
|
|
||||||
@@ -951,7 +941,6 @@ and at <a href="http://luaj.sourceforge.net/api/2.0/index.html">http://luaj.sour
|
|||||||
<li>Add explicit Globals object to manage global state, especially to imrpove thread safety </li>
|
<li>Add explicit Globals object to manage global state, especially to imrpove thread safety </li>
|
||||||
<li>Drop support for lua source to java surce (lua2java) in favor of direct java bytecode output (luajc) </li>
|
<li>Drop support for lua source to java surce (lua2java) in favor of direct java bytecode output (luajc) </li>
|
||||||
<li>Remove compatibility functions like table.getn(), table.maxn(), table.foreach(), and math.log10() </li>
|
<li>Remove compatibility functions like table.getn(), table.maxn(), table.foreach(), and math.log10() </li>
|
||||||
<li>Add ability to create runnable jar file from lua script with sample build file build-app.xml </li>
|
|
||||||
<li>Supply environment as second argument to LibFunction when loading via require() </li>
|
<li>Supply environment as second argument to LibFunction when loading via require() </li>
|
||||||
<li>Fix bug 3597515 memory leak due to string caching by simplifying caching logic.</li>
|
<li>Fix bug 3597515 memory leak due to string caching by simplifying caching logic.</li>
|
||||||
<li>Fix bug 3565008 so that short substrings are backed by short arrays.</li>
|
<li>Fix bug 3565008 so that short substrings are backed by short arrays.</li>
|
||||||
|
|||||||
108
build-app.xml
108
build-app.xml
@@ -1,108 +0,0 @@
|
|||||||
<!-- And build script to compile lua scripts into runnable jar files using the "luajc"
|
|
||||||
lua to java bytecode compiler.
|
|
||||||
|
|
||||||
Each source file is converted into a runnable jar file that takes arguments from the command line.
|
|
||||||
For example, the program test/lua/perf/binarytrees.lua is converted to a jar that can be run with
|
|
||||||
java -jar binarytrees.jar 15
|
|
||||||
-->
|
|
||||||
<project default="all">
|
|
||||||
<import file="build.xml"/>
|
|
||||||
|
|
||||||
<import file="build-libs.xml"/>
|
|
||||||
|
|
||||||
<available file="luaj-jse-${version}.jar" property="luaj.lib.exists"/>
|
|
||||||
|
|
||||||
<!-- this may need to be changed when building on mac -->
|
|
||||||
<property name="rt.jar" value="${java.home}/lib/rt.jar"/>
|
|
||||||
|
|
||||||
<target name="luaj-lib" unless="luaj.lib.exists">
|
|
||||||
<antcall target="jar-jse"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<macrodef name="perftest">
|
|
||||||
<attribute name="cmd"/>
|
|
||||||
<sequential>
|
|
||||||
<echo level="info">------ @{cmd}</echo>
|
|
||||||
<exec executable="bash">
|
|
||||||
<arg value="-c"/>
|
|
||||||
<arg value="time @{cmd}"/>
|
|
||||||
</exec>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<macrodef name="buildappjar">
|
|
||||||
<attribute name="luaprog"/>
|
|
||||||
<attribute name="arg" default=""/>
|
|
||||||
<attribute name="srcdir" default="test/lua/perf"/>
|
|
||||||
<sequential>
|
|
||||||
<echo level="info">=========== @{srcdir}/@{luaprog} =============</echo>
|
|
||||||
<delete dir="build/@{luaprog}"/>
|
|
||||||
<mkdir dir="build/@{luaprog}/class"/>
|
|
||||||
<java classname="luajc">
|
|
||||||
<classpath>
|
|
||||||
<pathelement path="luaj-jse-${version}.jar"/>
|
|
||||||
<pathelement path="lib/bcel-5.2.jar"/>
|
|
||||||
</classpath>
|
|
||||||
<arg value="-s"/>
|
|
||||||
<arg path="@{srcdir}"/>
|
|
||||||
<arg value="-d"/>
|
|
||||||
<arg path="build/@{luaprog}/class"/>
|
|
||||||
<arg value="-m"/>
|
|
||||||
<arg value="-v"/>
|
|
||||||
<arg value="@{luaprog}.lua"/>
|
|
||||||
</java>
|
|
||||||
<jar destfile="build/@{luaprog}.jar">
|
|
||||||
<fileset dir="build/@{luaprog}/class"/>
|
|
||||||
<zipfileset includes="org/luaj/vm2/*.class,org/luaj/vm2/lib/*.class,org/luaj/vm2/lib/jse/*.class,org/luaj/vm2/compiler/*.class" src="luaj-jse-${version}.jar" />
|
|
||||||
<manifest>
|
|
||||||
<attribute name="Main-Class" value="@{luaprog}" />
|
|
||||||
</manifest>
|
|
||||||
</jar>
|
|
||||||
<unjar src="build/@{luaprog}.jar" dest="build/@{luaprog}/unjarred"/>
|
|
||||||
<perftest cmd="java -jar build/@{luaprog}.jar @{arg}"/>
|
|
||||||
|
|
||||||
<!-- The following can be adapted to produce an optimized jar.
|
|
||||||
<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard.jar" />
|
|
||||||
<proguard>
|
|
||||||
-injars build/@{luaprog}.jar
|
|
||||||
-outjars build/@{luaprog}-opt.jar
|
|
||||||
-libraryjars ${rt.jar}
|
|
||||||
-overloadaggressively
|
|
||||||
-repackageclasses ''
|
|
||||||
-allowaccessmodification
|
|
||||||
-printmapping build/@{luaprog}.map
|
|
||||||
|
|
||||||
-keep public class @{luaprog} {
|
|
||||||
public static void main(java.lang.String[]);
|
|
||||||
}
|
|
||||||
</proguard>
|
|
||||||
<unjar src="build/@{luaprog}-opt.jar" dest="build/@{luaprog}/unjarred-opt"/>
|
|
||||||
<perftest cmd="java -jar build/@{luaprog}-opt.jar @{arg}"/>
|
|
||||||
-->
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<target name="binarytrees" depends="luaj-lib,proguard-lib">
|
|
||||||
<buildappjar luaprog="binarytrees" arg="15"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="fannkuch" depends="luaj-lib,proguard-lib">
|
|
||||||
<buildappjar luaprog="fannkuch" arg="10"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="nbody" depends="luaj-lib,proguard-lib">
|
|
||||||
<buildappjar luaprog="nbody" arg="1000000"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="nsieve" depends="luaj-lib,proguard-lib">
|
|
||||||
<buildappjar luaprog="nsieve" arg="8"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="swingapp" depends="luaj-lib,proguard-lib">
|
|
||||||
<buildappjar luaprog="swingapp" srcdir="examples/lua"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="allappjars" depends="binarytrees,fannkuch,nbody,nsieve,swingapp"/>
|
|
||||||
|
|
||||||
<target name="all" depends="allappjars"/>
|
|
||||||
</project>
|
|
||||||
116
build-applet.xml
116
build-applet.xml
@@ -1,116 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<project name="sample" default="main" basedir=".">
|
|
||||||
<property file="version.properties"/>
|
|
||||||
|
|
||||||
<!-- find libs -->
|
|
||||||
<import file="build-libs.xml"/>
|
|
||||||
|
|
||||||
<!-- main java class -->
|
|
||||||
<property name="java.dir" value="examples/jse"/>
|
|
||||||
<property name="java.name" value="SampleApplet"/>
|
|
||||||
|
|
||||||
<!-- main script -->
|
|
||||||
<property name="script.dir" value="examples/lua"/>
|
|
||||||
<property name="script.name" value="swingapplet"/>
|
|
||||||
<property name="image.name" value="logo.gif"/>
|
|
||||||
|
|
||||||
<!-- location of luaj jar -->
|
|
||||||
<property name="libs.dir" value="lib"/>
|
|
||||||
<property name="luaj.jar" value="${libs.dir}/luaj-jse-${version}.jar"/>
|
|
||||||
|
|
||||||
<!-- location of build results -->
|
|
||||||
<property name="build.dir" value="build/applet"/>
|
|
||||||
|
|
||||||
<target name="clean">
|
|
||||||
<delete failonerror="false" dir="${build.dir}"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="dirs">
|
|
||||||
<mkdir dir="build/applet/classes"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="classes" depends="dirs">
|
|
||||||
<copy todir="${build.dir}">
|
|
||||||
<fileset dir="${script.dir}" includes="${script.name}.lua,${image.name}"/>
|
|
||||||
</copy>
|
|
||||||
<javac destdir="${build.dir}/classes" source="1.4" target="1.4"
|
|
||||||
classpath="${luaj.jar}" srcdir="${java.dir}" includes="${java.name}.java"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="manifest" depends="dirs">
|
|
||||||
<manifest file="${build.dir}/MANIFEST.MF">
|
|
||||||
<attribute name="Permissions" value="sandbox"/>
|
|
||||||
<attribute name="Main-class" value="${java.name}"/>
|
|
||||||
</manifest>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="jar" depends="classes,manifest">
|
|
||||||
<jar destfile="${build.dir}/${script.name}.jar"
|
|
||||||
manifest="${build.dir}/MANIFEST.MF">
|
|
||||||
<fileset dir="${build.dir}" includes="*.lua"/>
|
|
||||||
<fileset dir="${build.dir}/classes"/>
|
|
||||||
<zipfileset
|
|
||||||
src="${luaj.jar}"
|
|
||||||
excludes="**/script/*,**/luajc/**,**/parser/**,**/ast/**,lua*"/>
|
|
||||||
</jar>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="obf" depends="jar,proguard-lib">
|
|
||||||
<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard.jar" />
|
|
||||||
<copy file="${build.dir}/${script.name}.jar"
|
|
||||||
tofile="${build.dir}/${script.name}-unobfuscated.jar"/>
|
|
||||||
<proguard>
|
|
||||||
-injars ${build.dir}/${script.name}-unobfuscated.jar
|
|
||||||
-outjars ${build.dir}/${script.name}.jar
|
|
||||||
-libraryjars ${java.home}/lib/rt.jar
|
|
||||||
-overloadaggressively
|
|
||||||
-repackageclasses ''
|
|
||||||
-allowaccessmodification
|
|
||||||
-printmapping ${build.dir}/mapping.txt
|
|
||||||
|
|
||||||
-keep public class * extends java.applet.Applet
|
|
||||||
|
|
||||||
-target 1.4
|
|
||||||
</proguard>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="sign" depends="obf">
|
|
||||||
<signjar jar="${build.dir}/${script.name}.jar"
|
|
||||||
alias="${sign.alias}"
|
|
||||||
storepass="${sign.storepass}"
|
|
||||||
keypass="${sign.keypass}"
|
|
||||||
keystore="${sign.keystore}" />
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="html" depends="dirs">
|
|
||||||
<echoxml file="build/applet/LuajSampleApplet.html">
|
|
||||||
<html>
|
|
||||||
<head><title>Luaj Sample Applet</title></head>
|
|
||||||
<body>
|
|
||||||
<h1>Luaj Sample Applet</h1>
|
|
||||||
Requires browser that supports applets.
|
|
||||||
${script.name}
|
|
||||||
<applet archive='${script.name}.jar'
|
|
||||||
code='${java.name}.class'
|
|
||||||
width='800'
|
|
||||||
height='640' >
|
|
||||||
<param name='luaj.script' value='${script.name}.lua'/>
|
|
||||||
<param name="java_version" value="1.4+"/>
|
|
||||||
</applet>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
</echoxml>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="run" depends="jar,html">
|
|
||||||
<exec executable="open" spawn="true">
|
|
||||||
<arg value="-a Firefox"/>
|
|
||||||
<arg path="build/applet/LuajSampleApplet.html"/>
|
|
||||||
</exec>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="all" depends="clean,sign,html,run"/>
|
|
||||||
|
|
||||||
<target name="main" depends="sign,html"/>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
<project default="all" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
|
|
||||||
<!--
|
|
||||||
Run code coverage for unit tests on the luaj vm and libraries.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<property name="classes.dir" value="build/classes-debug" />
|
|
||||||
<property name="instrumented.dir" value="build/instrumented" />
|
|
||||||
<property name="reports.xml.dir" value="build/reports-junit-xml" />
|
|
||||||
<property name="reports.html.dir" value="build/reports-junit-html" />
|
|
||||||
<property name="coverage.xml.dir" value="build/reports-coverage-xml" />
|
|
||||||
<property name="coverage.html.dir" value="build/reports-coverage-html" />
|
|
||||||
<property name="cobertura.serfile" value="cobertura.ser" />
|
|
||||||
<property name="cobertura.logfile" value="cobertura.log" />
|
|
||||||
|
|
||||||
<artifact:dependencies filesetId="cobutura.fileset">
|
|
||||||
<dependency groupId="net.sourceforge.cobertura" artifactId="cobertura" version="1.9.4.1"/>
|
|
||||||
<dependency groupId="junit" artifactId="junit" version="3.8.1"/>
|
|
||||||
</artifact:dependencies>
|
|
||||||
|
|
||||||
<path id="cobertura.classpath">
|
|
||||||
<fileset refid="cobutura.fileset" />
|
|
||||||
</path>
|
|
||||||
|
|
||||||
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
|
|
||||||
|
|
||||||
<import file="wtk.xml"/>
|
|
||||||
|
|
||||||
<property environment="env"/>
|
|
||||||
|
|
||||||
<target name="clean" description="Remove all files created by the build/test process.">
|
|
||||||
<delete dir="${classes.dir}" failonerror="yes"/>
|
|
||||||
<delete dir="${instrumented.dir}" failonerror="yes"/>
|
|
||||||
<delete file="${cobertura.logfile}" />
|
|
||||||
<delete file="${cobertura.serfile}" />
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="init">
|
|
||||||
<ant antfile="build.xml" target="bcel-lib"/>
|
|
||||||
<ant antfile="build.xml" target="luaj1-lib"/>
|
|
||||||
<mkdir dir="${classes.dir}" />
|
|
||||||
<mkdir dir="${instrumented.dir}" />
|
|
||||||
<mkdir dir="${reports.xml.dir}" />
|
|
||||||
<mkdir dir="${reports.html.dir}" />
|
|
||||||
<mkdir dir="${coverage.xml.dir}" />
|
|
||||||
<mkdir dir="${coverage.html.dir}" />
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="compile" depends="init,wtk-or-fail">
|
|
||||||
<javac destdir="${classes.dir}" debug="yes" target="1.5">
|
|
||||||
<classpath refid="cobertura.classpath" />
|
|
||||||
<classpath refid="wtk-libs" />
|
|
||||||
<classpath path="lib/bcel-5.2.jar" />
|
|
||||||
<src path="src/core"/>
|
|
||||||
<src path="src/jme"/>
|
|
||||||
<src path="src/jse"/>
|
|
||||||
<src path="test/junit"/>
|
|
||||||
</javac>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="instrument" depends="compile">
|
|
||||||
<delete file="${cobertura.serfile}"/>
|
|
||||||
<delete dir="${instrumented.dir}" failonerror="no"/>
|
|
||||||
<cobertura-instrument datafile="${cobertura.serfile}" todir="${instrumented.dir}">
|
|
||||||
<fileset dir="${classes.dir}">
|
|
||||||
<include name="org/luaj/vm2/*.class" />
|
|
||||||
<include name="org/luaj/vm2/lib/*.class" />
|
|
||||||
<include name="org/luaj/vm2/lib/jse/*.class" />
|
|
||||||
<include name="org/luaj/vm2/lib/jme/*.class" />
|
|
||||||
<include name="org/luaj/vm2/compiler/*.class" />
|
|
||||||
<include name="org/luaj/vm2/luajc/*.class" />
|
|
||||||
<include name="org/luaj/vm2/lua2java/*.class" />
|
|
||||||
<include name="org/luaj/vm2/parser/*.class" />
|
|
||||||
<include name="org/luaj/vm2/ast/*.class" />
|
|
||||||
<exclude name="**/*Test*.class" />
|
|
||||||
</fileset>
|
|
||||||
</cobertura-instrument>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="test">
|
|
||||||
<junit fork="yes" dir="${basedir}" showoutput="yes">
|
|
||||||
<sysproperty key="net.sourceforge.cobertura.serfile"
|
|
||||||
file="${basedir}/${cobertura.serfile}" />
|
|
||||||
<classpath location="${instrumented.dir}" />
|
|
||||||
<classpath location="${classes.dir}" />
|
|
||||||
<classpath refid="cobertura.classpath" />
|
|
||||||
<classpath location="test/lua" />
|
|
||||||
<classpath location="test/junit/org/luaj/vm2/compiler" />
|
|
||||||
<classpath location="test/junit/org/luaj/vm2/vm1" />
|
|
||||||
<classpath path="lib/bcel-5.2.jar" />
|
|
||||||
<formatter type="xml" />
|
|
||||||
<batchtest todir="${reports.xml.dir}">
|
|
||||||
<fileset dir="test/junit">
|
|
||||||
<include name="org/luaj/vm2/AllTests.java" />
|
|
||||||
</fileset>
|
|
||||||
</batchtest>
|
|
||||||
</junit>
|
|
||||||
|
|
||||||
<junitreport todir="${reports.xml.dir}">
|
|
||||||
<fileset dir="${reports.xml.dir}">
|
|
||||||
<include name="TEST-*.xml" />
|
|
||||||
</fileset>
|
|
||||||
<report format="frames" todir="${reports.html.dir}" />
|
|
||||||
</junitreport>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="report">
|
|
||||||
<cobertura-report datafile="${cobertura.serfile}" destdir="${coverage.xml.dir}" format="xml" />
|
|
||||||
<cobertura-report datafile="${cobertura.serfile}" destdir="${coverage.html.dir}">
|
|
||||||
<fileset dir="src/core"/>
|
|
||||||
<fileset dir="src/jse"/>
|
|
||||||
<fileset dir="src/jme"/>
|
|
||||||
</cobertura-report>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="coverage" depends="clean,init,compile,instrument,test,report"/>
|
|
||||||
|
|
||||||
<target name="all" depends="coverage" />
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
<project default="all-libs">
|
|
||||||
|
|
||||||
<available file="lib/midpapi20.jar" property="midpapi.lib.exists"/>
|
|
||||||
<available file="lib/bcel-5.2.jar" property="bcel.lib.exists"/>
|
|
||||||
<available file="lib/javacc.jar" property="javacc.lib.exists"/>
|
|
||||||
<available file="lib/proguard.jar" property="proguard.lib.exists"/>
|
|
||||||
<available file="lib/antenna-bin-1.2.0-beta.jar" property="antenna.lib.exists"/>
|
|
||||||
<available file="lib/junit.jar" property="junit.lib.exists"/>
|
|
||||||
<available file="lib/cobertura.jar" property="cobertura.lib.exists"/>
|
|
||||||
<available file="lib/microemulator.jar" property="microemulator.lib.exists"/>
|
|
||||||
|
|
||||||
<macrodef name="download">
|
|
||||||
<attribute name="zipname"/>
|
|
||||||
<attribute name="jars" default="**/*.jar"/>
|
|
||||||
<sequential>
|
|
||||||
<mkdir dir="lib"/>
|
|
||||||
<get src="http://luaj.sourceforge.net/lib/@{zipname}.tar.gz"
|
|
||||||
dest="lib/@{zipname}.tar.gz"/>
|
|
||||||
<gunzip src="lib/@{zipname}.tar.gz" dest="lib/@{zipname}.tar"/>
|
|
||||||
<untar src="lib/@{zipname}.tar" dest="lib" overwrite="true">
|
|
||||||
<patternset>
|
|
||||||
<include name="@{jars}"/>
|
|
||||||
</patternset>
|
|
||||||
<mapper type="flatten"/>
|
|
||||||
</untar>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<target name="wtk-libs" unless="midpapi.lib.exists">
|
|
||||||
<download zipname="wtk-2.5.2-api"/>
|
|
||||||
</target>
|
|
||||||
<target name="bcel-lib" unless="bcel.lib.exists">
|
|
||||||
<download zipname="/bcel-5.2"/>
|
|
||||||
</target>
|
|
||||||
<target name="javacc-lib" unless="javacc.lib.exists">
|
|
||||||
<download zipname="javacc-5.0"/>
|
|
||||||
</target>
|
|
||||||
<target name="proguard-lib" unless="proguard.lib.exists">
|
|
||||||
<download zipname="proguard4.6"/>
|
|
||||||
</target>
|
|
||||||
<target name="antenna-lib" unless="antenna.lib.exists">
|
|
||||||
<download zipname="antenna-bin-1.2.0-beta"/>
|
|
||||||
</target>
|
|
||||||
<target name="junit-lib" unless="junit.lib.exists">
|
|
||||||
<download zipname="junit-3.8.2"/>
|
|
||||||
</target>
|
|
||||||
<target name="cobertura-lib" unless="cobertura.lib.exists">
|
|
||||||
<download zipname="cobertura-1.9.4.1-bin"/>
|
|
||||||
</target>
|
|
||||||
<target name="microemulator-lib" unless="microemulator.lib.exists">
|
|
||||||
<download zipname="microemulator-2.0.4" jars="**/microemulator.jar"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="all-libs" depends="wtk-libs,bcel-lib,javacc-lib,proguard-lib,antenna-lib,junit-lib,cobertura-lib"/>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
176
build-maven.xml
176
build-maven.xml
@@ -1,176 +0,0 @@
|
|||||||
<project default="usage">
|
|
||||||
<!-- Ant file to deploy to maven once the distribution is released on sourceforge.
|
|
||||||
-->
|
|
||||||
<property file="version.properties"/>
|
|
||||||
|
|
||||||
<macrodef name="write_pom">
|
|
||||||
<attribute name="platform"/>
|
|
||||||
<attribute name="snapshot" default=""/>
|
|
||||||
<sequential>
|
|
||||||
<mkdir dir="build/maven-${version}"/>
|
|
||||||
<echo file="build/maven-${version}/luaj-@{platform}-${version}@{snapshot}.pom"><![CDATA[<project>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>org.luaj</groupId>
|
|
||||||
<artifactId>luaj-]]>@{platform}<![CDATA[</artifactId>
|
|
||||||
<version>]]>${version}@{snapshot}<![CDATA[</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<name>luaj-]]>@{platform}<![CDATA[</name>
|
|
||||||
<description>Luaj ]]>${version}<![CDATA[ for the ]]>@{platform}<![CDATA[ platform</description>
|
|
||||||
<url>http://sourceforge.net/projects/luaj/</url>
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>MIT License</name>
|
|
||||||
<url>http://luaj.sourceforge.net/license.txt</url>
|
|
||||||
<distribution>repo</distribution>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<id>jrosebor</id>
|
|
||||||
<name>James Roseborough</name>
|
|
||||||
<email>jim.roseborough@luaj.org</email>
|
|
||||||
<timezone>-8</timezone>
|
|
||||||
<roles></roles>
|
|
||||||
</developer>
|
|
||||||
<developer>
|
|
||||||
<id>ifarmer</id>
|
|
||||||
<name>Ian Farmer</name>
|
|
||||||
<email>ian.farmer@luaj.org</email>
|
|
||||||
<timezone>-8</timezone>
|
|
||||||
<roles></roles>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
<scm>
|
|
||||||
<url>http://luaj.cvs.sourceforge.net/viewvc/luaj/luaj-vm/</url>
|
|
||||||
</scm>
|
|
||||||
</project>
|
|
||||||
]]></echo>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<macrodef name="prepare_files">
|
|
||||||
<attribute name="platform"/>
|
|
||||||
<attribute name="snapshot" default=""/>
|
|
||||||
<sequential>
|
|
||||||
<mkdir dir="build/maven-${version}"/>
|
|
||||||
<write_pom platform="@{platform}" snapshot="@{snapshot}"/>
|
|
||||||
<copy file="luaj-${version}.zip" todir="build/maven-${version}"/>
|
|
||||||
<unzip src="build/maven-${version}/luaj-${version}.zip" dest="build/maven-${version}"/>
|
|
||||||
<copy file="build/maven-${version}/luaj-${version}/lib/luaj-@{platform}-${version}.jar" todir="build/maven-${version}"/>
|
|
||||||
|
|
||||||
<!-- make a -sources file -->
|
|
||||||
<mkdir dir="build/maven-${version}/sources-@{platform}"/>
|
|
||||||
<copy todir="build/maven-${version}/sources-@{platform}">
|
|
||||||
<fileset dir="build/maven-${version}/luaj-${version}/src/core"/>
|
|
||||||
<fileset dir="build/maven-${version}/luaj-${version}/src/@{platform}"/>
|
|
||||||
<filterchain>
|
|
||||||
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-@{platform} ${version}"'/></tokenfilter>
|
|
||||||
</filterchain>
|
|
||||||
</copy>
|
|
||||||
<zip destfile="build/maven-${version}/luaj-@{platform}-${version}-sources.jar"
|
|
||||||
basedir="build/maven-${version}/sources-@{platform}"/>
|
|
||||||
|
|
||||||
<!-- make a -javadoc file -->
|
|
||||||
<mkdir dir="build/maven-${version}/javadoc-@{platform}"/>
|
|
||||||
<javadoc defaultexcludes="yes"
|
|
||||||
destdir="build/maven-${version}/javadoc-@{platform}"
|
|
||||||
author="true"
|
|
||||||
version="true"
|
|
||||||
use="true"
|
|
||||||
windowtitle="Luaj API">
|
|
||||||
<fileset dir="build/maven-${version}/sources-@{platform}">
|
|
||||||
<include name="org/luaj/vm/*.java"/>
|
|
||||||
<include name="org/luaj/vm2/*.java"/>
|
|
||||||
<include name="org/luaj/vm2/server/*.java"/>
|
|
||||||
<include name="**/LuaC.java"/>
|
|
||||||
<include name="**/LuaJC.java"/>
|
|
||||||
<include name="**/lib/*/*.java"/>
|
|
||||||
</fileset>
|
|
||||||
<doctitle><![CDATA[<h1>Luaj API</h1>]]></doctitle>
|
|
||||||
<bottom><![CDATA[<i>Copyright © 2007-2015 Luaj.org. All Rights Reserved.</i>]]></bottom>
|
|
||||||
<tag name="todo" scope="all" description="To do:"/>
|
|
||||||
<link offline="true" href="http://sourceforge.net/projects/luaj/" packagelistLoc="C:\tmp"/>
|
|
||||||
<link href="http://sourceforge.net/projects/luaj/"/>
|
|
||||||
</javadoc>
|
|
||||||
<zip destfile="build/maven-${version}/luaj-@{platform}-${version}-javadoc.jar"
|
|
||||||
basedir="build/maven-${version}/javadoc-@{platform}"/>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<macrodef name="shapshot_files">
|
|
||||||
<attribute name="platform"/>
|
|
||||||
<sequential>
|
|
||||||
<exec executable="mvn">
|
|
||||||
<arg value="deploy:deploy-file"/>
|
|
||||||
<arg value="-Durl=https://oss.sonatype.org/content/repositories/snapshots"/>
|
|
||||||
<arg value="-DrepositoryId=nexus-releases"/>
|
|
||||||
<arg value="-DpomFile=build/maven-${version}/luaj-@{platform}-${version}-SNAPSHOT.pom"/>
|
|
||||||
<arg value="-Dfile=build/maven-${version}/luaj-@{platform}-${version}.jar"/>
|
|
||||||
<arg value="-Dsources=build/maven-${version}/luaj-@{platform}-${version}-sources.jar"/>
|
|
||||||
<arg value="-Djavadoc=build/maven-${version}/luaj-@{platform}-${version}-javadoc.jar"/>
|
|
||||||
</exec>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<macrodef name="sign_and_deploy">
|
|
||||||
<attribute name="platform"/>
|
|
||||||
<sequential>
|
|
||||||
<exec executable="mvn">
|
|
||||||
<arg value="gpg:sign-and-deploy-file"/>
|
|
||||||
<arg value="-Durl=http://oss.sonatype.org/service/local/staging/deploy/maven2"/>
|
|
||||||
<arg value="-DrepositoryId=nexus-releases"/>
|
|
||||||
<arg value="-DpomFile=build/maven-${version}/luaj-@{platform}-${version}.pom"/>
|
|
||||||
<arg value="-Dfile=build/maven-${version}/luaj-@{platform}-${version}.jar"/>
|
|
||||||
<arg value="-Dsources=build/maven-${version}/luaj-@{platform}-${version}-sources.jar"/>
|
|
||||||
<arg value="-Djavadoc=build/maven-${version}/luaj-@{platform}-${version}-javadoc.jar"/>
|
|
||||||
</exec>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<macrodef name="prepare_and_install">
|
|
||||||
<attribute name="platform"/>
|
|
||||||
<sequential>
|
|
||||||
<prepare_files platform="@{platform}"/>
|
|
||||||
<exec executable="mvn">
|
|
||||||
<arg value="install:install-file"/>
|
|
||||||
<arg value="-Dfile=build/maven-${version}/luaj-@{platform}-${version}.jar"/>
|
|
||||||
<arg value="-DpomFile=build/maven-${version}/luaj-@{platform}-${version}.pom"/>
|
|
||||||
</exec>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<macrodef name="prepare_and_snapshot">
|
|
||||||
<attribute name="platform"/>
|
|
||||||
<sequential>
|
|
||||||
<prepare_files platform="@{platform}" snapshot="-SNAPSHOT"/>
|
|
||||||
<shapshot_files platform="@{platform}"/>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<macrodef name="prepare_and_deploy">
|
|
||||||
<attribute name="platform"/>
|
|
||||||
<sequential>
|
|
||||||
<prepare_files platform="@{platform}"/>
|
|
||||||
<sign_and_deploy platform="@{platform}"/>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<target name="install">
|
|
||||||
<prepare_and_install platform="jse"/>
|
|
||||||
<prepare_and_install platform="jme"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="snapshot">
|
|
||||||
<prepare_and_snapshot platform="jse"/>
|
|
||||||
<prepare_and_snapshot platform="jme"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="deploy">
|
|
||||||
<prepare_and_deploy platform="jse"/>
|
|
||||||
<prepare_and_deploy platform="jme"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="usage">
|
|
||||||
<echo level="info">Usage: ant [-Dversion=${version}] -f build-maven.xml [install | shapshot | deploy]</echo>
|
|
||||||
</target>
|
|
||||||
</project>
|
|
||||||
113
build-midlet.xml
113
build-midlet.xml
@@ -1,113 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<project name="sample" default="all" basedir=".">
|
|
||||||
<property file="version.properties"/>
|
|
||||||
|
|
||||||
<!-- find libs -->
|
|
||||||
<import file="build-libs.xml"/>
|
|
||||||
|
|
||||||
<!-- main script -->
|
|
||||||
<property name="script.name" value="hello"/>
|
|
||||||
<property name="script.dir" value="examples/lua"/>
|
|
||||||
|
|
||||||
<target name="clean">
|
|
||||||
<delete failonerror="false" dir="build"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="dirs">
|
|
||||||
<mkdir dir="build"/>
|
|
||||||
<mkdir dir="build/tool"/>
|
|
||||||
<mkdir dir="build/classes"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="tools" depends="dirs,bcel-lib,wtk-libs,microemulator-lib">
|
|
||||||
<javac destdir="build/tool" classpath="lib/bcel-5.2.jar">
|
|
||||||
<src path="src/core"/>
|
|
||||||
<src path="src/jse"/>
|
|
||||||
</javac>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<!-- compile script into lua bytecode -->
|
|
||||||
<target name="luac" depends="tools">
|
|
||||||
<java classname="luac" classpath="build/tool">
|
|
||||||
<arg line="-o build/classes/${script.name}.lua"/>
|
|
||||||
<arg line="${script.dir}/${script.name}.lua"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<!-- compile script into java bytecode -->
|
|
||||||
<target name="luajc" depends="tools,wtk-libs">
|
|
||||||
<java classname="luajc" classpath="build/tool:lib/bcel-5.2.jar">
|
|
||||||
<arg line="-verbose"/>
|
|
||||||
<arg line="-srcdir ${script.dir}"/>
|
|
||||||
<arg line="-destdir build/classes"/>
|
|
||||||
<arg line="${script.name}.lua"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="classes" depends="dirs,wtk-libs">
|
|
||||||
<mkdir dir="build/midlet/src"/>
|
|
||||||
<copy todir="build/midlet/src">
|
|
||||||
<fileset dir="src/core"/>
|
|
||||||
<fileset dir="src/jme"/>
|
|
||||||
<fileset dir="examples/jme"/>
|
|
||||||
<filterchain>
|
|
||||||
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jme ${version}"'/></tokenfilter>
|
|
||||||
</filterchain>
|
|
||||||
</copy>
|
|
||||||
<path id="wtk-libs">
|
|
||||||
<pathelement path="lib/cldcapi11.jar"/>
|
|
||||||
<pathelement path="lib/midpapi20.jar"/>
|
|
||||||
<pathelement path="lib/mmapi.jar"/>
|
|
||||||
</path>
|
|
||||||
<javac destdir="build/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
|
||||||
srcdir="build/midlet/src"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="jar" depends="luajc,classes">
|
|
||||||
<jar destfile="build/sample-plain.jar"
|
|
||||||
basedir="build/classes"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="obf" depends="jar,proguard-lib">
|
|
||||||
<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard.jar" />
|
|
||||||
<proguard>
|
|
||||||
-injars build/sample-plain.jar
|
|
||||||
-outjars build/sample.jar
|
|
||||||
-libraryjars lib/midpapi20.jar
|
|
||||||
-libraryjars lib/cldcapi11.jar
|
|
||||||
-overloadaggressively
|
|
||||||
-repackageclasses ''
|
|
||||||
-microedition
|
|
||||||
|
|
||||||
-keep public class SampleMIDlet
|
|
||||||
-keep public class * extends org.luaj.vm2.LuaValue
|
|
||||||
</proguard>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="jad" depends="obf">
|
|
||||||
<length file="build/sample.jar" property="sample.jar.length" />
|
|
||||||
<echo level="info">Jar file length is ${sample.jar.length}</echo>
|
|
||||||
<manifest file="build/sample.jad">
|
|
||||||
<attribute name="Built-By" value="luaj-${version}"/>
|
|
||||||
<attribute name="MIDlet-Name" value="Luaj ${script.name}"/>
|
|
||||||
<attribute name="MIDlet-Version" value="${version}"/>
|
|
||||||
<attribute name="MIDlet-Vendor" value="luaj.org"/>
|
|
||||||
<attribute name="MIDlet-Description" value="Luaj Sample Midlet"/>
|
|
||||||
<attribute name="MIDlet-1" value="${script.name}-${version}, , SampleMIDlet"/>
|
|
||||||
<attribute name="MIDlet-Jar-URL" value="sample.jar"/>
|
|
||||||
<attribute name="MIDlet-Jar-Size" value="${sample.jar.length}"/>
|
|
||||||
<attribute name="script" value="${script.name}"/>
|
|
||||||
</manifest>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="package" depends="jad,jar,obf"/>
|
|
||||||
|
|
||||||
<target name="run" depends="jad,jar,obf,microemulator-lib">
|
|
||||||
<java jar="lib/microemulator.jar" fork="true">
|
|
||||||
<arg path="build/sample.jad"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="all" depends="clean,package,run"/>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
<project default="all">
|
|
||||||
<import file="build.xml"/>
|
|
||||||
|
|
||||||
<property name="lua.command" value="lua"/>
|
|
||||||
<available file="luaj-jse-${version}.jar" property="luaj.lib.exists"/>
|
|
||||||
<available file="lib/jill-1.0.1.jar" property="jill.lib.exists"/>
|
|
||||||
<available file="lib/kahlua.jar" property="kahlua.lib.exists"/>
|
|
||||||
<available file="lib/mochalua-1.0.jar" property="mochalua.lib.exists"/>
|
|
||||||
|
|
||||||
<target name="luaj-lib" unless="luaj.lib.exists">
|
|
||||||
<antcall target="jar-jse"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="jill-lib" unless="jill.lib.exists">
|
|
||||||
<mkdir dir="lib"/>
|
|
||||||
<get src="http://jillcode.googlecode.com/files/jill-1.0.1.zip"
|
|
||||||
dest="lib/jill-1.0.1.zip"/>
|
|
||||||
<unzip src="lib/jill-1.0.1.zip" dest="lib" overwrite="true"/>
|
|
||||||
<ant dir="lib/jill-1.0.1" target="compile"/>
|
|
||||||
<jar destfile="lib/jill-1.0.1.jar" basedir="lib/jill-1.0.1/compiled"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="kahlua-lib" unless="kahlua.lib.exists">
|
|
||||||
<get src="http://kahlua.googlecode.com/files/kahlua.jar"
|
|
||||||
dest="lib/kahlua.jar"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="mochalua-lib" unless="mochalua.lib.exists">
|
|
||||||
<get src="http://mochalua.googlecode.com/files/Mochalua%201.0.jar"
|
|
||||||
dest="lib/mochalua-1.0.jar"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="perf-libs" depends="luaj-lib,bcel-lib,jill-lib,kahlua-lib,mochalua-lib"/>
|
|
||||||
|
|
||||||
<macrodef name="perftest">
|
|
||||||
<attribute name="program" default="lua"/>
|
|
||||||
<attribute name="luaprog" default="fannkuch.lua 10"/>
|
|
||||||
<attribute name="basedir" default="test/lua/perf/"/>
|
|
||||||
<sequential>
|
|
||||||
<echo level="info">------ @{program} @{luaprog}</echo>
|
|
||||||
<exec executable="bash">
|
|
||||||
<arg value="-c"/>
|
|
||||||
<arg value="time @{program} @{basedir}@{luaprog}"/>
|
|
||||||
</exec>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
|
|
||||||
<macrodef name="testcase">
|
|
||||||
<attribute name="luaprog" default="fannkuch.lua 10"/>
|
|
||||||
<sequential>
|
|
||||||
<echo level="info">=========== @{luaprog} =============</echo>
|
|
||||||
<perftest program="java -version" luaprog="" basedir=""/>
|
|
||||||
<perftest program="${lua.command}" luaprog="@{luaprog}"/>
|
|
||||||
<perftest program="java -cp luaj-jse-${version}.jar lua -n" luaprog="@{luaprog}"/>
|
|
||||||
<perftest program="java -cp luaj-jse-${version}.jar${path.separator}lib/bcel-5.2.jar lua -b" luaprog="@{luaprog}"/>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
|
|
||||||
<target name="alltests">
|
|
||||||
<testcase luaprog="binarytrees.lua 15"/>
|
|
||||||
<testcase luaprog="fannkuch.lua 10"/>
|
|
||||||
<testcase luaprog="nbody.lua 1000000"/>
|
|
||||||
<testcase luaprog="nsieve.lua 9"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="all" depends="alltests"/>
|
|
||||||
</project>
|
|
||||||
212
build.xml
212
build.xml
@@ -1,212 +0,0 @@
|
|||||||
<project default="all">
|
|
||||||
<property file="version.properties"/>
|
|
||||||
|
|
||||||
<property name="jar.name.jme" value="luaj-jme-${version}.jar"/>
|
|
||||||
<property name="jar.name.jse" value="luaj-jse-${version}.jar"/>
|
|
||||||
<property name="jar.name.sources" value="luaj-sources-${version}.jar"/>
|
|
||||||
|
|
||||||
<target name="clean-build">
|
|
||||||
<delete dir="build"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="clean" depends="clean-build">
|
|
||||||
<delete>
|
|
||||||
<fileset dir="." includes="luaj-*.jar"/>
|
|
||||||
</delete>
|
|
||||||
<delete dir="examples/android/bin"/>
|
|
||||||
<delete dir="examples/android/build"/>
|
|
||||||
<delete dir="examples/android/gen"/>
|
|
||||||
<delete dir="examples/android/libs"/>
|
|
||||||
<delete dir="examples/maven/target"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<import file="build-libs.xml"/>
|
|
||||||
|
|
||||||
<target name="parser" depends="javacc-lib">
|
|
||||||
<java classname="javacc" classpath="lib/javacc.jar">
|
|
||||||
<arg line="grammar/LuaParser.jj"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="plain-parser" depends="javacc-lib">
|
|
||||||
<java dir="src/jse" fork="true" classname="javacc" classpath="lib/javacc.jar">
|
|
||||||
<arg line="../../grammar/Lua52.jj"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="compile" depends="wtk-libs,bcel-lib">
|
|
||||||
<delete dir="build/jme/src"/>
|
|
||||||
<delete dir="build/jse/src"/>
|
|
||||||
<mkdir dir="build/jme/src"/>
|
|
||||||
<mkdir dir="build/jse/src"/>
|
|
||||||
<mkdir dir="build/jme/classes"/>
|
|
||||||
<mkdir dir="build/jse/classes"/>
|
|
||||||
<copy todir="build/jme/src">
|
|
||||||
<fileset dir="src/core"/>
|
|
||||||
<fileset dir="src/jme"/>
|
|
||||||
<filterchain>
|
|
||||||
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jme ${version}"'/></tokenfilter>
|
|
||||||
</filterchain>
|
|
||||||
</copy>
|
|
||||||
<copy todir="build/jse/src">
|
|
||||||
<fileset dir="src/core"/>
|
|
||||||
<filterchain>
|
|
||||||
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jse ${version}"'/></tokenfilter>
|
|
||||||
</filterchain>
|
|
||||||
</copy>
|
|
||||||
<copy todir="build/jse/src">
|
|
||||||
<fileset dir="src/jse"/>
|
|
||||||
<filterchain>
|
|
||||||
<tokenfilter><replacestring from='<String>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Stat>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Exp>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Name>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Block>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<TableField>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<VarExp>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Exp.VarExp>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Object,String>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Double,String>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Integer,Integer>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Integer,LocalVariableGen>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<Exp,Integer>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<String,byte[]>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<String,Variable>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<LuaValue,String>' to=''/></tokenfilter>
|
|
||||||
<tokenfilter><replacestring from='<LuaString,String>' to=''/></tokenfilter>
|
|
||||||
</filterchain>
|
|
||||||
</copy>
|
|
||||||
<path id="wtk-libs">
|
|
||||||
<pathelement path="lib/cldcapi11.jar"/>
|
|
||||||
<pathelement path="lib/midpapi20.jar"/>
|
|
||||||
<pathelement path="lib/mmapi.jar"/>
|
|
||||||
</path>
|
|
||||||
<javac destdir="build/jme/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
|
||||||
debug="on"
|
|
||||||
srcdir="build/jme/src"/>
|
|
||||||
<javac destdir="build/jse/classes" encoding="utf-8" source="1.3" target="1.3"
|
|
||||||
classpath="lib/bcel-5.2.jar"
|
|
||||||
debug="on"
|
|
||||||
srcdir="build/jse/src"
|
|
||||||
excludes="**/script/*,**/Lua2Java*,**/server/*,lua*"/>
|
|
||||||
<javac destdir="build/jse/classes" encoding="utf-8" source="1.5" target="1.5"
|
|
||||||
classpath="build/jse/classes"
|
|
||||||
debug="on"
|
|
||||||
srcdir="build/jse/src"
|
|
||||||
includes="**/script/*,**/Lua2Java*,**/server/*"/>
|
|
||||||
<javac destdir="build/jse/classes" encoding="utf-8" source="1.3" target="1.3"
|
|
||||||
classpath="build/jse/classes"
|
|
||||||
debug="on"
|
|
||||||
srcdir="build/jse/src"
|
|
||||||
includes="lua*"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="jar-jme" depends="compile">
|
|
||||||
<jar destfile="${jar.name.jme}" basedir="build/jme/classes"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="jar-jse" depends="compile">
|
|
||||||
<jar destfile="${jar.name.jse}">
|
|
||||||
<fileset dir="build/jse/classes"/>
|
|
||||||
<fileset dir="src/jse/">
|
|
||||||
<include name="META-INF/services/**"/>
|
|
||||||
</fileset>
|
|
||||||
</jar>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="jar-jse-sources" depends="compile">
|
|
||||||
<jar destfile="${jar.name.sources}">
|
|
||||||
<fileset dir="build/jme/src"/>
|
|
||||||
<fileset dir="build/jse/src"/>
|
|
||||||
</jar>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="doc">
|
|
||||||
<delete dir="docs/api"/>
|
|
||||||
<mkdir dir="docs/api"/>
|
|
||||||
<javadoc defaultexcludes="yes"
|
|
||||||
destdir="docs/api"
|
|
||||||
author="true"
|
|
||||||
version="true"
|
|
||||||
use="true"
|
|
||||||
windowtitle="Luaj API">
|
|
||||||
<fileset dir="src/core" defaultexcludes="yes" includes="org/luaj/vm2/*.java,org/luaj/vm2/compiler/LuaC.java,org/luaj/vm2/lib/*.java"/>
|
|
||||||
<fileset dir="src/jse" defaultexcludes="yes" includes="org/luaj/vm2/lib/jse/*.java,org/luaj/vm2/luajc/LuaJC.java,org/luaj/vm2/server/*.java"/>
|
|
||||||
<fileset dir="src/jme" defaultexcludes="yes" includes="org/luaj/vm2/lib/jme/*.java"/>
|
|
||||||
<doctitle><![CDATA[<h1>Luaj API</h1>]]></doctitle>
|
|
||||||
<bottom><![CDATA[<i>Copyright © 2007-2015 Luaj.org. All Rights Reserved.</i>]]></bottom>
|
|
||||||
<tag name="todo" scope="all" description="To do:"/>
|
|
||||||
<group title="Core VM" packages="org.luaj.vm.*"/>
|
|
||||||
<link offline="true" href="http://sourceforge.net/projects/luaj/" packagelistLoc="C:\tmp"/>
|
|
||||||
<link href="http://sourceforge.net/projects/luaj/"/>
|
|
||||||
</javadoc>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="dist" depends="all,doc">
|
|
||||||
<delete dir="build/luaj-${version}"/>
|
|
||||||
<mkdir dir="build/luaj-${version}/src"/>
|
|
||||||
<mkdir dir="build/luaj-${version}/lib"/>
|
|
||||||
<copy todir="build/luaj-${version}/src">
|
|
||||||
<fileset dir="src">
|
|
||||||
<exclude name="src/test/**"/>
|
|
||||||
<exclude name="**/antlr/**"/>
|
|
||||||
<exclude name="**/lst/**"/>
|
|
||||||
<exclude name="**/JavaCodeGenerator.java"/>
|
|
||||||
<exclude name="**/LuaJCompiler.java"/>
|
|
||||||
</fileset>
|
|
||||||
</copy>
|
|
||||||
<copy todir="build/luaj-${version}/test">
|
|
||||||
<fileset dir="test"/>
|
|
||||||
</copy>
|
|
||||||
<copy todir="build/luaj-${version}/examples">
|
|
||||||
<fileset dir="examples">
|
|
||||||
<include name="android/*.*"/>
|
|
||||||
<include name="android/assets/**"/>
|
|
||||||
<include name="android/res/**"/>
|
|
||||||
<include name="android/src/**"/>
|
|
||||||
<include name="jme/*.java"/>
|
|
||||||
<include name="jse/*.java"/>
|
|
||||||
<include name="lua/*.*"/>
|
|
||||||
<include name="maven/pom.xml"/>
|
|
||||||
<include name="maven/src/**"/>
|
|
||||||
</fileset>
|
|
||||||
</copy>
|
|
||||||
<copy todir="build/luaj-${version}/lib">
|
|
||||||
<fileset dir=".">
|
|
||||||
<include name="*-${version}.jar"/>
|
|
||||||
</fileset>
|
|
||||||
</copy>
|
|
||||||
<copy todir="build/luaj-${version}">
|
|
||||||
<fileset dir=".">
|
|
||||||
<include name="build.xml"/>
|
|
||||||
<include name="build-libs.xml"/>
|
|
||||||
<include name="build-coverage.xml"/>
|
|
||||||
<include name="version.properties"/>
|
|
||||||
<include name="wtk.xml"/>
|
|
||||||
<include name="README.html"/>
|
|
||||||
<include name="names.csv"/>
|
|
||||||
<include name=".classpath"/>
|
|
||||||
<include name=".project"/>
|
|
||||||
</fileset>
|
|
||||||
</copy>
|
|
||||||
<copy todir="build/luaj-${version}/docs">
|
|
||||||
<fileset dir="docs"/>
|
|
||||||
</copy>
|
|
||||||
<zip destfile="luaj-${version}.zip"
|
|
||||||
basedir="build" includes="luaj-${version}/**"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="mvn_install" depends="jar-jse">
|
|
||||||
<exec executable="mvn">
|
|
||||||
<arg value="install:install-file"/>
|
|
||||||
<arg value="-Dfile=${jar.name.jse}"/>
|
|
||||||
<arg value="-DgroupId=org.luaj"/>
|
|
||||||
<arg value="-DartifactId=luaj-jse"/>
|
|
||||||
<arg value="-Dversion=${version}"/>
|
|
||||||
<arg value="-Dpackaging=jar"/>
|
|
||||||
</exec>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="all" depends="clean,jar-jme,jar-jse,jar-jse-sources"/>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
36
core/pom.xml
Normal file
36
core/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.openautonomousconnection.luaj</groupId>
|
||||||
|
<artifactId>parent</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals><goal>jar</goal></goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>21</source>
|
||||||
|
<target>21</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -502,10 +502,10 @@ public class LuaClosure extends LuaFunction {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
case Lua.OP_EXTRAARG:
|
case Lua.OP_EXTRAARG:
|
||||||
throw new java.lang.IllegalArgumentException("Uexecutable opcode: OP_EXTRAARG");
|
throw new IllegalArgumentException("Uexecutable opcode: OP_EXTRAARG");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new java.lang.IllegalArgumentException("Illegal opcode: " + (i & 0x3f));
|
throw new IllegalArgumentException("Illegal opcode: " + (i & 0x3f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch ( LuaError le ) {
|
} catch ( LuaError le ) {
|
||||||
309
core/src/main/java/org/luaj/vm2/LuaThread.java
Normal file
309
core/src/main/java/org/luaj/vm2/LuaThread.java
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007-2012 LuaJ. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
package org.luaj.vm2;
|
||||||
|
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.locks.Condition;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass of {@link LuaValue} that implements
|
||||||
|
* a lua coroutine thread using Java Threads.
|
||||||
|
* <p>
|
||||||
|
* A LuaThread is typically created in response to a scripted call to
|
||||||
|
* {@code coroutine.create()}
|
||||||
|
* <p>
|
||||||
|
* The threads must be initialized with the globals, so that
|
||||||
|
* the global environment may be passed along according to rules of lua.
|
||||||
|
* This is done via the constructor arguments {@link #LuaThread(Globals)} or
|
||||||
|
* {@link #LuaThread(Globals, LuaValue)}.
|
||||||
|
* <p>
|
||||||
|
* The utility classes {@link org.luaj.vm2.lib.jse.JsePlatform} and
|
||||||
|
* {@link org.luaj.vm2.lib.jme.JmePlatform}
|
||||||
|
* see to it that this {@link Globals} are initialized properly.
|
||||||
|
* <p>
|
||||||
|
* The behavior of coroutine threads matches closely the behavior
|
||||||
|
* of C coroutine library. However, because of the use of Java threads
|
||||||
|
* to manage call state, it is possible to yield from anywhere in luaj.
|
||||||
|
* <p>
|
||||||
|
* Each Java thread wakes up at regular intervals and checks a weak reference
|
||||||
|
* to determine if it can ever be resumed. If not, it throws
|
||||||
|
* {@link OrphanedThread} which is an {@link java.lang.Error}.
|
||||||
|
* Applications should not catch {@link OrphanedThread}, because it can break
|
||||||
|
* the thread safety of luaj. The value controlling the polling interval
|
||||||
|
* is {@link #thread_orphan_check_interval} and may be set by the user.
|
||||||
|
* <p>
|
||||||
|
* There are two main ways to abandon a coroutine. The first is to call
|
||||||
|
* {@code yield()} from lua, or equivalently {@link Globals#yield(Varargs)},
|
||||||
|
* and arrange to have it never resumed possibly by values passed to yield.
|
||||||
|
* The second is to throw {@link OrphanedThread}, which should put the thread
|
||||||
|
* in a dead state. In either case all references to the thread must be
|
||||||
|
* dropped, and the garbage collector must run for the thread to be
|
||||||
|
* garbage collected.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @see LuaValue
|
||||||
|
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||||
|
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||||
|
* @see org.luaj.vm2.lib.CoroutineLib
|
||||||
|
*/
|
||||||
|
public class LuaThread extends LuaValue {
|
||||||
|
|
||||||
|
/** Shared metatable for lua threads. */
|
||||||
|
public static LuaValue s_metatable;
|
||||||
|
|
||||||
|
/** The current number of coroutines. Should not be set. */
|
||||||
|
public static int coroutine_count = 0;
|
||||||
|
|
||||||
|
/** Polling interval, in milliseconds, which each thread uses while waiting to
|
||||||
|
* return from a yielded state to check if the lua threads is no longer
|
||||||
|
* referenced and therefore should be garbage collected.
|
||||||
|
* A short polling interval for many threads will consume server resources.
|
||||||
|
* Orphaned threads cannot be detected and collected unless garbage
|
||||||
|
* collection is run. This can be changed by Java startup code if desired.
|
||||||
|
*/
|
||||||
|
public static long thread_orphan_check_interval = 5000;
|
||||||
|
|
||||||
|
public static final String USE_PLATFORM_THREAD = "USE_PLATFORM_THREAD";
|
||||||
|
|
||||||
|
private static boolean SUPPORT_VIRTUAL_THREAD = false;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Thread.class.getMethod("ofVirtual");
|
||||||
|
SUPPORT_VIRTUAL_THREAD = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int STATUS_INITIAL = 0;
|
||||||
|
public static final int STATUS_SUSPENDED = 1;
|
||||||
|
public static final int STATUS_RUNNING = 2;
|
||||||
|
public static final int STATUS_NORMAL = 3;
|
||||||
|
public static final int STATUS_DEAD = 4;
|
||||||
|
public static final String[] STATUS_NAMES = {
|
||||||
|
"suspended",
|
||||||
|
"suspended",
|
||||||
|
"running",
|
||||||
|
"normal",
|
||||||
|
"dead",};
|
||||||
|
|
||||||
|
public final State state;
|
||||||
|
|
||||||
|
public static final int MAX_CALLSTACK = 256;
|
||||||
|
|
||||||
|
/** Thread-local used by DebugLib to store debugging state.
|
||||||
|
* This is an opaque value that should not be modified by applications. */
|
||||||
|
public Object callstack;
|
||||||
|
|
||||||
|
public final Globals globals;
|
||||||
|
|
||||||
|
/** Error message handler for this thread, if any. */
|
||||||
|
public LuaValue errorfunc;
|
||||||
|
|
||||||
|
/** Private constructor for main thread only */
|
||||||
|
public LuaThread(Globals globals) {
|
||||||
|
state = new State(globals, this, null);
|
||||||
|
state.status = STATUS_RUNNING;
|
||||||
|
this.globals = globals;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a LuaThread around a function and environment
|
||||||
|
* @param func The function to execute
|
||||||
|
*/
|
||||||
|
public LuaThread(Globals globals, LuaValue func) {
|
||||||
|
LuaValue.assert_(func != null, "function cannot be null");
|
||||||
|
state = new State(globals, this, func);
|
||||||
|
this.globals = globals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int type() {
|
||||||
|
return LuaValue.TTHREAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String typename() {
|
||||||
|
return "thread";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isthread() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LuaThread optthread(LuaThread defval) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LuaThread checkthread() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LuaValue getmetatable() {
|
||||||
|
return s_metatable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return STATUS_NAMES[state.status];
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMainThread() {
|
||||||
|
return this.state.function == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Varargs resume(Varargs args) {
|
||||||
|
final LuaThread.State s = this.state;
|
||||||
|
if (s.status > LuaThread.STATUS_SUSPENDED)
|
||||||
|
return LuaValue.varargsOf(LuaValue.FALSE,
|
||||||
|
LuaValue.valueOf("cannot resume "+(s.status==LuaThread.STATUS_DEAD? "dead": "non-suspended")+" coroutine"));
|
||||||
|
return s.lua_resume(this, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class State implements Runnable {
|
||||||
|
private final Globals globals;
|
||||||
|
final WeakReference lua_thread;
|
||||||
|
public final LuaValue function;
|
||||||
|
Varargs args = LuaValue.NONE;
|
||||||
|
Varargs result = LuaValue.NONE;
|
||||||
|
String error = null;
|
||||||
|
|
||||||
|
/** Hook function control state used by debug lib. */
|
||||||
|
public LuaValue hookfunc;
|
||||||
|
|
||||||
|
public boolean hookline;
|
||||||
|
public boolean hookcall;
|
||||||
|
public boolean hookrtrn;
|
||||||
|
public int hookcount;
|
||||||
|
public boolean inhook;
|
||||||
|
public int lastline;
|
||||||
|
public int bytecodes;
|
||||||
|
|
||||||
|
public int status = LuaThread.STATUS_INITIAL;
|
||||||
|
private Lock locker = new ReentrantLock();
|
||||||
|
private Condition cond = locker.newCondition();
|
||||||
|
|
||||||
|
State(Globals globals, LuaThread lua_thread, LuaValue function) {
|
||||||
|
this.globals = globals;
|
||||||
|
this.lua_thread = new WeakReference(lua_thread);
|
||||||
|
this.function = function;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
locker.lock();
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
Varargs a = this.args;
|
||||||
|
this.args = LuaValue.NONE;
|
||||||
|
this.result = function.invoke(a);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
this.error = t.getMessage();
|
||||||
|
} finally {
|
||||||
|
this.status = LuaThread.STATUS_DEAD;
|
||||||
|
cond.signal();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
locker.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Varargs lua_resume(LuaThread new_thread, Varargs args) {
|
||||||
|
locker.lock();
|
||||||
|
try {
|
||||||
|
LuaThread previous_thread = globals.running;
|
||||||
|
try {
|
||||||
|
globals.running = new_thread;
|
||||||
|
this.args = args;
|
||||||
|
if (this.status == STATUS_INITIAL) {
|
||||||
|
this.status = STATUS_RUNNING;
|
||||||
|
Thread t = null;
|
||||||
|
if(SUPPORT_VIRTUAL_THREAD) {
|
||||||
|
LuaValue setting = globals.get(USE_PLATFORM_THREAD);
|
||||||
|
if(setting.isnil()) {//default
|
||||||
|
if(Thread.currentThread().isVirtual()) {
|
||||||
|
t = Thread.ofVirtual().name("Coroutine-"+(++coroutine_count)).start(this);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(!setting.toboolean()) {
|
||||||
|
t = Thread.ofVirtual().name("Coroutine-"+(++coroutine_count)).start(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (t == null){
|
||||||
|
new Thread(this, "Coroutine-"+(++coroutine_count)).start();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cond.signal();
|
||||||
|
}
|
||||||
|
if (previous_thread != null)
|
||||||
|
previous_thread.state.status = STATUS_NORMAL;
|
||||||
|
this.status = STATUS_RUNNING;
|
||||||
|
cond.await();
|
||||||
|
return (this.error != null?
|
||||||
|
LuaValue.varargsOf(LuaValue.FALSE, LuaValue.valueOf(this.error)):
|
||||||
|
LuaValue.varargsOf(LuaValue.TRUE, this.result));
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
throw new OrphanedThread();
|
||||||
|
} finally {
|
||||||
|
this.args = LuaValue.NONE;
|
||||||
|
this.result = LuaValue.NONE;
|
||||||
|
this.error = null;
|
||||||
|
globals.running = previous_thread;
|
||||||
|
if (previous_thread != null)
|
||||||
|
globals.running.state.status =STATUS_RUNNING;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
locker.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Varargs lua_yield(Varargs args) {
|
||||||
|
locker.lock();
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
this.result = args;
|
||||||
|
this.status = STATUS_SUSPENDED;
|
||||||
|
cond.signal();
|
||||||
|
do {
|
||||||
|
cond.await(thread_orphan_check_interval,TimeUnit.MILLISECONDS);
|
||||||
|
if (this.lua_thread.get() == null) {
|
||||||
|
this.status = STATUS_DEAD;
|
||||||
|
throw new OrphanedThread();
|
||||||
|
}
|
||||||
|
} while (this.status == STATUS_SUSPENDED);
|
||||||
|
return this.args;
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
this.status = STATUS_DEAD;
|
||||||
|
throw new OrphanedThread();
|
||||||
|
} finally {
|
||||||
|
this.args = LuaValue.NONE;
|
||||||
|
this.result = LuaValue.NONE;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
locker.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3402,8 +3402,8 @@ public class LuaValue extends Varargs {
|
|||||||
switch ( v.length ) {
|
switch ( v.length ) {
|
||||||
case 0: return NONE;
|
case 0: return NONE;
|
||||||
case 1: return v[0];
|
case 1: return v[0];
|
||||||
case 2: return new Varargs.PairVarargs(v[0],v[1]);
|
case 2: return new PairVarargs(v[0],v[1]);
|
||||||
default: return new Varargs.ArrayVarargs(v,NONE);
|
default: return new ArrayVarargs(v,NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3419,12 +3419,12 @@ public class LuaValue extends Varargs {
|
|||||||
switch ( v.length ) {
|
switch ( v.length ) {
|
||||||
case 0: return r;
|
case 0: return r;
|
||||||
case 1: return r.narg()>0?
|
case 1: return r.narg()>0?
|
||||||
(Varargs) new Varargs.PairVarargs(v[0],r):
|
(Varargs) new PairVarargs(v[0],r):
|
||||||
(Varargs) v[0];
|
(Varargs) v[0];
|
||||||
case 2: return r.narg()>0?
|
case 2: return r.narg()>0?
|
||||||
(Varargs) new Varargs.ArrayVarargs(v,r):
|
(Varargs) new ArrayVarargs(v,r):
|
||||||
(Varargs) new Varargs.PairVarargs(v[0],v[1]);
|
(Varargs) new PairVarargs(v[0],v[1]);
|
||||||
default: return new Varargs.ArrayVarargs(v,r);
|
default: return new ArrayVarargs(v,r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3441,8 +3441,8 @@ public class LuaValue extends Varargs {
|
|||||||
switch ( length ) {
|
switch ( length ) {
|
||||||
case 0: return NONE;
|
case 0: return NONE;
|
||||||
case 1: return v[offset];
|
case 1: return v[offset];
|
||||||
case 2: return new Varargs.PairVarargs(v[offset+0],v[offset+1]);
|
case 2: return new PairVarargs(v[offset+0],v[offset+1]);
|
||||||
default: return new Varargs.ArrayPartVarargs(v, offset, length, NONE);
|
default: return new ArrayPartVarargs(v, offset, length, NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3463,12 +3463,12 @@ public class LuaValue extends Varargs {
|
|||||||
switch ( length ) {
|
switch ( length ) {
|
||||||
case 0: return more;
|
case 0: return more;
|
||||||
case 1: return more.narg()>0?
|
case 1: return more.narg()>0?
|
||||||
(Varargs) new Varargs.PairVarargs(v[offset],more):
|
(Varargs) new PairVarargs(v[offset],more):
|
||||||
(Varargs) v[offset];
|
(Varargs) v[offset];
|
||||||
case 2: return more.narg()>0?
|
case 2: return more.narg()>0?
|
||||||
(Varargs) new Varargs.ArrayPartVarargs(v,offset,length,more):
|
(Varargs) new ArrayPartVarargs(v,offset,length,more):
|
||||||
(Varargs) new Varargs.PairVarargs(v[offset],v[offset+1]);
|
(Varargs) new PairVarargs(v[offset],v[offset+1]);
|
||||||
default: return new Varargs.ArrayPartVarargs(v,offset,length,more);
|
default: return new ArrayPartVarargs(v,offset,length,more);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3485,7 +3485,7 @@ public class LuaValue extends Varargs {
|
|||||||
public static Varargs varargsOf(LuaValue v, Varargs r) {
|
public static Varargs varargsOf(LuaValue v, Varargs r) {
|
||||||
switch ( r.narg() ) {
|
switch ( r.narg() ) {
|
||||||
case 0: return v;
|
case 0: return v;
|
||||||
default: return new Varargs.PairVarargs(v,r);
|
default: return new PairVarargs(v,r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3502,8 +3502,8 @@ public class LuaValue extends Varargs {
|
|||||||
*/
|
*/
|
||||||
public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) {
|
public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) {
|
||||||
switch ( v3.narg() ) {
|
switch ( v3.narg() ) {
|
||||||
case 0: return new Varargs.PairVarargs(v1,v2);
|
case 0: return new PairVarargs(v1,v2);
|
||||||
default: return new Varargs.ArrayPartVarargs(new LuaValue[]{v1,v2}, 0, 2, v3);
|
default: return new ArrayPartVarargs(new LuaValue[]{v1,v2}, 0, 2, v3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
package org.luaj.vm2;
|
package org.luaj.vm2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link java.lang.Error} sublcass that indicates a lua thread that is no
|
* {@link Error} sublcass that indicates a lua thread that is no
|
||||||
* longer referenced has been detected.
|
* longer referenced has been detected.
|
||||||
* <p>
|
* <p>
|
||||||
* The java thread in which this is thrown should correspond to a
|
* The java thread in which this is thrown should correspond to a
|
||||||
@@ -537,7 +537,7 @@ public abstract class Varargs {
|
|||||||
if (newstart == this.end)
|
if (newstart == this.end)
|
||||||
return v.arg(this.end);
|
return v.arg(this.end);
|
||||||
if (newstart == this.end-1)
|
if (newstart == this.end-1)
|
||||||
return new Varargs.PairVarargs(v.arg(this.end-1), v.arg(this.end));
|
return new PairVarargs(v.arg(this.end-1), v.arg(this.end));
|
||||||
return new SubVarargs(v, newstart, this.end);
|
return new SubVarargs(v, newstart, this.end);
|
||||||
}
|
}
|
||||||
return new SubVarargs(v, newstart, this.end);
|
return new SubVarargs(v, newstart, this.end);
|
||||||
@@ -168,7 +168,7 @@ public class DumpState {
|
|||||||
break;
|
break;
|
||||||
case NUMBER_FORMAT_INTS_ONLY:
|
case NUMBER_FORMAT_INTS_ONLY:
|
||||||
if ( ! ALLOW_INTEGER_CASTING && ! o.isint() )
|
if ( ! ALLOW_INTEGER_CASTING && ! o.isint() )
|
||||||
throw new java.lang.IllegalArgumentException("not an integer: "+o);
|
throw new IllegalArgumentException("not an integer: "+o);
|
||||||
writer.write(LuaValue.TNUMBER);
|
writer.write(LuaValue.TNUMBER);
|
||||||
dumpInt(o.toint());
|
dumpInt(o.toint());
|
||||||
break;
|
break;
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009 Luaj.org. All rights reserved.
|
* Copyright (c) 2009 Luaj.org. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.vm2.compiler;
|
package org.luaj.vm2.compiler;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
@@ -97,7 +97,7 @@ public class FuncState extends Constants {
|
|||||||
for (i = bl.firstlabel; i < ll_n; i++) {
|
for (i = bl.firstlabel; i < ll_n; i++) {
|
||||||
if (label.eq_b(ll[i].name)) {
|
if (label.eq_b(ll[i].name)) {
|
||||||
String msg = ls.L.pushfstring(
|
String msg = ls.L.pushfstring(
|
||||||
"label '" + label + " already defined on line " + ll[i].line);
|
"label '" + label + " already defined on line " + ll[i].line);
|
||||||
ls.semerror(msg);
|
ls.semerror(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,10 +111,10 @@ public class FuncState extends Constants {
|
|||||||
|
|
||||||
void errorlimit (int limit, String what) {
|
void errorlimit (int limit, String what) {
|
||||||
// TODO: report message logic.
|
// TODO: report message logic.
|
||||||
String msg = (f.linedefined == 0) ?
|
String msg = (f.linedefined == 0) ?
|
||||||
ls.L.pushfstring("main function has more than "+limit+" "+what) :
|
ls.L.pushfstring("main function has more than "+limit+" "+what) :
|
||||||
ls.L.pushfstring("function at line "+f.linedefined+" has more than "+limit+" "+what);
|
ls.L.pushfstring("function at line "+f.linedefined+" has more than "+limit+" "+what);
|
||||||
ls.lexerror(msg, 0);
|
ls.lexerror(msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocVars getlocvar(int i) {
|
LocVars getlocvar(int i) {
|
||||||
@@ -124,19 +124,19 @@ public class FuncState extends Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void removevars (int tolevel) {
|
void removevars (int tolevel) {
|
||||||
ls.dyd.n_actvar -= (nactvar - tolevel);
|
ls.dyd.n_actvar -= (nactvar - tolevel);
|
||||||
while (nactvar > tolevel)
|
while (nactvar > tolevel)
|
||||||
getlocvar(--nactvar).endpc = pc;
|
getlocvar(--nactvar).endpc = pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int searchupvalue (LuaString name) {
|
int searchupvalue (LuaString name) {
|
||||||
int i;
|
int i;
|
||||||
Upvaldesc[] up = f.upvalues;
|
Upvaldesc[] up = f.upvalues;
|
||||||
for (i = 0; i < nups; i++)
|
for (i = 0; i < nups; i++)
|
||||||
if (up[i].name.eq_b(name))
|
if (up[i].name.eq_b(name))
|
||||||
return i;
|
return i;
|
||||||
return -1; /* not found */
|
return -1; /* not found */
|
||||||
}
|
}
|
||||||
|
|
||||||
int newupvalue (LuaString name, expdesc v) {
|
int newupvalue (LuaString name, expdesc v) {
|
||||||
@@ -144,7 +144,7 @@ public class FuncState extends Constants {
|
|||||||
if (f.upvalues == null || nups + 1 > f.upvalues.length)
|
if (f.upvalues == null || nups + 1 > f.upvalues.length)
|
||||||
f.upvalues = realloc( f.upvalues, nups > 0 ? nups*2 : 1 );
|
f.upvalues = realloc( f.upvalues, nups > 0 ? nups*2 : 1 );
|
||||||
f.upvalues[nups] = new Upvaldesc(name, v.k == LexState.VLOCAL, v.u.info);
|
f.upvalues[nups] = new Upvaldesc(name, v.k == LexState.VLOCAL, v.u.info);
|
||||||
return nups++;
|
return nups++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int searchvar(LuaString n) {
|
int searchvar(LuaString n) {
|
||||||
@@ -173,24 +173,24 @@ public class FuncState extends Constants {
|
|||||||
fs.markupval(v); /* local will be used as an upval */
|
fs.markupval(v); /* local will be used as an upval */
|
||||||
return LexState.VLOCAL;
|
return LexState.VLOCAL;
|
||||||
} else { /* not found at current level; try upvalues */
|
} else { /* not found at current level; try upvalues */
|
||||||
int idx = fs.searchupvalue(n); /* try existing upvalues */
|
int idx = fs.searchupvalue(n); /* try existing upvalues */
|
||||||
if (idx < 0) { /* not found? */
|
if (idx < 0) { /* not found? */
|
||||||
if (singlevaraux(fs.prev, n, var, 0) == LexState.VVOID) /* try upper levels */
|
if (singlevaraux(fs.prev, n, var, 0) == LexState.VVOID) /* try upper levels */
|
||||||
return LexState.VVOID; /* not found; is a global */
|
return LexState.VVOID; /* not found; is a global */
|
||||||
/* else was LOCAL or UPVAL */
|
/* else was LOCAL or UPVAL */
|
||||||
idx = fs.newupvalue(n, var); /* will be a new upvalue */
|
idx = fs.newupvalue(n, var); /* will be a new upvalue */
|
||||||
}
|
}
|
||||||
var.init(LexState.VUPVAL, idx);
|
var.init(LexState.VUPVAL, idx);
|
||||||
return LexState.VUPVAL;
|
return LexState.VUPVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** "export" pending gotos to outer level, to check them against
|
** "export" pending gotos to outer level, to check them against
|
||||||
** outer labels; if the block being exited has upvalues, and
|
** outer labels; if the block being exited has upvalues, and
|
||||||
** the goto exits the scope of any variable (which can be the
|
** the goto exits the scope of any variable (which can be the
|
||||||
** upvalue), close those variables being exited.
|
** upvalue), close those variables being exited.
|
||||||
*/
|
*/
|
||||||
void movegotosout(BlockCnt bl) {
|
void movegotosout(BlockCnt bl) {
|
||||||
int i = bl.firstgoto;
|
int i = bl.firstgoto;
|
||||||
final LexState.Labeldesc[] gl = ls.dyd.gt;
|
final LexState.Labeldesc[] gl = ls.dyd.gt;
|
||||||
@@ -209,35 +209,35 @@ public class FuncState extends Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void enterblock (BlockCnt bl, boolean isloop) {
|
void enterblock (BlockCnt bl, boolean isloop) {
|
||||||
bl.isloop = isloop;
|
bl.isloop = isloop;
|
||||||
bl.nactvar = nactvar;
|
bl.nactvar = nactvar;
|
||||||
bl.firstlabel = (short) ls.dyd.n_label;
|
bl.firstlabel = (short) ls.dyd.n_label;
|
||||||
bl.firstgoto = (short) ls.dyd.n_gt;
|
bl.firstgoto = (short) ls.dyd.n_gt;
|
||||||
bl.upval = false;
|
bl.upval = false;
|
||||||
bl.previous = this.bl;
|
bl.previous = this.bl;
|
||||||
this.bl = bl;
|
this.bl = bl;
|
||||||
_assert(this.freereg == this.nactvar);
|
_assert(this.freereg == this.nactvar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void leaveblock() {
|
void leaveblock() {
|
||||||
BlockCnt bl = this.bl;
|
BlockCnt bl = this.bl;
|
||||||
if (bl.previous != null && bl.upval) {
|
if (bl.previous != null && bl.upval) {
|
||||||
/* create a 'jump to here' to close upvalues */
|
/* create a 'jump to here' to close upvalues */
|
||||||
int j = this.jump();
|
int j = this.jump();
|
||||||
this.patchclose(j, bl.nactvar);
|
this.patchclose(j, bl.nactvar);
|
||||||
this.patchtohere(j);
|
this.patchtohere(j);
|
||||||
}
|
}
|
||||||
if (bl.isloop)
|
if (bl.isloop)
|
||||||
ls.breaklabel(); /* close pending breaks */
|
ls.breaklabel(); /* close pending breaks */
|
||||||
this.bl = bl.previous;
|
this.bl = bl.previous;
|
||||||
this.removevars(bl.nactvar);
|
this.removevars(bl.nactvar);
|
||||||
_assert(bl.nactvar == this.nactvar);
|
_assert(bl.nactvar == this.nactvar);
|
||||||
this.freereg = this.nactvar; /* free registers */
|
this.freereg = this.nactvar; /* free registers */
|
||||||
ls.dyd.n_label = bl.firstlabel; /* remove local labels */
|
ls.dyd.n_label = bl.firstlabel; /* remove local labels */
|
||||||
if (bl.previous != null) /* inner block? */
|
if (bl.previous != null) /* inner block? */
|
||||||
this.movegotosout(bl); /* update pending gotos to outer block */
|
this.movegotosout(bl); /* update pending gotos to outer block */
|
||||||
else if (bl.firstgoto < ls.dyd.n_gt) /* pending gotos in outer block? */
|
else if (bl.firstgoto < ls.dyd.n_gt) /* pending gotos in outer block? */
|
||||||
ls.undefgoto(ls.dyd.gt[bl.firstgoto]); /* error */
|
ls.undefgoto(ls.dyd.gt[bl.firstgoto]); /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
void closelistfield(ConsControl cc) {
|
void closelistfield(ConsControl cc) {
|
||||||
@@ -258,14 +258,14 @@ public class FuncState extends Constants {
|
|||||||
void lastlistfield (ConsControl cc) {
|
void lastlistfield (ConsControl cc) {
|
||||||
if (cc.tostore == 0) return;
|
if (cc.tostore == 0) return;
|
||||||
if (hasmultret(cc.v.k)) {
|
if (hasmultret(cc.v.k)) {
|
||||||
this.setmultret(cc.v);
|
this.setmultret(cc.v);
|
||||||
this.setlist(cc.t.u.info, cc.na, LUA_MULTRET);
|
this.setlist(cc.t.u.info, cc.na, LUA_MULTRET);
|
||||||
cc.na--; /** do not count last expression (unknown number of elements) */
|
cc.na--; /** do not count last expression (unknown number of elements) */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (cc.v.k != LexState.VVOID)
|
if (cc.v.k != LexState.VVOID)
|
||||||
this.exp2nextreg(cc.v);
|
this.exp2nextreg(cc.v);
|
||||||
this.setlist(cc.t.u.info, cc.na, cc.tostore);
|
this.setlist(cc.t.u.info, cc.na, cc.tostore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,7 +479,7 @@ public class FuncState extends Constants {
|
|||||||
return ((Integer) h.get(v)).intValue();
|
return ((Integer) h.get(v)).intValue();
|
||||||
}
|
}
|
||||||
final int idx = this.nk;
|
final int idx = this.nk;
|
||||||
this.h.put(v, new Integer(idx));
|
this.h.put(v, idx);
|
||||||
final Prototype f = this.f;
|
final Prototype f = this.f;
|
||||||
if (f.k == null || nk + 1 >= f.k.length)
|
if (f.k == null || nk + 1 >= f.k.length)
|
||||||
f.k = realloc( f.k, nk*2 + 1 );
|
f.k = realloc( f.k, nk*2 + 1 );
|
||||||
@@ -531,33 +531,33 @@ public class FuncState extends Constants {
|
|||||||
|
|
||||||
void dischargevars(expdesc e) {
|
void dischargevars(expdesc e) {
|
||||||
switch (e.k) {
|
switch (e.k) {
|
||||||
case LexState.VLOCAL: {
|
case LexState.VLOCAL: {
|
||||||
e.k = LexState.VNONRELOC;
|
e.k = LexState.VNONRELOC;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case LexState.VUPVAL: {
|
|
||||||
e.u.info = this.codeABC(OP_GETUPVAL, 0, e.u.info, 0);
|
|
||||||
e.k = LexState.VRELOCABLE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LexState.VINDEXED: {
|
|
||||||
int op = OP_GETTABUP; /* assume 't' is in an upvalue */
|
|
||||||
this.freereg(e.u.ind_idx);
|
|
||||||
if (e.u.ind_vt == LexState.VLOCAL) { /* 't' is in a register? */
|
|
||||||
this.freereg(e.u.ind_t);
|
|
||||||
op = OP_GETTABLE;
|
|
||||||
}
|
}
|
||||||
e.u.info = this.codeABC(op, 0, e.u.ind_t, e.u.ind_idx);
|
case LexState.VUPVAL: {
|
||||||
e.k = LexState.VRELOCABLE;
|
e.u.info = this.codeABC(OP_GETUPVAL, 0, e.u.info, 0);
|
||||||
break;
|
e.k = LexState.VRELOCABLE;
|
||||||
}
|
break;
|
||||||
case LexState.VVARARG:
|
}
|
||||||
case LexState.VCALL: {
|
case LexState.VINDEXED: {
|
||||||
this.setoneret(e);
|
int op = OP_GETTABUP; /* assume 't' is in an upvalue */
|
||||||
break;
|
this.freereg(e.u.ind_idx);
|
||||||
}
|
if (e.u.ind_vt == LexState.VLOCAL) { /* 't' is in a register? */
|
||||||
default:
|
this.freereg(e.u.ind_t);
|
||||||
break; /* there is one value available (somewhere) */
|
op = OP_GETTABLE;
|
||||||
|
}
|
||||||
|
e.u.info = this.codeABC(op, 0, e.u.ind_t, e.u.ind_idx);
|
||||||
|
e.k = LexState.VRELOCABLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LexState.VVARARG:
|
||||||
|
case LexState.VCALL: {
|
||||||
|
this.setoneret(e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break; /* there is one value available (somewhere) */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,38 +569,38 @@ public class FuncState extends Constants {
|
|||||||
void discharge2reg(expdesc e, int reg) {
|
void discharge2reg(expdesc e, int reg) {
|
||||||
this.dischargevars(e);
|
this.dischargevars(e);
|
||||||
switch (e.k) {
|
switch (e.k) {
|
||||||
case LexState.VNIL: {
|
case LexState.VNIL: {
|
||||||
this.nil(reg, 1);
|
this.nil(reg, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VFALSE:
|
case LexState.VFALSE:
|
||||||
case LexState.VTRUE: {
|
case LexState.VTRUE: {
|
||||||
this.codeABC(OP_LOADBOOL, reg, (e.k == LexState.VTRUE ? 1 : 0),
|
this.codeABC(OP_LOADBOOL, reg, (e.k == LexState.VTRUE ? 1 : 0),
|
||||||
0);
|
0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VK: {
|
case LexState.VK: {
|
||||||
this.codeK(reg, e.u.info);
|
this.codeK(reg, e.u.info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VKNUM: {
|
case LexState.VKNUM: {
|
||||||
this.codeK(reg, this.numberK(e.u.nval()));
|
this.codeK(reg, this.numberK(e.u.nval()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VRELOCABLE: {
|
case LexState.VRELOCABLE: {
|
||||||
InstructionPtr pc = this.getcodePtr(e);
|
InstructionPtr pc = this.getcodePtr(e);
|
||||||
SETARG_A(pc, reg);
|
SETARG_A(pc, reg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VNONRELOC: {
|
case LexState.VNONRELOC: {
|
||||||
if (reg != e.u.info)
|
if (reg != e.u.info)
|
||||||
this.codeABC(OP_MOVE, reg, e.u.info, 0);
|
this.codeABC(OP_MOVE, reg, e.u.info, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
_assert (e.k == LexState.VVOID || e.k == LexState.VJMP);
|
_assert (e.k == LexState.VVOID || e.k == LexState.VJMP);
|
||||||
return; /* nothing to do... */
|
return; /* nothing to do... */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.u.info = reg;
|
e.u.info = reg;
|
||||||
e.k = LexState.VNONRELOC;
|
e.k = LexState.VNONRELOC;
|
||||||
@@ -673,57 +673,57 @@ public class FuncState extends Constants {
|
|||||||
int exp2RK(expdesc e) {
|
int exp2RK(expdesc e) {
|
||||||
this.exp2val(e);
|
this.exp2val(e);
|
||||||
switch (e.k) {
|
switch (e.k) {
|
||||||
case LexState.VTRUE:
|
case LexState.VTRUE:
|
||||||
case LexState.VFALSE:
|
case LexState.VFALSE:
|
||||||
case LexState.VNIL: {
|
case LexState.VNIL: {
|
||||||
if (this.nk <= MAXINDEXRK) { /* constant fit in RK operand? */
|
if (this.nk <= MAXINDEXRK) { /* constant fit in RK operand? */
|
||||||
e.u.info = (e.k == LexState.VNIL) ? this.nilK()
|
e.u.info = (e.k == LexState.VNIL) ? this.nilK()
|
||||||
: this.boolK((e.k == LexState.VTRUE));
|
: this.boolK((e.k == LexState.VTRUE));
|
||||||
|
e.k = LexState.VK;
|
||||||
|
return RKASK(e.u.info);
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LexState.VKNUM: {
|
||||||
|
e.u.info = this.numberK(e.u.nval());
|
||||||
e.k = LexState.VK;
|
e.k = LexState.VK;
|
||||||
return RKASK(e.u.info);
|
/* go through */
|
||||||
} else
|
}
|
||||||
|
case LexState.VK: {
|
||||||
|
if (e.u.info <= MAXINDEXRK) /* constant fit in argC? */
|
||||||
|
return RKASK(e.u.info);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VKNUM: {
|
|
||||||
e.u.info = this.numberK(e.u.nval());
|
|
||||||
e.k = LexState.VK;
|
|
||||||
/* go through */
|
|
||||||
}
|
|
||||||
case LexState.VK: {
|
|
||||||
if (e.u.info <= MAXINDEXRK) /* constant fit in argC? */
|
|
||||||
return RKASK(e.u.info);
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* not a constant in the right range: put it in a register */
|
/* not a constant in the right range: put it in a register */
|
||||||
return this.exp2anyreg(e);
|
return this.exp2anyreg(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void storevar(expdesc var, expdesc ex) {
|
void storevar(expdesc var, expdesc ex) {
|
||||||
switch (var.k) {
|
switch (var.k) {
|
||||||
case LexState.VLOCAL: {
|
case LexState.VLOCAL: {
|
||||||
this.freeexp(ex);
|
this.freeexp(ex);
|
||||||
this.exp2reg(ex, var.u.info);
|
this.exp2reg(ex, var.u.info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case LexState.VUPVAL: {
|
case LexState.VUPVAL: {
|
||||||
int e = this.exp2anyreg(ex);
|
int e = this.exp2anyreg(ex);
|
||||||
this.codeABC(OP_SETUPVAL, e, var.u.info, 0);
|
this.codeABC(OP_SETUPVAL, e, var.u.info, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VINDEXED: {
|
case LexState.VINDEXED: {
|
||||||
int op = (var.u.ind_vt == LexState.VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
|
int op = (var.u.ind_vt == LexState.VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
|
||||||
int e = this.exp2RK(ex);
|
int e = this.exp2RK(ex);
|
||||||
this.codeABC(op, var.u.ind_t, var.u.ind_idx, e);
|
this.codeABC(op, var.u.ind_t, var.u.ind_idx, e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
_assert (false); /* invalid var kind to store */
|
_assert (false); /* invalid var kind to store */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.freeexp(ex);
|
this.freeexp(ex);
|
||||||
}
|
}
|
||||||
@@ -769,21 +769,21 @@ public class FuncState extends Constants {
|
|||||||
int pc; /* pc of last jump */
|
int pc; /* pc of last jump */
|
||||||
this.dischargevars(e);
|
this.dischargevars(e);
|
||||||
switch (e.k) {
|
switch (e.k) {
|
||||||
case LexState.VJMP: {
|
case LexState.VJMP: {
|
||||||
this.invertjump(e);
|
this.invertjump(e);
|
||||||
pc = e.u.info;
|
pc = e.u.info;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VK:
|
case LexState.VK:
|
||||||
case LexState.VKNUM:
|
case LexState.VKNUM:
|
||||||
case LexState.VTRUE: {
|
case LexState.VTRUE: {
|
||||||
pc = LexState.NO_JUMP; /* always true; do nothing */
|
pc = LexState.NO_JUMP; /* always true; do nothing */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
pc = this.jumponcond(e, 0);
|
pc = this.jumponcond(e, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.concat(e.f, pc); /* insert last jump in `f' list */
|
this.concat(e.f, pc); /* insert last jump in `f' list */
|
||||||
this.patchtohere(e.t.i);
|
this.patchtohere(e.t.i);
|
||||||
@@ -794,19 +794,19 @@ public class FuncState extends Constants {
|
|||||||
int pc; /* pc of last jump */
|
int pc; /* pc of last jump */
|
||||||
this.dischargevars(e);
|
this.dischargevars(e);
|
||||||
switch (e.k) {
|
switch (e.k) {
|
||||||
case LexState.VJMP: {
|
case LexState.VJMP: {
|
||||||
pc = e.u.info;
|
pc = e.u.info;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VNIL:
|
case LexState.VNIL:
|
||||||
case LexState.VFALSE: {
|
case LexState.VFALSE: {
|
||||||
pc = LexState.NO_JUMP; /* always false; do nothing */
|
pc = LexState.NO_JUMP; /* always false; do nothing */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
pc = this.jumponcond(e, 1);
|
pc = this.jumponcond(e, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.concat(e.t, pc); /* insert last jump in `t' list */
|
this.concat(e.t, pc); /* insert last jump in `t' list */
|
||||||
this.patchtohere(e.f.i);
|
this.patchtohere(e.f.i);
|
||||||
@@ -816,33 +816,33 @@ public class FuncState extends Constants {
|
|||||||
void codenot(expdesc e) {
|
void codenot(expdesc e) {
|
||||||
this.dischargevars(e);
|
this.dischargevars(e);
|
||||||
switch (e.k) {
|
switch (e.k) {
|
||||||
case LexState.VNIL:
|
case LexState.VNIL:
|
||||||
case LexState.VFALSE: {
|
case LexState.VFALSE: {
|
||||||
e.k = LexState.VTRUE;
|
e.k = LexState.VTRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VK:
|
case LexState.VK:
|
||||||
case LexState.VKNUM:
|
case LexState.VKNUM:
|
||||||
case LexState.VTRUE: {
|
case LexState.VTRUE: {
|
||||||
e.k = LexState.VFALSE;
|
e.k = LexState.VFALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VJMP: {
|
case LexState.VJMP: {
|
||||||
this.invertjump(e);
|
this.invertjump(e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VRELOCABLE:
|
case LexState.VRELOCABLE:
|
||||||
case LexState.VNONRELOC: {
|
case LexState.VNONRELOC: {
|
||||||
this.discharge2anyreg(e);
|
this.discharge2anyreg(e);
|
||||||
this.freeexp(e);
|
this.freeexp(e);
|
||||||
e.u.info = this.codeABC(OP_NOT, 0, e.u.info, 0);
|
e.u.info = this.codeABC(OP_NOT, 0, e.u.info, 0);
|
||||||
e.k = LexState.VRELOCABLE;
|
e.k = LexState.VRELOCABLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
_assert (false); /* cannot happen */
|
_assert (false); /* cannot happen */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* interchange true and false lists */
|
/* interchange true and false lists */
|
||||||
{
|
{
|
||||||
@@ -871,39 +871,39 @@ public class FuncState extends Constants {
|
|||||||
if (!e1.isnumeral() || !e2.isnumeral())
|
if (!e1.isnumeral() || !e2.isnumeral())
|
||||||
return false;
|
return false;
|
||||||
if ((op == OP_DIV || op == OP_MOD) && e2.u.nval().eq_b(LuaValue.ZERO))
|
if ((op == OP_DIV || op == OP_MOD) && e2.u.nval().eq_b(LuaValue.ZERO))
|
||||||
return false; /* do not attempt to divide by 0 */
|
return false; /* do not attempt to divide by 0 */
|
||||||
v1 = e1.u.nval();
|
v1 = e1.u.nval();
|
||||||
v2 = e2.u.nval();
|
v2 = e2.u.nval();
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case OP_ADD:
|
case OP_ADD:
|
||||||
r = v1.add(v2);
|
r = v1.add(v2);
|
||||||
break;
|
break;
|
||||||
case OP_SUB:
|
case OP_SUB:
|
||||||
r = v1.sub(v2);
|
r = v1.sub(v2);
|
||||||
break;
|
break;
|
||||||
case OP_MUL:
|
case OP_MUL:
|
||||||
r = v1.mul(v2);
|
r = v1.mul(v2);
|
||||||
break;
|
break;
|
||||||
case OP_DIV:
|
case OP_DIV:
|
||||||
r = v1.div(v2);
|
r = v1.div(v2);
|
||||||
break;
|
break;
|
||||||
case OP_MOD:
|
case OP_MOD:
|
||||||
r = v1.mod(v2);
|
r = v1.mod(v2);
|
||||||
break;
|
break;
|
||||||
case OP_POW:
|
case OP_POW:
|
||||||
r = v1.pow(v2);
|
r = v1.pow(v2);
|
||||||
break;
|
break;
|
||||||
case OP_UNM:
|
case OP_UNM:
|
||||||
r = v1.neg();
|
r = v1.neg();
|
||||||
break;
|
break;
|
||||||
case OP_LEN:
|
case OP_LEN:
|
||||||
// r = v1.len();
|
// r = v1.len();
|
||||||
// break;
|
// break;
|
||||||
return false; /* no constant folding for 'len' */
|
return false; /* no constant folding for 'len' */
|
||||||
default:
|
default:
|
||||||
_assert (false);
|
_assert (false);
|
||||||
r = null;
|
r = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( Double.isNaN(r.todouble()) )
|
if ( Double.isNaN(r.todouble()) )
|
||||||
return false; /* do not attempt to produce NaN */
|
return false; /* do not attempt to produce NaN */
|
||||||
@@ -951,131 +951,131 @@ public class FuncState extends Constants {
|
|||||||
expdesc e2 = new expdesc();
|
expdesc e2 = new expdesc();
|
||||||
e2.init(LexState.VKNUM, 0);
|
e2.init(LexState.VKNUM, 0);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case LexState.OPR_MINUS: {
|
case LexState.OPR_MINUS: {
|
||||||
if (e.isnumeral()) /* minus constant? */
|
if (e.isnumeral()) /* minus constant? */
|
||||||
e.u.setNval(e.u.nval().neg()); /* fold it */
|
e.u.setNval(e.u.nval().neg()); /* fold it */
|
||||||
else {
|
else {
|
||||||
this.exp2anyreg(e);
|
this.exp2anyreg(e);
|
||||||
this.codearith(OP_UNM, e, e2, line);
|
this.codearith(OP_UNM, e, e2, line);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.OPR_NOT:
|
case LexState.OPR_NOT:
|
||||||
this.codenot(e);
|
this.codenot(e);
|
||||||
break;
|
break;
|
||||||
case LexState.OPR_LEN: {
|
case LexState.OPR_LEN: {
|
||||||
this.exp2anyreg(e); /* cannot operate on constants */
|
this.exp2anyreg(e); /* cannot operate on constants */
|
||||||
this.codearith(OP_LEN, e, e2, line);
|
this.codearith(OP_LEN, e, e2, line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
_assert (false);
|
_assert (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void infix(int /* BinOpr */op, expdesc v) {
|
void infix(int /* BinOpr */op, expdesc v) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case LexState.OPR_AND: {
|
case LexState.OPR_AND: {
|
||||||
this.goiftrue(v);
|
this.goiftrue(v);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.OPR_OR: {
|
case LexState.OPR_OR: {
|
||||||
this.goiffalse(v);
|
this.goiffalse(v);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.OPR_CONCAT: {
|
case LexState.OPR_CONCAT: {
|
||||||
this.exp2nextreg(v); /* operand must be on the `stack' */
|
this.exp2nextreg(v); /* operand must be on the `stack' */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.OPR_ADD:
|
case LexState.OPR_ADD:
|
||||||
case LexState.OPR_SUB:
|
case LexState.OPR_SUB:
|
||||||
case LexState.OPR_MUL:
|
case LexState.OPR_MUL:
|
||||||
case LexState.OPR_DIV:
|
case LexState.OPR_DIV:
|
||||||
case LexState.OPR_MOD:
|
case LexState.OPR_MOD:
|
||||||
case LexState.OPR_POW: {
|
case LexState.OPR_POW: {
|
||||||
if (!v.isnumeral())
|
if (!v.isnumeral())
|
||||||
|
this.exp2RK(v);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
this.exp2RK(v);
|
this.exp2RK(v);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
|
||||||
this.exp2RK(v);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void posfix(int op, expdesc e1, expdesc e2, int line) {
|
void posfix(int op, expdesc e1, expdesc e2, int line) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case LexState.OPR_AND: {
|
case LexState.OPR_AND: {
|
||||||
_assert (e1.t.i == LexState.NO_JUMP); /* list must be closed */
|
_assert (e1.t.i == LexState.NO_JUMP); /* list must be closed */
|
||||||
this.dischargevars(e2);
|
this.dischargevars(e2);
|
||||||
this.concat(e2.f, e1.f.i);
|
this.concat(e2.f, e1.f.i);
|
||||||
// *e1 = *e2;
|
// *e1 = *e2;
|
||||||
e1.setvalue(e2);
|
e1.setvalue(e2);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case LexState.OPR_OR: {
|
|
||||||
_assert (e1.f.i == LexState.NO_JUMP); /* list must be closed */
|
|
||||||
this.dischargevars(e2);
|
|
||||||
this.concat(e2.t, e1.t.i);
|
|
||||||
// *e1 = *e2;
|
|
||||||
e1.setvalue(e2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LexState.OPR_CONCAT: {
|
|
||||||
this.exp2val(e2);
|
|
||||||
if (e2.k == LexState.VRELOCABLE
|
|
||||||
&& GET_OPCODE(this.getcode(e2)) == OP_CONCAT) {
|
|
||||||
_assert (e1.u.info == GETARG_B(this.getcode(e2)) - 1);
|
|
||||||
this.freeexp(e1);
|
|
||||||
SETARG_B(this.getcodePtr(e2), e1.u.info);
|
|
||||||
e1.k = LexState.VRELOCABLE;
|
|
||||||
e1.u.info = e2.u.info;
|
|
||||||
} else {
|
|
||||||
this.exp2nextreg(e2); /* operand must be on the 'stack' */
|
|
||||||
this.codearith(OP_CONCAT, e1, e2, line);
|
|
||||||
}
|
}
|
||||||
break;
|
case LexState.OPR_OR: {
|
||||||
}
|
_assert (e1.f.i == LexState.NO_JUMP); /* list must be closed */
|
||||||
case LexState.OPR_ADD:
|
this.dischargevars(e2);
|
||||||
this.codearith(OP_ADD, e1, e2, line);
|
this.concat(e2.t, e1.t.i);
|
||||||
break;
|
// *e1 = *e2;
|
||||||
case LexState.OPR_SUB:
|
e1.setvalue(e2);
|
||||||
this.codearith(OP_SUB, e1, e2, line);
|
break;
|
||||||
break;
|
}
|
||||||
case LexState.OPR_MUL:
|
case LexState.OPR_CONCAT: {
|
||||||
this.codearith(OP_MUL, e1, e2, line);
|
this.exp2val(e2);
|
||||||
break;
|
if (e2.k == LexState.VRELOCABLE
|
||||||
case LexState.OPR_DIV:
|
&& GET_OPCODE(this.getcode(e2)) == OP_CONCAT) {
|
||||||
this.codearith(OP_DIV, e1, e2, line);
|
_assert (e1.u.info == GETARG_B(this.getcode(e2)) - 1);
|
||||||
break;
|
this.freeexp(e1);
|
||||||
case LexState.OPR_MOD:
|
SETARG_B(this.getcodePtr(e2), e1.u.info);
|
||||||
this.codearith(OP_MOD, e1, e2, line);
|
e1.k = LexState.VRELOCABLE;
|
||||||
break;
|
e1.u.info = e2.u.info;
|
||||||
case LexState.OPR_POW:
|
} else {
|
||||||
this.codearith(OP_POW, e1, e2, line);
|
this.exp2nextreg(e2); /* operand must be on the 'stack' */
|
||||||
break;
|
this.codearith(OP_CONCAT, e1, e2, line);
|
||||||
case LexState.OPR_EQ:
|
}
|
||||||
this.codecomp(OP_EQ, 1, e1, e2);
|
break;
|
||||||
break;
|
}
|
||||||
case LexState.OPR_NE:
|
case LexState.OPR_ADD:
|
||||||
this.codecomp(OP_EQ, 0, e1, e2);
|
this.codearith(OP_ADD, e1, e2, line);
|
||||||
break;
|
break;
|
||||||
case LexState.OPR_LT:
|
case LexState.OPR_SUB:
|
||||||
this.codecomp(OP_LT, 1, e1, e2);
|
this.codearith(OP_SUB, e1, e2, line);
|
||||||
break;
|
break;
|
||||||
case LexState.OPR_LE:
|
case LexState.OPR_MUL:
|
||||||
this.codecomp(OP_LE, 1, e1, e2);
|
this.codearith(OP_MUL, e1, e2, line);
|
||||||
break;
|
break;
|
||||||
case LexState.OPR_GT:
|
case LexState.OPR_DIV:
|
||||||
this.codecomp(OP_LT, 0, e1, e2);
|
this.codearith(OP_DIV, e1, e2, line);
|
||||||
break;
|
break;
|
||||||
case LexState.OPR_GE:
|
case LexState.OPR_MOD:
|
||||||
this.codecomp(OP_LE, 0, e1, e2);
|
this.codearith(OP_MOD, e1, e2, line);
|
||||||
break;
|
break;
|
||||||
default:
|
case LexState.OPR_POW:
|
||||||
_assert (false);
|
this.codearith(OP_POW, e1, e2, line);
|
||||||
|
break;
|
||||||
|
case LexState.OPR_EQ:
|
||||||
|
this.codecomp(OP_EQ, 1, e1, e2);
|
||||||
|
break;
|
||||||
|
case LexState.OPR_NE:
|
||||||
|
this.codecomp(OP_EQ, 0, e1, e2);
|
||||||
|
break;
|
||||||
|
case LexState.OPR_LT:
|
||||||
|
this.codecomp(OP_LT, 1, e1, e2);
|
||||||
|
break;
|
||||||
|
case LexState.OPR_LE:
|
||||||
|
this.codecomp(OP_LE, 1, e1, e2);
|
||||||
|
break;
|
||||||
|
case LexState.OPR_GT:
|
||||||
|
this.codecomp(OP_LT, 0, e1, e2);
|
||||||
|
break;
|
||||||
|
case LexState.OPR_GE:
|
||||||
|
this.codecomp(OP_LE, 0, e1, e2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_assert (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,7 @@ import org.luaj.vm2.lib.BaseLib;
|
|||||||
* using a user-supplied environment.
|
* using a user-supplied environment.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Implements the {@link org.luaj.vm2.Globals.Compiler} interface for loading
|
* Implements the {@link Globals.Compiler} interface for loading
|
||||||
* initialized chunks, which is an interface common to
|
* initialized chunks, which is an interface common to
|
||||||
* lua bytecode compiling and java bytecode compiling.
|
* lua bytecode compiling and java bytecode compiling.
|
||||||
*
|
*
|
||||||
Binary file not shown.
@@ -0,0 +1,2 @@
|
|||||||
|
#Sun Mar 01 11:42:21 CET 2026
|
||||||
|
gradle.version=9.0.0
|
||||||
@@ -7,16 +7,25 @@
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<name>maven-example</name>
|
<name>maven-example</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>oac</id>
|
||||||
|
<url>https://repo.open-autonomous-connection.org/api/packages/open-autonomous-connection/maven</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<!--<dependency>
|
||||||
<groupId>org.luaj</groupId>
|
<groupId>org.openautonomousconnection.luaj</groupId>
|
||||||
<artifactId>luaj-jse</artifactId>
|
<artifactId>jse</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>VERSION</version>
|
||||||
</dependency>
|
</dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>4.13.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
122
jme/pom.xml
Normal file
122
jme/pom.xml
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.openautonomousconnection.luaj</groupId>
|
||||||
|
<artifactId>parent</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>jme</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openautonomousconnection.luaj</groupId>
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>jme</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>env.WTK_HOME</name>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-sources</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals><goal>copy-resources</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/generated-sources/luaj-jme</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/../luaj-core/src/main/java</directory>
|
||||||
|
<includes><include>**/*.java</include></includes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/src/main/java</directory>
|
||||||
|
<includes><include>**/*.java</include></includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||||
|
<artifactId>replacer</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>rewrite-branding</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals><goal>replace</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<basedir>${project.build.directory}/generated-sources/luaj-jme</basedir>
|
||||||
|
<includes><include>**/*.java</include></includes>
|
||||||
|
<replacements>
|
||||||
|
<replacement>
|
||||||
|
<token>"Luaj 0.0"</token>
|
||||||
|
<value>"${luaj.brand.jme}"</value>
|
||||||
|
</replacement>
|
||||||
|
</replacements>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>add-generated-sources</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals><goal>add-source</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<sources>
|
||||||
|
<source>${project.build.directory}/generated-sources/luaj-jme</source>
|
||||||
|
</sources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<release>8</release>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-bootclasspath</arg>
|
||||||
|
<arg>${env.WTK_HOME}/lib/cldcapi11.jar${path.separator}${env.WTK_HOME}/lib/midpapi20.jar${path.separator}${env.WTK_HOME}/lib/mmapi.jar</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals><goal>jar</goal></goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.openautonomousconnection.luaj;
|
||||||
|
|
||||||
|
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||||
|
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||||
|
public class Main {
|
||||||
|
static void main() {
|
||||||
|
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||||
|
// to see how IntelliJ IDEA suggests fixing it.
|
||||||
|
IO.println(String.format("Hello and welcome!"));
|
||||||
|
|
||||||
|
for (int i = 1; i <= 5; i++) {
|
||||||
|
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||||
|
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||||
|
IO.println("i = " + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
134
jse/pom.xml
Normal file
134
jse/pom.xml
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.openautonomousconnection.luaj</groupId>
|
||||||
|
<artifactId>parent</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>jse</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openautonomousconnection.luaj</groupId>
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.bcel</groupId>
|
||||||
|
<artifactId>bcel</artifactId>
|
||||||
|
<version>6.12.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-sources</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals><goal>copy-resources</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/generated-sources/luaj-jse</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/../luaj-core/src/main/java</directory>
|
||||||
|
<includes><include>**/*.java</include></includes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/src/main/java</directory>
|
||||||
|
<includes><include>**/*.java</include></includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||||
|
<artifactId>replacer</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>rewrite-branding-and-cleanup</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals><goal>replace</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<basedir>${project.build.directory}/generated-sources/luaj-jse</basedir>
|
||||||
|
<includes>
|
||||||
|
<include>**/*.java</include>
|
||||||
|
</includes>
|
||||||
|
<replacements>
|
||||||
|
<replacement>
|
||||||
|
<token>"Luaj 0.0"</token>
|
||||||
|
<value>"${luaj.brand.jse}"</value>
|
||||||
|
</replacement>
|
||||||
|
<replacement><token><String></token><value></value></replacement>
|
||||||
|
<replacement><token><Stat></token><value></value></replacement>
|
||||||
|
<replacement><token><Exp></token><value></value></replacement>
|
||||||
|
<replacement><token><Name></token><value></value></replacement>
|
||||||
|
<replacement><token><Block></token><value></value></replacement>
|
||||||
|
<replacement><token><TableField></token><value></value></replacement>
|
||||||
|
<replacement><token><VarExp></token><value></value></replacement>
|
||||||
|
<replacement><token><Exp.VarExp></token><value></value></replacement>
|
||||||
|
<replacement><token><Object,String></token><value></value></replacement>
|
||||||
|
<replacement><token><Double,String></token><value></value></replacement>
|
||||||
|
<replacement><token><Integer,Integer></token><value></value></replacement>
|
||||||
|
<replacement><token><Integer,LocalVariableGen></token><value></value></replacement>
|
||||||
|
<replacement><token><Exp,Integer></token><value></value></replacement>
|
||||||
|
<replacement><token><String,byte[]></token><value></value></replacement>
|
||||||
|
<replacement><token><String,Variable></token><value></value></replacement>
|
||||||
|
<replacement><token><LuaValue,String></token><value></value></replacement>
|
||||||
|
<replacement><token><LuaString,String></token><value></value></replacement>
|
||||||
|
</replacements>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>add-generated-sources</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals><goal>add-source</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<sources>
|
||||||
|
<source>${project.build.directory}/generated-sources/luaj-jse</source>
|
||||||
|
</sources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.4.2</version>
|
||||||
|
<configuration>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals><goal>jar</goal></goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -155,7 +155,7 @@ abstract public class Visitor {
|
|||||||
public void visitVars(List<VarExp> vars) {
|
public void visitVars(List<VarExp> vars) {
|
||||||
if ( vars != null )
|
if ( vars != null )
|
||||||
for ( int i=0, n=vars.size(); i<n; i++ )
|
for ( int i=0, n=vars.size(); i<n; i++ )
|
||||||
((Exp.VarExp)vars.get(i)).accept(this);
|
((VarExp)vars.get(i)).accept(this);
|
||||||
}
|
}
|
||||||
public void visitExps(List<Exp> exps) {
|
public void visitExps(List<Exp> exps) {
|
||||||
if ( exps != null )
|
if ( exps != null )
|
||||||
@@ -34,7 +34,7 @@ import org.luaj.vm2.Prototype;
|
|||||||
import org.luaj.vm2.compiler.LuaC;
|
import org.luaj.vm2.compiler.LuaC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link org.luaj.vm2.Globals.Compiler} which does direct
|
* Implementation of {@link Globals.Compiler} which does direct
|
||||||
* lua-to-java-bytecode compiling.
|
* lua-to-java-bytecode compiling.
|
||||||
* <p>
|
* <p>
|
||||||
* By default, when using {@link org.luaj.vm2.lib.jse.JsePlatform} or
|
* By default, when using {@link org.luaj.vm2.lib.jse.JsePlatform} or
|
||||||
@@ -59,7 +59,7 @@ import org.luaj.vm2.compiler.LuaC;
|
|||||||
*
|
*
|
||||||
* @see Globals#compiler
|
* @see Globals#compiler
|
||||||
* @see #install(Globals)
|
* @see #install(Globals)
|
||||||
* @see org.luaj.vm2.compiler.LuaC
|
* @see LuaC
|
||||||
* @see LuaValue
|
* @see LuaValue
|
||||||
*/
|
*/
|
||||||
public class LuaJC implements Globals.Loader {
|
public class LuaJC implements Globals.Loader {
|
||||||
@@ -1741,7 +1741,7 @@ public class LuaParser implements LuaParserConstants {
|
|||||||
throw generateParseException();
|
throw generateParseException();
|
||||||
}
|
}
|
||||||
|
|
||||||
static private final class LookaheadSuccess extends java.lang.Error { }
|
static private final class LookaheadSuccess extends Error { }
|
||||||
final private LookaheadSuccess jj_ls = new LookaheadSuccess();
|
final private LookaheadSuccess jj_ls = new LookaheadSuccess();
|
||||||
private boolean jj_scan_token(int kind) {
|
private boolean jj_scan_token(int kind) {
|
||||||
if (jj_scanpos == jj_lastpos) {
|
if (jj_scanpos == jj_lastpos) {
|
||||||
@@ -1791,7 +1791,7 @@ public class LuaParser implements LuaParserConstants {
|
|||||||
return (jj_ntk = jj_nt.kind);
|
return (jj_ntk = jj_nt.kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
private java.util.List jj_expentries = new java.util.ArrayList();
|
private List jj_expentries = new ArrayList();
|
||||||
private int[] jj_expentry;
|
private int[] jj_expentry;
|
||||||
private int jj_kind = -1;
|
private int jj_kind = -1;
|
||||||
private int[] jj_lasttokens = new int[100];
|
private int[] jj_lasttokens = new int[100];
|
||||||
@@ -1806,7 +1806,7 @@ public class LuaParser implements LuaParserConstants {
|
|||||||
for (int i = 0; i < jj_endpos; i++) {
|
for (int i = 0; i < jj_endpos; i++) {
|
||||||
jj_expentry[i] = jj_lasttokens[i];
|
jj_expentry[i] = jj_lasttokens[i];
|
||||||
}
|
}
|
||||||
jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) {
|
jj_entries_loop: for (Iterator it = jj_expentries.iterator(); it.hasNext();) {
|
||||||
int[] oldentry = (int[])(it.next());
|
int[] oldentry = (int[])(it.next());
|
||||||
if (oldentry.length == jj_expentry.length) {
|
if (oldentry.length == jj_expentry.length) {
|
||||||
for (int i = 0; i < jj_expentry.length; i++) {
|
for (int i = 0; i < jj_expentry.length; i++) {
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008-2013 LuaJ. All rights reserved.
|
* Copyright (c) 2008-2013 LuaJ. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.vm2.script;
|
package org.luaj.vm2.script;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -44,33 +44,33 @@ import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
|||||||
public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngine, Compilable {
|
public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngine, Compilable {
|
||||||
|
|
||||||
private static final String __ENGINE_VERSION__ = Lua._VERSION;
|
private static final String __ENGINE_VERSION__ = Lua._VERSION;
|
||||||
private static final String __NAME__ = "Luaj";
|
private static final String __NAME__ = "Luaj";
|
||||||
private static final String __SHORT_NAME__ = "Luaj";
|
private static final String __SHORT_NAME__ = "Luaj";
|
||||||
private static final String __LANGUAGE__ = "lua";
|
private static final String __LANGUAGE__ = "lua";
|
||||||
private static final String __LANGUAGE_VERSION__ = "5.2";
|
private static final String __LANGUAGE_VERSION__ = "5.2";
|
||||||
private static final String __ARGV__ = "arg";
|
private static final String __ARGV__ = "arg";
|
||||||
private static final String __FILENAME__ = "?";
|
private static final String __FILENAME__ = "?";
|
||||||
|
|
||||||
private static final ScriptEngineFactory myFactory = new LuaScriptEngineFactory();
|
private static final ScriptEngineFactory myFactory = new LuaScriptEngineFactory();
|
||||||
|
|
||||||
private LuajContext context;
|
private LuajContext context;
|
||||||
|
|
||||||
public LuaScriptEngine() {
|
public LuaScriptEngine() {
|
||||||
// set up context
|
// set up context
|
||||||
context = new LuajContext();
|
context = new LuajContext();
|
||||||
context.setBindings(createBindings(), ScriptContext.ENGINE_SCOPE);
|
context.setBindings(createBindings(), ScriptContext.ENGINE_SCOPE);
|
||||||
setContext(context);
|
setContext(context);
|
||||||
|
|
||||||
// set special values
|
// set special values
|
||||||
put(LANGUAGE_VERSION, __LANGUAGE_VERSION__);
|
put(LANGUAGE_VERSION, __LANGUAGE_VERSION__);
|
||||||
put(LANGUAGE, __LANGUAGE__);
|
put(LANGUAGE, __LANGUAGE__);
|
||||||
put(ENGINE, __NAME__);
|
put(ENGINE, __NAME__);
|
||||||
put(ENGINE_VERSION, __ENGINE_VERSION__);
|
put(ENGINE_VERSION, __ENGINE_VERSION__);
|
||||||
put(ARGV, __ARGV__);
|
put(ARGV, __ARGV__);
|
||||||
put(FILENAME, __FILENAME__);
|
put(FILENAME, __FILENAME__);
|
||||||
put(NAME, __SHORT_NAME__);
|
put(NAME, __SHORT_NAME__);
|
||||||
put("THREADING", null);
|
put("THREADING", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompiledScript compile(String script) throws ScriptException {
|
public CompiledScript compile(String script) throws ScriptException {
|
||||||
@@ -80,11 +80,11 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin
|
|||||||
@Override
|
@Override
|
||||||
public CompiledScript compile(Reader script) throws ScriptException {
|
public CompiledScript compile(Reader script) throws ScriptException {
|
||||||
try {
|
try {
|
||||||
InputStream is = new Utf8Encoder(script);
|
InputStream is = new Utf8Encoder(script);
|
||||||
try {
|
try {
|
||||||
final Globals g = context.globals;
|
final Globals g = context.globals;
|
||||||
final LuaFunction f = g.load(script, "script").checkfunction();
|
final LuaFunction f = g.load(script, "script").checkfunction();
|
||||||
return new LuajCompiledScript(f, g);
|
return new LuajCompiledScript(f, g);
|
||||||
} catch ( LuaError lee ) {
|
} catch ( LuaError lee ) {
|
||||||
throw new ScriptException(lee.getMessage() );
|
throw new ScriptException(lee.getMessage() );
|
||||||
} finally {
|
} finally {
|
||||||
@@ -124,7 +124,7 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin
|
|||||||
@Override
|
@Override
|
||||||
public Object eval(Reader reader, ScriptContext context)
|
public Object eval(Reader reader, ScriptContext context)
|
||||||
throws ScriptException {
|
throws ScriptException {
|
||||||
return compile(reader).eval(context);
|
return compile(reader).eval(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,20 +145,20 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin
|
|||||||
return LuaScriptEngine.this;
|
return LuaScriptEngine.this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object eval() throws ScriptException {
|
public Object eval() throws ScriptException {
|
||||||
return eval(getContext());
|
return eval(getContext());
|
||||||
}
|
|
||||||
|
|
||||||
public Object eval(Bindings bindings) throws ScriptException {
|
|
||||||
return eval(((LuajContext) getContext()).globals, bindings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object eval(ScriptContext context) throws ScriptException {
|
|
||||||
return eval(((LuajContext) context).globals, context.getBindings(ScriptContext.ENGINE_SCOPE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object eval(Globals g, Bindings b) throws ScriptException {
|
public Object eval(Bindings bindings) throws ScriptException {
|
||||||
g.setmetatable(new BindingsMetatable(b));
|
return eval(((LuajContext) getContext()).globals, bindings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object eval(ScriptContext context) throws ScriptException {
|
||||||
|
return eval(((LuajContext) context).globals, context.getBindings(ScriptContext.ENGINE_SCOPE));
|
||||||
|
}
|
||||||
|
|
||||||
|
Object eval(Globals g, Bindings b) throws ScriptException {
|
||||||
|
g.setmetatable(new BindingsMetatable(b));
|
||||||
LuaFunction f = function;
|
LuaFunction f = function;
|
||||||
if (f.isclosure())
|
if (f.isclosure())
|
||||||
f = new LuaClosure(f.checkclosure().p, g);
|
f = new LuaClosure(f.checkclosure().p, g);
|
||||||
@@ -234,32 +234,32 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin
|
|||||||
|
|
||||||
static private LuaValue toLua(Object javaValue) {
|
static private LuaValue toLua(Object javaValue) {
|
||||||
return javaValue == null? LuaValue.NIL:
|
return javaValue == null? LuaValue.NIL:
|
||||||
javaValue instanceof LuaValue? (LuaValue) javaValue:
|
javaValue instanceof LuaValue? (LuaValue) javaValue:
|
||||||
CoerceJavaToLua.coerce(javaValue);
|
CoerceJavaToLua.coerce(javaValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static private Object toJava(LuaValue luajValue) {
|
static private Object toJava(LuaValue luajValue) {
|
||||||
switch ( luajValue.type() ) {
|
switch ( luajValue.type() ) {
|
||||||
case LuaValue.TNIL: return null;
|
case LuaValue.TNIL: return null;
|
||||||
case LuaValue.TSTRING: return luajValue.tojstring();
|
case LuaValue.TSTRING: return luajValue.tojstring();
|
||||||
case LuaValue.TUSERDATA: return luajValue.checkuserdata(Object.class);
|
case LuaValue.TUSERDATA: return luajValue.checkuserdata(Object.class);
|
||||||
case LuaValue.TNUMBER: return luajValue.isinttype()?
|
case LuaValue.TNUMBER: return luajValue.isinttype()?
|
||||||
(Object) new Integer(luajValue.toint()):
|
luajValue.toint():
|
||||||
(Object) new Double(luajValue.todouble());
|
luajValue.todouble();
|
||||||
default: return luajValue;
|
default: return luajValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static private Object toJava(Varargs v) {
|
static private Object toJava(Varargs v) {
|
||||||
final int n = v.narg();
|
final int n = v.narg();
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 0: return null;
|
case 0: return null;
|
||||||
case 1: return toJava(v.arg1());
|
case 1: return toJava(v.arg1());
|
||||||
default:
|
default:
|
||||||
Object[] o = new Object[n];
|
Object[] o = new Object[n];
|
||||||
for (int i=0; i<n; ++i)
|
for (int i=0; i<n; ++i)
|
||||||
o[i] = toJava(v.arg(i+1));
|
o[i] = toJava(v.arg(i+1));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user