Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor argument metadata representation and rendering.
Browse files Browse the repository at this point in the history
headius committed May 9, 2015
1 parent 60b462e commit 03a8fff
Showing 38 changed files with 203 additions and 1,846 deletions.
10 changes: 0 additions & 10 deletions core/src/main/java/org/jruby/AbstractRubyMethod.java
Original file line number Diff line number Diff line change
@@ -31,23 +31,13 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ext.jruby.JRubyLibrary;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.IRMethodArgs;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.CompiledBlockCallback19;
import org.jruby.runtime.CompiledBlockLight19;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.PositionAware;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.DataType;

10 changes: 0 additions & 10 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -112,7 +112,6 @@
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.CallbackFactory;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.EventHook;
@@ -4804,15 +4803,6 @@ private void addEvalParseToStats() {
if (parserStats != null) parserStats.addEvalParse();
}

private void addJRubyModuleParseToStats() {
if (parserStats != null) parserStats.addJRubyModuleParse();
}

@Deprecated
public CallbackFactory callbackFactory(Class<?> type) {
throw new RuntimeException("callback-style handles are no longer supported in JRuby");
}

@Deprecated
public boolean is1_8() {
return false;
45 changes: 15 additions & 30 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
@@ -38,17 +38,15 @@
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.IRMethodArgs;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.CompiledBlockCallback19;
import org.jruby.runtime.CompiledBlockLight19;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.MethodBlockBody;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.PositionAware;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;

/**
@@ -186,36 +184,22 @@ public RubyMethod rbClone() {
*
*/
@JRubyMethod
public IRubyObject to_proc(ThreadContext context, Block unusedBlock) {
public IRubyObject to_proc(ThreadContext context) {
Ruby runtime = context.runtime;
CompiledBlockCallback19 callback = new CompiledBlockCallback19() {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
return method.call(context, receiver, originModule, originName, args, block);
}

@Override
public String getFile() {
return getFilename();
}

@Override
public int getLine() {
return RubyMethod.this.getLine();
}
};

BlockBody body;
String[] parameterList = JRubyLibrary.MethodExtensions.methodParameters(method);
MethodBlockBody body;
Signature signature;
ArgumentDescriptor[] argsDesc;
if (method instanceof IRMethodArgs) {
Signature signature = ((IRMethodArgs) method).getSignature();
body = CompiledBlockLight19.newCompiledBlockLight(signature,
runtime.getStaticScopeFactory().getDummyScope(), callback, false, -1, parameterList);
signature = ((IRMethodArgs) method).getSignature();
argsDesc = ((IRMethodArgs) method).getArgumentDescriptors();
} else {
body = CompiledBlockLight19.newCompiledBlockLight(method.getArity(),
runtime.getStaticScopeFactory().getDummyScope(), callback, false, -1, parameterList);
signature = Signature.from(method.getArity());
argsDesc = Helpers.methodToArgumentDescriptors(method);
}
Block b = new Block(body, context.currentBinding(receiver, Visibility.PUBLIC));

body = new MethodBlockBody(runtime.getStaticScopeFactory().getDummyScope(), signature, method, argsDesc, receiver, originModule, originName, getFilename(), getLine());
Block b = MethodBlockBody.createMethodBlock(body);

return RubyProc.newProc(runtime, b, Block.Type.LAMBDA);
}
@@ -311,7 +295,7 @@ public IRubyObject parameters(ThreadContext context) {

@JRubyMethod(optional = 1)
public IRubyObject curry(ThreadContext context, IRubyObject[] args) {
return to_proc(context, Block.NULL_BLOCK).callMethod(context, "curry", args);
return to_proc(context).callMethod(context, "curry", args);
}

@JRubyMethod
@@ -327,5 +311,6 @@ public IRubyObject original_name(ThreadContext context) {
}
return name(context);
}

}

