Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Code cleanup #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions java/runtime/Rakudo/Metamodel/SharedTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class SharedTable // C# has public sealed
public RakudoObject HOW;

/// <summary>
/// The type-object. If we do $obj.WHAT then it will refer to a
/// The type-object. If we do $obj.WHAT then it will refer to a
/// getting of this field.
/// </summary>
public RakudoObject WHAT;
Expand Down Expand Up @@ -71,7 +71,10 @@ public RakudoObject FindMethod(ThreadContext tc, RakudoObject obj, String name,

// Otherwise, try method cache.
else if (MethodCache != null && MethodCache.containsKey(name))
{ cachedMethod = MethodCache.get(name); return cachedMethod; }
{
cachedMethod = MethodCache.get(name);
return cachedMethod;
}

// Otherwise, go ask the meta-object.
else
Expand All @@ -84,7 +87,11 @@ else if (MethodCache != null && MethodCache.containsKey(name))
tc, HOW, "find_method", Hints.NO_HINT);

// Call it.
RakudoObject capture = CaptureHelper.FormWith(new RakudoObject[] { HOW, obj, Ops.box_str(tc, name, tc.DefaultStrBoxType) });
RakudoObject capture = CaptureHelper.FormWith(new RakudoObject[] {
HOW,
obj,
Ops.box_str(tc, name, tc.DefaultStrBoxType)
} );
return method.getSTable().Invoke(tc, method, capture);
}
}
Expand All @@ -111,7 +118,12 @@ public RakudoObject Invoke(ThreadContext threadContext, RakudoObject method, Rak
if (SpecialInvoke != null)
return SpecialInvoke.Invoke(threadContext, method, capture);
SharedTable sharedTable = method.getSTable();
RakudoObject invokable = sharedTable.CachedInvoke; if (invokable == null) { invokable = sharedTable.CachedInvoke = method.getSTable().FindMethod(threadContext, method, "postcircumfix:<( )>", Hints.NO_HINT); }
RakudoObject invokable = sharedTable.CachedInvoke;
if (invokable == null)
{ invokable
= sharedTable.CachedInvoke
= method.getSTable().FindMethod(threadContext, method, "postcircumfix:<( )>", Hints.NO_HINT);
}
return invokable.getSTable().Invoke(threadContext, method, capture);
}

Expand Down Expand Up @@ -184,4 +196,3 @@ public long getTypeCacheID () {
private static long TypeCacheIDSource = 4;

}

2 changes: 1 addition & 1 deletion java/runtime/Rakudo/Runtime/CaptureHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static RakudoObject GetPositional(RakudoObject capture, int pos)
if (nativeCapture != null)
{
RakudoObject[] possies = nativeCapture.Positionals;
if (possies != null && pos < possies.length)
if (possies != null && pos < possies.length && pos >= 0)
return possies[pos];
else
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public static ArrayList<RakudoCodeRef.Instance> FindCandidates(Context callerSco
break;

// Any candidates here?
if (curScope.LexPad.SlotMapping != null && curScope.LexPad.SlotMapping.containsKey(candidateHolderName)) {
if (curScope.LexPad.SlotMapping != null && curScope.LexPad.SlotMapping.containsKey(candidateHolderName))
{
Integer index = curScope.LexPad.SlotMapping.get(candidateHolderName);
P6list.Instance p6listInstance = (P6list.Instance)curScope.LexPad.Storage[index];
for (RakudoObject candidate : p6listInstance.Storage) {
for (RakudoObject candidate : p6listInstance.Storage)
result.add((RakudoCodeRef.Instance)candidate);
}
}
} while (curScope != protoScope);
return result;
Expand Down
10 changes: 5 additions & 5 deletions java/runtime/Rakudo/Runtime/MultiDispatch/MultiDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ else if (possiblesList.size() > 1)
continue;
}
}

