Skip to content

Commit

Permalink
[java/runtime] sync with dotnet/ and clean out some debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
mberends committed Jan 20, 2011
1 parent 3ced6a4 commit 1e7f3cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
18 changes: 11 additions & 7 deletions java/runtime/Rakudo/Init.java
Expand Up @@ -24,7 +24,7 @@
/// <summary>
/// Does initialization of the Rakudo library.
/// </summary>
public class Init // public static in the C# version
public class Init // C# has public static
{
/// <summary>
/// Have we already registered the representations?
Expand Down Expand Up @@ -63,6 +63,8 @@ public static ThreadContext Initialize(String settingName)
threadContext.DefaultNumBoxType = settingContext.LexPad.GetByName("NQPNum");
threadContext.DefaultStrBoxType = settingContext.LexPad.GetByName("NQPStr");
threadContext.DefaultListType = settingContext.LexPad.GetByName("NQPList");
// TODO threadContext.DefaultArrayType = settingContext.LexPad.GetByName("NQPArray");
// TODO threadContext.DefaultHashType = settingContext.LexPad.GetByName("NQPHash");

return threadContext;
}
Expand Down Expand Up @@ -96,7 +98,7 @@ private static void RegisterRepresentations()
/// <returns></returns>
private static Context BootstrapSetting(RakudoObject knowHOW, RakudoObject knowHOWAttribute)
{
System.err.println( "calling new Context from Init" );
// System.err.println( "calling new Context from Init" );
Context settingContext = new Context();
settingContext.LexPad = new Lexpad(new String[]
{ "KnowHOW", "KnowHOWAttribute", "capture", "NQPInt", "NQPNum", "NQPStr", "NQPList", "NQPCode", "list" });
Expand All @@ -111,7 +113,7 @@ private static Context BootstrapSetting(RakudoObject knowHOW, RakudoObject knowH
REPRRegistry.get_REPR_by_name("P6list").type_object_for(null,null),
REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(null,knowHOW.getSTable().REPR.instance_of(null,knowHOW)),
CodeObjectUtility.WrapNativeMethod(new RakudoCodeRef.IFunc_Body()
{ // an anonymous class instead of the lambda in the C# version
{ // C# has a lambda instead of the anonymous class
public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject capture) {
RakudoObject nqpList = Ops.get_lex(tc, "NQPList");
P6list.Instance list = (P6list.Instance)(nqpList.getSTable().REPR.instance_of(tc, nqpList));
Expand All @@ -120,7 +122,9 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject cap
list.Storage.add(obj);
return list;
}
})
}) // TODO ,
// TODO null,
// TODO null
};
return settingContext;
}
Expand All @@ -134,7 +138,7 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject cap
public static Context LoadSetting(String settingName, RakudoObject knowHOW, RakudoObject knowHOWAttribute)
{
// Load the assembly.
System.err.println("Init.LoadSetting begin loading " + settingName );
// System.err.println("Init.LoadSetting begin loading " + settingName );
ClassLoader loader = ClassLoader.getSystemClassLoader();
Class<?> classNQPSetting = null; // grrr, a wildcard type :-(
try {
Expand Down Expand Up @@ -177,7 +181,7 @@ public static Context LoadSetting(String settingName, RakudoObject knowHOW, Raku
System.exit(1);
}
else {
System.err.println("methodLoadSetting is ok: " + methodLoadSetting );
// System.err.println("methodLoadSetting is ok: " + methodLoadSetting );
}

// Run it to get the context we want.
Expand All @@ -198,7 +202,7 @@ public static Context LoadSetting(String settingName, RakudoObject knowHOW, Raku
// Fudge a few more things in.
// XXX Should be able to toss all of these but KnowHOW.
settingContext.LexPad.Extend(new String[]
{ "KnowHOW", "KnowHOWAttribute", "print", "say", "capture", "LLCode" });
{ "KnowHOW", "KnowHOWAttribute", "print", "say", "capture" });

settingContext.LexPad.SetByName("KnowHOW", knowHOW);
settingContext.LexPad.SetByName("KnowHOWAttribute", knowHOWAttribute);
Expand Down
29 changes: 16 additions & 13 deletions java/runtime/Rakudo/Metamodel/Representations/RakudoCodeRef.java
Expand Up @@ -16,28 +16,30 @@
import Rakudo.Serialization.SerializationContext;

/// <summary>
/// A representation for low-level code references. This is something
/// specific to this Rakudo backend, not something standard accross all
/// Rakudo backends.
/// A representation for a low-level code object (something that actually
/// references a piece of code that we'll run). This is used for things
/// that serve the role of an only sub (that has a body) and a dispatcher
/// (which has a body as well as a list of candidates that it operates
/// on).
/// </summary>
public final class RakudoCodeRef implements Representation
public final class RakudoCodeRef implements Representation // C# has public sealed class
{
// Interface for the purpose of constructing anonymous classes that
// implement it, as the Java equivalent of a C# lambda expression.
// Used in for example: CodeObjectUtility
public interface IFunc_Body {
public RakudoObject Invoke(ThreadContext tc, RakudoObject meth, RakudoObject capt);
} // C# has public Func<ThreadContext, RakudoObject, RakudoObject, RakudoObject>; // TODO: why 4 parameters and not 3? Is the last one the return type?
} // C# has public Func<ThreadContext, RakudoObject, RakudoObject, RakudoObject>;

/// <summary>
/// This is how the boxed form of a P6str looks.
/// Instance that uses the RakudoCodeRef representation.
/// </summary>
public final class Instance extends RakudoObject
public final class Instance extends RakudoObject // C# has public sealed class
{
/// <summary>
/// The code body - the thing that actually runs instructions.
/// </summary>
public RakudoCodeRef.IFunc_Body Body; // IFunc_Body is defined above Instance
public RakudoCodeRef.IFunc_Body Body; // see above IFunc_Body interface explanation

/// <summary>
/// The static lexpad.
Expand Down Expand Up @@ -81,8 +83,9 @@ public final class Instance extends RakudoObject
public Context OuterForNextInvocation;

/// <summary>
/// Constructor.
/// Creates a new instance with the given S-Table.
/// </summary>
/// <param name="STable"></param>
public Instance(SharedTable sharedTable)
{
this.setSTable(sharedTable);
Expand All @@ -102,9 +105,9 @@ public RakudoObject type_object_for(ThreadContext tc, RakudoObject metaPackage)
sharedTable.REPR = this;
sharedTable.WHAT = new Instance(sharedTable);

// Also twiddle the S-Table's Invoke to invoke the contained
// Also twiddle the Shared Table's Invoke to invoke the contained
// function.
sharedTable.Invoke = new IFunc_Body() { // the C# version has a lambda
sharedTable.Invoke = new IFunc_Body() { // C# has a lambda
public RakudoObject Invoke(ThreadContext tci, RakudoObject methObj, RakudoObject capture)
{
return ((RakudoCodeRef.Instance)methObj).Body.Invoke(tci, methObj, capture);
Expand All @@ -118,9 +121,9 @@ public RakudoObject Invoke(ThreadContext tci, RakudoObject methObj, RakudoObject
/// </summary>
/// <param name="WHAT"></param>
/// <returns></returns>
public RakudoObject instance_of(ThreadContext tc, RakudoObject rakudoObject)
public RakudoObject instance_of(ThreadContext tc, RakudoObject typeObject)
{
return new Instance(rakudoObject.getSTable());
return new Instance(typeObject.getSTable());
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion java/runtime/Rakudo/Runtime/Context.java
Expand Up @@ -43,7 +43,7 @@ public class Context
/// </summary>
public Context() // it could be private, except that Init() calls it.
{
System.err.println( "new empty Context created" );
// System.err.println( "new empty Context created" );
// this.LexPad = new Lexpad( new String[] {} ); // parameter is an empty list of strings
}

Expand Down

0 comments on commit 1e7f3cb

Please sign in to comment.