@@ -21,6 +21,7 @@ local util = require 'utility'
2121--- @field castIndex integer ?
2222local mt = {}
2323mt .__index = mt
24+ mt .fastCalc = true
2425
2526--- @return parser.object[]
2627function mt :getCasts ()
@@ -66,6 +67,21 @@ function mt:collectCare(obj)
6667 return
6768 end
6869 self .careMap [obj ] = true
70+
71+ if self .fastCalc then
72+ if obj .type == ' if'
73+ or obj .type == ' while'
74+ or obj .type == ' binary' then
75+ self .fastCalc = false
76+ end
77+ if obj .type == ' call' and obj .node then
78+ if obj .node .special == ' assert'
79+ or obj .node .special == ' type' then
80+ self .fastCalc = false
81+ end
82+ end
83+ end
84+
6985 obj = obj .parent
7086 end
7187end
@@ -104,6 +120,10 @@ function mt:collectLocal()
104120 self .casts [# self .casts + 1 ] = cast
105121 end
106122 end
123+
124+ if # self .casts > 0 then
125+ self .fastCalc = false
126+ end
107127end
108128
109129function mt :collectGlobal ()
@@ -139,15 +159,15 @@ end
139159--- @param finish integer
140160--- @return parser.object ?
141161function mt :getLastAssign (start , finish )
142- local assign
162+ local assign = self . assigns [ 1 ]
143163 for _ , obj in ipairs (self .assigns ) do
144164 if obj .start < start then
145165 goto CONTINUE
146166 end
147167 if (obj .range or obj .start ) >= finish then
148168 break
149169 end
150- local objBlock = guide .getParentBlock (obj )
170+ local objBlock = guide .getTopBlock (obj )
151171 if not objBlock then
152172 break
153173 end
@@ -683,21 +703,35 @@ function mt:lookIntoBlock(block, start, node)
683703 end
684704 if self .careMap [action ] then
685705 node = self :lookIntoChild (action , node )
706+ if action .type == ' do'
707+ or action .type == ' loop'
708+ or action .type == ' in'
709+ or action .type == ' repeat' then
710+ return
711+ end
686712 end
687713 if action .finish > start and self .assignMap [action ] then
688714 return
689715 end
690716 :: CONTINUE::
691717 end
692718 self .nodes [block ] = node
719+ if block .type == ' do'
720+ or block .type == ' loop'
721+ or block .type == ' in'
722+ or block .type == ' repeat' then
723+ self :lookIntoBlock (block .parent , block .finish , node )
724+ end
693725end
694726
695727--- @param source parser.object
696728function mt :calcNode (source )
697729 if self .getMap [source ] then
698730 local lastAssign = self :getLastAssign (0 , source .finish )
699- if not lastAssign then
700- lastAssign = source .node
731+ assert (lastAssign )
732+ if self .fastCalc then
733+ self .nodes [source ] = vm .compileNode (lastAssign )
734+ return
701735 end
702736 self :calcNode (lastAssign )
703737 return
0 commit comments