Permalink
Browse files

Modified the build files to properly build and package up Babylscript.

  • Loading branch information...
1 parent bb43c89 commit 4f65bbdacbbf9eae1df49202c3b1c1380d69d5c4 Ming Iu committed Apr 6, 2012
Showing with 207 additions and 0 deletions.
  1. +41 −0 README.Babylscript.txt
  2. +30 −0 babylrunner/README.bin.txt
  3. +78 −0 babylrunner/Runner.java
  4. +15 −0 babylrunner/sample.js
  5. +43 −0 build.xml
View
@@ -0,0 +1,41 @@
+The code for Babylscript is based on Mozilla's Rhino JavaScript interpreter,
+version 1.7R2. Since the Babylscript implementation is merely a modification
+of Rhino's source code, the Babylscript code has the same license terms (a mix
+of MPL1.1 and GPL2).
+
+This package contains the raw source files. You can suck them into an IDE to
+use the code. Any build scripts in the package were left-over from the original
+Rhino source code, and may not properly build all the source files.
+
+Only the interpreter portion of the Rhino JavaScript engine was modified. The
+optimizer/bytecode-compiler does not work properly after the Babylscript
+changes. As a result, to use Babylscript, you must run with optimizations
+disabled:
+
+ Context cx = Context.enter();
+ cx.setOptimizationLevel(-1); // disable optimizations
+ try {
+ Scriptable scope = cx.initStandardObjects();
+ cx.evaluateString(scope, code /* Your code here */, null, 0, null)
+ } finally {
+ Context.exit();
+ }
+
+Some of the more non-ECMAScript portions of the engine were also left unchanged
+(e.g. destructuring assignments, let, E4X, etc.), so this functionality may
+not work properly with Babylscript features or may not work at all.
+
+
+QUICK-START GUIDE
+=================
+
+A small runner program is included in this source package. Compile it using
+the Ant build.xml script in the root directory:
+
+ ant babylscriptrun
+
+It will create a babylscriptrun.jar file which you can use to run a file
+filled with UTF-8 encoded Babylscript code. A sample HelloWorld Babylscript
+program is provided called "sample.js". Run this program using
+
+ java -jar build/babylscriptrun.jar babylrunner/sample.js
View
@@ -0,0 +1,30 @@
+The code for Babylscript is based on Mozilla's Rhino JavaScript interpreter,
+version 1.7R2. Since the Babylscript implementation is merely a modification
+of Rhino's source code, the Babylscript code has the same license terms (a mix
+of MPL1.1 and GPL2).
+
+This package a jar file with the Babylscript engine in it wrapped in simple
+harness that lets you run Babylscript/Rhino/JavaScript code from the
+command-line. You need Java (version 1.5 or later) to run this jar file.
+
+
+QUICK-START GUIDE
+=================
+
+A sample HelloWorld Babylscript program is provided called "sample.js".
+Run this program using
+
+ java -jar babylscriptrun.jar sample.js
+
+
+ADDITIONAL INFO
+===============
+
+You can also run multiple files by listing each one in turn. This is useful
+for including libraries.
+
+ java -jar babylscriptrun.jar lib.js sample.js
+
+The programs run using this Babylscript harness must be encoded in UTF-8
+(e.g. in Windows Notepad, when you choose the "Save As..." option, there is an
+option that lets you change the encoding).
View
@@ -0,0 +1,78 @@
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.util.Locale;
+
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ScriptableObject;
+
+
+
+public class Runner
+{
+ ScriptableObject scope;
+
+ public Runner()
+ {
+ Context cx = Context.enter();
+ cx.setLocale(Locale.ENGLISH);
+ cx.setOptimizationLevel(-1);
+ try {
+ scope = cx.initStandardObjects();
+ cx.evaluateString(scope, "function alert(text) { java.lang.System.out.println(text); } this['fr':'alerter'] = this['ar':'\u062a\u062d\u0630\u064a\u0631'] = 'alert';", null, 0, null);
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public String runCode(String code, String filename)
+ {
+ Context cx = Context.enter();
+ cx.setOptimizationLevel(-1);
+ try {
+ return Context.toString(cx.evaluateString(scope, code, filename, 0, null));
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public void runFile(String filename) throws IOException
+ {
+ FileInputStream f = new FileInputStream(filename);
+ InputStreamReader reader = new InputStreamReader(f, "UTF-8");
+
+ StringWriter str = new StringWriter();
+ char [] buf = new char[1024];
+ int numRead = reader.read(buf);
+ while (numRead >= 0)
+ {
+ str.write(buf, 0, numRead);
+ numRead = reader.read(buf);
+ }
+
+ reader.close();
+ f.close();
+
+ runCode(str.toString(), filename);
+ }
+
+ public static void main(String[] args) throws IOException
+ {
+ if (args.length != 1)
+ {
+ System.out.println(
+ "Run a Babylscript/JavaScript/ECMAScript program by \n" +
+ "providing the name of the file to run on the command \n " +
+ "line. The file should be text files in UTF-8 format. \n" +
+ "More than one file can be specified on the command, \n" +
+ "line and they will be executed sequentially. \n");
+ return;
+ }
+
+ Runner runner = new Runner();
+ for (String filename: args)
+ runner.runFile(filename);
+ }
+
+}
View
@@ -0,0 +1,15 @@
+// Sample Babylscript program that creates a French function called "afficher"
+// for displaying text to console out. It uses Rhino's ability to call into
+// Java to do the actual displaying of text.
+//
+// This "afficher" function is translated as "show" in English, and in English
+// mode, the "show" function is used to display 'Hello world" to the screen
+
+---fr---
+fonction afficher(texte) {
+ java.lang.System.out.println(texte);
+}
+ceci['en':'show'] = ceci['ro':'afișează'] = 'afficher';
+
+---en---
+show('Hello world');
View
@@ -180,6 +180,44 @@
<copy file="${dist.dir}/${small-rhino-14.jar}" tofile="${dist.dir}/babylscript14.jar"/>
</target>
+ <target name="babylscriptrun" depends="smalljar">
+ <javac srcdir="babylrunner"
+ destdir="${dist.dir}"
+ includes="*.java"
+ deprecation="on"
+ debug="${debug}"
+ target="${target-jvm}"
+ source="${source-level}"
+ includeantruntime="false"
+ >
+ <classpath location="${classes}"/>
+ </javac>
+ <jar destfile="${build.dir}/babylscriptrun.jar">
+ <zipfileset src="${dist.dir}/${small-rhino.jar}"/>
+ <fileset dir="${dist.dir}" includes="Runner.class"/>
+ <manifest>
+ <attribute name="Main-Class" value="Runner"/>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="babylpkg" depends="babylscriptrun">
+ <tstamp>
+ <format property="DSTAMP" pattern="yyyy-MM-dd"/>
+ </tstamp>
+ <zip destfile="${dist.dir}/babylscript-bin-${DSTAMP}.zip">
+ <zipfileset file="${build.dir}/babylscriptrun.jar" fullpath="babylscriptrun.jar"/>
+ <zipfileset file="babylrunner/README.bin.txt" fullpath="README.txt"/>
+ <zipfileset file="babylrunner/sample.js" fullpath="sample.js"/>
+ </zip>
+ <zip destfile="${dist.dir}/babylscript-src-${DSTAMP}.zip">
+ <fileset dir="." includes="examples/**,testsrc/**,src/**,toolsrc/**,xmlimplsrc/**"/>
+ <fileset dir="." includes="babyltest/**,babylrunner/**"/>
+ <fileset dir="." includes="deprecatedsrc/**"/>
+ <fileset dir="." includes="*.properties,build-date,build.xml,LICENSE.txt,README.html,README.Babylscript.txt"/>
+ </zip>
+ </target>
+
<target name="copy-examples" depends="init">
<mkdir dir="${dist.dir}/examples"/>
<copy todir="${dist.dir}/examples">
@@ -298,6 +336,11 @@
<target name="help" depends="properties">
<echo>The following targets are available with this build file:
+babylscriptrun creates a simple command-line tool for running
+ Babylscript programs
+
+babylpkg packages up Babylscript in distributable form
+
clean remove all compiled classes and copied property files
compile compile classes and copy all property files

0 comments on commit 4f65bbd

Please sign in to comment.