Fixed compiler to produce correct(ish) variable table jv
authorJan Vrany <jan.vrany@labware.com>
Tue, 09 Jun 2020 14:01:25 +0100
branchjv
changeset 4654 f001d36a3229
parent 4653 cc24fb996651
child 4655 0e104f727335
Fixed compiler to produce correct(ish) variable table This commit fixes a number of issues w.r.t inlined blocks and variable tables: * inlined blocks were mis-detected, we have to use `#isInlinable` as the `#isInlined` actually return `false` always, * there we duplicated records in variable table because some blocks have been visitied more than once, * block-locals for inlined blocks in method have wrong offsets since method arguments were not take into the account. For example, before this commit `ExternalLibraryFunction >> ffiCall:` had completely bogus info when bytecode-compiled.
BlockNode.st
DIVariable.st
DIVariableTable.st
MethodNode.st
--- a/BlockNode.st	Wed May 27 15:47:18 2020 +0100
+++ b/BlockNode.st	Tue Jun 09 14:01:25 2020 +0100
@@ -1,6 +1,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
  COPYRIGHT (c) 2015-2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
 	      All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -31,6 +32,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
  COPYRIGHT (c) 2015-2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
 	      All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -234,6 +236,19 @@
     "Created: 23.10.1996 / 15:51:50 / cg"
 !
 
+method
+    "Return top-level MethodNode (or nil, if not hooked
+     under MethodNode, i.e., if top-level node is free-standing"
+
+    | top |
+
+    top := self.
+    [ top parent notNil ] whileTrue:[ top := top parent ].
+    ^ top isMethodNode ifTrue:[ top ] ifFalse: [ nil ]
+
+    "Created: / 09-06-2020 / 14:28:00 / Jan Vrany <jan.vrany@labware.com>"
+!
+
 needsHome
     ^ needsHome
 !
@@ -649,19 +664,27 @@
     
     | base physical |
 
