diff --git a/lua/compiler/IndexersReplacements.txt b/lua/compiler/IndexersReplacements.txt index aabba75..da22fe0 100644 --- a/lua/compiler/IndexersReplacements.txt +++ b/lua/compiler/IndexersReplacements.txt @@ -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]( @@ -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 \ No newline at end of file +%.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 \ No newline at end of file diff --git a/lua/compiler/PAST2LSTCompiler.pm b/lua/compiler/PAST2LSTCompiler.pm index 732e1e9..270a923 100644 --- a/lua/compiler/PAST2LSTCompiler.pm +++ b/lua/compiler/PAST2LSTCompiler.pm @@ -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)' ), diff --git a/lua/runtime/Runtime/Context.lua b/lua/runtime/Runtime/Context.lua index 2f5dfb4..cedfe28 100644 --- a/lua/runtime/Runtime/Context.lua +++ b/lua/runtime/Runtime/Context.lua @@ -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); diff --git a/lua/runtime/Runtime/Lexpad.lua b/lua/runtime/Runtime/Lexpad.lua index 818d27c..b9773cb 100644 --- a/lua/runtime/Runtime/Lexpad.lua +++ b/lua/runtime/Runtime/Lexpad.lua @@ -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; @@ -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; diff --git a/lua/runtime/Runtime/Ops/Coercion.lua b/lua/runtime/Runtime/Ops/Coercion.lua index eb337d8..3d391f5 100644 --- a/lua/runtime/Runtime/Ops/Coercion.lua +++ b/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; diff --git a/lua/runtime/Runtime/Ops/Comparison.lua b/lua/runtime/Runtime/Ops/Comparison.lua index 863f93b..b443ce8 100644 --- a/lua/runtime/Runtime/Ops/Comparison.lua +++ b/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; diff --git a/lua/runtime/Runtime/Ops/ControlFlow.lua b/lua/runtime/Runtime/Ops/ControlFlow.lua index cde0056..3ff6051 100644 --- a/lua/runtime/Runtime/Ops/ControlFlow.lua +++ b/lua/runtime/Runtime/Ops/ControlFlow.lua @@ -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 @@ -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 @@ -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; diff --git a/lua/runtime/Runtime/Ops/Dispatch.lua b/lua/runtime/Runtime/Ops/Dispatch.lua index c9a18fb..abdf4e6 100644 --- a/lua/runtime/Runtime/Ops/Dispatch.lua +++ b/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; @@ -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; @@ -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"); @@ -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); diff --git a/lua/runtime/Runtime/Ops/Introspection.lua b/lua/runtime/Runtime/Ops/Introspection.lua index 75a2bda..464e607 100644 --- a/lua/runtime/Runtime/Ops/Introspection.lua +++ b/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 @@ -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 diff --git a/lua/runtime/Runtime/Ops/Library.lua b/lua/runtime/Runtime/Ops/Library.lua index 5cb5f30..fe237da 100644 --- a/lua/runtime/Runtime/Ops/Library.lua +++ b/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 () diff --git a/lua/runtime/Runtime/Ops/P6capture.lua b/lua/runtime/Runtime/Ops/P6capture.lua index 8f3399d..b6aa88c 100644 --- a/lua/runtime/Runtime/Ops/P6capture.lua +++ b/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 = {}; @@ -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); @@ -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 = {}; @@ -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 = {}; diff --git a/lua/runtime/Runtime/Ops/P6list.lua b/lua/runtime/Runtime/Ops/P6list.lua index 4e106a2..28c0910 100644 --- a/lua/runtime/Runtime/Ops/P6list.lua +++ b/lua/runtime/Runtime/Ops/P6list.lua @@ -1,10 +1,10 @@ -function Ops.lllist_get_at_pos(TC, LLList, Index) +function Ops.lllist_get_at_pos (TC, LLList, Index) if (Index.Value ~= nil) then Index = Index.Value end return LLList.Storage[Index + 1]; end Ops[62] = Ops.lllist_get_at_pos; -function Ops.lllist_bind_at_pos(TC, LLList, IndexObj, Value) +function Ops.lllist_bind_at_pos (TC, LLList, IndexObj, Value) local ix = Ops.unbox_int(TC, IndexObj) + 1; if ix == LLList.Storage.Count + 1 then -- the compiler likes to generate code to bind outside the range of @@ -17,33 +17,33 @@ function Ops.lllist_bind_at_pos(TC, LLList, IndexObj, Value) end Ops[63] = Ops.lllist_bind_at_pos; -function Ops.lllist_elems(TC, LLList) +function Ops.lllist_elems (TC, LLList) return Ops.box_int(TC, LLList.Storage.Count, TC.DefaultIntBoxType); end Ops[64] = Ops.lllist_elems; -function Ops.lllist_push(TC, LLList, item) +function Ops.lllist_push (TC, LLList, item) List.Push(LLList.Storage, item); end Ops[65] = Ops.lllist_push; -function Ops.lllist_pop(TC, LLList) +function Ops.lllist_pop (TC, LLList) return List.Pop(LLList.Storage); end Ops[66] = Ops.lllist_pop; -function Ops.lllist_truncate_to(TC, LLList, Length) +function Ops.lllist_truncate_to (TC, LLList, Length) List.Truncate(LLList.Storage, Ops.unbox_int(TC, Length)); return LLList; end Ops[67] = Ops.lllist_truncate_to; -function Ops.lllist_shift(TC, LLList) +function Ops.lllist_shift (TC, LLList) return List.Shift(LLList.Storage); end Ops[68] = Ops.lllist_shift; -function Ops.lllist_unshift(TC, LLList, item) +function Ops.lllist_unshift (TC, LLList, item) return List.Unshift(LLList.Storage, item); end Ops[69] = Ops.lllist_unshift; diff --git a/lua/runtime/Runtime/Ops/P6mapping.lua b/lua/runtime/Runtime/Ops/P6mapping.lua index cdb21d5..dd30bcb 100644 --- a/lua/runtime/Runtime/Ops/P6mapping.lua +++ b/lua/runtime/Runtime/Ops/P6mapping.lua @@ -1,4 +1,4 @@ -function Ops.llmapping_get_at_key(TC, LLMapping, Key) +function Ops.llmapping_get_at_key (TC, LLMapping, Key) --if (LLMapping.class == "P6mapping") then local Storage = LLMapping.Storage; local StrKey = Ops.unbox_str(TC, Key); @@ -9,7 +9,7 @@ function Ops.llmapping_get_at_key(TC, LLMapping, Key) end Ops[70] = Ops.llmapping_get_at_key; -function Ops.llmapping_bind_at_key(TC, LLMapping, Key, Value) +function Ops.llmapping_bind_at_key (TC, LLMapping, Key, Value) --if (LLMapping.class == "P6mapping") then local Storage = LLMapping.Storage; local StrKey = Ops.unbox_str(TC, Key); @@ -21,7 +21,7 @@ function Ops.llmapping_bind_at_key(TC, LLMapping, Key, Value) end Ops[71] = Ops.llmapping_bind_at_key; -function Ops.llmapping_elems(TC, LLMapping) +function Ops.llmapping_elems (TC, LLMapping) --if (LLMapping.class == "P6mapping") then return Ops.box_int(TC, LLMapping.Storage.Count, TC.DefaultIntBoxType); --else diff --git a/lua/runtime/Runtime/Ops/Primitive.lua b/lua/runtime/Runtime/Ops/Primitive.lua index a6551cc..2640767 100644 --- a/lua/runtime/Runtime/Ops/Primitive.lua +++ b/lua/runtime/Runtime/Ops/Primitive.lua @@ -1,76 +1,76 @@ -function Ops.logical_not_int(TC, x) +function Ops.logical_not_int (TC, x) return x == 0 and 1 or 0; end Ops[73] = Ops.logical_not_int; -function Ops.add_int(TC, x, y) +function Ops.add_int (TC, x, y) return x + y; end Ops[74] = Ops.add_int; -function Ops.sub_int(TC, x, y) +function Ops.sub_int (TC, x, y) return x - y; end Ops[75] = Ops.sub_int; -function Ops.mul_int(TC, x, y) +function Ops.mul_int (TC, x, y) return x * y; end Ops[76] = Ops.mul_int; -function Ops.div_int(TC, x, y) +function Ops.div_int (TC, x, y) return x / y; end Ops[77] = Ops.div_int; -function Ops.mod_int(TC, x, y) +function Ops.mod_int (TC, x, y) return x % y; end Ops[78] = Ops.mod_int; -function Ops.add_num(TC, x, y) +function Ops.add_num (TC, x, y) return Ops.box_num(TC, Ops.unbox_num(TC, x) + Ops.unbox_num(TC, y), TC.DefaultNumBoxType); end Ops[79] = Ops.add_num; -function Ops.sub_num(TC, x, y) +function Ops.sub_num (TC, x, y) return Ops.box_num(TC, Ops.unbox_num(TC, x) - Ops.unbox_num(TC, y), TC.DefaultNumBoxType); end Ops[80] = Ops.sub_num; -function Ops.mul_num(TC, x, y) +function Ops.mul_num (TC, x, y) return Ops.box_num(TC, Ops.unbox_num(TC, x) * Ops.unbox_num(TC, y), TC.DefaultNumBoxType); end Ops[81] = Ops.mul_num; -function Ops.div_num(TC, x, y) +function Ops.div_num (TC, x, y) return Ops.box_num(TC, Ops.unbox_num(TC, x) / Ops.unbox_num(TC, y), TC.DefaultNumBoxType); end Ops[82] = Ops.div_num; -function Ops.bitwise_or_int(TC, x, y) +function Ops.bitwise_or_int (TC, x, y) return Ops.box_int(TC, bit.bor(Ops.unbox_int(TC, x), Ops.unbox_int(TC, y)), TC.DefaultIntBoxType); end Ops[83] = Ops.bitwise_or_int; -function Ops.bitwise_and_int(TC, x, y) +function Ops.bitwise_and_int (TC, x, y) return Ops.box_int(TC, bit.band(Ops.unbox_int(TC, x), Ops.unbox_int(TC, y)), TC.DefaultIntBoxType); end Ops[84] = Ops.bitwise_and_int; -function Ops.bitwise_xor_int(TC, x, y) +function Ops.bitwise_xor_int (TC, x, y) return Ops.box_int(TC, bit.bxor(Ops.unbox_int(TC, x), Ops.unbox_int(TC, y)), TC.DefaultIntBoxType); end Ops[85] = Ops.bitwise_xor_int; -function Ops.concat(TC, x, y) +function Ops.concat (TC, x, y) return Ops.box_str(TC, Ops.unbox_str(TC, x) .. Ops.unbox_str(TC, y), TC.DefaultStrBoxType); end Ops[86] = Ops.concat; -- skip num bitwise -function Ops.substr(TC, x, y, z) +function Ops.substr (TC, x, y, z) local str; local REPR = z.STable.REPR; if (z ~= nil and REPR.defined(REPR, TC, z)) then @@ -83,12 +83,12 @@ end Ops[87] = Ops.substr; -- skip format_str -function Ops.index_str(TC, x, y) +function Ops.index_str (TC, x, y) return Ops.box_int(TC, Ops.unbox_str(TC, x).find(Ops.unbox_str(TC, y)) - 1); end Ops[88] = Ops.index_str; -local split = function(string, pattern) +local split = function (string, pattern) local vals = {}; local valindex = 0; local word = ""; @@ -114,7 +114,7 @@ local split = function(string, pattern) return vals end -function Ops.split_str(TC, x, y) +function Ops.split_str (TC, x, y) local list = Ops.instance_of(TC, Ops.get_lex(TC, "NQPList")); local store = list.Storage; local splitted = split(Ops.unbox_str(TC, x), Ops.unbox_str(TC, y)); diff --git a/lua/runtime/Runtime/Ops/Variables.lua b/lua/runtime/Runtime/Ops/Variables.lua index 0cbbfe6..c06f91a 100644 --- a/lua/runtime/Runtime/Ops/Variables.lua +++ b/lua/runtime/Runtime/Ops/Variables.lua @@ -1,5 +1,5 @@ -function Ops.get_lex(TC, Name) +function Ops.get_lex (TC, Name) local CurContext = TC.CurrentContext; while (CurContext ~= nil) do local Index; @@ -13,7 +13,7 @@ function Ops.get_lex(TC, Name) end Ops[90] = Ops.get_lex; -function Ops.get_lex_skip_current(TC, Name) +function Ops.get_lex_skip_current (TC, Name) local CurContext = TC.CurrentContext.Outer; while (CurContext ~= nil) do local Index; @@ -26,7 +26,7 @@ function Ops.get_lex_skip_current(TC, Name) end Ops[91] = Ops.get_lex_skip_current; -function Ops.bind_lex(TC, Name, Value) +function Ops.bind_lex (TC, Name, Value) local CurContext = TC.CurrentContext; while (CurContext ~= nil) do local Index; @@ -40,7 +40,7 @@ function Ops.bind_lex(TC, Name, Value) end Ops[92] = Ops.bind_lex; -function Ops.get_dynamic(TC, Name) +function Ops.get_dynamic (TC, Name) local CurContext = TC.CurrentContext; while (CurContext ~= nil) do local Index; @@ -53,7 +53,7 @@ function Ops.get_dynamic(TC, Name) end Ops[93] = Ops.get_dynamic; -function Ops.bind_dynamic(TC, Name, Value) +function Ops.bind_dynamic (TC, Name, Value) local CurContext = TC.CurrentContext; while (CurContext ~= nil) do local Index;