Browse Source

Several improvements to jtalkc and some fixes in nodejs Makefiles and README.

Göran Krampe 13 years ago
parent
commit
f829a24f13
6 changed files with 77 additions and 47 deletions
  1. 73 42
      bin/jtalkc
  2. 0 1
      nodejs/README
  3. 1 1
      nodejs/benchfib/Makefile
  4. 1 1
      nodejs/hello/Makefile
  5. 1 1
      nodejs/nodecompile.js
  6. 1 1
      nodejs/trivialserver/Makefile

+ 73 - 42
bin/jtalkc

@@ -3,31 +3,35 @@
 # This is a "compiler" for JTalk code. Run without arguments for help.
 
 # Get JTalk root directory from the location of this script.
-JTALK=`dirname ${0}`/..
+JTALK=$(readlink -f `dirname ${0}`/..)
 
 function usage {
 	cat <<ENDOFHELP
-Usage: $0 [-N|D] [-K|C] [-o] [-O] [-m class] [-M file] [-i] [-I file] file1 [file2 ...] [Program]
+Usage: $0 [-N|D] [-K|C] [-o] [-O] [-m class] [-M file]
+          [-i] [-I file] file1 [file2 ...] [Program]
 
-   Will compile Jtalk files - either separately or into a runnable complete program.
-   Files listed will be handled using these rules:
+   Will compile Jtalk files - either separately or into a runnable complete
+   program. Files listed will be handled using these rules:
 
    *.js
-     Files are concatenated in listed order. If not found we look in $JTALK/js
+     Files are concatenated in listed order.
+     If not found we look in $JTALK/js
 
    *.st
-     Files are compiled into .js files before concatenated. If not found we look
-     in $JTALK/st.
+     Files are compiled into .js files before concatenated.
+     If not found we look in $JTALK/st.
 
      NOTE: Each file is currently considered to be a fileout of a single class
      category of the same name as the file!
 
-   If no Program is specified each given .st file will be compiled into a .js file.
-   Otherwise a <Program>.js file is linked together based on the options:
+   If no Program is specified each given .st file will be compiled into
+   a .js file. Otherwise a <Program>.js file is linked together based on
+   the options:
 
-  -N or -D
-     Compile for Node.js or D8 (V8 shell). Implies "-K -i -m Main" so boot.js and Kernel.js
-     are added first and init.js is added last with a call to Main class>>main.
+  -N or -D or -E
+     Compilation target. Currently Node.js, D8 (V8 shell) or Enyo (webOS 3.0).
+     All Implies "-K -I" so boot.js and Kernel.js are added first and init.js
+     is added last.
 
   -K
      Add libraries to get minimal JTalk Kernel running.
@@ -36,22 +40,25 @@ Usage: $0 [-N|D] [-K|C] [-o] [-O] [-m class] [-M file] [-i] [-I file] file1 [fil
      Add libraries to get minimal JTalk Compiler running.
 
   -o
-     Optimize each js file using the Google closure compiler. Using ~/compiler.jar    
+     Optimize each js file using the Google closure compiler.
+     Using Closure at ~/compiler.jar    
 
   -O
-     Optimize <Program>.js using the Google closure compiler. Using ~/compiler.jar
+     Optimize final <Program>.js using the Google closure compiler.
+     Using Closure at ~/compiler.jar    
 
-  -l libray1,library2
-     Load listed libraries (no spaces) in Compiler before compiling.
+  -l library1,library2
+     Load listed libraries (no spaces) into Compiler before compiling.
 
-  -L
-     Loads all libraries in directory js in Compiler before compiling.
+  -L library1,library2
+     Load listed libraries (no spaces) into Compiler before compiling and also
+     into Program.js in listed order.
 
   -i
-     Add library standard initializer $JTALK/js/init.js
+     Add library initializer <file>.
 
   -I file
-     Add library initializer <file>.
+     Add library standard initializer $JTALK/js/init.js  
 
   -m class
      Add call to #main in class <class>. 
@@ -62,7 +69,7 @@ Usage: $0 [-N|D] [-K|C] [-o] [-O] [-m class] [-M file] [-i] [-I file] file1 [fil
 
      Example invocations:
 
-     Compile Kernel.st to Kernel.js:
+     Just compile Kernel.st to Kernel.js:
 
         jtalkc Kernel.st
 
@@ -73,8 +80,8 @@ Usage: $0 [-N|D] [-K|C] [-o] [-O] [-m class] [-M file] [-i] [-I file] file1 [fil
         jtalkc -N -m Hello Hello.st Program
 
      Compile two .st files into corresponding .js files,
-     and manually link with specific myboot.js, myKernel.js, myinit.js and main.js
-     and create complete program called Program.js:
+     and link with specific myboot.js, myKernel.js, myinit.js
+     and main.js and create complete program called Program.js:
 
         jtalkc -M main.js -I myinit.js myboot.js myKernel.js Cat1.st Cat2.st Program
 
@@ -91,7 +98,7 @@ fi
 BOOT="$JTALK/js/boot.js"
 KERNEL="$BOOT $JTALK/js/Kernel.js"
 COMPILER="$KERNEL $JTALK/js/Parser.js $JTALK/js/Compiler.js"
-CANVAS="$COMPILER $JTALK/js/Canvas.js"
+KITCHENSINK="$COMPILER $JTALK/js/Canvas.js"
 
 # Predefined initializer
 INITIALIZER="$JTALK/js/init.js"
@@ -103,9 +110,10 @@ MAIN=
 MAINFILE=
 BASE=$KERNEL
 LOAD=
+LOADANDADD=
 
 # Read options and shift them away
-while getopts "NDKCoOl:LiI:M:m:h?" o; do
+while getopts "NDKCoOl:L:i:IM:m:h?" o; do
 case "$o" in
    N) ENV=NODE
       BASE=$KERNEL
@@ -122,7 +130,7 @@ case "$o" in
    O) CLOSURE=true
       CLOSUREFULL=true;;
    l) LOAD=$OPTARG;;
-   L) LOAD="$JTALK/*.js";;
+   L) LOADANDADD=$OPTARG;;
    I) INIT=$INITIALIZER;;
    i) INIT=$OPTARG;;
    M) MAINFILE=$OPTARG;;
