Skip to content

Commit

Permalink
All representation methods should probably get the ThreadContext in t…
Browse files Browse the repository at this point in the history
…he .Net version (just as the Parrot ones will all want to get the interp). Gets us a step closer to P6opaque slot alloc actually working.
  • Loading branch information
jnthn committed Sep 12, 2010
1 parent c5dac2d commit 3ab10e5
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 182 deletions.
2 changes: 1 addition & 1 deletion dotnet/compiler/PAST2DNSTCompiler.pm
Expand Up @@ -89,7 +89,7 @@ method compile(PAST::Node $node) {
DNST::MethodCall.new(
:on('StaticBlockInfo[1].StaticLexPad'), :name('SetByName'),
DNST::Literal.new( :value('NQPStr'), :escape(1) ),
'REPRRegistry.get_REPR_by_name("P6str").type_object_for(null)'
'REPRRegistry.get_REPR_by_name("P6str").type_object_for(null, null)'
),

# We do the loadinit calls before building the constants, as we
Expand Down
16 changes: 8 additions & 8 deletions dotnet/runtime/Init.cs
Expand Up @@ -92,15 +92,15 @@ private static Context BootstrapSetting(RakudoObject KnowHOW)
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.STable.REPR.instance_of(KnowHOW)),
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.STable.REPR.instance_of(null, KnowHOW)),
CodeObjectUtility.WrapNativeMethod((TC, self, C) =>
{
var NQPList = Ops.get_lex(TC, "NQPList");
var List = NQPList.STable.REPR.instance_of(NQPList) as P6list.Instance;
var List = NQPList.STable.REPR.instance_of(TC, NQPList) as P6list.Instance;
var NativeCapture = C as P6capture.Instance;
foreach (var Obj in NativeCapture.Positionals)
List.Storage.Add(Obj);
Expand Down Expand Up @@ -151,8 +151,8 @@ public static Context LoadSetting(string Name, RakudoObject KnowHOW)
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.STable.REPR.instance_of(KnowHOW)));
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.STable.REPR.instance_of(null, KnowHOW)));

