Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[java/runtime] add P6mapping and sync all recent dotnet changes
  • Loading branch information
mberends committed Oct 21, 2010
1 parent 1fea9b0 commit 588770d
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 37 deletions.
9 changes: 9 additions & 0 deletions java/runtime/Makefile
Expand Up @@ -69,6 +69,7 @@ OTHER_DEPENDENT_TARGETS = \
$(CLASSES)Rakudo/Metamodel/Representation.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6capture.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6list.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6mapping.class \
$(CLASSES)Rakudo/Metamodel/Representations/RakudoCodeRef.class \
$(CLASSES)Rakudo/Runtime/Context.class \
$(CLASSES)Rakudo/Runtime/MultiDispatch/LexicalCandidateFinder.class \
Expand Down Expand Up @@ -114,6 +115,7 @@ $(CLASSES)Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.jav
Rakudo/Runtime/Signature.java \
Rakudo/Metamodel/Representations/P6capture.java \
Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Representations/P6mapping.java \
Rakudo/Metamodel/Representations/RakudoCodeRef.java \
Rakudo/Metamodel/REPRRegistry.java \
Rakudo/Runtime/Context.java \
Expand All @@ -132,6 +134,7 @@ $(CLASSES)Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.jav
Rakudo/Runtime/Signature.java \
Rakudo/Metamodel/Representations/P6capture.java \
Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Representations/P6mapping.java \
Rakudo/Metamodel/Representations/RakudoCodeRef.java \
Rakudo/Metamodel/REPRRegistry.java \
Rakudo/Runtime/Context.java \
Expand All @@ -153,6 +156,7 @@ $(CLASSES)Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.class: Rakudo/Metamodel/K
$(CLASSES)Rakudo/Metamodel/Representation.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6capture.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6list.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6mapping.class \
$(CLASSES)Rakudo/Metamodel/Representations/RakudoCodeRef.class \
$(CLASSES)Rakudo/Metamodel/REPRRegistry.class \
$(CLASSES)Rakudo/Metamodel/SharedTable.class \
Expand Down Expand Up @@ -234,6 +238,7 @@ $(CLASSES)Rakudo/Init.class: Rakudo/Init.java \
$(CLASSES)Rakudo/Metamodel/Representations/P6hash.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6int.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6list.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6mapping.class \
$(CLASSES)Rakudo/Metamodel/Representations/P6opaque.class \
$(CLASSES)Rakudo/Metamodel/REPRRegistry.class \
$(CLASSES)Rakudo/Runtime/CaptureHelper.class \
Expand All @@ -259,6 +264,7 @@ TRANSLATED_SOURCE_FILES = \
Rakudo/Metamodel/Representations/P6hash.java \
Rakudo/Metamodel/Representations/P6int.java \
Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Representations/P6mapping.java \
Rakudo/Metamodel/Representations/P6num.java \
Rakudo/Metamodel/Representations/P6opaque.java \
Rakudo/Metamodel/Representations/P6str.java \
Expand Down Expand Up @@ -308,6 +314,9 @@ Rakudo/Metamodel/Representations/P6int.java: ../../dotnet/runtime/Metamodel/Repr
Rakudo/Metamodel/Representations/P6list.java: ../../dotnet/runtime/Metamodel/Representations/P6list.cs
@echo "todo: $@ is older than $<"

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

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

Expand Down
13 changes: 6 additions & 7 deletions java/runtime/Rakudo/Init.java
Expand Up @@ -8,6 +8,7 @@
import Rakudo.Metamodel.Representations.P6hash;
import Rakudo.Metamodel.Representations.P6int;
import Rakudo.Metamodel.Representations.P6list;
import Rakudo.Metamodel.Representations.P6mapping;
import Rakudo.Metamodel.Representations.P6num;
import Rakudo.Metamodel.Representations.P6opaque;
import Rakudo.Metamodel.Representations.P6str;
Expand All @@ -23,8 +24,7 @@
/// <summary>
/// Does initialization of the Rakudo library.
/// </summary>
public class Init
//public static class Init
public class Init // public static in the C# version
{
/// <summary>
/// Have we already registered the representations?
Expand All @@ -44,7 +44,7 @@ public static ThreadContext Initialize(String settingName)
// Either load a named setting or use the fake bootstrapping one.
Context settingContext =
// Comment out the next line to always use the fake Setting.
(settingName != null) ? LoadSetting(settingName, knowHOW) :
// (settingName != null) ? LoadSetting(settingName, knowHOW) :
BootstrapSetting(knowHOW);

// Cache native capture and LLCode type object.
Expand All @@ -60,6 +60,7 @@ public static ThreadContext Initialize(String settingName)
threadContext.DefaultIntBoxType = settingContext.LexPad.GetByName("NQPInt");
threadContext.DefaultNumBoxType = settingContext.LexPad.GetByName("NQPNum");
threadContext.DefaultStrBoxType = settingContext.LexPad.GetByName("NQPStr");
threadContext.DefaultListType = settingContext.LexPad.GetByName("NQPList");
return threadContext;
}

