[Vm-dev] VM Maker: VMMaker.oscog-eem.2361.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Mar 17 22:46:51 UTC 2018


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2361.mcz

==================== Summary ====================

Name: VMMaker.oscog-eem.2361
Author: eem
Time: 17 March 2018, 3:46:08.32065 pm
UUID: 7ca2f89a-de70-422f-b92b-54f91ac4e47b
Ancestors: VMMaker.oscog-eem.2360

Spur:
Make read-only (-DIMMUTABILITY) the default wth Spur VMs.

Add MT versions to the Slang generation.

Slang:
Refactor define generation into putConditionalDefineOf:as:comment:on: putDefineOf:as:on:.  To make use of these refactor writeVMHeaderTo:bytesPerWord: to writeVMHeaderTo:bytesPerWord:generator:.

=============== Diff against VMMaker.oscog-eem.2360 ===============

Item was changed:
  ----- Method: CCodeGenerator>>emitCConstants:on: (in category 'C code generator') -----
  emitCConstants: constList on: aStream
  	"Store the global variable declarations on the given stream."
  	constList isEmpty ifTrue: [^self].
  	aStream cr; nextPutAll: '/*** Constants ***/'; cr.
  	(self sortStrings: constList) do:
+ 		[:varName| | node default value |
- 		[:varName| | node default value conditional |
  		node := constants at: varName.
  		node name isEmpty ifFalse:
  			["If the definition includes a C comment, or looks like a conditional, take it as is, otherwise convert
  			  the value from Smalltalk to C.
  			  Allow the class to provide an alternative definition, either of just the value or the whole shebang."
  			default := (node value isString
  						and: [(node value includesSubstring: '/*')
  								or: [(node value includesSubstring: ' ? ') and: [node value includesSubstring: ' : ']]])
  							ifTrue: [node value]
  							ifFalse: [self cLiteralFor: node value name: varName].
  			default = #undefined
  				ifTrue: [aStream nextPutAll: '#undef '; nextPutAll: node name; cr]
  				ifFalse:
+ 					[value := vmClass
- 					[conditional := (vmClass ifNil: VMBasicConstants) defineAtCompileTime: node name.
- 					conditional ifTrue:
- 						[aStream nextPutAll: '#if !!defined('; nextPutAll: node name; nextPutAll: ') /* Allow this to be overridden on the compiler command line */'; cr].
- 					value := vmClass
  								ifNotNil:
  									[(vmClass specialValueForConstant: node name default: default)
  										ifNotNil: [:specialDef| specialDef]
  										ifNil: [default]]
  								ifNil: [default].
+ 					((vmClass ifNil: VMBasicConstants) defineAtCompileTime: node name)
+ 						ifTrue: [self putConditionalDefineOf: node name
+ 									as: value
+ 									comment: 'Allow this to be overridden on the compiler command line'
+ 									on: aStream]
+ 						ifFalse: [self putDefineOf: node name as: value on: aStream]]]].
- 					value first ~= $# ifTrue:
- 						[aStream nextPutAll: (conditional ifTrue: ['# define '] ifFalse: ['#define ']); nextPutAll: node name; space].
- 					aStream nextPutAll: value; cr.
- 					conditional ifTrue:
- 						[aStream nextPutAll: '#endif'; cr]]]].
  	aStream cr!

Item was added:
+ ----- Method: CCodeGenerator>>putConditionalDefineOf:as:comment:on: (in category 'C code generator') -----
+ putConditionalDefineOf: aConstantNameString as: valueOrValueString comment: commentOrNil on: aStream
+ 	self withConditionalDefineOf: aConstantNameString
+ 		comment: commentOrNil
+ 		on: aStream
+ 		do: [| valueAsString |
+ 			 valueAsString := valueOrValueString asString.
+ 			 valueAsString first ~= $# ifTrue:
+ 				[aStream nextPutAll: '# define '; nextPutAll: aConstantNameString; space].
+ 			 aStream nextPutAll: valueAsString; cr]!

Item was added:
+ ----- Method: CCodeGenerator>>putDefineOf:as:on: (in category 'C code generator') -----
+ putDefineOf: aConstantNameString as: valueOrValueString on: aStream
+ 	aStream
+ 		nextPutAll: '#define ';
+ 		nextPutAll: aConstantNameString;
+ 		space;
+ 		nextPutAll: valueOrValueString asString;
+ 		cr!

