Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
revert most of the last week's "progress"
  • Loading branch information
diakopter committed Nov 13, 2011
1 parent 6ec1991 commit ac8f6f4
Show file tree
Hide file tree
Showing 47 changed files with 578 additions and 612 deletions.
2 changes: 0 additions & 2 deletions dotnet/runtime/Metamodel/KnowHOW/KnowHOWBootstrapper.cs
Expand Up @@ -94,9 +94,7 @@ public static RakudoObject Bootstrap()
}));
KnowHOWMeths.Add("compose", CodeObjectUtility.WrapNativeMethod((TC, Ignored, Cap) =>
{
var HOW = CaptureHelper.GetPositional(Cap, 0) as KnowHOWREPR.KnowHOWInstance;
var Obj = CaptureHelper.GetPositional(Cap, 1);
Obj.STable.MethodCache = HOW.Methods;
return Obj;
}));
KnowHOWMeths.Add("attributes", CodeObjectUtility.WrapNativeMethod((TC, Ignored, Cap) =>
Expand Down
50 changes: 2 additions & 48 deletions lua/compiler/IndexersReplacements.txt
@@ -1,48 +1,2 @@
%.FormWith%( [1]( # on SharedTable
%.FindMethod%( [2]( # on SharedTable
%.Invoke%( [3]( # on SharedTable
%.TypeCheck%( [4]( # on SharedTable
%.REPR [5] # on SharedTable
%.HOW [6] # on SharedTable
%.WHAT [7] # on SharedTable
%.SpecialInvoke [8] # on SharedTable
%.CachedInvoke [9] # on SharedTable
%.TypeCheckCache [10] # on SharedTable
%.CachedFindMethod [11] # on SharedTable
%.TypeCacheID [12] # on SharedTable
%.new%( [1]( # all classes with constructors named new
%.CurrentContext [0] # dual purpose (ThreadContext and RakudoCodeRef instance)
%.OuterForNextInvocation [18] # on RakudoCodeRef
%.OuterBlock [19] # on RakudoCodeRef
%.StaticLexPad [20] # on RakudoCodeRef
Ops%.box_int%( Ops[1](
Ops%.box_num%( Ops[2](
Ops%.box_str%( Ops[3](
Ops%.unbox_int%( Ops[4](
Ops%.unbox_num%( Ops[5](
Ops%.unbox_str%( Ops[6](
Ops%.type_object_for%( Ops[43](
Ops%.instance_of%( Ops[44](
DefinednessConstraint%.None 0
DefinednessConstraint%.DefinedOnly 1
DefinednessConstraint%.UndefinedOnly 2
%.STable [1] # on every RakudoObject impl (inner classes of the repr classes)
%.Value [2] # some RakudoObject impl
%.Undefined [3] # some RakudoObject impl
%.Positionals [2] # on P6capture
%.Nameds [3] # on P6capture
%.type_object_for%( [2]( # all REPR impl
%.instance_of%( [3]( # all REPR impl
%.defined%( [4]( # all REPR impl
%.hint_for%( [5]( # all REPR impl
%.set_int%( [10]( # P6int
%.get_int%( [11]( # P6int
Hints%.NO_HINT=%-1 unused=0
Hints%.NO_HINT -1
%.DefaultStrBoxType [2] # on ThreadContext
%.DefaultBoolBoxType [3] # on ThreadContext
%.SlotMapping [5] # on LexPad
%.SlotCount [6] # on LexPad
%.Storage [0] # on LexPad and P6list
%.Outer [3] # on Context
%.StaticCodeObject [4] # on Context
%.STable [1]
%.FormWith%( [1](
23 changes: 0 additions & 23 deletions lua/compiler/LST.pm
Expand Up @@ -262,29 +262,6 @@ class LST::TryCatch is LST::Node {
}
}

class LST::TryCatchFinally is LST::Node {
has $!exception_type;
has $!exception_var;

method exception_type($set?) {
if $set { $!exception_type := $set }
$!exception_type
}

method exception_var($set?) {
if $set { $!exception_var := $set }
$!exception_var
}

method new(*@children, :$exception_type!, :$exception_var!) {
my $obj := self.CREATE;
$obj.exception_type($exception_type);
$obj.exception_var($exception_var);
$obj.set_children(@children);
$obj;
}
}

class LST::Throw is LST::Node {
method new() {
my $obj := self.CREATE;
Expand Down
68 changes: 12 additions & 56 deletions lua/compiler/LST2Lua.pm
@@ -1,4 +1,4 @@
# This compiles a Lua Syntax Tree down to Lua.
# This compiles a .Net Syntax Tree down to C#.
class LST2LuaCompiler;

method compile(LST::Node $node) {
Expand Down Expand Up @@ -125,80 +125,36 @@ our multi sub cs_for(LST::Stmts $stmts) {
our multi sub cs_for(LST::TryFinally $tf) {
unless +@($tf) == 2 { pir::die('LST::TryFinally nodes must have 2 children') }
my $try_result := get_unique_id('try_result');
my $code := " local ok2, exc2 = pcall(\n" ~
my $code := " try\{\n" ~
" function ()\n" ~
cs_for((@($tf))[0]);
$code := $code ~
" $try_result = $*LAST_TEMP;\n" ~
" end);\n";
# " local caught = false;\n" ~
# " if not ok then\n" ~
# " local is_table = type(exc) == \"table\"\n" ~
# " if is_table and exc.class == \"" ~ $tc.exception_type ~ "\" then\n" ~
# cs_for((@($tc))[1]);
$code := $code ~
# " caught = true\n" ~
# " $try_result = $*LAST_TEMP;\n" ~
# " end\n" ~
# " end\n" ~
" end\n" ~
" }.finally()\{\n" ~
" function (catchClass, exceptions, exc)\n" ~
cs_for((@($tf))[1]) ~
" if not ok2 then\n" ~
" error(exc2);\n" ~
" end\n";
" end\n" ~
" }\n";
$*LAST_TEMP := $try_result;
return $code;
}

our multi sub cs_for(LST::TryCatch $tc) {
unless +@($tc) == 2 { pir::die('LST::TryCatch nodes must have 2 children') }
my $try_result := get_unique_id('try_result');
my $code := " local ok, exc = pcall(\n" ~
my $code := " try\{\n" ~
" function ()\n" ~
cs_for((@($tc))[0]);
$code := $code ~
" $try_result = $*LAST_TEMP;\n" ~
" end);\n" ~
" local caught = false;\n" ~
" if not ok then\n" ~
" local is_table = type(exc) == \"table\"\n" ~
" if is_table and exc.class == \"" ~ $tc.exception_type ~ "\" then\n" ~
cs_for((@($tc))[1]);
$code := $code ~
" caught = true\n" ~
" $try_result = $*LAST_TEMP;\n" ~
" end\n" ~
" end\n" ~
# cs_for((@($tc))[2]) ~
" if exc ~= nil and not caught then\n" ~
" error(exc);\n" ~
" end\n";
$*LAST_TEMP := $try_result;
return $code;
}

our multi sub cs_for(LST::TryCatchFinally $tc) {
unless +@($tc) == 3 { pir::die('LST::TryCatchFinally nodes must have 3 children') }
my $try_result := get_unique_id('try_result');
my $code := " local ok, exc = pcall(\n" ~
" function ()\n" ~
cs_for((@($tc))[0]);
$code := $code ~
" }.except(\"" ~ $tc.exception_type ~ "\")\{\n" ~
" function (catchClass, exceptions, exc)\n" ~
cs_for((@($tc))[1]) ~
" $try_result = $*LAST_TEMP;\n" ~
" end);\n" ~
" local caught = false;\n" ~
" if not ok then\n" ~
" local is_table = type(exc) == \"table\"\n" ~
" if is_table and exc.class == \"" ~ $tc.exception_type ~ "\" then\n" ~
cs_for((@($tc))[1]);
$code := $code ~
" caught = true\n" ~
" $try_result = $*LAST_TEMP;\n" ~
" end\n" ~
" end\n" ~
cs_for((@($tc))[2]) ~
" if exc ~= nil and not caught then\n" ~
" error(exc);\n" ~
" end\n";
" }\n";
$*LAST_TEMP := $try_result;
return $code;
}
Expand Down
40 changes: 18 additions & 22 deletions lua/compiler/PAST2LSTCompiler.pm
Expand Up @@ -112,7 +112,7 @@ method compile(PAST::Node $node) {
# We fudge in a fake NQPStr, for the :repr('P6Str'). Bit hacky,
# but best I can think of for now. :-)
LST::MethodCall.new(
:on('StaticBlockInfo[1][20]'), :name('SetByName'), :void(1), :type('RakudoObject'),
:on('StaticBlockInfo[1].StaticLexPad'), :name('SetByName'), :void(1), :type('RakudoObject'),
LST::Literal.new( :value('NQPStr'), :escape(1) ),
'REPRRegistry[4]("P6str"):type_object_for(nil, nil)'
),
Expand All @@ -122,7 +122,7 @@ method compile(PAST::Node $node) {
$loadinit_calls,
LST::Call.new( :name('constants_init'), :void(1), TC() ),
$main_block_call,
"TC[0]"
"TC.CurrentContext"
));
}
else {
Expand Down Expand Up @@ -210,7 +210,7 @@ sub make_blocks_init_method($name) {
)
),
LST::Bind.new(
'StaticBlockInfo[0][0]',
'StaticBlockInfo[0].CurrentContext',
'TC.Domain.Setting'
),

Expand Down Expand Up @@ -241,15 +241,15 @@ sub make_constants_init_method($name) {
'StaticBlockInfo[1]',
LST::ArrayLiteral.new( :type('string') )
),
'TC[0]',
'TC.CurrentContext',
LST::Null.new()
)
),

# Create array for storing these.
LST::Bind.new(
loc('ConstantsTable', 'RakudoObject[]'),
'List.create(' ~ +@*CONSTANTS ~ ')'
'List.new(' ~ +@*CONSTANTS ~ ')'
)
);

Expand Down Expand Up @@ -362,7 +362,7 @@ our multi sub lst_for(PAST::Block $block) {
%handler<code> := lst_for(PAST::Block.new(PAST::Stmts.new(
PAST::Var.new( :name('$!'), :scope('parameter') ),
emit_op('leave_block',
LST::Literal.new( :value('TC[0].Outer.StaticCodeObject') ),
LST::Literal.new( :value('TC.CurrentContext.Outer.StaticCodeObject') ),
lst_for(PAST::Var.new( :name('$!'), :scope('lexical') ))
)
)));
Expand Down Expand Up @@ -395,17 +395,17 @@ our multi sub lst_for(PAST::Block $block) {
"StaticBlockInfo[$our_sbi]",
LST::ArrayLiteral.new( :type('string') ),
),
'TC[0]',
'TC.CurrentContext',
LST::Null.new()
)
),
LST::Bind.new( 'TC[0]', loc('C', 'Context') ),
LST::Bind.new( 'TC.CurrentContext', loc('C', 'Context') ),
LST::Bind.new(
"StaticBlockInfo[$our_sbi].Sig",
compile_signature(@*PARAMS)
),
$handlers_setup_placeholder,
LST::Bind.new( 'TC[0]', 'C.Caller' )
LST::Bind.new( 'TC.CurrentContext', 'C.Caller' )
));
@*SIGINITS.push(LST::Call.new( :name($sig_setup_block), :void(1), TC() ));

Expand All @@ -418,9 +418,9 @@ our multi sub lst_for(PAST::Block $block) {
# Wrap in block prelude/postlude.
$result.push(LST::Local.new(
:name('local C'), :isdecl(1), :type('Context'),
LST::New.new( :type('Context'), "Block", "TC[0]", loc("Capture") )
LST::New.new( :type('Context'), "Block", "TC.CurrentContext", loc("Capture") )
));
$result.push(LST::Bind.new( 'TC[0]', loc('C', 'Context') ));
$result.push(LST::Bind.new( 'TC.CurrentContext', loc('C', 'Context') ));
$result.push(LST::TryFinally.new(
LST::TryCatch.new(
:exception_type('LeaveStackUnwinderException'),
Expand All @@ -437,7 +437,7 @@ our multi sub lst_for(PAST::Block $block) {
"exc.PayLoad"
)
),
LST::Bind.new( 'TC[0]', 'C.Caller' )
LST::Bind.new( 'TC.CurrentContext', 'C.Caller' )
));

# Add nested inner blocks after it (.Net does not support
Expand Down Expand Up @@ -484,9 +484,8 @@ our multi sub lst_for(PAST::Block $block) {
# low level code object.
if $block.blocktype eq 'immediate' {
return LST::MethodCall.new(
:name('[1][3]'), :type('RakudoObject'),
:name('[1]:Invoke'), :type('RakudoObject'),
"StaticBlockInfo[$our_sbi]",
"StaticBlockInfo[$our_sbi][1]",
TC(),
"StaticBlockInfo[$our_sbi]",
LST::MethodCall.new(
Expand Down Expand Up @@ -591,22 +590,20 @@ our multi sub lst_for(PAST::Op $op) {
my $callee := LST::Local.new(
:name(get_unique_id('callee')), :isdecl(1), :type('RakudoObject'),
LST::MethodCall.new(
:on($inv.name ~ '[1]'), :name('[2]'), :type('RakudoObject'),
$inv.name ~ '[1]',
:on($inv.name), :name('[1]:FindMethod'), :type('RakudoObject'),
TC(),
$inv.name,
$name,
'-1'
'Hints.NO_HINT'
)
);

# Emit the call.
return LST::Stmts.new(
$inv,
LST::MethodCall.new(
:name('[1][3]'), :type('RakudoObject'),
:name('[1]:Invoke'), :type('RakudoObject'),
$callee,
$callee.name ~ '[1]',
TC(),
$callee.name,
form_capture(@args, $inv)
Expand All @@ -632,9 +629,8 @@ our multi sub lst_for(PAST::Op $op) {

# Emit call.
return LST::MethodCall.new(
:name('[1][3]'), :type('RakudoObject'),
:name('[1]:Invoke'), :type('RakudoObject'),
$callee,
$callee.name ~ '[1]',
TC(),
$callee.name,
form_capture(@args)
Expand Down Expand Up @@ -1727,7 +1723,7 @@ sub temp_str($arg?, :$name) {
# Emits a boxing operation to an int/num/str.
sub box($type, $arg) {
LST::MethodCall.new(
:on('Ops'), :name($type eq 'str' ?? '[3]' !! $type eq 'int' ?? '[1]' !! '[2]'), :type('RakudoObject'),
:on('Ops'), :name("box_$type"), :type('RakudoObject'),
TC(), lst_for($arg)
)
}
Expand Down
8 changes: 4 additions & 4 deletions lua/runtime/Dictionary.lua
@@ -1,14 +1,14 @@
function makeDictionary ()
local Dictionary = {};
local mt = { __index = Dictionary };
function Dictionary.new ()
function Dictionary.new()
return setmetatable({}, mt);
end
Dictionary[1] = Dictionary.new;
function Dictionary:Add (key, value)
Dictionary[0] = Dictionary.new;
function Dictionary:Add(key, value)
self[key] = value;
end
Dictionary[2] = Dictionary.Add;
Dictionary[1] = Dictionary.Add;
return Dictionary;
end
Dictionary = makeDictionary();
2 changes: 1 addition & 1 deletion lua/runtime/Init.lua
Expand Up @@ -154,7 +154,7 @@ function makeInit ()
local List = tmp1.instance_of(tmp1, TC, NQPList);
local NativeCapture = C;
for unused, Obj in ipairs(NativeCapture.Positionals) do
List.Add(List.Storage, Obj);
List.Storage:Add(Obj);
end
return List;
end),
Expand Down

0 comments on commit ac8f6f4

Please sign in to comment.