Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jnthn/6model
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Sep 15, 2010
2 parents b6d5448 + d70553b commit e86a007
Show file tree
Hide file tree
Showing 18 changed files with 1,046 additions and 197 deletions.
10 changes: 10 additions & 0 deletions java/README.txt
Expand Up @@ -33,8 +33,14 @@ methods getSTable(), setSTable, getSC() and setSC().
C# to Java translation guidelines (in case insensitive alphabetical order)
--------------------------------------------------------------------------

C# abstract class becomes Java interface.

C# bool becomes Java boolean.

C# Console.Write becomes Java System.out.print.

C# const becomes Java static final.

C# Dictionary becomes Java HashMap. The HashMap is not quite as
versatile, because the value part must be a reference type, it cannot be
a value type. Therefore C# Dictionary<string, int> becomes Java
Expand Down Expand Up @@ -72,8 +78,12 @@ NoSuchMethodException.

C# override does not become anything in Java (just delete it).

C# out parameters become...

C# sealed class becomes Java final class. Effect is not quite the same.

C# static becomes Java final.

C# string becomes Java String.

C# using becomes Java import. In general, avoid the * (Whatever) form,
Expand Down
30 changes: 26 additions & 4 deletions java/runtime/Makefile
Expand Up @@ -20,9 +20,9 @@
# | | | | | | | |
# | | +-------------- ThreadContext | | |
# | | | | | |
# | | P6capture | | | |
# | | P6int P6hash | | | |
# | | P6opaque IFindMethod | REPRRegistry
# | | P6capture Ops | | | |
# | | P6int P6hash | | | | |
# | | P6opaque IFindMethod | REPRRegistry
# | | | | | |
# | | CaptureHelper | | |
# | | | | | |
Expand All @@ -42,15 +42,17 @@ ALL_BUILD_TARGETS = \
Rakudo/Metamodel/RakudoObject.class \
Rakudo/Metamodel/REPRRegistry.class \
Rakudo/Metamodel/Representations/P6capture.class \
Rakudo/Metamodel/Representations/P6int.class \
Rakudo/Metamodel/Representations/P6hash.class \
Rakudo/Metamodel/Representations/P6int.class \
Rakudo/Metamodel/Representations/P6list.class \
Rakudo/Metamodel/Representations/P6opaque.class \
Rakudo/Runtime/CodeObjectUtility.class \
Rakudo/Metamodel/KnowHOW/KnowHOWREPR.class \
Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.class \
Rakudo/Init.class

OTHER_DEPENDENT_TARGETS = \
Rakudo/Runtime/CaptureHelper.class \
Rakudo/Runtime/Lexpad.class \
Rakudo/Runtime/Parameter.class \
Rakudo/Runtime/Signature.class \
Expand Down Expand Up @@ -79,6 +81,7 @@ Rakudo/Runtime/ExecutionDomain.class: Rakudo/Runtime/ExecutionDomain.java
Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.java \
Rakudo/Serialization/SerializationContext.class \
Rakudo/Metamodel/Representation.java \
Rakudo/Runtime/CaptureHelper.java \
Rakudo/Runtime/Lexpad.java \
Rakudo/Runtime/Parameter.java \
Rakudo/Runtime/Signature.java \
Expand All @@ -90,6 +93,7 @@ Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.java \
javac \
Rakudo/Metamodel/RakudoObject.java \
Rakudo/Metamodel/Representation.java \
Rakudo/Runtime/CaptureHelper.java \
Rakudo/Runtime/Lexpad.java \
Rakudo/Runtime/Parameter.java \
Rakudo/Runtime/Signature.java \
Expand Down Expand Up @@ -146,6 +150,14 @@ Rakudo/Metamodel/Representations/P6int.class: Rakudo/Metamodel/Representations/P
Rakudo/Serialization/SerializationContext.class
javac Rakudo/Metamodel/Representations/P6int.java

Rakudo/Metamodel/Representations/P6list.class: Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Hints.class \
Rakudo/Metamodel/RakudoObject.class \
Rakudo/Metamodel/Representation.class \
Rakudo/Metamodel/SharedTable.class \
Rakudo/Serialization/SerializationContext.class
javac Rakudo/Metamodel/Representations/P6list.java