return SettingContext;
}
Expand Down
10 changes: 5 additions & 5 deletions dotnet/runtime/Metamodel/KnowHOW/KnowHOWBootstrapper.cs
Expand Up @@ -28,7 +28,7 @@ public static RakudoObject Bootstrap()
// Create our KnowHOW type object. Note we don't have a HOW
// just yet, so pass in null.
var REPR = REPRRegistry.get_REPR_by_name("KnowHOWREPR");
var KnowHOW = REPR.type_object_for(null);
var 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 All @@ -37,7 +37,7 @@ public static RakudoObject Bootstrap()
{
// We first create a new HOW instance.
var KnowHOWTypeObj = CaptureHelper.GetPositional(Cap, 0);
var HOW = KnowHOWTypeObj.STable.REPR.instance_of(KnowHOWTypeObj.STable.WHAT);
var HOW = KnowHOWTypeObj.STable.REPR.instance_of(TC, KnowHOWTypeObj.STable.WHAT);
// Now create a new type object to go with it of the
// desired REPR; we default to P6opaque (note that the
Expand All @@ -50,12 +50,12 @@ public static RakudoObject Bootstrap()
{
// Look up the REPR.
var REPRToUse = REPRRegistry.get_REPR_by_name(Ops.unbox_str(null, REPRName));
return REPRToUse.type_object_for(HOW);
return REPRToUse.type_object_for(null, HOW);
}
else
{
// Just go with the P6opaque REPR.
return REPRRegistry.get_REPR_by_name("P6opaque").type_object_for(HOW);
return REPRRegistry.get_REPR_by_name("P6opaque").type_object_for(TC, HOW);
}
}));
KnowHOWMeths.Add("add_attribute", CodeObjectUtility.WrapNativeMethod((TC, Ignored, Cap) =>
Expand Down Expand Up @@ -94,7 +94,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.
var KnowHOWHOW = (KnowHOWREPR.KnowHOWInstance)REPR.instance_of(KnowHOW);
var KnowHOWHOW = (KnowHOWREPR.KnowHOWInstance)REPR.instance_of(null, KnowHOW);
foreach (var Method in KnowHOWMeths)
KnowHOWHOW.Methods.Add(Method.Key, Method.Value);

Expand Down
29 changes: 15 additions & 14 deletions dotnet/runtime/Metamodel/KnowHOW/KnowHOWREPR.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rakudo.Runtime;

namespace Rakudo.Metamodel.KnowHOW
{
Expand Down Expand Up @@ -31,7 +32,7 @@ public KnowHOWInstance(SharedTable STable)
/// </summary>
/// <param name="HOW"></param>
/// <returns></returns>
public override RakudoObject type_object_for(RakudoObject HOW)
public override RakudoObject type_object_for(ThreadContext TC, RakudoObject HOW)
{
var STable = new SharedTable();
STable.HOW = HOW;
Expand All @@ -45,7 +46,7 @@ public override RakudoObject type_object_for(RakudoObject HOW)
/// </summary>
/// <param name="WHAT"></param>
/// <returns></returns>
public override RakudoObject instance_of(RakudoObject WHAT)
public override RakudoObject instance_of(ThreadContext TC, RakudoObject WHAT)
{
var Object = new KnowHOWInstance(WHAT.STable);
Object.Methods = new Dictionary<string, RakudoObject>();
Expand All @@ -58,27 +59,27 @@ public override RakudoObject instance_of(RakudoObject WHAT)
/// </summary>
/// <param name="Obj"></param>
/// <returns></returns>
public override bool defined(RakudoObject Obj)
public override bool defined(ThreadContext TC, RakudoObject Obj)
{
return ((KnowHOWInstance)Obj).Methods != null;
}

public override RakudoObject get_attribute(RakudoObject Object, RakudoObject ClassHandle, string Name)
public override RakudoObject get_attribute(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name)
{
throw new NotImplementedException();
}

public override RakudoObject get_attribute_with_hint(RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint)
public override RakudoObject get_attribute_with_hint(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint)
{
throw new NotImplementedException();
}

public override void bind_attribute(RakudoObject Object, RakudoObject ClassHandle, string Name, RakudoObject Value)
public override void bind_attribute(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, RakudoObject Value)
{
throw new NotImplementedException();
}

public override void bind_attribute_with_hint(RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint, RakudoObject Value)
public override void bind_attribute_with_hint(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint, RakudoObject Value)
{
throw new NotImplementedException();
}
Expand All @@ -90,37 +91,37 @@ public override void bind_attribute_with_hint(RakudoObject Object, RakudoObject
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <returns></returns>
public override int hint_for(RakudoObject ClassHandle, string Name)
public override int hint_for(ThreadContext TC, RakudoObject ClassHandle, string Name)
{
return Hints.NO_HINT;
}

public override void set_int(RakudoObject Object, int Value)
public override void set_int(ThreadContext TC, RakudoObject Object, int Value)
{
throw new InvalidOperationException("This type of representation cannot box a native int");
}

public override int get_int(RakudoObject Object)
public override int get_int(ThreadContext TC, RakudoObject Object)
{
throw new InvalidOperationException("This type of representation cannot unbox to a native int");
}

public override void set_num(RakudoObject Object, double Value)
public override void set_num(ThreadContext TC, RakudoObject Object, double Value)
{
throw new InvalidOperationException("This type of representation cannot box a native num");
}

public override double get_num(RakudoObject Object)
public override double get_num(ThreadContext TC, RakudoObject Object)
{
throw new InvalidOperationException("This type of representation cannot unbox to a native num");
}

public override void set_str(RakudoObject Object, string Value)
public override void set_str(ThreadContext TC, RakudoObject Object, string Value)
{
throw new InvalidOperationException("This type of representation cannot box a native string");
}

public override string get_str(RakudoObject Object)
public override string get_str(ThreadContext TC, RakudoObject Object)
{
throw new InvalidOperationException("This type of representation cannot unbox to a native string");
}
Expand Down
29 changes: 15 additions & 14 deletions dotnet/runtime/Metamodel/Representation.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rakudo.Runtime;

namespace Rakudo.Metamodel
{
Expand All @@ -17,29 +18,29 @@ public abstract class Representation
/// </summary>
/// <param name="HOW"></param>
/// <returns></returns>
public abstract RakudoObject type_object_for(RakudoObject HOW);
public abstract RakudoObject type_object_for(ThreadContext TC, RakudoObject HOW);

/// <summary>
/// Creates a new instance based on the type object.
/// </summary>
/// <param name="WHAT"></param>
/// <returns></returns>
public abstract RakudoObject instance_of(RakudoObject WHAT);
public abstract RakudoObject instance_of(ThreadContext TC, RakudoObject WHAT);

/// <summary>
/// Checks if a given object is defined.
/// </summary>
/// <param name="Obj"></param>
/// <returns></returns>
public abstract bool defined(RakudoObject Obj);
public abstract bool defined(ThreadContext TC, RakudoObject Obj);

/// <summary>
/// Gets the current value for an attribute.
/// </summary>
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <returns></returns>
public abstract RakudoObject get_attribute(RakudoObject Object, RakudoObject ClassHandle, string Name);
public abstract RakudoObject get_attribute(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name);

/// <summary>
/// Gets the current value for an attribute, obtained using the
Expand All @@ -49,15 +50,15 @@ public abstract class Representation
/// <param name="Name"></param>
/// <param name="Hint"></param>
/// <returns></returns>
public abstract RakudoObject get_attribute_with_hint(RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint);
public abstract RakudoObject get_attribute_with_hint(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint);

/// <summary>
/// Binds the given value to the specified attribute.
/// </summary>
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <param name="Value"></param>
public abstract void bind_attribute(RakudoObject Object, RakudoObject ClassHandle, string Name, RakudoObject Value);
public abstract void bind_attribute(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, RakudoObject Value);

/// <summary>
/// Binds the given value to the specified attribute, using the
Expand All @@ -67,63 +68,63 @@ public abstract class Representation
/// <param name="Name"></param>
/// <param name="Hint"></param>
/// <param name="Value"></param>
public abstract void bind_attribute_with_hint(RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint, RakudoObject Value);
public abstract void bind_attribute_with_hint(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint, RakudoObject Value);

/// <summary>
/// Gets the hint for the given attribute ID.
/// </summary>
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <returns></returns>
public abstract int hint_for(RakudoObject ClassHandle, string Name);
public abstract int hint_for(ThreadContext TC, RakudoObject ClassHandle, string Name);

/// <summary>
/// Used with boxing. Sets an integer value, for representations that
/// can hold one.
/// </summary>
/// <param name="Object"></param>
/// <param name="Value"></param>
public abstract void set_int(RakudoObject Object, int Value);
public abstract void set_int(ThreadContext TC, RakudoObject Object, int Value);

/// <summary>
/// Used with boxing. Gets an integer value, for representations that
/// can hold one.
/// </summary>
/// <param name="Object"></param>
/// <param name="Value"></param>
public abstract int get_int(RakudoObject Object);
public abstract int get_int(ThreadContext TC, RakudoObject Object);

/// <summary>
/// Used with boxing. Sets a floating point value, for representations that
/// can hold one.
/// </summary>
/// <param name="Object"></param>
/// <param name="Value"></param>
public abstract void set_num(RakudoObject Object, double Value);
public abstract void set_num(ThreadContext TC, RakudoObject Object, double Value);

/// <summary>
/// Used with boxing. Gets a floating point value, for representations that
/// can hold one.
/// </summary>
/// <param name="Object"></param>
/// <param name="Value"></param>
public abstract double get_num(RakudoObject Object);
public abstract double get_num(ThreadContext TC, RakudoObject Object);

/// <summary>
/// Used with boxing. Sets a string value, for representations that
/// can hold one.
/// </summary>
/// <param name="Object"></param>
/// <param name="Value"></param>
public abstract void set_str(RakudoObject Object, string Value);
public abstract void set_str(ThreadContext TC, RakudoObject Object, string Value);

/// <summary>
/// Used with boxing. Gets a string value, for representations that
/// can hold one.
/// </summary>
/// <param name="Object"></param>
/// <param name="Value"></param>
public abstract string get_str(RakudoObject Object);
public abstract string get_str(ThreadContext TC, RakudoObject Object);
}

public static class Hints
Expand Down

0 comments on commit 3ab10e5

Please sign in to comment.