[Vm-dev] VM Maker: VMMaker.oscog-AlistairGrant.2456.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Oct 15 18:25:19 UTC 2018


Alistair Grant uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-AlistairGrant.2456.mcz

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

Name: VMMaker.oscog-AlistairGrant.2456
Author: AlistairGrant
Time: 14 October 2018, 9:25:11.249348 pm
UUID: 47b0319d-df10-4ece-84fc-324d0d35fe1d
Ancestors: VMMaker.oscog-AlistairGrant.2455

FakeStdinStream and FilePluginSimulator do double duty with the #atEnd flag to allow #sqFile:Read:Into:At: to break out of its loop.  This is brittle as a additional calls to #atEnd breaks the simulation - which is what Pharo does.

Instead of doing double duty with #atEnd, do the same as the actual plugin (sqFileReadIntoAt() in sqFilePluginBasicPrims.c) and ignore the number of bytes to read when input is from stdin (FakeStdinStream) and only ever read a single byte (fixes the problem and is closer to the real plugin behaviour).

=============== Diff against VMMaker.oscog-AlistairGrant.2455 ===============

Item was changed:
  ----- Method: FakeStdinStream>>next (in category 'accessing') -----
  next
  	"Answer the next object in the Stream represented by the receiver.
  	 If there are no more elements in the stream fill up the buffer by prompting for input"
  	| sem threadIndex inputLine next |
  	position >= readLimit ifTrue:
  		[simulator isThreadedVM
  			ifTrue:
  				["(simulator cogit singleStep not
  				  and: [UIManager confirm: 'Single step?']) ifTrue:
  					[simulator cogit singleStep: true]."
  				 threadIndex := simulator disownVM: DisownVMLockOutFullGC.
  				 simulator forceInterruptCheckFromHeartbeat.
  				 sem := Semaphore new.
  				 WorldState addDeferredUIMessage:
  					[inputLine := UIManager default request: 'Input please!!'.
  					 sem signal].
  				 sem wait]
  			ifFalse: "simulate line-oriented input"
  				[inputLine := ((Smalltalk classNamed: #FillInTheBlankMorph)
  								ifNotNil: "Squeak"
  									[:fITBM|
  									 fITBM
  										request: 'Input please!!'
  										initialAnswer: ''
  										centerAt: ActiveHand cursorPoint
  										inWorld: ActiveWorld
  										onCancelReturn: nil
  										acceptOnCR: true]
  								ifNil: "Pharo; onCancelReturn: nil is the default here"
  									[UIManager default 
  										request: 'Input please!!' 
  										initialAnswer: '']).
  				inputLine ifNil: [self atEnd: true. ^nil]].
  		 collection size <= inputLine size ifTrue:
  			[collection := collection species new: inputLine size + 1].
  		 collection
  			replaceFrom: 1 to: inputLine size with: inputLine startingAt: 1;
  		 	at: (readLimit := inputLine size + 1) put: Character lf.
  		 position := 0.
  		 simulator isThreadedVM ifTrue:
  			[simulator ownVM: threadIndex]].
  	next := collection at: (position := position + 1).
- 	"This is set temporarily to allow (FilePluginSimulator>>#sqFile:Read:Into:At:
- 	 to brwak out of its loop.  sqFile:Read:Into:At: resets it on the way out."
- 	atEnd := position >= readLimit.
  	^next
  	
  
  " This does it with workspaces:
  | ws r s |
  s := Semaphore new.
  ws := Workspace new contents: ''.
  ws acceptAction: [:t| r := t asString. s signal].
  [ws openLabel: 'Yo!!'; shouldStyle: false.
  (ws dependents detect: [:dep | dep isKindOf: PluggableTextMorph] ifNone: [nil]) ifNotNil:
  	[:textMorph| textMorph acceptOnCR: true; hasUnacceptedEdits: true]] fork.
  Processor activeProcess ==  Project uiProcess
  	ifTrue: [[r isNil] whileTrue: [World doOneCycle]]
  	ifFalse: [s wait].
  ws topView delete.
  s wait. s signal.
  r"!

Item was changed:
  ----- Method: FilePluginSimulator>>sqFile:Read:Into:At: (in category 'simulation') -----
+ sqFile: file Read: countArg Into: byteArrayIndexArg At: startIndex
+ 	| byteArrayIndex count |
+ 	count := file isFakeStdinStream
+ 		ifTrue: [1]
+ 		ifFalse: [countArg].
- sqFile: file Read: count Into: byteArrayIndexArg At: startIndex
- 	| byteArrayIndex |
  	byteArrayIndex := byteArrayIndexArg asInteger. "Coerces CArray et al correctly"
  	[[startIndex to: startIndex + count - 1 do:
  		[ :i |
+ 		file atEnd ifTrue: [^i - startIndex].
- 		file atEnd ifTrue:
- 			[file isFakeStdinStream ifTrue: [file atEnd: false].
- 			 ^i - startIndex].
  		interpreterProxy
  			byteAt: byteArrayIndex + i
  			put: (file next ifNil: [file isFakeStdinStream ifTrue: [^0]] ifNotNil: [:c| c asInteger])]]
  			on: Error
  			do: [:ex|
  				(file isStream and: [file isTranscriptStream]) ifFalse:
  					[ex pass].
  				^0]]
  		ensure: [self recordStateOf: file].
  	^count!



More information about the Vm-dev mailing list