Block source position support [1/2]: generate SOURCEPOS pseudoinstruction before each MAKE_BLOCK insn jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sun, 31 May 2015 16:49:23 +0100
branchjv
changeset 3645 695fc26d7207
parent 3644 e2b3a53205f2
child 3646 0db7ccc50da9
Block source position support [1/2]: generate SOURCEPOS pseudoinstruction before each MAKE_BLOCK insn Interpreter and jit compiler will use that to fill in Block's sourcePos slot.
.hgignore
BlockNode.st
ByteCodeCompiler.st
Decompiler.st
ParseNode.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sun May 31 16:49:23 2015 +0100
@@ -0,0 +1,16 @@
+
+syntax: glob
+*Init.c   
+makefile
+*.so
+*.H
+*.o
+*.STH
+*.sc
+objbc
+objvc
+*.class
+java/libs/*.jar
+java/libs-src/*.jar
+*-Test.xml
+st.chg
--- a/BlockNode.st	Tue Jun 09 06:38:50 2015 +0200
+++ b/BlockNode.st	Sun May 31 16:49:23 2015 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
@@ -562,10 +560,14 @@
 
     "cheap block detection filters out blocks with no statements"
 
+    startPosition notNil ifTrue:[ 
+        self codeSourcePosition: startPosition on: aStream for: aCompiler.
+    ].
+
     pos := aStream position.
 
     aStream nextPut:#makeBlock.                                 "+0"
-    aStream nextPut:0.                                          "+1"
+    aStream nextPut:0."/block's bytecode end index,patched later"+1"
     aStream nextPut:(blockVars size + (maxNumTemp?0)).          "+2"
     aStream nextPut:(blockArgs size).                           "+3"
                                                                 "+4"
@@ -596,7 +598,8 @@
     "set the end of the block's code"
     code at:pos+2 put:(aStream position + 1)
 
-    "Modified: 26.6.1997 / 10:48:56 / cg"
+    "Modified: / 26-06-1997 / 10:48:56 / cg"
+    "Modified: / 31-05-2015 / 04:00:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !BlockNode methodsFor:'code generation helpers'!
@@ -660,6 +663,7 @@
     "Modified: / 22-10-2006 / 12:03:27 / cg"
 ! !
 
+
 !BlockNode methodsFor:'evaluation'!
 
 evaluateIn:anEnvironment
@@ -1148,6 +1152,11 @@
     ^ '$Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.95 2015-02-27 20:22:49 cg Exp $'
 !
 
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+!
+
 version_SVN
     ^ '$ Id $'
 ! !
--- a/ByteCodeCompiler.st	Tue Jun 09 06:38:50 2015 +0200
+++ b/ByteCodeCompiler.st	Sun May 31 16:49:23 2015 +0100
@@ -353,9 +353,9 @@
         F2          STORE_OUTBLOCK_LVAR store local variable in outer context 0..numArgs-1 for args; numArgs..numArgs+nLocal-1 for bVars
         F3          SWAP            swap TOS with NOS
 
-        F4          UNUSED_244
-        F5          UNUSED_245
-        F6          UNUSED_246
+        F4          SOURCEPOS8 uu   source position information (offset in source, dummy) 
+        F5          SOURCEPOS16 uuuu  source position information (offset in source, dummy) 
+        F6          SOURCEPOS32 uuuuuuuu source position information (offset in source, dummy) 
         F7          UNUSED_247
         F8          UNUSED_248
         F9          UNUSED_249
@@ -1165,6 +1165,10 @@
     (aSymbol == #lineno) ifTrue:[lineno := true. ^ 8].
     (aSymbol == #lineno16) ifTrue:[lineno := true. ^ 9].
 
+    (aSymbol == #sourcepos8)  ifTrue:[extra := #index.      ^ 244].
+    (aSymbol == #sourcepos16) ifTrue:[extra := #unsigned16. ^ 245].
+    (aSymbol == #sourcepos32) ifTrue:[extra := #unsigned32. ^ 246].
+
     (aSymbol == #send) ifTrue:[lineno := true. extra := #special. ^ 19].
     (aSymbol == #superSend) ifTrue:[lineno := true. extra := #special. ^ 20].
     (aSymbol == #sendSelf) ifTrue:[lineno := true. extra := #special. ^ 13].
@@ -1424,6 +1428,7 @@
     "Modified: / 03-09-1995 / 12:58:47 / claus"
     "Modified: / 25-10-2011 / 21:56:43 / cg"
     "Modified (comment): / 31-10-2011 / 11:34:37 / cg"
+    "Modified (format): / 31-05-2015 / 03:55:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 checkForCommonCode:symbolicCodeArray
@@ -2033,6 +2038,35 @@
     ].
 !
 
+codeSourcePosition:nr on:codeStream
+    "generate source position information"
+
+    "/ caveat: (currently) there is no separate line number, position or symbol table;
+    "/ the source positions are coded right into the instruction stream.
+    "/ This might change in the future.
+    "/ (It is not a problem speed wise: the Jitter just skips them.)
+
+    nr <= 255 ifTrue:[
+        codeStream 
+            nextPut:#sourcepos8;
+            nextPut:nr.
+    ] ifFalse:[
+        nr <= 16rFFFF ifTrue:[
+            codeStream 
+                nextPut:#sourcepos16;
+                nextPutShort:nr MSB:true.
+        ] ifFalse:[ 
+            nr <= 16rFFFFFFFF ifTrue:[ 
+                codeStream 
+                    nextPut:#sourcepos32;
+                    nextPutLong:nr MSB:true.
+            ].
+        ].
+    ].
+
+    "Created: / 31-05-2015 / 03:43:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 createMethod
     |newMethod|
 
--- a/Decompiler.st	Tue Jun 09 06:38:50 2015 +0200
+++ b/Decompiler.st	Sun May 31 16:49:23 2015 +0100
@@ -11,6 +11,8 @@
 "
 "{ Package: 'stx:libcomp' }"
 
+"{ NameSpace: Smalltalk }"
+
 ByteCodeCompiler subclass:#Decompiler
 	instanceVariableNames:'hasLineNo bytes literals index listStream outputStream'
 	classVariableNames:''
@@ -784,6 +786,9 @@
                 storeBlockLocal       " 241 "
                 storeOuterBlockLocal  " 242 "
                 swap                  " 243 "
+                SOURCEPOS8            " 244 "
+                SOURCEPOS16           " 245 "
+                SOURCEPOS32           " 246 "
               ).
 
     lnos := #(  false          " 0  "
@@ -1030,6 +1035,9 @@
                 false           " 241 "
                 false           " 242 "
                 false           " 243 "
+                false           " 244 "
+                false           " 245 "
+                false           " 246 "
               ).
 
     extras := #(nil             " 0  "
@@ -1276,6 +1284,9 @@
                 index           " 241 "
                 levelIndex      " 242 "
                 nil             " 243 "
+                index           " 244 "
+                unsigned16      " 245 "
+                unsigned32      " 246 "
              ).
 
     sym := syms at:(aByte + 1).
@@ -1290,7 +1301,7 @@
 
     "Modified: / 02-09-1995 / 00:12:11 / claus"
     "Modified: / 25-10-2011 / 21:58:24 / cg"
-    "Modified: / 12-04-2013 / 01:31:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 31-05-2015 / 04:05:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !Decompiler class methodsFor:'documentation'!
--- a/ParseNode.st	Tue Jun 09 06:38:50 2015 +0200
+++ b/ParseNode.st	Sun May 31 16:49:23 2015 +0100
@@ -183,6 +183,7 @@
     ^ type
 ! !
 
+
 !ParseNode methodsFor:'attributes access'!
 
 objectAttributes
@@ -240,6 +241,14 @@
 
 codeOn:aStream inBlock:codeBlock for:aCompiler
     ^ self subclassResponsibility
+!
+
+codeSourcePosition:nr on:codeStream for:aCompiler
+    "generate source position information"
+
+    aCompiler codeSourcePosition:nr on:codeStream
+
+    "Created: / 31-05-2015 / 03:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ParseNode methodsFor:'code generation helpers'!
@@ -432,6 +441,8 @@
     "Created: / 22-02-2011 / 16:29:50 / Jakub <zelenja7@fel.cvut.cz>"
 ! !
 
+
+
 !ParseNode methodsFor:'printing & storing'!
 
 printOn:aStream
@@ -694,9 +705,11 @@
 !
 
 isSelector
-    "return true, if this is a node is a selector node"
+    "return true, if this is a node for an selctors"
 
     ^ false
+
+    "Created: / 22-02-2011 / 21:44:45 / Jakub <zelenja7@fel.cvut.cz>"
 !
 
 isSelf