Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[java/runtime] use assertions for sanity checks, add P6list and P6map…
…ping
  • Loading branch information
mberends committed Jan 22, 2011
1 parent 1e7f3cb commit 7d44ea3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
2 changes: 2 additions & 0 deletions java/README.txt
Expand Up @@ -45,6 +45,8 @@ C# abstract class becomes Java interface.

C# Add(item) (to a List) becomes Java add(item) (to an ArrayList).

C# AddRange(...) (to a List) becomes Java XXX TODO ???

C# bool becomes Java boolean.

C# Console.Write becomes Java System.out.print.
Expand Down
2 changes: 1 addition & 1 deletion java/compiler/try.sh
Expand Up @@ -9,4 +9,4 @@ echo -n 'compiler: '; make || exit 2
parrot compile.pir $1 > RakudoOutput.java || exit 3
javac -classpath ../runtime/RakudoRuntime.jar RakudoOutput.java || exit 4
echo ---
java -classpath classes:../runtime/RakudoRuntime.jar:. RakudoOutput
java -enableassertions -classpath classes:../runtime/RakudoRuntime.jar:. RakudoOutput
43 changes: 17 additions & 26 deletions java/runtime/Rakudo/Init.java
Expand Up @@ -63,8 +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");
threadContext.DefaultArrayType = settingContext.LexPad.GetByName("NQPArray");
threadContext.DefaultHashType = settingContext.LexPad.GetByName("NQPHash");

