Skip to content

Commit

Permalink
more minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
diakopter committed Nov 9, 2011
1 parent 98852e3 commit a7073fd
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 104 deletions.
10 changes: 9 additions & 1 deletion lua/compiler/IndexersReplacements.txt
Expand Up @@ -10,6 +10,9 @@
%.TypeCheckCache [10] # 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](
Expand All @@ -27,4 +30,9 @@ Ops%.instance_of%( Ops[44](
Hints%.NO_HINT=%-1 unused=0
Hints%.NO_HINT -1
%.DefaultStrBoxType [2] # on ThreadContext
%.DefaultBoolBoxType [3] # 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
2 changes: 1 addition & 1 deletion 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].StaticLexPad'), :name('SetByName'), :void(1), :type('RakudoObject'),
:on('StaticBlockInfo[1][20]'), :name('SetByName'), :void(1), :type('RakudoObject'),
LST::Literal.new( :value('NQPStr'), :escape(1) ),
'REPRRegistry[4]("P6str"):type_object_for(nil, nil)'
),
Expand Down
46 changes: 26 additions & 20 deletions lua/runtime/Runtime/Context.lua
Expand Up @@ -9,29 +9,35 @@ function makeContext ()

StaticCodeObject.CurrentContext = this;

this.LexPad = Lexpad.new({});
this.LexPad.SlotMapping = StaticCodeObject.StaticLexPad.SlotMapping;
this.LexPad.Storage = table_clone(StaticCodeObject.StaticLexPad.Storage);
local lexpad = Lexpad.new({});
this.LexPad = lexpad;
local staticCodeObject = StaticCodeObject.StaticLexPad;
lexpad.SlotMapping = staticCodeObject.SlotMapping;
lexpad.Storage = table_clone(staticCodeObject.Storage);

if (StaticCodeObject.OuterForNextInvocation ~= nil) then
this.Outer = StaticCodeObject.OuterForNextInvocation;
elseif (StaticCodeObject.OuterBlock.CurrentContext ~= nil) then
this.Outer = StaticCodeObject.OuterBlock.CurrentContext;
local outer = StaticCodeObject.OuterForNextInvocation;
if (outer ~= nil) then
this.Outer = outer;
else
local CurContext = this;
local OuterBlock = StaticCodeObject.OuterBlock;
while (OuterBlock ~= nil) do
if (OuterBlock.CurrentContext ~= nil) then
CurContext.Outer = OuterBlock.CurrentContext;
break;
local cur = StaticCodeObject.OuterBlock.CurrentContext;
if (cur ~= nil) then
this.Outer = cur;
else
local CurContext = this;
local OuterBlock = StaticCodeObject.OuterBlock;
while (OuterBlock ~= nil) do
if (OuterBlock.CurrentContext ~= nil) then
CurContext.Outer = OuterBlock.CurrentContext;
break;
end

local OuterContext = Context.newplain();
OuterContext.StaticCodeObject = OuterBlock;
OuterContext.LexPad = OuterBlock.StaticLexPad;
CurContext.Outer = OuterContext;
CurContext = OuterContext;
OuterBlock = OuterBlock.OuterBlock;
end

local OuterContext = Context.newplain();
OuterContext.StaticCodeObject = OuterBlock;
OuterContext.LexPad = OuterBlock.StaticLexPad;
CurContext.Outer = OuterContext;
CurContext = OuterContext;
OuterBlock = OuterBlock.OuterBlock;
end
end
return setmetatable(this, mt);
Expand Down
21 changes: 12 additions & 9 deletions lua/runtime/Runtime/Lexpad.lua
Expand Up @@ -3,12 +3,14 @@ function makeLexpad ()
local mt = { __index = Lexpad };
function Lexpad.new (SlotNames)
local this = {};
this.SlotMapping = {};
local mapping = {};
this.SlotMapping = mapping;
for k,v in ipairs(SlotNames) do
this.SlotMapping[v] = k;
mapping[v] = k;
end
this.SlotCount = #SlotNames;
this.Storage = List.create(this.SlotCount);
local count = #SlotNames;
this.SlotCount = count;
this.Storage = List.create(count);
return setmetatable(this, mt);
end
Lexpad[1] = Lexpad.new;
Expand All @@ -25,16 +27,17 @@ function makeLexpad ()
for k,v in pairs(self.SlotMapping) do
SlotMapping[k] = v;
end
local SlotCount = self.Storage.Count;
for k,v in ipairs(Names) do
SlotMapping[v] = self.Storage.Count + k;
SlotMapping[v] = SlotCount + k;
end
self.SlotMapping = SlotMapping;
local new = self.Storage.Count + #Names;
local NewStorage = List.create(new);
for i = 1, self.Storage.Count do
local newSlotCount = SlotCount + #Names;
local NewStorage = List.create(newSlotCount);
for i = 1, SlotCount do
NewStorage[i] = self.Storage[i];
end
self.SlotCount = new;
self.SlotCount = newSlotCount;
self.Storage = NewStorage;
end
Lexpad[4] = Lexpad.Extend;
Expand Down
12 changes: 6 additions & 6 deletions lua/runtime/Runtime/Ops/Coercion.lua
@@ -1,29 +1,29 @@
function Ops.coerce_int_to_str(TC, Int, TargetType)
function Ops.coerce_int_to_str (TC, Int, TargetType)
return Ops.box_str(TC, "".. Ops.unbox_int(TC, Int), TargetType);
end
Ops[7] = Ops.coerce_int_to_str;