Rakudo/Metamodel/Representations/P6opaque.class: Rakudo/Metamodel/Representations/P6opaque.java \
Rakudo/Metamodel/Hints.class \
Rakudo/Metamodel/RakudoObject.class \
Expand All @@ -162,6 +174,7 @@ Rakudo/Init.class: Rakudo/Init.java \
Rakudo/Metamodel/Representations/P6capture.class \
Rakudo/Metamodel/Representations/P6hash.class \
Rakudo/Metamodel/Representations/P6int.class \
Rakudo/Metamodel/Representations/P6list.class \
Rakudo/Metamodel/Representations/P6opaque.class \
Rakudo/Metamodel/REPRRegistry.class \
Rakudo/Runtime/CaptureHelper.class \
Expand All @@ -181,12 +194,14 @@ TRANSLATED_SOURCE_FILES = \
Rakudo/Runtime/ExecutionDomain.java \
Rakudo/Metamodel/RakudoObject.java \
Rakudo/Metamodel/Representation.java \
Rakudo/Runtime/CaptureHelper.java \
Rakudo/Runtime/Lexpad.java \
Rakudo/Runtime/Parameter.java \
Rakudo/Runtime/Signature.java \
Rakudo/Metamodel/Representations/P6capture.java \
Rakudo/Metamodel/Representations/P6hash.java \
Rakudo/Metamodel/Representations/P6int.java \
Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Representations/P6opaque.java \
Rakudo/Metamodel/Representations/RakudoCodeRef.java \
Rakudo/Runtime/Context.java \
Expand All @@ -203,6 +218,7 @@ TRANSLATED_SOURCE_FILES = \
# then to refresh the java file to be newer than the dotnet one.
Rakudo/Metamodel/Hints.java: ../../dotnet/runtime/Metamodel/Representation.cs
@echo "todo: Rakudo/Metamodel/Hints.java is older than ../../dotnet/runtime/Metamodel/Representation.cs"
# There is no Hints.cs file, the Hints class is in Representation.cs.

Rakudo/Serialization/SerializationContext.java: ../../dotnet/runtime/Serialization/SerializationContext.cs
@echo "todo: Rakudo/Serialization/SerializationContext.java is older than ../../dotnet/runtime/Serialization/SerializationContext.cs"
Expand All @@ -216,6 +232,9 @@ Rakudo/Metamodel/RakudoObject.java: ../../dotnet/runtime/Metamodel/RakudoObject.
Rakudo/Metamodel/Representation.java: ../../dotnet/runtime/Metamodel/Representation.cs
@echo "todo: Rakudo/Metamodel/Representation.java is older than ../../dotnet/runtime/Metamodel/Representation.cs"

Rakudo/Runtime/CaptureHelper.java: ../../dotnet/runtime/Runtime/CaptureHelper.cs
@echo "todo: Rakudo/Runtime/CaptureHelper.java is older than ../../dotnet/runtime/Runtime/Signatures/CaptureHelper.cs"

Rakudo/Runtime/Lexpad.java: ../../dotnet/runtime/Runtime/Lexpad.cs
@echo "todo: Rakudo/Runtime/Lexpad.java is older than ../../dotnet/runtime/Runtime/Signatures/Lexpad.cs"

Expand All @@ -234,6 +253,9 @@ Rakudo/Metamodel/Representations/P6hash.java: ../../dotnet/runtime/Metamodel/Rep
Rakudo/Metamodel/Representations/P6int.java: ../../dotnet/runtime/Metamodel/Representations/P6int.cs
@echo "todo: $@ is older than $<"

Rakudo/Metamodel/Representations/P6list.java: ../../dotnet/runtime/Metamodel/Representations/P6list.cs
@echo "todo: $@ is older than $<"

Rakudo/Metamodel/Representations/P6opaque.java: ../../dotnet/runtime/Metamodel/Representations/P6opaque.cs
@echo "todo: $@ is older than $<"