return threadContext;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ private static Context BootstrapSetting(RakudoObject knowHOW, RakudoObject knowH
// 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" });
{ "KnowHOW", "KnowHOWAttribute", "capture", "NQPInt", "NQPNum", "NQPStr", "NQPList", "NQPCode", "list", "NQPArray", "NQPHash" });
settingContext.LexPad.Storage = new RakudoObject[]
{
knowHOW,
Expand All @@ -112,19 +112,19 @@ private static Context BootstrapSetting(RakudoObject knowHOW, RakudoObject knowH
REPRRegistry.get_REPR_by_name("P6str").type_object_for(null,null),
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()
{ // C# has a lambda instead of the anonymous class
CodeObjectUtility.WrapNativeMethod(new RakudoCodeRef.IFunc_Body() // 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));
P6list.Instance list = (P6list.Instance)nqpList.getSTable().REPR.instance_of(tc, nqpList);
P6capture.Instance nativeCapture = (P6capture.Instance)capture;
for (RakudoObject obj : nativeCapture.Positionals)
list.Storage.add(obj);
return list;
}
}) // TODO ,
// TODO null,
// TODO null
}),
null,
null
};
return settingContext;
}
Expand All @@ -138,6 +138,7 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject cap
public static Context LoadSetting(String settingName, RakudoObject knowHOW, RakudoObject knowHOWAttribute)
{
// Load the assembly.
// This is quite unlike the C# version
// System.err.println("Init.LoadSetting begin loading " + settingName );
ClassLoader loader = ClassLoader.getSystemClassLoader();
Class<?> classNQPSetting = null; // grrr, a wildcard type :-(
Expand All @@ -153,12 +154,7 @@ public static Context LoadSetting(String settingName, RakudoObject knowHOW, Raku
System.err.println("loadClass(\"" + settingName + "\") exception: " + ex.getMessage());
System.exit(1);
}

// TODO: remove
if ( classNQPSetting == null ) {
System.err.println("classNQPSetting is null");
System.exit(1);
}
assert classNQPSetting != null : "classNQPSetting is null";

// Find the setting type and its LoadSetting method.
java.lang.reflect.Method methodLoadSetting = null;
Expand All @@ -175,14 +171,7 @@ public static Context LoadSetting(String settingName, RakudoObject knowHOW, Raku
System.exit(1);
}

// TODO: remove
if ( methodLoadSetting == null ) {
System.err.println("methodLoadSetting is null");
System.exit(1);
}
else {
// System.err.println("methodLoadSetting is ok: " + methodLoadSetting );
}
assert methodLoadSetting != null : "methodLoadSetting is null";

// Run it to get the context we want.
Context settingContext = null;
Expand All @@ -203,15 +192,16 @@ public static Context LoadSetting(String settingName, RakudoObject knowHOW, Raku
// XXX Should be able to toss all of these but KnowHOW.
settingContext.LexPad.Extend(new String[]
{ "KnowHOW", "KnowHOWAttribute", "print", "say", "capture" });

settingContext.LexPad.SetByName("KnowHOW", knowHOW);
settingContext.LexPad.SetByName("KnowHOWAttribute", knowHOWAttribute);
settingContext.LexPad.SetByName("print",
CodeObjectUtility.WrapNativeMethod( new RakudoCodeRef.IFunc_Body()
{ // an anonymous class where C# has a => (lambda)
public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject capture)
{
for (int i = 0; i < CaptureHelper.NumPositionals(capture); i++) {
int numPositionals = CaptureHelper.NumPositionals(capture);
for (int i = 0; i < numPositionals; i++)
{
RakudoObject value = CaptureHelper.GetPositional(capture, i);
RakudoObject strMeth = self.getSTable().FindMethod.FindMethod(tc, value, "Str", 0);
RakudoObject strVal = strMeth.getSTable().Invoke.Invoke(tc, strMeth,
Expand All @@ -227,7 +217,8 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject cap
{ // an anonymous class where C# has a => (lambda)
public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject capture)
{
for (int i = 0; i < CaptureHelper.NumPositionals(capture); i++) {
int numPositionals = CaptureHelper.NumPositionals(capture);
for (int i = 0; i < numPositionals; i++) {
RakudoObject value = CaptureHelper.GetPositional(capture, i);
RakudoObject strMeth = self.getSTable().FindMethod.FindMethod(tc, value, "Str", 0);
RakudoObject strVal = strMeth.getSTable().Invoke.Invoke(tc, strMeth,
Expand Down
7 changes: 2 additions & 5 deletions java/runtime/Rakudo/Metamodel/RakudoObject.java
Expand Up @@ -7,23 +7,20 @@
/// The commonalities of every object.
/// </summary>
public abstract class RakudoObject
// public abstract class RakudoObject // the C# version
{
/// <summary>
/// Every object must have a way to refer to the shared table,
/// which contains the commonalities this object has.
/// </summary>
private SharedTable sTable;
private SharedTable sTable; // C# has public SharedTable STable;
public SharedTable getSTable() { return sTable; }
public void setSTable( SharedTable st ) { sTable = st; }
// SharedTable STable { get; set; } // the C# version

/// <summary>
/// The serialization context this object belongs to.
/// </summary>
private SerializationContext SC;
private SerializationContext SC; // C# has public SerializationContext;
public SerializationContext getSC() { return SC; }
public void setSC( SerializationContext sc ) { SC = sc; }
// SerializationContext SC { get; set; } // the C# version
}

6 changes: 3 additions & 3 deletions java/runtime/Rakudo/Runtime/CaptureHelper.java
Expand Up @@ -16,17 +16,17 @@ public class CaptureHelper // the C# version has a static class
/// <summary>
/// Don't flatten.
/// </summary>
public final int FLATTEN_NONE = 0; // C# has public const
public static final int FLATTEN_NONE = 0; // C# has public const

/// <summary>
/// Flatten positionally.
/// </summary>
public final int FLATTEN_POS = 1;
public static final int FLATTEN_POS = 1;

/// <summary>
/// Flatten named.
/// </summary>
public final int FLATTEN_NAMED = 2;
public static final int FLATTEN_NAMED = 2;

/// <summary>
/// Cache of the native capture type object.
Expand Down

0 comments on commit 7d44ea3

Please sign in to comment.