BCompiler.st
changeset 192 5f5ecdcffc67
parent 191 5c285632f2ea
child 197 6f9037e14497
--- a/BCompiler.st	Thu Jan 11 20:41:34 1996 +0100
+++ b/BCompiler.st	Sat Jan 13 16:27:27 1996 +0100
@@ -15,7 +15,7 @@
 		maxStackDepth relocList'
 	classVariableNames:'JumpToAbsJump SequenceNumber STCCompilationDefines
 		STCCompilationIncludes STCCompilationOptions STCCompilation
-		KeepSource STCKeepCIntermediate'
+		KeepSource ShareCode STCKeepCIntermediate'
 	poolDictionaries:''
 	category:'System-Compiler'
 !
@@ -452,6 +452,13 @@
     self error
 ! !
 
+!ByteCodeCompiler class methodsFor:'initialization'!
+
+initialize
+    ShareCode := true.
+    KeepSource := true
+! !
+
 !ByteCodeCompiler class methodsFor:'stc compilation defaults'!
 
 canCreateMachineCode
@@ -1127,6 +1134,22 @@
     ^ nil
 !
 
+checkForCommonCode:symbolicCodeArray
+    "hook to return the code for common code sequences.
+     Not yet fully implemented - just an idea ..."
+
+    |insn1|
+
+    symbolicCodeArray size == 2 ifTrue:[
+	(insn1 := symbolicCodeArray at:1) == #pushLit1 ifTrue:[
+	    (symbolicCodeArray at:2) == #retTop ifTrue:[
+		^ #[222 0]
+	    ]
+	]
+    ].
+    ^ nil
+!
+
 genByteCodeFrom:symbolicCodeArray
     "convert symbolicCode into bytecodes"
 
@@ -1142,6 +1165,12 @@
     round := 0.
     needRetry := true.
     symCodeSize := symbolicCodeArray size.
+    ShareCode ifTrue:[
+	codeBytes := self checkForCommonCode:symbolicCodeArray.
+	codeBytes notNil ifTrue:[
+	    ^ self
+	].
+    ].
     codeSize := symCodeSize.
 
     [needRetry] whileTrue:[
@@ -1965,5 +1994,5 @@
 !ByteCodeCompiler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Attic/BCompiler.st,v 1.60 1996-01-11 19:41:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Attic/BCompiler.st,v 1.61 1996-01-13 15:27:27 cg Exp $'
 ! !