/* Check if it's admissible by arity. */
int numArgs = nativeCapture.Positionals.length;
if (numArgs < candidate.Sig.NumRequiredPositionals ||
Expand Down Expand Up @@ -142,9 +142,9 @@ else if (possiblesList.size() > 1)
private static ArrayList<RakudoObject> candidateSort(RakudoObject[] unsorted)
{
ArrayList<RakudoObject> sorted = new ArrayList<RakudoObject>();
for (RakudoObject obj : unsorted) {
for (RakudoObject obj : unsorted)
sorted.add(obj);
}

sorted.add(null); // XXX does this actually sort?
return sorted;
}
Expand All @@ -171,7 +171,8 @@ else if (a.Sig.NumRequiredPositionals == b.Sig.NumRequiredPositionals)
return 0;

/* Analyse each parameter in the two candidates. */
for (i = 0; i < TypesToCheck; i++) {
for (i = 0; i < TypesToCheck; i++)
{
RakudoObject TypeObjA = a.Sig.Parameters[i].Type;
RakudoObject TypeObjB = b.Sig.Parameters[i].Type;
if (TypeObjA == TypeObjB)
Expand Down Expand Up @@ -216,4 +217,3 @@ public static boolean IsNarrowerType(RakudoObject A, RakudoObject B)
return true;
}
}

16 changes: 9 additions & 7 deletions java/runtime/Rakudo/Runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -1116,13 +1116,13 @@ public static RakudoObject load_module(ThreadContext tc, RakudoObject path)
// Load the assembly and grab the first type in it.
//var assembly = AppDomain.CurrentDomain.Load(Ops.unbox_str(tc, path));
//var class = Assembly.GetTypes()[0];

// Call the Load method, passing along the current thread context
// and the setting to use with it. What's returned is what the main
// body of the compilation unit evaluates to.
//var method = class.GetMethod("Load", BindingFlags.NonPublic | BindingFlags.Static);
if (true) // sneak by the "unreachable code" monster
throw new UnsupportedOperationException("load_module NYI");
throw new UnsupportedOperationException("load_module NYI");
return (RakudoObject)null;
//return (RakudoObject)method.Invoke.Invoke(null, new Object[] { tc, tc.Domain.Setting });
}
Expand All @@ -1136,7 +1136,8 @@ public static RakudoObject get_lex(ThreadContext tc, String name)
{
Context curContext = tc.CurrentContext;
while (curContext != null) {
if (curContext.LexPad.SlotMapping.containsKey(name)) {
if (curContext.LexPad.SlotMapping.containsKey(name))
{
int index = curContext.LexPad.SlotMapping.get(name);
return curContext.LexPad.Storage[index];
}
Expand All @@ -1157,7 +1158,8 @@ public static RakudoObject get_lex_skip_current(ThreadContext tc, String name)
Context curContext = tc.CurrentContext.Outer;
while (curContext != null)
{
if (curContext.LexPad.SlotMapping.containsKey(name)) {
if (curContext.LexPad.SlotMapping.containsKey(name))
{
int index = curContext.LexPad.SlotMapping.get(name);
return curContext.LexPad.Storage[index];
}
Expand All @@ -1179,7 +1181,7 @@ public static RakudoObject bind_lex(ThreadContext tc, String name, RakudoObject
{
if (curContext.LexPad.SlotMapping.containsKey(name))
{
int index = curContext.LexPad.SlotMapping.get(name);
int index = curContext.LexPad.SlotMapping.get(name);
curContext.LexPad.Storage[index] = value;
return value;
}
Expand All @@ -1198,7 +1200,8 @@ public static RakudoObject get_dynamic(ThreadContext tc, String name)
{
Context curContext = tc.CurrentContext;
while (curContext != null) {
if (curContext.LexPad.SlotMapping.containsKey(name)) {
if (curContext.LexPad.SlotMapping.containsKey(name))
{
int index = curContext.LexPad.SlotMapping.get(name);
return curContext.LexPad.Storage[index];
}
Expand Down Expand Up @@ -1230,4 +1233,3 @@ public static RakudoObject bind_dynamic(ThreadContext tc, String name, RakudoObj
}

}