Expand Down
90 changes: 49 additions & 41 deletions java/runtime/Rakudo/Init.java
Expand Up @@ -7,13 +7,15 @@
import Rakudo.Metamodel.Representations.P6capture;
import Rakudo.Metamodel.Representations.P6hash;
import Rakudo.Metamodel.Representations.P6int;
import Rakudo.Metamodel.Representations.P6list;
import Rakudo.Metamodel.Representations.P6opaque;
import Rakudo.Metamodel.REPRRegistry;
import Rakudo.Runtime.CaptureHelper;
import Rakudo.Runtime.CodeObjectUtility;
import Rakudo.Runtime.Context;
import Rakudo.Runtime.ExecutionDomain;
import Rakudo.Runtime.Lexpad;
import Rakudo.Runtime.Ops;
import Rakudo.Runtime.ThreadContext;

/// <summary>
Expand Down Expand Up @@ -80,7 +82,7 @@ private static void RegisterRepresentations()
// TODO REPRRegistry.register_REPR("P6str", new P6str());
REPRRegistry.register_REPR("P6capture", new P6capture());
REPRRegistry.register_REPR("RakudoCodeRef", new RakudoCodeRef());
// TODO REPRRegistry.register_REPR("P6list", new P6list());
REPRRegistry.register_REPR("P6list", new P6list());
REPRS_Registered = true;
}
}
Expand All @@ -96,25 +98,26 @@ private static Context BootstrapSetting(RakudoObject KnowHOW)
Context settingContext = new Context();
settingContext.LexPad = new Lexpad(new String[]
{ "KnowHOW", "capture", "NQPInt", "NQPNum", "NQPStr", "LLCode", "list" });
RakudoCodeRef.IFunc_Body funcBody = new RakudoCodeRef.IFunc_Body()
{ // create an 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);
P6capture.Instance NativeCapture = (P6capture.Instance)capture;
for (RakudoObject obj : NativeCapture.Positionals)
list.Storage.add(obj);
return list;
}
};
settingContext.LexPad.Storage = new RakudoObject[]
{
KnowHOW,
REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null),
REPRRegistry.get_REPR_by_name("P6int").type_object_for(null),
REPRRegistry.get_REPR_by_name("P6num").type_object_for(null),
REPRRegistry.get_REPR_by_name("P6str").type_object_for(null),
REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(KnowHOW.getSTable().REPR.instance_of(KnowHOW)),
/* TODO
CodeObjectUtility.WrapNativeMethod((TC, self, C) =>
{
var NQPList = Ops.get_lex(TC, "NQPList");
var List = NQPList.STable.REPR.instance_of(NQPList) as P6list.Instance;
var NativeCapture = C as P6capture.Instance;
foreach (var Obj in NativeCapture.Positionals)
List.Storage.Add(Obj);
return List;
})
*/
REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null,null),
REPRRegistry.get_REPR_by_name("P6int").type_object_for(null,null),
REPRRegistry.get_REPR_by_name("P6num").type_object_for(null,null),
REPRRegistry.get_REPR_by_name("P6str").type_object_for(null,null),
REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(null,KnowHOW.getSTable().REPR.instance_of(null,KnowHOW)),
CodeObjectUtility.WrapNativeMethod(funcBody)
};
return settingContext;
}
Expand Down Expand Up @@ -143,30 +146,35 @@ public static Context LoadSetting(String Name, RakudoObject KnowHOW)
settingContext.LexPad.Extend(new String[]
{ "KnowHOW", "print", "say", "capture", "LLCode" });
settingContext.LexPad.SetByName("KnowHOW", KnowHOW);
/* TODO
settingContext.LexPad.SetByName("print",
CodeObjectUtility.WrapNativeMethod((TC, self, C) =>
{
var Value = CaptureHelper.GetPositional(C, 0);
var StrMeth = self.STable.FindMethod(TC, Value, "Str", 0);
var StrVal = StrMeth.STable.Invoke(TC, StrMeth, C);
Console.Write(Ops.unbox_str(null, StrVal));
return CaptureHelper.Nil();
}));
*/
/* TODO
settingContext.LexPad.SetByName("say",
CodeObjectUtility.WrapNativeMethod((TC, self, C) =>
{
var Value = CaptureHelper.GetPositional(C, 0);
var StrMeth = self.STable.FindMethod(TC, Value, "Str", 0);
var StrVal = StrMeth.STable.Invoke(TC, StrMeth, C);
Console.WriteLine(Ops.unbox_str(null, StrVal));
return CaptureHelper.Nil();
}));
*/
settingContext.LexPad.SetByName("capture", REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null));
settingContext.LexPad.SetByName("LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(KnowHOW.getSTable().REPR.instance_of(KnowHOW)));

RakudoCodeRef.IFunc_Body funcPrint = new RakudoCodeRef.IFunc_Body()
{ // create an anonymous class
public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject capture)
{
RakudoObject value = CaptureHelper.GetPositional(capture, 0);
RakudoObject strMeth = self.getSTable().FindMethod.FindMethod(tc, value, "Str", 0);
RakudoObject strVal = strMeth.getSTable().Invoke.Invoke(tc, strMeth, capture);
System.out.print(Ops.unbox_str(null, strVal));
return CaptureHelper.Nil();
}
};
settingContext.LexPad.SetByName("print", CodeObjectUtility.WrapNativeMethod(funcPrint));

