Permalink
Browse files

Add a first cut of a P6list representation and a list sub that makes …

…one (hardcoded rather than in the setting for now). Stub in NQPList in the setting; expect we'll base NQPArray on this representation too.
  • Loading branch information...
1 parent a389552 commit eae223f3921747ec858ffa3c9235199f6088de77 @jnthn committed Aug 22, 2010
View
@@ -47,6 +47,12 @@ knowhow NQPNum is repr('P6num') {
}
}
+knowhow NQPList is repr('P6list') {
+}
+
+knowhow NQPArray is repr('P6list') {
+}
+
## XXX All of these should become multi when we can do that.
sub &infix:<==>($x, $y) {
View
@@ -73,6 +73,7 @@ private static void RegisterRepresentations()
REPRRegistry.register_REPR("P6str", new P6str());
REPRRegistry.register_REPR("P6capture", new P6capture());
REPRRegistry.register_REPR("RakudoCodeRef", new RakudoCodeRef());
+ REPRRegistry.register_REPR("P6list", new P6list());
REPRS_Registered = true;
}
}
@@ -89,6 +90,11 @@ private static Context BootstrapSetting(RakudoObject KnowHOW)
SettingContext.LexPad = new Dictionary<string, RakudoObject>()
{
{ "KnowHOW", KnowHOW },
+ { "capture", REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null) },
+ { "NQPInt", REPRRegistry.get_REPR_by_name("P6int").type_object_for(null) },
+ { "NQPNum", REPRRegistry.get_REPR_by_name("P6num").type_object_for(null) },
+ { "NQPStr", REPRRegistry.get_REPR_by_name("P6str").type_object_for(null) },
+ { "LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(KnowHOW.STable.REPR.instance_of(KnowHOW)) },
{ "print", CodeObjectUtility.WrapNativeMethod((TC, self, C) =>
{
var Value = CaptureHelper.GetPositional(C, 0);
@@ -107,11 +113,16 @@ private static Context BootstrapSetting(RakudoObject KnowHOW)
return CaptureHelper.Nil();
})
},
- { "capture", REPRRegistry.get_REPR_by_name("P6capture").type_object_for(null) },
- { "NQPInt", REPRRegistry.get_REPR_by_name("P6int").type_object_for(null) },
- { "NQPNum", REPRRegistry.get_REPR_by_name("P6num").type_object_for(null) },
- { "NQPStr", REPRRegistry.get_REPR_by_name("P6str").type_object_for(null) },
- { "LLCode", REPRRegistry.get_REPR_by_name("RakudoCodeRef").type_object_for(KnowHOW.STable.REPR.instance_of(KnowHOW)) }
+ { "list", 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;
+ })
+ }
};
return SettingContext;
}
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Rakudo.Metamodel.Representations
+{
+ /// <summary>
+ /// This is a very first cut at a list representation. Essentially,
+ /// it just knows how to store a list of objects at the moment. At
+ /// some point we need to define the way that it will handle compact
+ /// arrays.
+ /// </summary>
+ public class P6list : Representation
+ {
+ internal class Instance : RakudoObject
+ {
+ /// <summary>
+ /// Just use a .Net List at the moment, but an array would
+ /// be more efficient in the long run (though give us more
+ /// stuff to implement ourselves).
+ /// </summary>
+ public List<RakudoObject> Storage;
+ public Instance(SharedTable STable)
+ {
+ this.STable = STable;
+ }
+ }
+
+ /// <summary>
+ /// Create a new type object.
+ /// </summary>
+ /// <param name="HOW"></param>
+ /// <returns></returns>
+ public override RakudoObject type_object_for(RakudoObject MetaPackage)
+ {
+ var STable = new SharedTable();
+ STable.HOW = MetaPackage;
+ STable.REPR = this;
+ STable.WHAT = new Instance(STable);
+ return STable.WHAT;
+ }
+
+ /// <summary>
+ /// Creates an instance of the type with the given type object.
+ /// </summary>
+ /// <param name="WHAT"></param>
+ /// <returns></returns>
+ public override RakudoObject instance_of(RakudoObject WHAT)
+ {
+ var Object = new Instance(WHAT.STable);
+ Object.Storage = new List<RakudoObject>();
+ return Object;
+ }
+
+ /// <summary>
+ /// Determines if the representation is defined or not.
+ /// </summary>
+ /// <param name="Obj"></param>
+ /// <returns></returns>
+ public override bool defined(RakudoObject Obj)
+ {
+ return ((Instance)Obj).Storage != null;
+ }
+
+ public override RakudoObject get_attribute(RakudoObject Object, RakudoObject ClassHandle, string Name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override RakudoObject get_attribute_with_hint(RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void bind_attribute(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)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int hint_for(RakudoObject ClassHandle, string Name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void set_int(RakudoObject Object, int Value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int get_int(RakudoObject Object)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void set_num(RakudoObject Object, double Value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override double get_num(RakudoObject Object)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void set_str(RakudoObject Object, string Value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override string get_str(RakudoObject Object)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
@@ -56,6 +56,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Init.cs" />
+ <Compile Include="Metamodel\Representations\P6list.cs" />
<Compile Include="Metamodel\Representations\P6capture.cs" />
<Compile Include="Metamodel\Representations\P6int.cs" />
<Compile Include="Metamodel\Representations\P6num.cs" />

0 comments on commit eae223f

Please sign in to comment.