Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add integer indexes for all the representations; put .class in the me…
…tatables (sorear++)
  • Loading branch information
diakopter committed Nov 6, 2011
1 parent 64f520a commit 0cbe07e
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 153 deletions.
2 changes: 0 additions & 2 deletions lua/runtime/List.lua
Expand Up @@ -39,7 +39,6 @@ function makeList ()
self.Count = length;
return self;
end

function List:Shift()
local idx = self.Count;
self.Count = self.Count - 1;
Expand All @@ -53,7 +52,6 @@ function makeList ()
table.remove(self, idx);
return item;
end

function List:Unshift(item)
if (self.Count > 0) then
for i = self.Count, 1, -1 do
Expand Down
33 changes: 21 additions & 12 deletions lua/runtime/Metamodel/KnowHOW/KnowHOWBootstrapper.lua
Expand Up @@ -2,29 +2,32 @@ KnowHOWBootstrapper = {};

function KnowHOWBootstrapper.Bootstrap ()
local REPR = REPRRegistry.get_REPR_by_name("KnowHOWREPR");
local KnowHOW = REPR:type_object_for(nil, nil);
local KnowHOW = REPR.type_object_for(REPR, nil, nil);

local KnowHOWMeths = {};
KnowHOWMeths.new_type = CodeObjectUtility.WrapNativeMethod(
function (TC, Ignored, Cap)
local KnowHOWTypeObj = CaptureHelper.GetPositional(Cap, 1);
local HOW = KnowHOWTypeObj.STable.REPR:instance_of(TC, KnowHOWTypeObj.STable.WHAT);
local REPR = KnowHOWTypeObj.STable.REPR;
local HOW = REPR.instance_of(REPR, TC, KnowHOWTypeObj.STable.WHAT);

local TypeName = CaptureHelper.GetNamed(Cap, "name");
HOW.Name = TypeName or Ops.box_str(TC, "<anon>");

local REPRName = CaptureHelper.GetNamed(Cap, "repr");
if (REPRName ~= nil) then
return REPRRegistry.get_REPR_by_name(Ops.unbox_str(nil, REPRName)):type_object_for(nil, HOW);
REPR = REPRRegistry.get_REPR_by_name(Ops.unbox_str(nil, REPRName));
return REPR.type_object_for(REPR, nil, HOW);
else
return REPRRegistry.get_REPR_by_name("P6opaque"):type_object_for(TC, HOW);
REPR = REPRRegistry.get_REPR_by_name("P6opaque");
return REPR.type_object_for(REPR, TC, HOW);
end
end);
KnowHOWMeths.add_attribute = CodeObjectUtility.WrapNativeMethod(
function (TC, Ignored, Cap)
local HOW = CaptureHelper.GetPositional(Cap, 1);
local Attr = CaptureHelper.GetPositional(Cap, 3);
HOW.Attributes:Add(Attr);
List.Add(HOW.Attributes, Attr);
return CaptureHelper.Nil(TC);
end);
KnowHOWMeths.add_method = CodeObjectUtility.WrapNativeMethod(
Expand Down Expand Up @@ -60,24 +63,28 @@ function KnowHOWBootstrapper.Bootstrap ()
function (TC, Ignored, Cap)
local HOW = CaptureHelper.GetPositional(Cap, 1);
local ListType = KnowHOWBootstrapper.MostDefinedListType(TC);
local Result = ListType.STable.REPR:instance_of(TC, ListType);
local REPR = ListType.STable.REPR;
local Result = REPR.instance_of(REPR, TC, ListType);
Result.Storage = HOW.Attributes;
return Result;
end);
KnowHOWMeths.methods = CodeObjectUtility.WrapNativeMethod(
function (TC, Ignored, Cap)
local HOW = CaptureHelper.GetPositional(Cap, 1);
local ListType = KnowHOWBootstrapper.MostDefinedListType(TC);
local Result = ListType.STable.REPR:instance_of(TC, ListType);
local REPR = ListType.STable.REPR;
local Result = REPR.instance_of(REPR, TC, ListType);
local store = Result.Storage;
for key, value in pairs(HOW.Methods) do
Result.Storage:Add(value);
List.Add(store, value);
end
return Result;
end);
KnowHOWMeths.parents = CodeObjectUtility.WrapNativeMethod(
function (TC, Ignored, Cap)
local ListType = KnowHOWBootstrapper.MostDefinedListType(TC);
return ListType.STable.REPR:instance_of(TC, ListType);
local REPR = ListType.STable.REPR;
return REPR.instance_of(REPR, TC, ListType);
end);
KnowHOWMeths.type_check = CodeObjectUtility.WrapNativeMethod(
function (TC, Ignored, Cap)
Expand All @@ -86,7 +93,7 @@ function KnowHOWBootstrapper.Bootstrap ()
return Ops.box_int(TC, self.STable.WHAT == check.STable.WHAT and 1 or 0, TC.DefaultBoolBoxType);
end);

