Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more fixes; Setting begins to compile.
  • Loading branch information
diakopter committed Nov 2, 2011
1 parent de55f49 commit c7d3c7d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
10 changes: 3 additions & 7 deletions lua/compiler/LST2Lua.pm
Expand Up @@ -34,15 +34,11 @@ our multi sub cs_for(LST::Using $using) {
}

our multi sub cs_for(LST::Class $class) {
my $code := '';
#if $class.namespace {
# $code := $code ~ 'namespace ' ~ $class.namespace ~ " \{\n";
#}
$code := $code ~ $class.name ~ "= (function ()\n";
my $code := "return (function ()\n";
for @($class) {
$code := $code ~ cs_for($_);
}
$code := $code ~ "return Main or LoadSetting;\nend)();\n";
$code := $code ~ "return LoadSetting or Main;\nend)()();\n";
#if $class.namespace {
# $code := $code ~ "}\n";
#}
Expand Down Expand Up @@ -140,7 +136,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") ?? "." !! ":") ~ $mc.name ~
$code := $code ~ "$invocant" ~ (($mc.name eq 'STable.Invoke' || $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
12 changes: 6 additions & 6 deletions lua/compiler/PAST2LSTCompiler.pm
Expand Up @@ -128,7 +128,7 @@ method compile(PAST::Node $node) {
my @params;
@params.push('TC');
$class.push(LST::Method.new(
:name('Init'),
:name('Initialize'),
:params(@params),
:return_type('void'),
LST::Call.new( :name('blocks_init'), :void(1), TC() ),
Expand All @@ -146,7 +146,7 @@ method compile(PAST::Node $node) {
LST::Literal.new( :value('NQPSetting'), :escape(1) )
)
),
LST::Call.new( :name('Init'), :void(1), TC() ),
LST::Call.new( :name('Initialize'), :void(1), TC() ),
$main_block_call
));

Expand All @@ -155,7 +155,7 @@ method compile(PAST::Node $node) {
:name('Load'),
:params('TC', 'Setting'),
:return_type('RakudoObject'),
LST::Call.new( :name('Init'), :void(1), TC() ),
LST::Call.new( :name('Initialize'), :void(1), TC() ),
$main_block_call
));
}
Expand Down Expand Up @@ -477,7 +477,7 @@ our multi sub lst_for(PAST::Block $block) {
# low level code object.
if $block.blocktype eq 'immediate' {
return LST::MethodCall.new(
:name('STable:Invoke'), :type('RakudoObject'),
:name('STable.Invoke'), :type('RakudoObject'),
"StaticBlockInfo[$our_sbi]",
TC(),
"StaticBlockInfo[$our_sbi]",
Expand Down Expand Up @@ -595,7 +595,7 @@ our multi sub lst_for(PAST::Op $op) {
return LST::Stmts.new(
$inv,
LST::MethodCall.new(
:name('STable:Invoke'), :type('RakudoObject'),
:name('STable.Invoke'), :type('RakudoObject'),
$callee,
TC(),
$callee.name,
Expand All @@ -622,7 +622,7 @@ our multi sub lst_for(PAST::Op $op) {

# Emit call.
return LST::MethodCall.new(
:name('STable:Invoke'), :type('RakudoObject'),
:name('STable.Invoke'), :type('RakudoObject'),
$callee,
TC(),
$callee.name,
Expand Down
14 changes: 7 additions & 7 deletions lua/runtime/Init.lua
Expand Up @@ -73,8 +73,8 @@ function makeInit ()
end

function Init.BootstrapSetting(KnowHOW, KnowHOWAttribute)
local SettingContext = Context.new();
SettingContext.LexPad = new Lexpad(
local SettingContext = Context.newplain();
SettingContext.LexPad = Lexpad.new(
{ "KnowHOW", "KnowHOWAttribute", "capture", "NQPInt", "NQPNum", "NQPStr", "NQPList", "NQPCode", "list", "NQPArray", "NQPHash" });
SettingContext.LexPad.Storage =
{
Expand All @@ -85,10 +85,10 @@ function makeInit ()
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)),
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 List = NQPList.STable.REPR:instance_of(TC, NQPList);
local NativeCapture = C;
for unused, Obj in ipairs(NativeCapture.Positionals) do
List.Storage:Add(Obj);
Expand All @@ -103,9 +103,9 @@ function makeInit ()

function Init.LoadSetting(Name, KnowHOW, KnowHOWAttribute)
local success, SettingContext;
success, SettingContext = pcall(function ()
dofile(Name .. '.lbc')
end);
--success, SettingContext = pcall(function ()
-- dofile(Name .. '.lbc')
--end);
if not success then
SettingContext = dofile(Name .. '.lua');
end
Expand Down
4 changes: 2 additions & 2 deletions lua/runtime/Metamodel/KnowHOW/KnowHOWBootstrapper.lua
Expand Up @@ -111,13 +111,13 @@ function KnowHOWBootstrapper.SetupKnowHOWAttribute (KnowHOW)

HOW.Methods.new = CodeObjectUtility.WrapNativeMethod(
function (TC, Code, Cap)
local WHAT = CaptureHelper.GetPositional(Cap, 0).STable.WHAT;
local WHAT = CaptureHelper.GetPositional(Cap, 1).STable.WHAT;
local Name = Ops.unbox_str(TC, CaptureHelper.GetNamed(Cap, "name"));
return Ops.box_str(TC, Name, WHAT);
end);
HOW.Methods.name = CodeObjectUtility.WrapNativeMethod(
function (TC, Code, Cap)
local self = CaptureHelper.GetPositional(Cap, 0);
local self = CaptureHelper.GetPositional(Cap, 1);
return Ops.box_str(TC, Ops.unbox_str(TC, self), TC.DefaultStrBoxType);
end);

Expand Down
6 changes: 5 additions & 1 deletion lua/runtime/Runtime/Context.lua
@@ -1,6 +1,10 @@
function makeContext ()
local Context = {};
local mt = { __index = Context };
function Context.newplain()
local this = {};
return setmetatable(this, mt);
end
function Context.new(StaticCodeObject, Caller, Capture)
local this = {};
this.StaticCodeObject = StaticCodeObject;
Expand All @@ -26,7 +30,7 @@ function makeContext ()
break;
end

local OuterContext = Context.new();
local OuterContext = Context.newplain();
OuterContext.StaticCodeObject = OuterBlock;
OuterContext.LexPad = OuterBlock.StaticLexPad;
CurContext.Outer = OuterContext;
Expand Down

0 comments on commit c7d3c7d

Please sign in to comment.