function Ops.coerce_num_to_str(TC, Int, TargetType)
function Ops.coerce_num_to_str (TC, Int, TargetType)
return Ops.box_str(TC, "".. Ops.unbox_num(TC, Int), TargetType);
end
Ops[8] = Ops.coerce_num_to_str;

function Ops.coerce_int_to_num(TC, Int, TargetType)
function Ops.coerce_int_to_num (TC, Int, TargetType)
return Ops.box_num(TC, Ops.unbox_int(TC, Int), TargetType);
end
Ops[9] = Ops.coerce_int_to_num;

function Ops.coerce_num_to_int(TC, Num, TargetType)
function Ops.coerce_num_to_int (TC, Num, TargetType)
return Ops.box_int(TC, Ops.unbox_num(TC, Int), TargetType);
end
Ops[10] = Ops.coerce_num_to_int;

function Ops.coerce_str_to_int(TC, Str, TargetType)
function Ops.coerce_str_to_int (TC, Str, TargetType)
return Ops.box_int(TC, 0 + Ops.unbox_str(TC, Str), TargetType);
end
Ops[11] = Ops.coerce_str_to_int;

function Ops.coerce_str_to_num(TC, Str, TargetType)
function Ops.coerce_str_to_num (TC, Str, TargetType)
return Ops.box_num(TC, 0 + Ops.unbox_str(TC, Str), TargetType);
end
Ops[12] = Ops.coerce_str_to_num;
32 changes: 16 additions & 16 deletions lua/runtime/Runtime/Ops/Comparison.lua
@@ -1,79 +1,79 @@
function Ops.equal_nums(TC, x, y)
function Ops.equal_nums (TC, x, y)
return x == y and 1 or 0;
end
Ops[13] = Ops.equal_nums;

function Ops.equal_ints(TC, x, y)
function Ops.equal_ints (TC, x, y)
return x == y and 1 or 0;
end
Ops[14] = Ops.equal_ints;

function Ops.equal_strs(TC, x, y)
function Ops.equal_strs (TC, x, y)
return x == y and 1 or 0;
end
Ops[15] = Ops.equal_strs;