local KnowHOWHOW = REPR:instance_of(nil, KnowHOW);
local KnowHOWHOW = REPR.instance_of(REPR, nil, KnowHOW);
for key, value in pairs(KnowHOWMeths) do
KnowHOWHOW.Methods[key] = value;
end
Expand All @@ -111,9 +118,11 @@ function KnowHOWBootstrapper.Bootstrap ()
end

function KnowHOWBootstrapper.SetupKnowHOWAttribute (KnowHOW)
local HOW = KnowHOW.STable.REPR:instance_of(nil, KnowHOW);
local REPR = KnowHOW.STable.REPR;
local HOW = REPR.instance_of(REPR, nil, KnowHOW);

local KnowHOWAttribute = REPRRegistry.get_REPR_by_name("P6str"):type_object_for(null, HOW);
REPR = REPRRegistry.get_REPR_by_name("P6str");
local KnowHOWAttribute = REPR.type_object_for(REPR, null, HOW);

HOW.Methods.new = CodeObjectUtility.WrapNativeMethod(
function (TC, Code, Cap)
Expand Down
27 changes: 12 additions & 15 deletions lua/runtime/Metamodel/KnowHOW/KnowHOWREPR.lua
@@ -1,49 +1,46 @@

function makeKnowHOWREPR ()
local KnowHOWREPR = {};
local KnowHOWREPR = { ["class"] = "KnowHOWREPR" };
local mt = { __index = KnowHOWREPR };

local makeInstance = function ()
local Instance = {};
local Instance = { ["class"] = "KnowHOW" };
local mt = { __index = Instance };
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "KnowHOW";
return setmetatable(instance, mt);
local this = {};
this.STable = STable;
return setmetatable(this, mt);
end
return Instance;
end
local Instance = makeInstance();

function KnowHOWREPR.new()
local this = {};
this.class = "KnowHOWREPR";
return setmetatable(this, mt);
return setmetatable({}, mt);
end
KnowHOWREPR[1] = KnowHOWREPR.new;
function KnowHOWREPR:type_object_for(TC, MetaPackage)
local STable = SharedTable.new();
STable.HOW = MetaPackage;
STable.REPR = self;
STable.WHAT = Instance.new(STable);
return STable.WHAT;
end
KnowHOWREPR[2] = KnowHOWREPR.type_object_for;
function KnowHOWREPR:instance_of(TC, WHAT)
local Object = Instance.new(WHAT.STable);
Object.Methods = {};
Object.Attributes = List.new();
return Object;
end
KnowHOWREPR[3] = KnowHOWREPR.instance_of;
function KnowHOWREPR:defined(TC, Obj)
if (Obj.Methods ~= nil) then
return true;
else
return false;
end
return Obj.Methods ~= nil;
end
KnowHOWREPR[4] = KnowHOWREPR.defined;
function KnowHOWREPR:hint_for(TC, ClassHandle, Name)
return Hints.NO_Hint;
end
KnowHOWREPR[5] = KnowHOWREPR.hint_for;
return KnowHOWREPR;
end
KnowHOWREPR = makeKnowHOWREPR();
4 changes: 4 additions & 0 deletions lua/runtime/Metamodel/REPRRegistry.lua
Expand Up @@ -7,19 +7,23 @@ function makeREPRRegistry ()
function REPRRegistry.new()
return setmetatable({}, mt);
end
REPRRegistry[1] = REPRRegistry.new;
function REPRRegistry.register_REPR(Name, REPR)
Registry:Add(REPR);
REPR.class = Name;
local ID = Registry.Count;
NamedToIDMapper:Add(Name, ID);
return ID;
end
REPRRegistry[2] = REPRRegistry.register_REPR;
function REPRRegistry.get_REPR_by_id(ID)
return Registry[ID];
end
REPRRegistry[3] = REPRRegistry.get_REPR_by_id;
function REPRRegistry.get_REPR_by_name(Name)
return Registry[NamedToIDMapper[Name]];
end
REPRRegistry[4] = REPRRegistry.get_REPR_by_name;
return REPRRegistry;
end
REPRRegistry = makeREPRRegistry();
Expand Down
24 changes: 11 additions & 13 deletions lua/runtime/Metamodel/Representations/P6capture.lua
@@ -1,46 +1,44 @@

function makeP6capture ()
local P6capture = {};
local P6capture = { ["class"] = "P6captureREPR" };
local mt = { __index = P6capture };

local makeInstance = function ()
local Instance = {};
local Instance = { ["class"] = "P6capture"};
local mt = { __index = Instance };
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6capture";
return setmetatable(instance, mt);
local this = {};
this.STable = STable;
return setmetatable(this, mt);
end
return Instance;
end
local Instance = makeInstance();

function P6capture.new()
local this = {};
this.class = "P6captureREPR";
return setmetatable(this, mt);
end
P6capture[1] = P6capture.new;
function P6capture:type_object_for(TC, MetaPackage)
local STable = SharedTable.new();
STable.HOW = MetaPackage;
STable.REPR = self;
STable.WHAT = Instance.new(STable);
return STable.WHAT;
end
P6capture[2] = P6capture.type_object_for;
function P6capture:instance_of(TC, WHAT)
return Instance.new(WHAT.STable);
end
P6capture[3] = P6capture.instance_of;
function P6capture:defined(TC, Obj)
if (Obj.Positionals ~= nil or Obj.Nameds ~= nil) then
return true;
else
return false;
end
return Obj.Positionals ~= nil or Obj.Nameds ~= nil;
end
P6capture[4] = P6capture.defined;
function P6capture:hint_for(TC, ClassHandle, Name)
return Hints.NO_HINT;
end
P6capture[5] = P6capture.hint_for;
return P6capture;
end
P6capture = makeP6capture();
31 changes: 18 additions & 13 deletions lua/runtime/Metamodel/Representations/P6hash.lua
@@ -1,63 +1,68 @@

function makeP6hash ()
local P6hash = {};
local P6hash = { ["class"] = "P6hashREPR" };
local mt = { __index = P6hash };

-- inner class
local makeInstance = function ()
local Instance = {};
local Instance = { ["class"] = "P6hash" };
local mt = { __index = Instance };
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6hash";
return setmetatable(instance, mt);
local this = {};
this.STable = STable;
return setmetatable(this, mt);
end
return Instance;
end
local Instance = makeInstance();

function P6hash.new()
local this = {};
this.class = "P6hashREPR";
return setmetatable(this, mt);
return setmetatable({}, mt);
end
P6hash[1] = P6hash.new;
function P6hash:type_object_for(TC, MetaPackage)
local STable = SharedTable.new();
STable.HOW = MetaPackage;
STable.REPR = self;
STable.WHAT = Instance.new(STable);
return STable.WHAT;
end
P6hash[2] = P6hash.type_object_for;
function P6hash:instance_of(TC, WHAT)
local Object = Instance.new(WHAT.STable);
Object.Storage = {};
return Object;
end
P6hash[3] = P6hash.instance_of;
function P6hash:defined(TC, O)
return O.Storage ~= nil;
end
P6hash[4] = P6hash.defined;
function P6hash:hint_for(TC, ClassHandle, Name)
return Hints.NO_HINT;
end
P6hash[5] = P6hash.hint_for;
function P6hash:get_attribute(TC, I, ClassHandle, Name)
if (I.Storage ~= nil or I.Storage[ClassHandle] == nil) then
return nil;
end
return I.Storage[ClassHandle][Name];
end
P6hash[6] = P6hash.get_attribute;
function P6hash:get_attribute_with_hint(TC, I, ClassHandle, Name, Hint)
return self:get_attribute(TC, Object, ClassHandle, Name);
end
P6hash[7] = P6hash.get_attribute_with_hint;
function P6hash:bind_attribute(TC, Object, ClassHandle, Name, Value)
Object.Storage = Object.Storage or {};
local ClassStore = Object.Storage[ClassHandle] or {};
Object.Storage[ClassHandle] = ClassStore;
ClassStore[Name] = Value;
end
P6hash[8] = P6hash.bind_attribute;
function P6hash:bind_attribute_with_hint(TC, Object, ClassHandle, Name, Hint, Value)
self:bind_attribute(TC, Object, ClassHandle, Name, Value);
end
function P6hash:hint_for(TC, ClassHandle, Name)
return Hints.NO_HINT;
end
P6hash[9] = P6hash.bind_attribute_with_hint;
return P6hash;
end
P6hash = makeP6hash();

0 comments on commit 0cbe07e

Please sign in to comment.