Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
oodles of fixes. many many more to come.
  • Loading branch information
diakopter committed Nov 2, 2011
1 parent 37485f2 commit 358cadd
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lua/compiler/LST2Lua.pm
Expand Up @@ -140,7 +140,7 @@ our multi sub cs_for(LST::MethodCall $mc) {
my $method_name := $invocant ~ '.' ~ $mc.name;
$code := $code ~ "$*LAST_TEMP = ";
}
$code := $code ~ "$invocant" ~ (($mc.name ~~ /":"/ || $invocant eq "Ops" || $invocant eq "SignatureBinder" || $invocant eq "CaptureHelper" || $invocant eq "CodeObjectUtility" || $invocant eq "Init" || $invocant eq "SignatureBinder" || $invocant eq "SignatureBinder" || $invocant eq "SignatureBinder" || $invocant eq "SignatureBinder" || $invocant eq "SignatureBinder" || $invocant eq "SignatureBinder" || $invocant eq "SignatureBinder") ?? "." !! ":") ~ $mc.name ~
$code := $code ~ "$invocant" ~ (($mc.name ~~ /":"/ || $invocant eq "Ops" || $invocant eq "SignatureBinder" || $invocant eq "CaptureHelper" || $invocant eq "CodeObjectUtility" || $invocant eq "Init") ?? "." !! ":") ~ $mc.name ~
"(" ~ pir::join(', ', @arg_names) ~ ");\n";
return $code;
}
Expand Down
17 changes: 13 additions & 4 deletions lua/compiler/Makefile
Expand Up @@ -6,7 +6,7 @@ RM_RF = perl -MExtUtils::Command -e rm_f
RT_SRC = ../runtime/*.lua ../runtime/Metamodel/*.lua ../runtime/Metamodel/KnowHOW/*.lua ../runtime/Metamodel/Representations/*.lua ../runtime/Runtime/*.lua ../runtime/Runtime/Exceptions/*.lua ../runtime/Runtime/MultiDispatch/*.lua ../runtime/Runtime/Ops/*.lua ../runtime/Runtime/Signatures/*.lua
LUA = luajit

all: compile.pir gen_actions.pir gen_grammar.pir gen_nqpoptimizer.pir gen_lst.pir gen_past2lst.pir gen_lst2lua.pir NQPSetting.lua P6Objects.lua
all: P6Objects.lbc

gen_actions.pir: Actions.pm
parrot-nqp --target=pir Actions.pm > gen_actions.pir
Expand All @@ -29,17 +29,26 @@ gen_lst2lua.pir: LST2Lua.pm
RakudoRuntime.lua: $(RT_SRC)
$(CAT) $(RT_SRC) > RakudoRuntime.lua

NQPSetting.lua: compile.pir gen_actions.pir gen_grammar.pir gen_nqpoptimizer.pir gen_lst.pir gen_past2lst.pir gen_lst2lua.pir ../../common/NQP/NQPSetting.pm RakudoRuntime.lua
RakudoRuntime.lbc: RakudoRuntime.lua
luajit -b RakudoRuntime.lua RakudoRuntime.lbc

NQPSetting.lua: compile.pir gen_actions.pir gen_grammar.pir gen_nqpoptimizer.pir gen_lst.pir gen_past2lst.pir gen_lst2lua.pir ../../common/NQP/NQPSetting.pm RakudoRuntime.lbc
parrot compile.pir ../../common/NQP/NQPSetting.pm --setting > NQPSetting.lua

P6Objects.lua: compile.pir gen_actions.pir gen_grammar.pir gen_nqpoptimizer.pir gen_lst.pir gen_past2lst.pir gen_lst2lua.pir ../../common/NQP/P6Objects.pm NQPSetting.lua
NQPSetting.lbc: NQPSetting.lua
luajit -b NQPSetting.lua NQPSetting.lbc

P6Objects.lua: compile.pir gen_actions.pir gen_grammar.pir gen_nqpoptimizer.pir gen_lst.pir gen_past2lst.pir gen_lst2lua.pir ../../common/NQP/P6Objects.pm NQPSetting.lbc
parrot compile.pir ../../common/NQP/P6Objects.pm --no-core-libs > P6Objects.lua

P6Objects.lbc: P6Objects.lua
luajit -b P6Objects.lua P6Objects.lbc

test: all
prove -r --exec try ..\..\t\nqp

test-unixy: all
prove -r --exec ./try.sh ../../t/nqp

clean:
$(RM_RF) gen_*.pir *.lua
$(RM_RF) gen_*.pir *.lua *.lbc
2 changes: 1 addition & 1 deletion lua/compiler/PAST2LSTCompiler.pm
Expand Up @@ -142,7 +142,7 @@ method compile(PAST::Node $node) {
:return_type('void'),
LST::Local.new( :name('TC'), :isdecl(1), :type('ThreadContext'),
LST::MethodCall.new(
:on('Rakudo.Init'), :name('Initialize'), :type('ThreadContext'),
:on('Init'), :name('Initialize'), :type('ThreadContext'),
LST::Literal.new( :value('NQPSetting'), :escape(1) )
)
),
Expand Down
70 changes: 69 additions & 1 deletion lua/runtime/Init.lua
Expand Up @@ -71,7 +71,75 @@ function makeInit ()
REPRS_Registered = true;
end
end


function Init.BootstrapSetting(KnowHOW, KnowHOWAttribute)
local SettingContext = Context.new();
SettingContext.LexPad = new Lexpad(
{ "KnowHOW", "KnowHOWAttribute", "capture", "NQPInt", "NQPNum", "NQPStr", "NQPList", "NQPCode", "list", "NQPArray", "NQPHash" });
SettingContext.LexPad.Storage =
{
KnowHOW,
KnowHOWAttribute,
REPRRegistry.get_REPR_by_name("P6capture"):type_object_for(nil, nil),
REPRRegistry.get_REPR_by_name("P6int"):type_object_for(nil, nil),
REPRRegistry.get_REPR_by_name("P6num"):type_object_for(nil, nil),
REPRRegistry.get_REPR_by_name("P6str"):type_object_for(nil, nil),
REPRRegistry.get_REPR_by_name("P6list"):type_object_for(nil, nil),
REPRRegistry.get_REPR_by_name("RakudoCodeRef"):type_object_for(nil, KnowHOW.STable.REPR.instance_of(nil, KnowHOW)),
CodeObjectUtility.WrapNativeMethod(function (TC, self, C)
local NQPList = Ops.get_lex(TC, "NQPList");
local List = NQPList.STable.REPR.instance_of(TC, NQPList);
local NativeCapture = C;
for unused, Obj in ipairs(NativeCapture.Positionals) do
List.Storage:Add(Obj);
end
return List;
end),
nil,
nil
};
return SettingContext;
end

function Init.LoadSetting(Name, KnowHOW, KnowHOWAttribute)
local success, SettingContext;
success, SettingContext = pcall(function ()
dofile(Name .. '.lbc')
end);
if not success then
SettingContext = dofile(Name .. '.lua');
end
SettingContext.LexPad:Extend(
{ "KnowHOW", "KnowHOWAttribute", "print", "say", "capture" });
SettingContext.LexPad:SetByName("KnowHOW", KnowHOW);
SettingContext.LexPad:SetByName("KnowHOWAttribute", KnowHOWAttribute);
SettingContext.LexPad:SetByName("print",
CodeObjectUtility.WrapNativeMethod(function (TC, self, C)
for i = 1, CaptureHelper.NumPositionals(C) do
local Value = CaptureHelper.GetPositional(C, i);
local StrMeth = self.STable:FindMethod(TC, Value, "Str", 0);
local StrVal = StrMeth.STable:Invoke(TC, StrMeth,
CaptureHelper.FormWith( { Value }));
io.write(Ops.unbox_str(nil, StrVal));
end
return CaptureHelper.Nil();
end));
SettingContext.LexPad.SetByName("say",
CodeObjectUtility.WrapNativeMethod(function (TC, self, C)
for i = 1, CaptureHelper.NumPositionals(C) do
local Value = CaptureHelper.GetPositional(C, i);
local StrMeth = self.STable:FindMethod(TC, Value, "Str", 0);
local StrVal = StrMeth.STable:Invoke(TC, StrMeth,
CaptureHelper.FormWith( { Value }));
io.write(Ops.unbox_str(nil, StrVal), "\n");
end
return CaptureHelper.Nil();
end));
SettingContext.LexPad:SetByName("capture", REPRRegistry.get_REPR_by_name("P6capture"):type_object_for(nil, nil));

return SettingContext;
end

return Init;
end
Init = makeInit();
Expand Down
9 changes: 8 additions & 1 deletion lua/runtime/List.lua
Expand Up @@ -18,10 +18,17 @@ function makeList ()
error("Cannot pop from an empty list");
end
local item = self[idx];
self[idx] = nil;
table.remove(self, idx);
self.Count = self.Count - 1;
return item;
end
function List:Peek()
local idx = self.Count;
if (idx < 1) then
error("Cannot peek into an empty list");
end
return self[idx];
end
function List:Truncate(length)
local count = self.Count;
if (length < count) then
Expand Down
22 changes: 12 additions & 10 deletions lua/runtime/Metamodel/KnowHOW/KnowHOWREPR.lua
@@ -1,45 +1,47 @@

function makeKnowHowREPR ()
local KnowHowREPR = {};
local mt = { __index = KnowHowREPR };
function makeKnowHOWREPR ()
local KnowHOWREPR = {};
local mt = { __index = KnowHOWREPR };

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

function KnowHowREPR.new()
function KnowHOWREPR.new()
return setmetatable({}, mt);
end
function KnowHowREPR:type_object_for(TC, MetaPackage)
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
function KnowHowREPR:instance_of(TC, WHAT)
function KnowHOWREPR:instance_of(TC, WHAT)
local Object = Instance.new(WHAT.STable);
Object.Methods = {};
Object.Attributes = List.new();
return Object;
end
function KnowHowREPR:defined(TC, Obj)
function KnowHOWREPR:defined(TC, Obj)
if (Obj.Methods ~= nil) then
return true;
else
return false;
end
end
function KnowHowREPR:hint_for(TC, ClassHandle, Name)
function KnowHOWREPR:hint_for(TC, ClassHandle, Name)
return Hints.NO_Hint;
end
return KnowHowREPR;
return KnowHOWREPR;
end
KnowHowREPR = makeKnowHowREPR();
KnowHOWREPR = makeKnowHOWREPR();
8 changes: 4 additions & 4 deletions lua/runtime/Metamodel/REPRRegistry.lua
Expand Up @@ -8,15 +8,15 @@ function makeREPRRegistry ()
return setmetatable({}, mt);
end
function REPRRegistry.register_REPR(Name, REPR)
Registry.Add(REPR);
Registry:Add(REPR);
local ID = Registry.Count + 1;
NamedToIDMapper.Add(Name, ID);
NamedToIDMapper:Add(Name, ID);
return ID;
end
function get_REPR_by_id(ID)
function REPRRegistry.get_REPR_by_id(ID)
return Registry[ID];
end
function get_REPR_by_name(Name)
function REPRRegistry.get_REPR_by_name(Name)
return Registry[NamedToIDMapper[Name]];
end
return REPRRegistry;
Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6capture.lua
Expand Up @@ -9,8 +9,10 @@ function makeP6capture ()
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6capture";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6hash.lua
Expand Up @@ -10,8 +10,10 @@ function makeP6hash ()
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6hash";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6int.lua
Expand Up @@ -12,8 +12,10 @@ function makeP6int ()
instance.STable = STable;
instance.Undefined = false;
instance.Value = 0;
instance.class = "P6int";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6list.lua
Expand Up @@ -9,8 +9,10 @@ function makeP6list ()
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6list";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6mapping.lua
Expand Up @@ -9,8 +9,10 @@ function makeP6mapping ()
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6mapping";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6num.lua
Expand Up @@ -12,8 +12,10 @@ function makeP6num ()
instance.STable = STable;
instance.Undefined = false;
instance.Value = 0.0;
instance.class = "P6num";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6opaque.lua
Expand Up @@ -10,8 +10,10 @@ function makeP6opaque ()
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6opaque";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/P6str.lua
Expand Up @@ -10,8 +10,10 @@ function makeP6str ()
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "P6str";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();

Expand Down
2 changes: 2 additions & 0 deletions lua/runtime/Metamodel/Representations/RakudoCodeRef.lua
Expand Up @@ -9,8 +9,10 @@ function makeRakudoCodeRef ()
function Instance.new(STable)
local instance = {};
instance.STable = STable;
instance.class = "RakudoCodeRef";
return setmetatable(instance, mt);
end
return Instance;
end
local Instance = makeInstance();
RakudoCodeRef.Instance = Instance;
Expand Down
1 change: 1 addition & 0 deletions lua/runtime/Metamodel/SharedTable.lua
Expand Up @@ -42,5 +42,6 @@ function makeSharedTable ()
return Meth.STable.Invoke(TC, Meth, Cap);
end
end
return SharedTable;
end
SharedTable = makeSharedTable();

0 comments on commit 358cadd

Please sign in to comment.