Item was changed:
  ----- Method: CCodeGenerator>>vmHeaderContentsWithBytesPerWord: (in category 'public') -----
  vmHeaderContentsWithBytesPerWord: bytesPerWord
  	"Store C header code on the given stream."
  
+ 	^ ByteString
+ 		streamContents: [ :tempStream | vmClass writeVMHeaderTo: tempStream bytesPerWord: bytesPerWord generator: self ]!
- 	^ByteString streamContents:
- 		[:tempStream|
- 		vmClass writeVMHeaderTo: tempStream bytesPerWord: bytesPerWord]!

Item was added:
+ ----- Method: CCodeGenerator>>withConditionalDefineOf:comment:on:do: (in category 'C code generator') -----
+ withConditionalDefineOf: aConstantNameString comment: commentOrNil on: aStream do: aBlock
+ 	| start |
+ 	aStream nextPutAll: '#if !!defined('; nextPutAll: aConstantNameString; nextPut: $).
+ 	commentOrNil ifNotNil: [aStream nextPutAll: ' /* '; nextPutAll: commentOrNil; nextPutAll: ' */'].
+ 	aStream cr.
+ 	start := aStream position.
+ 	aBlock value.
+ 	aStream nextPutAll: '#endif'.
+ 	aStream position - start > 80 ifTrue:
+ 		[aStream nextPutAll: ' /* !!defined('; nextPutAll: aConstantNameString; nextPutAll: ') */'].
+ 	aStream cr!

Item was removed:
- ----- Method: CoInterpreter class>>writeVMHeaderTo:bytesPerWord: (in category 'translation') -----
- writeVMHeaderTo: aStream bytesPerWord: bytesPerWord
- 	super writeVMHeaderTo: aStream bytesPerWord: bytesPerWord.
- 	aStream
- 		nextPutAll: '#define COGVM 1'; cr;
- 		nextPutAll: '#if !!defined(COGMTVM)'; cr;
- 		nextPutAll: '#	define COGMTVM 0'; cr;
- 		nextPutAll: '#endif'; cr; cr.
- 	"This constant is a hack for the MT VM on SqueakV3.  Eventually it will disappear.
- 	 But having it here rather than in CoInterpreterMT means that the interp.h header
- 	 doesn't  get regenerated every time the sources are, which means less recompilation."
- 	((VMBasicConstants classPool associations select: [:a| a key beginsWith: 'DisownVM'])
- 		asSortedCollection: [:a1 :a2| a1 value <= a2 value])
- 		do: [:a|
- 			aStream nextPutAll: '#define '; nextPutAll: a key; space; print: a value; cr]!

Item was added:
+ ----- Method: CoInterpreter class>>writeVMHeaderTo:bytesPerWord:generator: (in category 'translation') -----
+ writeVMHeaderTo: aStream bytesPerWord: bytesPerWord generator: aCCodeGenerator
+ 	super writeVMHeaderTo: aStream bytesPerWord: bytesPerWord generator: aCCodeGenerator.
+ 	aCCodeGenerator
+ 		putDefineOf: #COGVM as: 1 on: aStream;
+ 		putConditionalDefineOf: #COGMTVM as: 0 comment: nil on: aStream.
+ 	aStream cr.
+ 	"This constant is a hack for the MT VM on SqueakV3.  Eventually it will disappear.
+ 	 But having it here rather than in CoInterpreterMT means that the interp.h header
+ 	 doesn't get regenerated every time the sources are, which is a good thing."
+ 	aCCodeGenerator
+ 		putDefineOf: #DisownVMLockOutFullGC as: DisownVMLockOutFullGC on: aStream!

Item was removed:
- ----- Method: Interpreter class>>writeVMHeaderTo:bytesPerWord: (in category 'translation') -----
- writeVMHeaderTo: aStream bytesPerWord: bytesPerWord
- 	"Currently the Interpreter adds nothing to interp.h above and beyond VMClass's default.
- 	 But the code in trunk's CCodeGenerator>>emitDefineBytesPerWordOn: is a candidate."
- 	super writeVMHeaderTo: aStream bytesPerWord: bytesPerWord!

