Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flesh out STable a little more; this adds find_method and postcircumf…
…ix:<{ }> caching.
  • Loading branch information
jnthn committed Aug 23, 2010
1 parent 4c8ee84 commit b23a318
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions dotnet/runtime/Metamodel/SharedTable.cs
Expand Up @@ -15,6 +15,23 @@ namespace Rakudo.Metamodel
/// </summary>
public sealed class SharedTable
{
/// <summary>
/// The representation object that manages object layout.
/// </summary>
public Representation REPR;

/// <summary>
/// The HOW (which is the meta-package). If we do $obj.HOW then
/// it will refer to a getting of this field.
/// </summary>
public RakudoObject HOW;

/// <summary>
/// The type-object. If we do $obj.WHAT then it will refer to a
/// getting of this field.
/// </summary>
public RakudoObject WHAT;

/// <summary>
/// This finds a method with the given name or using a hint.
/// </summary>
Expand All @@ -31,41 +48,38 @@ public sealed class SharedTable
{
// Find the find_method method.
var HOW = Obj.STable.HOW;
var Meth = HOW.STable.FindMethod(TC, HOW, "find_method", Hints.NO_HINT);
RakudoObject Meth = Obj.STable.CachedFindMethod;
if (Meth == null)
Obj.STable.CachedFindMethod = Meth = HOW.STable.FindMethod(
TC, HOW, "find_method", Hints.NO_HINT);
// Call it.
var Cap = CaptureHelper.FormWith(new RakudoObject[] { HOW, Ops.box_str(TC, Name, TC.DefaultStrBoxType) });
return Meth.STable.Invoke(TC, Meth, Cap);
}
};

/// <summary>
/// We keep a cache of the find_method method.
/// </summary>
internal RakudoObject CachedFindMethod;

/// <summary>
/// The default invoke looks up a postcircumfix:<( )> and runs that.
/// XXX Cache the hint where we can.
/// </summary>
public Func<ThreadContext, RakudoObject, RakudoObject, RakudoObject> Invoke =
(TC, Obj, Cap) =>
{
var Invokable = Obj.STable.FindMethod(TC, Obj, "postcircumfix:<( )>", Hints.NO_HINT);
var STable = Obj.STable;
var Invokable = STable.CachedInvoke ?? (STable.CachedInvoke = Obj.STable.FindMethod(TC, Obj, "postcircumfix:<( )>", Hints.NO_HINT));
return Invokable.STable.Invoke(TC, Obj, Cap);
};

/// <summary>
/// The representation object that manages object layout.
/// We keep a cache of the postcircumfix:<( )> method.
/// </summary>
public Representation REPR;

/// <summary>
/// The HOW (which is the meta-package). If we do $obj.HOW then
/// it will refer to a getting of this field.
/// </summary>
public RakudoObject HOW;

/// <summary>
/// The type-object. If we do $obj.WHAT then it will refer to a
/// getting of this field.
/// </summary>
public RakudoObject WHAT;
internal RakudoObject CachedInvoke;

/// <summary>
/// The serialization context of this STable, if any.
Expand Down

0 comments on commit b23a318

Please sign in to comment.