-    self isInlineBlock ifTrue:[
+    self isInlinable ifTrue:[
         | h |
 
         base := self indexOfFirstTemp.
         h := self.
         [
-            h notNil and:[ h isInlineBlock ]
+            h notNil and:[ h isInlinable ]
         ] whileTrue:[ h := h home ].
         h notNil ifTrue:[
             physical := h.
             base := base + h numArgs.
         ] ifFalse:[
+            | method |
+
             physical := nil.
+            method := self method.
+            method notNil ifTrue:[ 
+                base := base + method numArgs
+            ] ifFalse:[ 
+                self breakPoint: #jv.  
+            ].
         ].
     ] ifFalse:[
         base := 1.
@@ -694,6 +717,7 @@
 
     "Created: / 15-07-2018 / 15:10:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 06-02-2019 / 22:28:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 09-06-2020 / 14:30:45 / Jan Vrany <jan.vrany@labware.com>"
 ! !
 
 !BlockNode methodsFor:'enumerating'!
--- a/DIVariable.st	Wed May 27 15:47:18 2020 +0100
+++ b/DIVariable.st	Tue Jun 09 14:01:25 2020 +0100
@@ -1,6 +1,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger / eXept Software AG
  COPYRIGHT (c) 2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
               All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -28,6 +29,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger / eXept Software AG
  COPYRIGHT (c) 2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
               All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -102,6 +104,29 @@
     "Created: / 06-02-2019 / 22:19:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!DIVariable methodsFor:'comparing'!
+
+= another
+    ^ self class == another class
+        and:[ self physicalBlockSourceOffset = another physicalBlockSourceOffset
+        and:[ self lexicalBlockSourceOffset = another lexicalBlockSourceOffset
+        and:[ self isArgument = another isArgument
+        and:[ self frameOffset = another frameOffset
+        and:[ self name = another name ]]]]]
+
+    "Created: / 09-06-2020 / 13:12:43 / Jan Vrany <jan.vrany@labware.com>"
+!
+
+hash
+    ^ ((((phy_block_source_offset hash 
+        bitXor: lex_block_source_offset hash)
+        bitXor: frame_offset hash)
+        bitXor: is_argument hash)
+        bitXor: name hash)
+
+    "Created: / 09-06-2020 / 13:10:51 / Jan Vrany <jan.vrany@labware.com>"
+! !
+
 !DIVariable methodsFor:'printing & storing'!
 
 printOn: aStream
--- a/DIVariableTable.st	Wed May 27 15:47:18 2020 +0100
+++ b/DIVariableTable.st	Tue Jun 09 14:01:25 2020 +0100
@@ -1,6 +1,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger / eXept Software AG
  COPYRIGHT (c) 2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
               All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -27,6 +28,7 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger / eXept Software AG
  COPYRIGHT (c) 2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
               All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -61,10 +63,14 @@
 !DIVariableTable methodsFor:'adding & removing'!
 
 addVariable: aDIVariable
+    (variables includes: aDIVariable) ifTrue:[ 
+        self error: 'Oops, trying to add the same variable twice?'
+    ].
     variables := variables copyWith: aDIVariable.
     variables_count := variables_count + 1
 
     "Created: / 14-07-2018 / 20:52:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 09-06-2020 / 13:25:54 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 addVariableNamed:aString isArgument:aBoolean offset:anOnteger physicalBlock: physical lexicalBlock: lexical
@@ -123,3 +129,10 @@
     "Created: / 15-07-2018 / 11:27:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!DIVariableTable class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+
--- a/MethodNode.st	Wed May 27 15:47:18 2020 +0100
+++ b/MethodNode.st	Tue Jun 09 14:01:25 2020 +0100
@@ -1,5 +1,6 @@
 "
  COPYRIGHT (c) 1995 by Claus Gittinger
+ COPYRIGHT (c) 2020 LabWare
 	      All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -25,6 +26,7 @@
 copyright
 "
  COPYRIGHT (c) 1995 by Claus Gittinger
+ COPYRIGHT (c) 2020 LabWare
 	      All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -63,9 +65,10 @@
 arguments:argVars locals:localVars statements:stats
     arguments := argVars. 
     locals := localVars. 
-    statements := stats.
+    self statements: statements.
 
     "Created: / 06-08-2006 / 03:04:18 / cg"
+    "Modified: / 09-06-2020 / 14:34:57 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 encoder
@@ -80,6 +83,12 @@
     ^ locals
 !
 
+numArgs
+    ^ arguments size
+
+    "Created: / 09-06-2020 / 14:30:41 / Jan Vrany <jan.vrany@labware.com>"
+!
+
 selector
     ^ selector
 !
@@ -94,7 +103,9 @@
     selector := sel. 
     arguments := argVars. 
     locals := localVars. 
-    statements := stats.
+    self statements: stats.
+
+    "Modified: / 09-06-2020 / 14:35:40 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 statementCollection
@@ -115,8 +126,13 @@
     ^ statements 
 !
 
-statements:something
-    statements := something.
+statements:aCollection
+    statements := aCollection.
+    statements notEmpty ifTrue:[ 
+        statements first parent: self.
+    ].
+
+    "Modified: / 09-06-2020 / 14:32:14 / Jan Vrany <jan.vrany@labware.com>"
 ! !
 
 !MethodNode methodsFor:'code generation'!
@@ -196,10 +212,13 @@
     evaluating `aBlock` for (all) nested blocks.
     If `aBoolean` is false, stop at any block node.
     " 
-    ^ statements do:[:statement | statement blockNodesDo:aBlock recursively: aBoolean ]
+    statements notEmpty ifTrue:[
+        statements first blockNodesDo:aBlock recursively: aBoolean
+    ]
 
     "Created: / 15-07-2018 / 15:50:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified (format): / 15-07-2018 / 23:57:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 09-06-2020 / 13:57:44 / Jan Vrany <jan.vrany@labware.com>"
 ! !
 
 !MethodNode methodsFor:'printing'!