Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] Implement slurpy array and hash parameters.
  • Loading branch information
jnthn committed Nov 13, 2010
1 parent 355ceac commit 784b227
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dotnet/compiler/PAST2DNSTCompiler.pm
Expand Up @@ -402,7 +402,7 @@ our multi sub dnst_for(PAST::Block $block) {

# Before start of statements, we want to bind the signature.
$stmts.unshift(DNST::MethodCall.new(
:on('SignatureBinder'), :name('Bind'), :void(1), 'C', 'Capture'
:on('SignatureBinder'), :name('Bind'), :void(1), 'TC', 'C', 'Capture'
));

# Wrap in block prelude/postlude.
Expand Down
8 changes: 6 additions & 2 deletions dotnet/runtime/Init.cs
Expand Up @@ -57,6 +57,8 @@ public static ThreadContext Initialize(string SettingName)
Thread.DefaultNumBoxType = SettingContext.LexPad.GetByName("NQPNum");
Thread.DefaultStrBoxType = SettingContext.LexPad.GetByName("NQPStr");
Thread.DefaultListType = SettingContext.LexPad.GetByName("NQPList");
Thread.DefaultArrayType = SettingContext.LexPad.GetByName("NQPArray");
Thread.DefaultHashType = SettingContext.LexPad.GetByName("NQPHash");

return Thread;
}
Expand Down Expand Up @@ -92,7 +94,7 @@ private static Context BootstrapSetting(RakudoObject KnowHOW, RakudoObject KnowH
{
var 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 @@ -111,7 +113,9 @@ private static Context BootstrapSetting(RakudoObject KnowHOW, RakudoObject KnowH
foreach (var Obj in NativeCapture.Positionals)
List.Storage.Add(Obj);
return List;
})
}),
null,
null
};
return SettingContext;
}
Expand Down
1 change: 0 additions & 1 deletion dotnet/runtime/Runtime/Signatures/Signature.cs
Expand Up @@ -32,7 +32,6 @@ public Signature(Parameter[] Parameters)
break;
}


/// <summary>
/// The parameters we have.
/// </summary>
Expand Down
23 changes: 19 additions & 4 deletions dotnet/runtime/Runtime/Signatures/SignatureBinder.cs
Expand Up @@ -36,7 +36,7 @@ public static class SignatureBinder
/// </summary>
/// <param name="C"></param>
/// <param name="Capture"></param>
public static void Bind(Context C, RakudoObject Capture)
public static void Bind(ThreadContext TC, Context C, RakudoObject Capture)
{
// Make sure the object is really a low level capture (don't handle
// otherwise yet) and grab the pieces.
Expand All @@ -45,6 +45,7 @@ public static void Bind(Context C, RakudoObject Capture)
throw new NotImplementedException("Can only deal with native captures at the moment");
var Positionals = NativeCapture.Positionals ?? EmptyPos;
var Nameds = NativeCapture.Nameds ?? EmptyNamed;
Dictionary<string, bool> SeenNames = null;

// If we have no signature, that's same as an empty signature.
var Sig = C.StaticCodeObject.Sig;
Expand Down Expand Up @@ -98,13 +99,24 @@ public static void Bind(Context C, RakudoObject Capture)
// Named slurpy?
else if ((Param.Flags & Parameter.NAMED_SLURPY_FLAG) != 0)
{
throw new Exception("Named slurpy parameters are not yet implemented.");
var SlurpyHolder = TC.DefaultHashType.STable.REPR.instance_of(TC, TC.DefaultHashType);
C.LexPad.Storage[Param.VariableLexpadPosition] = SlurpyHolder;
foreach (var Name in Nameds.Keys)
if (SeenNames == null || !SeenNames.ContainsKey(Name))
Ops.llmapping_bind_at_key(TC, SlurpyHolder,
Ops.box_str(TC, Name, TC.DefaultStrBoxType),
Nameds[Name]);
}

// Named positional?
// Positional slurpy?
else if ((Param.Flags & Parameter.POS_SLURPY_FLAG) != 0)
{
throw new Exception("Positional slurpy parameters are not yet implemented.");
var SlurpyHolder = TC.DefaultArrayType.STable.REPR.instance_of(TC, TC.DefaultArrayType);
C.LexPad.Storage[Param.VariableLexpadPosition] = SlurpyHolder;
int j;
for (j = CurPositional; j < Positionals.Length; j++)
Ops.lllist_push(TC, SlurpyHolder, Positionals[j]);
CurPositional = j;
}

// Named?
Expand All @@ -116,6 +128,9 @@ public static void Bind(Context C, RakudoObject Capture)
{
// We have an argument, just bind it.
C.LexPad.Storage[Param.VariableLexpadPosition] = Value;
if (SeenNames == null)
SeenNames = new Dictionary<string, bool>();
SeenNames.Add(Param.Name, true);
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions dotnet/runtime/Runtime/ThreadContext.cs
Expand Up @@ -45,5 +45,15 @@ public class ThreadContext
/// The default list type.
/// </summary>
public RakudoObject DefaultListType;

/// <summary>
/// The default array type.
/// </summary>
public RakudoObject DefaultArrayType;

/// <summary>
/// The default hash type.
/// </summary>
public RakudoObject DefaultHashType;
}
}

0 comments on commit 784b227

Please sign in to comment.