Expand All @@ -79,6 +80,7 @@ private static void RegisterRepresentations()
REPRRegistry.register_REPR("P6capture", new P6capture());
REPRRegistry.register_REPR("RakudoCodeRef", new RakudoCodeRef());
REPRRegistry.register_REPR("P6list", new P6list());
REPRRegistry.register_REPR("P6mapping", new P6mapping());
REPRS_Registered = true;
}
}
Expand Down Expand Up @@ -113,6 +115,7 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject self, RakudoObject cap
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("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(funcBody)
};
Expand Down Expand Up @@ -150,10 +153,6 @@ public static Context LoadSetting(String settingName, RakudoObject knowHOW)
}

// Find the setting type and its LoadSetting method.
// var Class = settingAssembly.GetType("NQPSetting");
// var Method = Class.GetMethod("LoadSetting", BindingFlags.NonPublic | BindingFlags.Static);
// String s = new String();
// Class stringClass = s.getClass();
java.lang.reflect.Method methodLoadSetting = null;
try {
methodLoadSetting = classNQPSetting.getMethod("LoadSetting");
Expand Down
1 change: 0 additions & 1 deletion java/runtime/Rakudo/Metamodel/Representations/P6list.java
@@ -1,7 +1,6 @@
package Rakudo.Metamodel.Representations;

import java.util.ArrayList;
//import Rakudo.Metamodel.Hints;
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representation;
import Rakudo.Metamodel.SharedTable;
Expand Down
116 changes: 116 additions & 0 deletions java/runtime/Rakudo/Metamodel/Representations/P6mapping.java
@@ -0,0 +1,116 @@
package Rakudo.Metamodel.Representations;
import java.util.HashMap;
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representation;
import Rakudo.Metamodel.SharedTable;
import Rakudo.Runtime.ThreadContext;
import Rakudo.Serialization.SerializationContext;

/// <summary>
/// This is a very first cut at a mapping representation. Just stores
/// hash mappings of one string to object at the moment. Not really
/// efficient, and no compact struct support, but gets us started.
/// </summary>
public class P6mapping implements Representation
{
public class Instance extends RakudoObject
{
public HashMap<String,RakudoObject> Storage;
public Instance(SharedTable sharedTable)
{
this.setSTable(sharedTable);
}
}

/// <summary>
/// Create a new type object.
/// </summary>
/// <param name="HOW"></param>
/// <returns></returns>
public RakudoObject type_object_for(ThreadContext tc, RakudoObject metaPackage)
{
SharedTable sharedTable = new SharedTable();
sharedTable.HOW = metaPackage;
sharedTable.REPR = this;
sharedTable.WHAT = new Instance(sharedTable);
return sharedTable.WHAT;
}

/// <summary>
/// Creates an instance of the type with the given type object.
/// </summary>
/// <param name="WHAT"></param>
/// <returns></returns>
public RakudoObject instance_of(ThreadContext tc, RakudoObject WHAT)
{
Instance object = new Instance(WHAT.getSTable());
object.Storage = new HashMap<String,RakudoObject>();
return object;
}

/// <summary>
/// Determines if the representation is defined or not.
/// </summary>
/// <param name="Obj"></param>
/// <returns></returns>
public boolean defined(ThreadContext tc, RakudoObject object)
{
return ((Instance)object).Storage != null;
}

public RakudoObject get_attribute(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name)
{
throw new UnsupportedOperationException();
}

public RakudoObject get_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint)
{
throw new UnsupportedOperationException();
}

public void bind_attribute(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, RakudoObject value)
{
throw new UnsupportedOperationException();
}

public void bind_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint, RakudoObject value)
{
throw new UnsupportedOperationException();
}

public int hint_for(ThreadContext tc, RakudoObject classHandle, String name)
{
throw new UnsupportedOperationException();
}

public void set_int(ThreadContext tc, RakudoObject object, int value)
{
throw new UnsupportedOperationException();
}

public int get_int(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}

public void set_num(ThreadContext tc, RakudoObject object, double value)
{
throw new UnsupportedOperationException();
}

public double get_num(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}

public void set_str(ThreadContext tc, RakudoObject object, String value)
{
throw new UnsupportedOperationException();
}

public String get_str(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}
}

0 comments on commit 588770d

Please sign in to comment.