function Ops.equal_refs(TC, x, y)
function Ops.equal_refs (TC, x, y)
return Ops.box_int(TC, x == y and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[16] = Ops.equal_refs;

function Ops.less_than_nums(TC, x, y)
function Ops.less_than_nums (TC, x, y)
return Ops.box_int(TC, Ops.unbox_num(TC, x) < Ops.unbox_num(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[17] = Ops.less_than_nums;

function Ops.less_than_ints(TC, x, y)
function Ops.less_than_ints (TC, x, y)
return Ops.box_int(TC, Ops.unbox_int(TC, x) < Ops.unbox_int(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[18] = Ops.less_than_ints;

function Ops.less_than_or_equal_nums(TC, x, y)
function Ops.less_than_or_equal_nums (TC, x, y)
return Ops.box_int(TC, Ops.unbox_num(TC, x) <= Ops.unbox_num(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[19] = Ops.less_than_or_equal_nums;

function Ops.less_than_or_equal_ints(TC, x, y)
function Ops.less_than_or_equal_ints (TC, x, y)
return Ops.box_int(TC, Ops.unbox_int(TC, x) <= Ops.unbox_int(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[20] = Ops.less_than_or_equal_ints;

function Ops.greater_than_nums(TC, x, y)
function Ops.greater_than_nums (TC, x, y)
return Ops.box_int(TC, Ops.unbox_num(TC, x) > Ops.unbox_num(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[21] = Ops.greater_than_nums;

function Ops.greater_than_ints(TC, x, y)
function Ops.greater_than_ints (TC, x, y)
return Ops.box_int(TC, Ops.unbox_int(TC, x) > Ops.unbox_int(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[22] = Ops.greater_than_ints;

function Ops.greater_than_or_equal_nums(TC, x, y)
function Ops.greater_than_or_equal_nums (TC, x, y)
return Ops.box_int(TC, Ops.unbox_num(TC, x) >= Ops.unbox_num(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[23] = Ops.greater_than_or_equal_nums;

function Ops.greater_than_or_equal_ints(TC, x, y)
function Ops.greater_than_or_equal_ints (TC, x, y)
return Ops.box_int(TC, Ops.unbox_int(TC, x) >= Ops.unbox_int(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[24] = Ops.greater_than_or_equal_ints;

function Ops.less_than_strs(TC, x, y)
function Ops.less_than_strs (TC, x, y)
return Ops.box_int(TC, Ops.unbox_str(TC, x) < Ops.unbox_str(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[25] = Ops.less_than_strs;

function Ops.less_than_or_equal_strs(TC, x, y)
function Ops.less_than_or_equal_strs (TC, x, y)
return Ops.box_int(TC, Ops.unbox_str(TC, x) <= Ops.unbox_str(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[26] = Ops.less_than_or_equal_strs;

function Ops.greater_than_strs(TC, x, y)
function Ops.greater_than_strs (TC, x, y)
return Ops.box_int(TC, Ops.unbox_str(TC, x) > Ops.unbox_str(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[27] = Ops.greater_than_strs;

function Ops.greater_than_or_equal_strs(TC, x, y)
function Ops.greater_than_or_equal_strs (TC, x, y)
return Ops.box_int(TC, Ops.unbox_str(TC, x) >= Ops.unbox_str(TC, y) and 1 or 0, TC.DefaultBoolBoxType);
end
Ops[28] = Ops.greater_than_or_equal_strs;
Expand Down
10 changes: 5 additions & 5 deletions lua/runtime/Runtime/Ops/ControlFlow.lua
Expand Up @@ -4,12 +4,12 @@ function Ops.vivify(TC, Check, VivifyWith)
end
Ops[29] = Ops.vivify;

function Ops.leave_block(TC, Block, ReturnValue)
function Ops.leave_block (TC, Block, ReturnValue)
error(Exceptions.LeaveStackUnwinderException.new(Block, ReturnValue));
end
Ops[30] = Ops.leave_block;

function Ops.throw_dynamic(TC, ExceptionObject, ExceptionType)
function Ops.throw_dynamic (TC, ExceptionObject, ExceptionType)
local WantType = Ops.unbox_int(TC, ExceptionType);
local CurContext = TC.CurrentContext;
while (CurContext ~= nil) do
Expand All @@ -31,7 +31,7 @@ function Ops.throw_dynamic(TC, ExceptionObject, ExceptionType)
end
Ops[31] = Ops.throw_dynamic;

function Ops.throw_lexical(TC, ExceptionObject, ExceptionType)
function Ops.throw_lexical (TC, ExceptionObject, ExceptionType)
local WantType = Ops.unbox_int(TC, ExceptionType);
local CurContext = TC.CurrentContext;
while (CurContext ~= nil) do
Expand All @@ -53,13 +53,13 @@ function Ops.throw_lexical(TC, ExceptionObject, ExceptionType)
end
Ops[32] = Ops.throw_lexical;

function Ops.capture_outer(TC, Block)
function Ops.capture_outer (TC, Block)
Block.OuterForNextInvocation = TC.CurrentContext;
return Block;
end
Ops[33] = Ops.capture_outer;

function Ops.new_closure(TC, Block)
function Ops.new_closure (TC, Block)
local NewBlock = RakudoCodeRef.Instance.new(Block.STable);
NewBlock.Body = Block.Body;
NewBlock.CurrentContext = Block.CurrentContext;
Expand Down
10 changes: 5 additions & 5 deletions lua/runtime/Runtime/Ops/Dispatch.lua
@@ -1,4 +1,4 @@
function Ops.multi_dispatch_over_lexical_candidates(TC)
function Ops.multi_dispatch_over_lexical_candidates (TC)
local CurOuter = TC.CurrentContext;
while (CurOuter ~= nil) do
local CodeObj = CurOuter.StaticCodeObject;
Expand All @@ -14,13 +14,13 @@ function Ops.multi_dispatch_over_lexical_candidates(TC)
end
Ops[35] = Ops.multi_dispatch_over_lexical_candidates;

function Ops.set_dispatchees(TC, CodeObject, Dispatchees)
function Ops.set_dispatchees (TC, CodeObject, Dispatchees)
CodeObject.Dispatchees = Dispatchees.Storage;
return CodeObject;
end
Ops[36] = Ops.set_dispatchees;

function Ops.create_dispatch_and_add_candidates(TC, ToInstantiate, ExtraDispatchees)
function Ops.create_dispatch_and_add_candidates (TC, ToInstantiate, ExtraDispatchees)
-- Make sure we got the right things.
local Source = ToInstantiate;
local AdditionalDispatchList = ExtraDispatchees;
Expand Down Expand Up @@ -51,7 +51,7 @@ function Ops.create_dispatch_and_add_candidates(TC, ToInstantiate, ExtraDispatch
end
Ops[37] = Ops.create_dispatch_and_add_candidates;

function Ops.push_dispatchee(TC, Dispatcher, Dispatchee)
function Ops.push_dispatchee (TC, Dispatcher, Dispatchee)
local Target = Dispatcher;
if (Target.Dispatchees == nil) then
error("push_dispatchee passed something that is not a dispatcher");
Expand All @@ -62,7 +62,7 @@ function Ops.push_dispatchee(TC, Dispatcher, Dispatchee)
end
Ops[38] = Ops.push_dispatchee;

function Ops.is_dispatcher(TC, Check)
function Ops.is_dispatcher (TC, Check)
local Checkee = Check;
if (Checkee ~= nil and Checkee.Dispatchees ~= nil) then
return Ops.box_int(TC, 1, TC.DefaultBoolBoxType);
Expand Down
4 changes: 2 additions & 2 deletions lua/runtime/Runtime/Ops/Introspection.lua
@@ -1,4 +1,4 @@
function Ops.get_caller_sub(TC, Level)
function Ops.get_caller_sub (TC, Level)
local ToLevel = Ops.unbox_int(TC, Level);
local Context = TC.CurrentContext;
while (ToLevel >= 0) do
Expand All @@ -12,7 +12,7 @@ function Ops.get_caller_sub(TC, Level)
end
Ops[40] = Ops.get_caller_sub;

function Ops.get_outer_sub(TC, Level)
function Ops.get_outer_sub (TC, Level)
local ToLevel = Ops.unbox_int(TC, Level);
local Context = TC.CurrentContext;
while (ToLevel >= 0) do
Expand Down
2 changes: 1 addition & 1 deletion lua/runtime/Runtime/Ops/Library.lua
@@ -1,4 +1,4 @@
function Ops.load_module(TC, Path)
function Ops.load_module (TC, Path)
local Name = Ops.unbox_str(TC, Path);
local success;
--success = pcall(function ()
Expand Down
8 changes: 4 additions & 4 deletions lua/runtime/Runtime/Ops/P6capture.lua
@@ -1,4 +1,4 @@
function Ops.llcap_get_at_pos(TC, Capture, Index)
function Ops.llcap_get_at_pos (TC, Capture, Index)
local Cap = Capture;
if (Cap.Positionals == nil) then
Cap.Positionals = {};
Expand All @@ -10,7 +10,7 @@ function Ops.llcap_get_at_pos(TC, Capture, Index)
end
Ops[58] = Ops.llcap_get_at_pos;

function Ops.llcap_bind_at_pos(TC, Capture, IndexObj, Value)
function Ops.llcap_bind_at_pos (TC, Capture, IndexObj, Value)
local Cap = Capture;
local Storage = Cap.Positionals;
local Index = Ops.unbox_int(TC, IndexObj);
Expand All @@ -23,7 +23,7 @@ function Ops.llcap_bind_at_pos(TC, Capture, IndexObj, Value)
end
Ops[59] = Ops.llcap_bind_at_pos;

function Ops.llcap_get_at_key(TC, Capture, Key)
function Ops.llcap_get_at_key (TC, Capture, Key)
local Storage = Capture.Nameds;
if (Storage == nil) then
Capture.Nameds = {};
Expand All @@ -38,7 +38,7 @@ function Ops.llcap_get_at_key(TC, Capture, Key)
end
Ops[60] = Ops.llcap_get_at_key;

function Ops.llcap_bind_at_key(TC, Capture, Key, Value)
function Ops.llcap_bind_at_key (TC, Capture, Key, Value)
local Storage = Capture.Nameds;
if (Storage == nil) then
Capture.Nameds = {};
Expand Down

0 comments on commit a7073fd

Please sign in to comment.