4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -345,8 +345,8 @@ public IRubyObject source_location(ThreadContext context) {
public IRubyObject parameters(ThreadContext context) {
BlockBody body = this.getBlock().getBody();

return Helpers.parameterListToParameters(context.runtime,
body.getParameterList(), isLambda());
return Helpers.argumentDescriptorsToParameters(context.runtime,
body.getArgumentDescriptors(), isLambda());
}

@JRubyMethod(name = "lambda?")
46 changes: 2 additions & 44 deletions core/src/main/java/org/jruby/ast/executable/AbstractScript.java
Original file line number Diff line number Diff line change
@@ -5,10 +5,8 @@

package org.jruby.ast.executable;

import java.math.BigInteger;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jruby.Ruby;
import org.jruby.RubyFixnum;
import org.jruby.RubyFloat;
import org.jruby.RubyModule;
@@ -18,14 +16,14 @@
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.CompiledBlockCallback;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;

import java.math.BigInteger;

/**
*
* @author headius
@@ -105,46 +103,6 @@ public IRubyObject run(ThreadContext context, IRubyObject self, IRubyObject[] ar
public final CallSite getCallSite8() {return runtimeCache.callSites[8];}
public final CallSite getCallSite9() {return runtimeCache.callSites[9];}

public static final int NUMBERED_BLOCKBODY_COUNT = 10;

public final BlockBody getBlockBody(ThreadContext context, StaticScope scope, int i, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, i, descriptor);}
public final BlockBody getBlockBody0(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 0, descriptor);}
public final BlockBody getBlockBody1(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 1, descriptor);}
public final BlockBody getBlockBody2(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 2, descriptor);}
public final BlockBody getBlockBody3(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 3, descriptor);}
public final BlockBody getBlockBody4(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 4, descriptor);}
public final BlockBody getBlockBody5(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 5, descriptor);}
public final BlockBody getBlockBody6(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 6, descriptor);}
public final BlockBody getBlockBody7(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 7, descriptor);}
public final BlockBody getBlockBody8(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 8, descriptor);}
public final BlockBody getBlockBody9(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 9, descriptor);}

public final BlockBody getBlockBody19(ThreadContext context, StaticScope scope, int i, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, i, descriptor);}
public final BlockBody getBlockBody190(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 0, descriptor);}
public final BlockBody getBlockBody191(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 1, descriptor);}
public final BlockBody getBlockBody192(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 2, descriptor);}
public final BlockBody getBlockBody193(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 3, descriptor);}
public final BlockBody getBlockBody194(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 4, descriptor);}
public final BlockBody getBlockBody195(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 5, descriptor);}
public final BlockBody getBlockBody196(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 6, descriptor);}
public final BlockBody getBlockBody197(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 7, descriptor);}
public final BlockBody getBlockBody198(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 8, descriptor);}
public final BlockBody getBlockBody199(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 9, descriptor);}

public static final int NUMBERED_BLOCKCALLBACK_COUNT = 10;

public final CompiledBlockCallback getBlockCallback(int i, String method) {return runtimeCache.getBlockCallback(this, i, method);}
public final CompiledBlockCallback getBlockCallback0(String method) {return runtimeCache.getBlockCallback(this, 0, method);}
public final CompiledBlockCallback getBlockCallback1(String method) {return runtimeCache.getBlockCallback(this, 1, method);}
public final CompiledBlockCallback getBlockCallback2(String method) {return runtimeCache.getBlockCallback(this, 2, method);}
public final CompiledBlockCallback getBlockCallback3(String method) {return runtimeCache.getBlockCallback(this, 3, method);}
public final CompiledBlockCallback getBlockCallback4(String method) {return runtimeCache.getBlockCallback(this, 4, method);}
public final CompiledBlockCallback getBlockCallback5(String method) {return runtimeCache.getBlockCallback(this, 5, method);}
public final CompiledBlockCallback getBlockCallback6(String method) {return runtimeCache.getBlockCallback(this, 6, method);}
public final CompiledBlockCallback getBlockCallback7(String method) {return runtimeCache.getBlockCallback(this, 7, method);}
public final CompiledBlockCallback getBlockCallback8(String method) {return runtimeCache.getBlockCallback(this, 8, method);}
public final CompiledBlockCallback getBlockCallback9(String method) {return runtimeCache.getBlockCallback(this, 9, method);}

public static final int NUMBERED_SYMBOL_COUNT = 10;

public final RubySymbol getSymbol(ThreadContext context, int i, String name, String encoding) {return runtimeCache.getSymbol(context, i, name, encoding);}
81 changes: 1 addition & 80 deletions core/src/main/java/org/jruby/ast/executable/RuntimeCache.java
Original file line number Diff line number Diff line change
@@ -19,10 +19,8 @@
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.runtime.Helpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.CallType;
import org.jruby.runtime.CompiledBlockCallback;
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
@@ -53,50 +51,6 @@ public final CallSite getCallSite(int index) {
return callSites[index];
}

/**
* descriptor format is
*
* closure_method_name,arity,varname1;varname2;varname3,has_multi_args_head,arg_type,light
*
* @param context
* @param index
* @param descriptor
* @return
*/
public final BlockBody getBlockBody(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) {
BlockBody body = blockBodies[index];
if (body == null) {
return createBlockBody(scriptObject, context, scope, index, descriptor);
}
return body;
}

/**
* descriptor format is
*
* closure_method_name,arity,varname1;varname2;varname3,has_multi_args_head,arg_type,light
*
* @param context
* @param index
* @param descriptor
* @return
*/
public final BlockBody getBlockBody19(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) {
BlockBody body = blockBodies[index];
if (body == null) {
return createBlockBody19(scriptObject, context, scope, index, descriptor);
}
return body;
}

public final CompiledBlockCallback getBlockCallback(Object scriptObject, int index, String method) {
CompiledBlockCallback callback = blockCallbacks[index];
if (callback == null) {
return createCompiledBlockCallback(scriptObject, index, method);
}
return callback;
}

public final RubySymbol getSymbol(ThreadContext context, int index, String name, String encodingName) {
RubySymbol symbol = symbols[index];
if (symbol == null) {
@@ -288,9 +242,7 @@ public final void initFromDescriptor(String descriptor) {
private static final int BIGINTEGER = REGEXP + 1;
private static final int VARIABLEREADER = BIGINTEGER + 1;
private static final int VARIABLEWRITER = VARIABLEREADER + 1;
private static final int BLOCKBODY = VARIABLEWRITER + 1;
private static final int BLOCKCALLBACK = BLOCKBODY + 1;
private static final int METHOD = BLOCKCALLBACK + 1;
private static final int METHOD = VARIABLEWRITER + 1;
private static final int STRING = METHOD + 1;
private static final int ENCODING = STRING + 1;
private static final int FROZEN_STRING = ENCODING + 1;
@@ -335,10 +287,6 @@ public final void initFromDescriptor(String descriptor) {
if (variableReaderCount > 0) initVariableReaders(variableReaderCount);
int variableWriterCount = getDescriptorValue(descriptor, VARIABLEWRITER);
if (variableWriterCount > 0) initVariableWriters(variableWriterCount);
int blockBodyCount = getDescriptorValue(descriptor, BLOCKBODY);
if (blockBodyCount > 0) initBlockBodies(blockBodyCount);
int blockCallbackCount = getDescriptorValue(descriptor, BLOCKCALLBACK);
if (blockCallbackCount > 0) initBlockCallbacks(blockCallbackCount);
int methodCount = getDescriptorValue(descriptor, METHOD);
if (methodCount > 0) initMethodCache(methodCount);
int stringCount = getDescriptorValue(descriptor, STRING);
@@ -353,14 +301,6 @@ private static int getDescriptorValue(String descriptor, int type) {
return descriptor.charAt(type);
}

public final void initBlockBodies(int size) {
blockBodies = new BlockBody[size];
}

public final void initBlockCallbacks(int size) {
blockCallbacks = new CompiledBlockCallback[size];
}

public final void initSymbols(int size) {
symbols = new RubySymbol[size];
}
@@ -463,21 +403,6 @@ public IRubyObject reCacheFrom(RubyModule target, ThreadContext context, String
return value;
}

private BlockBody createBlockBody(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) throws NumberFormatException {
BlockBody body = Helpers.createCompiledBlockBody(context, scriptObject, scope, descriptor);
return blockBodies[index] = body;
}

private BlockBody createBlockBody19(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) throws NumberFormatException {
BlockBody body = Helpers.createCompiledBlockBody19(context, scriptObject, scope, descriptor);
return blockBodies[index] = body;
}

private CompiledBlockCallback createCompiledBlockCallback(Object scriptObject, int index, String method) {
CompiledBlockCallback callback = Helpers.createBlockCallback(scriptObject, method, "(internal)", -1);
return blockCallbacks[index] = callback;
}

public DynamicMethod getMethod(ThreadContext context, RubyClass selfType, int index, String methodName) {
CacheEntry myCache = getCacheEntry(index);
if (CacheEntry.typeOk(myCache, selfType)) {
@@ -660,10 +585,6 @@ private CacheEntry getCacheEntry(int index) {
public CallSite[] callSites = EMPTY_CALLSITES;
private static final CacheEntry[] EMPTY_CACHEENTRIES = {};
public CacheEntry[] methodCache = EMPTY_CACHEENTRIES;
private static final BlockBody[] EMPTY_BLOCKBODIES = {};
public BlockBody[] blockBodies = EMPTY_BLOCKBODIES;
private static final CompiledBlockCallback[] EMPTY_COMPILEDBLOCKCALLBACKS = {};
public CompiledBlockCallback[] blockCallbacks = EMPTY_COMPILEDBLOCKCALLBACKS;
private static final RubySymbol[] EMPTY_RUBYSYMBOLS = {};
public RubySymbol[] symbols = EMPTY_RUBYSYMBOLS;
private static final ByteList[] EMPTY_BYTELISTS = {};
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ public Object get(String key) {

public ScriptEngine getEngineByName(String shortName) {
if (shortName == null) {
throw new NullPointerException("Null shortName");
throw new NullPointerException("Null symbolicName");
}
ScriptEngineFactory factory = nameMap.get(shortName);
if (factory == null) {
Loading

0 comments on commit 03a8fff

Please sign in to comment.