forked from jruby/jruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://svn.codehaus.org/jruby/branches/jruby-joni@5071 961051c9-f516-0410-bf72-c9f7e237a7b7
- Loading branch information
Showing
108 changed files
with
2,648 additions
and
1,462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,46 @@ | ||
#!/bin/bash | ||
# ----------------------------------------------------------------------------- | ||
# jruby.sh - Start Script for the JRuby interpreter | ||
# | ||
# Environment Variable Prequisites | ||
# | ||
# JRUBY_BASE (Optional) Base directory for resolving dynamic portions | ||
# of a JRuby installation. If not present, resolves to | ||
# the same directory that JRUBY_HOME points to. | ||
# | ||
# JRUBY_HOME (Optional) May point at your JRuby "build" directory. | ||
# If not present, the current working directory is assumed. | ||
# | ||
# JRUBY_OPTS (Optional) Default JRuby command line args | ||
# JRUBY_SHELL Where/What is system shell | ||
# | ||
# JAVA_HOME Must point at your Java Development Kit installation. | ||
# | ||
# ----------------------------------------------------------------------------- | ||
#!/usr/bin/env jruby | ||
|
||
cygwin=false | ||
require 'jruby' | ||
|
||
# ----- Identify OS we are running under -------------------------------------- | ||
case "`uname`" in | ||
CYGWIN*) cygwin=true | ||
esac | ||
runtime = JRuby.runtime | ||
|
||
# ----- Verify and Set Required Environment Variables ------------------------- | ||
if ARGV.size < 1 | ||
puts "Usage: jrubyc <filename.rb> [<filename.rb> ...]" | ||
exit | ||
end | ||
|
||
if [ -z "$JRUBY_HOME" ] ; then | ||
## resolve links - $0 may be a link to home | ||
PRG=$0 | ||
progname=`basename "$0"` | ||
ARGV.each do |filename| | ||
unless File.exists? filename | ||
puts "Error -- file not found: #{filename}" | ||
next | ||
end | ||
|
||
while [ -h "$PRG" ] ; do | ||
ls=`ls -ld "$PRG"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '.*/.*' > /dev/null; then | ||
PRG="$link" | ||
else | ||
PRG="`dirname $PRG`/$link" | ||
fi | ||
done | ||
begin | ||
file = File.open(filename) | ||
destdir = Dir.pwd | ||
|
||
JRUBY_HOME_1=`dirname "$PRG"` # the ./bin dir | ||
JRUBY_HOME_1=`dirname "$JRUBY_HOME_1"` # the . dir | ||
if [ -d "${JRUBY_HOME_1}/lib" ] ; then | ||
JRUBY_HOME="${JRUBY_HOME_1}" | ||
fi | ||
else | ||
if $cygwin; then | ||
JRUBY_HOME=`cygpath -u "$JRUBY_HOME"` | ||
fi | ||
fi | ||
|
||
if [ -z "$JRUBY_OPTS" ] ; then | ||
JRUBY_OPTS="" | ||
fi | ||
|
||
if [ -z "$JAVA_HOME" ] ; then | ||
JAVA_CMD='java' | ||
else | ||
if $cygwin; then | ||
JAVA_HOME=`cygpath -u "$JAVA_HOME"` | ||
fi | ||
JAVA_CMD="$JAVA_HOME/bin/java" | ||
fi | ||
|
||
JRUBY_SHELL=/bin/sh | ||
|
||
# ----- Set Up The System Classpath ------------------------------------------- | ||
|
||
if [ "$JRUBY_PARENT_CLASSPATH" != "" ]; then | ||
# Use same classpath propagated from parent jruby | ||
CP=$JRUBY_PARENT_CLASSPATH | ||
else | ||
if [ "$CLASSPATH" != "" ]; then | ||
CP="$CLASSPATH" | ||
if $cygwin; then | ||
CP=`cygpath -p -u "$CP"` | ||
fi | ||
else | ||
CP="" | ||
fi | ||
|
||
CP_DELIMETER=":" | ||
|
||
# add necessary jars for command-line execution | ||
for j in "$JRUBY_HOME"/lib/*.jar; do | ||
if [ "$CP" ]; then | ||
CP="$CP$CP_DELIMETER$j" | ||
else | ||
CP="$j" | ||
fi | ||
done | ||
|
||
if $cygwin; then | ||
CP=`cygpath -p -w "$CP"` | ||
fi | ||
fi | ||
|
||
# ----- Set Up JRUBY_BASE If Necessary ------------------------------------- | ||
|
||
if [ -z "$JRUBY_BASE" ] ; then | ||
JRUBY_BASE="$JRUBY_HOME" | ||
fi | ||
|
||
# ----- Execute The Requested Command ----------------------------------------- | ||
|
||
DEBUG="" | ||
if [ "$1" = "JAVA_DEBUG" ]; then | ||
DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" | ||
shift | ||
else | ||
if [ "$1" = "JPROFILER" ]; then | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JPROFILER_PATH/bin/linux-x86 | ||
DEBUG="-Xrunjprofiler:port=8000,noexit -Xbootclasspath/a:/$JPROFILER_PATH/bin/agent.jar" | ||
shift | ||
else if [ "$1" = "HPROF" ]; then | ||
DEBUG="-Xrunhprof:cpu=samples" | ||
shift | ||
fi | ||
fi | ||
fi | ||
|
||
if $cygwin; then | ||
JAVA_HOME=`cygpath --mixed "$JAVA_HOME"` | ||
JRUBY_BASE=`cygpath --mixed "$JRUBY_BASE"` | ||
JRUBY_HOME=`cygpath --mixed "$JRUBY_HOME"` | ||
JRUBY_SHELL=`cygpath --mixed "$JRUBY_SHELL"` | ||
fi | ||
|
||
EN_US= | ||
if [ "$1" = "EN_US" ]; then | ||
EN_US="-Duser.language=en -Duser.country=US" | ||
shift | ||
fi | ||
|
||
if [ "$1" = "SERVER" ]; then | ||
DEBUG="-server" | ||
shift | ||
fi | ||
|
||
exec "$JAVA_CMD" $JAVA_OPTS $DEBUG -Xmx256m -Xss1024k -ea -classpath "$CP" \ | ||
"-Djruby.base=$JRUBY_BASE" "-Djruby.home=$JRUBY_HOME" \ | ||
"-Djruby.lib=$JRUBY_BASE/lib" -Djruby.script=jruby \ | ||
"-Djruby.shell=$JRUBY_SHELL" $EN_US \ | ||
org.jruby.JRubyC $JRUBY_OPTS "$@" | ||
BAIS = java.io.ByteArrayInputStream | ||
Mangler = org.jruby.util.JavaNameMangler | ||
BytecodeCompiler = org.jruby.compiler.impl.StandardASMCompiler | ||
ASTCompiler = org.jruby.compiler.ASTCompiler | ||
JavaFile = java.io.File | ||
|
||
inspector = org.jruby.compiler.ASTInspector.new | ||
|
||
source = file.read | ||
node = runtime.parse_file(BAIS.new(source.to_java_bytes), filename, nil) | ||
|
||
classpath = Mangler.mangle_filename_for_classpath(filename) | ||
|
||
inspector.inspect(node) | ||
|
||
compiler = BytecodeCompiler.new(classpath, filename) | ||
ASTCompiler.compile_root(node, compiler, inspector) | ||
|
||
compiler.write_class(JavaFile.new(destdir)) | ||
rescue | ||
puts "Failure during compilation of file #{filename}:\n#{$!}" | ||
ensure | ||
file.close unless file.nil? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +0,0 @@ | ||
/* | ||
* JRubyC.java | ||
* | ||
* Created on January 11, 2007, 11:24 PM | ||
* | ||
* To change this template, choose Tools | Template Manager | ||
* and open the template in the editor. | ||
*/ | ||
|
||
package org.jruby; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
import java.nio.charset.CharsetDecoder; | ||
import org.jruby.ast.Node; | ||
import org.jruby.compiler.ASTInspector; | ||
import org.jruby.compiler.ASTCompiler; | ||
import org.jruby.compiler.NotCompilableException; | ||
import org.jruby.compiler.impl.StandardASMCompiler; | ||
import org.jruby.util.KCode; | ||
|
||
/** | ||
* | ||
* @author headius | ||
*/ | ||
public class JRubyC { | ||
|
||
public static void main(String args[]) { | ||
Ruby runtime = Ruby.newInstance(); | ||
|
||
try { | ||
if (args.length < 1) { | ||
System.out.println("Usage: jrubyc <filename> [<filename> ...]"); | ||
return; | ||
} | ||
for (int i = 0; i < args.length; i++) { | ||
String filename = args[i]; | ||
if (filename.startsWith("./")) filename = filename.substring(2); | ||
File srcfile = new File(filename); | ||
if (!srcfile.exists()) { | ||
System.out.println("Error -- file not found: " + filename); | ||
return; | ||
} | ||
|
||
// destination directory | ||
File destfile = new File(System.getProperty("user.dir")); | ||
|
||
int size = (int)srcfile.length(); | ||
byte[] chars = new byte[size]; | ||
new FileInputStream(srcfile).read(chars); | ||
// FIXME: -K encoding? | ||
String content = new String(chars); | ||
Node scriptNode = runtime.parseFile(new ByteArrayInputStream(content.getBytes("ISO-8859-1")), filename, null); | ||
|
||
ASTInspector inspector = new ASTInspector(); | ||
inspector.inspect(scriptNode); | ||
|
||
// do the compile | ||
String classPath = filename.substring(0, filename.lastIndexOf(".")).replace('-', '_').replace('.', '_'); | ||
int lastSlashIndex = classPath.lastIndexOf('/'); | ||
if (!Character.isJavaIdentifierStart(classPath.charAt(lastSlashIndex + 1))) { | ||
if (lastSlashIndex == -1) { | ||
classPath = "_" + classPath; | ||
} else { | ||
classPath = classPath.substring(0, lastSlashIndex + 1) + "_" + classPath.substring(lastSlashIndex + 1); | ||
} | ||
} | ||
StandardASMCompiler compiler = new StandardASMCompiler(classPath, filename); | ||
ASTCompiler.compileRoot(scriptNode, compiler, inspector); | ||
|
||
compiler.writeClass(destfile); | ||
} | ||
} catch (IOException ioe) { | ||
ioe.printStackTrace(); | ||
System.err.println("Error -- IO exception during compile: " + ioe.getMessage()); | ||
} catch (NotCompilableException nce) { | ||
System.err.println("Error -- Not compilable: " + nce.getMessage()); | ||
} | ||
} | ||
|
||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.