RakudoCodeRef.IFunc_Body funcSay = new RakudoCodeRef.IFunc_Body()
{ // create an anonymous class
public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject capture)
{
RakudoObject value = CaptureHelper.GetPositional(capture, 0);
RakudoObject strMeth = self.getSTable().FindMethod.FindMethod(tc, value, "Str", 0);
RakudoObject strVal = strMeth.getSTable().Invoke.Invoke(tc, strMeth, capture);
System.out.println(Ops.unbox_str(null, strVal));
return CaptureHelper.Nil();
}
};
settingContext.LexPad.SetByName("say", CodeObjectUtility.WrapNativeMethod(funcSay));

settingContext.LexPad.SetByName("capture", REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null,null));
settingContext.LexPad.SetByName("LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(null,KnowHOW.getSTable().REPR.instance_of(null,KnowHOW)));

return settingContext;
}
Expand Down
2 changes: 0 additions & 2 deletions java/runtime/Rakudo/Metamodel/Hints.java
@@ -1,12 +1,10 @@
package Rakudo.Metamodel;

//public static class Hints
public final class Hints
{
/// <summary>
/// Special value indicating that we have no hint.
/// </summary>
// public const int NO_HINT = -1;
public static final int NO_HINT = -1;
}

10 changes: 5 additions & 5 deletions java/runtime/Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.java
Expand Up @@ -3,11 +3,11 @@
import java.util.HashMap;
import java.util.Iterator;

import Rakudo.Metamodel.REPRRegistry;
import Rakudo.Metamodel.SharedTable;
import Rakudo.Metamodel.KnowHOW.KnowHOWREPR;
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representation;
import Rakudo.Metamodel.KnowHOW.KnowHOWREPR;
import Rakudo.Metamodel.REPRRegistry;
import Rakudo.Metamodel.SharedTable;
import Rakudo.Runtime.CodeObjectUtility;

/// <summary>
Expand All @@ -32,7 +32,7 @@ public static RakudoObject Bootstrap()
// Create our KnowHOW type object. Note we don't have a HOW
// just yet, so pass in null.
Representation REPR = REPRRegistry.get_REPR_by_name("KnowHOWREPR");
RakudoObject KnowHOW = REPR.type_object_for(null);
RakudoObject KnowHOW = REPR.type_object_for(null,null);

// We'll set up a dictionary of our various methods to go into
// KnowHOW's HOW, since we'll want to work with them a bit.
Expand Down Expand Up @@ -100,7 +100,7 @@ public static RakudoObject Bootstrap()
// We create a KnowHOW instance that can describe itself. This
// means .HOW.HOW.HOW.HOW etc will always return that, which
// closes the model up.
KnowHOWREPR.KnowHOWInstance KnowHOWHOW = (KnowHOWREPR.KnowHOWInstance)REPR.instance_of(KnowHOW);
KnowHOWREPR.KnowHOWInstance KnowHOWHOW = (KnowHOWREPR.KnowHOWInstance)REPR.instance_of(null,KnowHOW);
// TODO for (Iterator iter = KnowHOWMeths.entrySet.Iterator(); iter.hasNext(); )
// foreach (var Method in KnowHOWMeths)
{
Expand Down

0 comments on commit e86a007

Please sign in to comment.