@@ -147,17 +155,48 @@ if [ ! -z $CLOSURE ]; then
   fi
 fi
 
-# Define our Compiler
-# We need to add extra listed libraries in $LOAD not already in $CANVAS
-OURCOMPILER="$CANVAS $JTALK/js/init.js $JTALK/nodejs/nodecompile.js"
+# Function for looking up listed js files
+function resolvejs {
+  if [ -f "$1" ]; then
+    RESOLVED="$1" 
+  else
+    if [ -f $JTALK/js/$1 ]; then
+      RESOLVED="$JTALK/js/$1"
+    else
+      echo "Javascript file not found: $1"
+      exit 1
+    fi
+  fi
+}
 
-# Combine supplied libraries
-LIBS="$BASE $ADDONS"
+# Resolve listed libraries in $LOAD separated by spaces
+LOAD=${LOAD//,/\ }
+for FILE in $LOAD
+do
+   resolvejs $FILE
+   TOLOAD="$TOLOAD $RESOLVED"
+done
+
+# Resolve listed libraries in $LOADANDADD separated by spaces
+LOADANDADD=${LOADANDADD//,/\ }
+for FILE in $LOADANDADD
+do
+   resolvejs $FILE
+   TOLOAD="$TOLOAD $RESOLVED"
+   TOADD="$TOADD $RESOLVED"
+done
+
+# Define our Compiler loading supplied libraries
+OURCOMPILER="$KITCHENSINK $TOLOAD $JTALK/js/init.js $JTALK/nodejs/nodecompile.js"
+
+# Add supplied libraries
+LIBS="$BASE $TOADD"
 
 # Get a unique tempdir and make it get auto removed on exit
 TMPDIR=`mktemp -d`
 trap "rm -rf $TMPDIR" EXIT
 
+
 # --------------------------------------------------
 # Collect libraries and Smalltalk files looking
 # both locally and in $JTALK/js and $JTALK/st 
@@ -183,16 +222,8 @@ do
         ;;
 
      *.js)
-        if [ -f "$1" ]; then
-           LIBS="$LIBS $1" 
-        else
-           if [ -f $JTALK/js/$1 ]; then
-             LIBS="$LIBS $JTALK/js/$1"
-           else
-             echo "Javascript file not found: $1"
-             exit 1
-           fi
-        fi
+        resolvejs $1
+	LIBS="$LIBS $RESOLVED" 
         ;;
       *)
         # Will end up being the last non js/st argument
@@ -210,7 +241,7 @@ done
 cat $OURCOMPILER > $TMPDIR/compiler.js
 
 # Compile all collected .st files to .js
-echo "Compiling ..."
+echo "Loading libraries $KITCHENSINK $TOLOAD and compiling ..."
 node $TMPDIR/compiler.js $COMPILE
 
 # Verify all .js files corresponding to .st files were created, otherwise exit

+ 0 - 1
nodejs/README

@@ -5,6 +5,5 @@ These are some experiments of using JTalk together with Node.js:
 hello           - Hello world example with a simple Makefile.
 benchfib        - Port of tinybenchmarks from Squeak.
 trivialserver   - A slightly larger example.
-trivialserver2  - A variation on trivialserver that tries to do more in JTalk.
 
 You will need "node" in your path to try all the above.

+ 1 - 1
nodejs/benchfib/Makefile

@@ -5,4 +5,4 @@ run: Program.js
 	./benchfib
 
 clean:
-	rm Program.js* Benchfib.js
+	rm -f Program.js* Benchfib.js

+ 1 - 1
nodejs/hello/Makefile

@@ -5,4 +5,4 @@ run: Program.js
 	./hello
 
 clean:
-	rm Program.js Hello.js
+	rm -f Program.js Hello.js

+ 1 - 1
nodejs/nodecompile.js

@@ -1,4 +1,4 @@
-// NOTE: This code is called using the ntalkc bash script - do not use directly.
+// NOTE: This code is called using the jtalkc bash script - do not use directly.
 // The arguments variable is a series of .st filenames and category names.
 // If it is a .st file we import it, if it is a category name we export it
 // as aCategoryName.js.

+ 1 - 1
nodejs/trivialserver/Makefile

@@ -5,4 +5,4 @@ run: Program.js
 	./trivial
 
 clean:
-	rm Program.js TrivialServer.js
+	rm -f Program.js TrivialServer.js