Item was removed:
- ----- Method: StackInterpreter class>>writeVMHeaderTo:bytesPerWord: (in category 'translation') -----
- writeVMHeaderTo: aStream bytesPerWord: bytesPerWord
- 	super writeVMHeaderTo: aStream bytesPerWord: bytesPerWord.
- 	SistaVM ifTrue:
- 		[aStream nextPutAll: '#define SistaVM 1'; cr].
- 	NewspeakVM ifTrue:
- 		[aStream nextPutAll: '#define NewspeakVM 1'; cr].
- 	MULTIPLEBYTECODESETS ifTrue:
- 		[aStream nextPutAll: '#define MULTIPLEBYTECODESETS 1'; cr].
- 	IMMUTABILITY ifTrue:
- 		[aStream nextPutAll: '#define IMMUTABILITY 1'; cr].
- 	NewspeakVM | MULTIPLEBYTECODESETS | IMMUTABILITY ifTrue:
- 		[aStream cr].
- 	aStream nextPutAll: '#define STACKVM 1'; cr.
- 	(initializationOptions at: #SpurObjectMemory ifAbsent: false) ifTrue:
- 		[aStream nextPutAll: '#define SPURVM 1'; cr]!

Item was added:
+ ----- Method: StackInterpreter class>>writeVMHeaderTo:bytesPerWord:generator: (in category 'translation') -----
+ writeVMHeaderTo: aStream bytesPerWord: bytesPerWord generator: aCCodeGenerator
+ 	super writeVMHeaderTo: aStream bytesPerWord: bytesPerWord generator: aCCodeGenerator.
+ 	SistaVM ifTrue:
+ 		[aCCodeGenerator putDefineOf: #SistaVM as: 1 on: aStream].
+ 	NewspeakVM ifTrue:
+ 		[aCCodeGenerator putDefineOf: #NewspeakVM as: 1 on: aStream].
+ 	MULTIPLEBYTECODESETS ifTrue:
+ 		[aCCodeGenerator putDefineOf: #MULTIPLEBYTECODESETS as: 1 on: aStream].
+ 	IMMUTABILITY ifTrue:
+ 		[aCCodeGenerator
+ 			putConditionalDefineOf: #IMMUTABILITY
+ 			as: 1
+ 			comment: 'Allow this to be overridden on the compiler command line'
+ 			on: aStream].
+ 	SistaVM | NewspeakVM | MULTIPLEBYTECODESETS | IMMUTABILITY ifTrue:
+ 		[aStream cr].
+ 	aCCodeGenerator putDefineOf: #STACKVM as: 1 on: aStream.
+ 	(initializationOptions at: #SpurObjectMemory ifAbsent: false) ifTrue:
+ 		[aCCodeGenerator putDefineOf: #SPURVM as: 1 on: aStream]!

Item was changed:
  ----- Method: VMClass class>>initializeMiscConstants (in category 'initialization') -----
  initializeMiscConstants
  	"Falsify the `what type of VM is this?' flags that are defined in the various interp.h files.
  	 Subclass implementations need to include a super initializeMiscConstants"
  
  	| omc |
  	VMBIGENDIAN class. "Mention this for the benefit of CCodeGenerator>>emitCConstantsOn:"
  	SPURVM := STACKVM := COGVM := COGMTVM := false.
  
  	initializationOptions ifNil: [self initializationOptions: Dictionary new].
  	omc := initializationOptions at: #ObjectMemory ifAbsent: nil.
  	(omc isNil and: [self defaultObjectMemoryClass notNil]) ifTrue:
  		[omc := initializationOptions at: #ObjectMemory put: self defaultObjectMemoryClass name].
  	initializationOptions
  		at: #SqueakV3ObjectMemory	"the good ole default"
  			ifAbsentPut: (omc
  					ifNil: [true]
  					ifNotNil: [(Smalltalk at: omc) includesBehavior: ObjectMemory]);
  		at: #SpurObjectMemory		"the new contender"
  			ifAbsentPut: (omc
  					ifNil: [false]
  					ifNotNil: [(Smalltalk at: omc) includesBehavior: SpurMemoryManager]).
  
  	"Use ifAbsentPut: so that they will get copied back to the
  	 VMMaker's options and dead code will likely be eliminated."
  	PharoVM := initializationOptions at: #PharoVM ifAbsentPut: [false].
  	NewspeakVM := initializationOptions at: #NewspeakVM ifAbsentPut: [false].
  	SistaVM := initializationOptions at: #SistaVM ifAbsentPut: [false].
  	LowcodeVM := initializationOptions at: #LowcodeVM ifAbsentPut: [false].
  	MULTIPLEBYTECODESETS := initializationOptions at: #MULTIPLEBYTECODESETS ifAbsentPut: [false].
- 	"But not these; they're compile-time"
- 	IMMUTABILITY := initializationOptions at: #IMMUTABILITY ifAbsent: [false].
  
  	"These must be set only if specified, not defaulted, because they are set on the command line or in include files."
  	initializationOptions
  		at: #VMBIGENDIAN	ifPresent: [:value| VMBIGENDIAN := value];
  		at: #ObjectMemory	ifPresent: [:value| SPURVM := value beginsWith: 'Spur'];
  		at: #STACKVM		ifPresent: [:value| STACKVM := value];
  		at: #COGVM		ifPresent: [:value| COGVM := initializationOptions at: #COGVM];
+ 		at: #COGMTVM		ifPresent: [:value| COGMTVM := initializationOptions at: #COGMTVM].
+ 
+ 	"And not these; they're compile-time"
+ 	IMMUTABILITY := initializationOptions at: #IMMUTABILITY ifAbsent: [SPURVM] "Default as enabled for Spur VMs"!
- 		at: #COGMTVM		ifPresent: [:value| COGMTVM := initializationOptions at: #COGMTVM]!

Item was removed:
- ----- Method: VMClass class>>writeVMHeaderTo:bytesPerWord: (in category 'translation') -----
- writeVMHeaderTo: aStream bytesPerWord: bytesPerWord
- 	"Generate the contents of interp.h on aStream.  Specific Interpreter subclasses
- 	 override to add more stuff."
- 	aStream
- 		nextPutAll: '#define VM_PROXY_MAJOR '; print: self vmProxyMajorVersion; cr;
- 		nextPutAll: '#define VM_PROXY_MINOR '; print: self vmProxyMinorVersion; cr;
- 		cr;
- 		nextPutAll: '#define SQ_VI_BYTES_PER_WORD '; print: bytesPerWord; cr;
- 		cr.
- 
- 	"The most basic constants must be defined here, not in e.g. the plugin sources, so allow those
- 	 other sources to be shared between different builds (Spur vs SqueakV3, 32-bit vs 64-bit, etc)"
- 	VMBasicConstants mostBasicConstantNames asSet asArray sort do:
- 		[:constName|
- 		(VMBasicConstants classPool at: constName ifAbsent: []) ifNotNil:
- 			[:const|
- 			aStream nextPutAll: '#define '; nextPutAll: constName; space; print: const; cr]].
- 	aStream cr.
- 
- 	((VMBasicConstants classPool associations select: [:a| a key beginsWith: 'PrimErr'])
- 		asSortedCollection: [:a1 :a2| a1 value <= a2 value])
- 		do: [:a|
- 			aStream nextPutAll: '#define '; nextPutAll: a key; space; print: a value; cr].
- 	aStream cr.
- 
- 	aStream
- 		nextPutAll: '#define MinSmallInteger '; print: self objectMemoryClass minSmallInteger; cr;
- 		nextPutAll: '#define MaxSmallInteger '; print: self objectMemoryClass maxSmallInteger; cr;
- 		nextPutAll: '#define NumSmallIntegerTagBits '; print: self objectMemoryClass numSmallIntegerTagBits; cr;
- 		cr.!

Item was added:
+ ----- Method: VMClass class>>writeVMHeaderTo:bytesPerWord:generator: (in category 'translation') -----
+ writeVMHeaderTo: aStream bytesPerWord: bytesPerWord generator: aCCodeGenerator
+ 	"Generate the contents of interp.h on aStream.  Specific Interpreter subclasses
+ 	 override to add more stuff."
+ 	aCCodeGenerator
+ 		putDefineOf: 'VM_PROXY_MAJOR' as: self vmProxyMajorVersion on: aStream;
+ 		putDefineOf: 'VM_PROXY_MINOR' as: self vmProxyMinorVersion on: aStream.
+ 	aStream cr.
+ 	aCCodeGenerator
+ 		putDefineOf: 'SQ_VI_BYTES_PER_WORD' as: bytesPerWord on: aStream.
+ 	aStream cr.
+ 
+ 	"The most basic constants must be defined here, not in e.g. the plugin sources, to allow those
+ 	 other sources to be shared between different builds (Spur vs SqueakV3, 32-bit vs 64-bit, etc)"
+ 	VMBasicConstants mostBasicConstantNames asSet sorted do:
+ 		[:constName|
+ 		(VMBasicConstants classPool at: constName ifAbsent: []) ifNotNil:
+ 			[:const| aCCodeGenerator putDefineOf: constName as: const on: aStream]].
+ 	aStream cr.
+ 
+ 	((VMBasicConstants classPool associations select: [:a| a key beginsWith: 'PrimErr'])
+ 		sorted: [:a1 :a2| a1 value <= a2 value])
+ 		do: [:a| aCCodeGenerator putDefineOf: a key as: a value on: aStream].
+ 	aStream cr.
+ 
+ 	aCCodeGenerator
+ 		putDefineOf: 'MinSmallInteger' as: self objectMemoryClass minSmallInteger on: aStream;
+ 		putDefineOf: 'MaxSmallInteger' as: self objectMemoryClass maxSmallInteger on: aStream;
+ 		putDefineOf: 'NumSmallIntegerTagBits' as: self objectMemoryClass numSmallIntegerTagBits on: aStream.
+ 	aStream cr!

Item was changed:
  ----- Method: VMMaker class>>generateAllSpurConfigurationsUnderVersionControl (in category 'configurations') -----
  generateAllSpurConfigurationsUnderVersionControl
  	self generateNewspeakSpurStackVM;
  		generateNewspeakSpurCog64VM;
  		generateSqueakSpurStackVM;
  		generateSqueakSpurStack64VM;
  		generateNewspeakSpurCogVM;
  		generateSqueakSpurCogVM;
  		generateSqueakSpurCog64VM;
+ 		generateSqueakSpurCogMTVM;
+ 		generateSqueakSpurCog64MTVM;
  		generateSqueakSpurCogSistaVM;
  		generateSqueakSpurCogSista64VM!

Item was changed:
  ----- Method: VMPluginCodeGenerator>>generateInterpreterProxyFunctionDereference:on:indent: (in category 'C translation') -----
  generateInterpreterProxyFunctionDereference: aNode on: aStream indent: anInteger
  	| pluginsToClone |
  	pluginsToClone := self pluginFunctionsToClone copyWithoutAll: self selectorsThatAreGeneratedAsMacros.
  	pluginsToClone isEmpty ifTrue:
  		[^self].
+ 	aStream cr.
+ 	self withConditionalDefineOf: 'SQUEAK_BUILTIN_PLUGIN'
+ 		comment: nil
+ 		on: aStream
+ 		do: [pluginsToClone do:
+ 				[:s| | cs |
+ 				cs := self cFunctionNameFor: s.
+ 				self withOptionalVerbiageFor: s
+ 					on: aStream
+ 					do: [aStream tab: anInteger; nextPutAll: cs; nextPutAll: ' = interpreterProxy->'; nextPutAll: cs; nextPut: $;; cr]
+ 					ifOptionalDo:
+ 						[self
+ 							withConditionalDefineOf: cs
+ 							comment: nil
+ 							on: aStream
+ 							do: [aStream tab: anInteger; nextPutAll: cs; nextPutAll: ' = 0;']]]]!
- 	aStream cr; nextPutAll: '#if !!defined(SQUEAK_BUILTIN_PLUGIN)'; cr.
- 	pluginsToClone do:
- 		[:s| | cs |
- 		cs := self cFunctionNameFor: s.
- 		self withOptionalVerbiageFor: s
- 			on: aStream
- 			do: [aStream tab: anInteger; nextPutAll: cs; nextPutAll: ' = interpreterProxy->'; nextPutAll: cs; nextPut: $;; cr]
- 			ifOptionalDo: [aStream
- 							nextPutAll: '# if !!defined('; nextPutAll: cs; nextPut: $);
- 							crtab: anInteger; nextPutAll: cs; nextPutAll: ' = 0;';
- 							cr; nextPutAll: '# endif'; cr]].
- 	aStream nextPutAll: '#endif /* !!defined(SQUEAK_BUILTIN_PLUGIN) */'.!

Item was changed:
  ----- Method: VMPluginCodeGenerator>>withGuardAgainstDefinitionOf:on:do: (in category 'C translation') -----
  withGuardAgainstDefinitionOf: selector on: aStream do: aBlock
  	"Evaluate aBlock, surrounded by a define if selector is defined as a macro (i.e. by preDeclareInterpreterProxyOn:"
  	(self selectorsThatMayBeGeneratedAsMacros includes: selector) ifFalse:
  		[^aBlock value].
+ 	self
+ 		withConditionalDefineOf: (self cFunctionNameFor: selector)
+ 		comment: nil
+ 		on: aStream
+ 		do: aBlock value!
- 	aStream nextPutAll: '#if !!defined('; nextPutAll: (self cFunctionNameFor: selector); nextPut: $); cr.
- 	aBlock value.
- 	aStream nextPutAll: '#endif'; cr!



More information about the Vm-dev mailing list