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

commits at source.squeak.org commits at source.squeak.org
Wed Nov 9 06:07:38 UTC 2022

Eliot Miranda uploaded a new version of VMMaker to project VM Maker:

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

Name: VMMaker.oscog-eem.3274
Author: eem
Time: 8 November 2022, 10:07:17.602603 pm
UUID: 84bfb378-bbd5-45c7-9ca4-4d2aa64d326b
Ancestors: VMMaker.oscog-eem.3273

Transform better expressions returning integers, floats or booleans in SmartSyntaxInterpreterPlugin methods.

Fix an old bug in isBinaryArithmeticOrConditional that is failing to spot effect-free code.

Fix printing of TSendNode instances to parenthesize better.

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

Item was changed:
  ----- Method: SmartSyntaxPluginTMethod>>fixUpReturnOneStmt:previous:on: (in category 'transforming') -----
  fixUpReturnOneStmt: stmt previous: previousStmtOrNil on: sStream
  	| expr exprRetStmts "p t" |
  	stmt isReturn ifFalse: [^sStream nextPut: stmt].
  	expr := stmt expression.
  	(self resultExpressionAlwaysFails: expr) ifTrue:
  		["failure returns"
  		 returnType = #sqInt
  			ifTrue: [sStream nextPut: (TReturnNode new setExpression: expr)]
  			ifFalse: [sStream nextPut: expr; nextPut: self nullReturnExpr].
  	(expr isVariable and: ['nil' = expr name]) ifTrue:
  		["^ nil -- this is never right unless automatically generated"
  		 sStream nextPut: stmt.
  	(expr isVariable and: ['self' = expr name]) ifTrue:
  		["^ self"
  		 (previousStmtOrNil notNil
  		  and: [self resultExpressionAlwaysFails: previousStmtOrNil]) ifFalse:
  			 [fullArgs isEmpty ifFalse:
  				[sStream nextPut: (self statementGuardedWithSuccess: (self popExpr: fullArgs size))]].
  		 sStream nextPut: self nullReturnExpr.
  	(expr isVariable or: [expr isConstant]) ifTrue:
  		["^ variable or ^ constant without guardchecking"
  			nextPut: (sStream isEmpty "No statements to cause failure, therefore no need for failure guard."
  							[self pop: fullArgs size + 1 thenReturnExpr: expr]
  							[self statementGuardedWithSuccess:
  								(self pop: fullArgs size + 1 thenReturnExpr: expr)]);
  			nextPut: self nullReturnExpr.
  	"^ expr with necessary guard checking"
  	"p := sStream position."
  	exprRetStmts := Array streamContents:
  		 (self resultExpressionCanFail: expr)
  				["t := 1."
+ 				self maybeTransform: expr assignedTo: (self oopVariable: '_return_value') forReturnInto:
+ 					[:valueExpr :returnExpr :variable|
+ 					ersStream
+ 						nextPut: (self assign: variable expression: valueExpr);
+ 						nextPut: (self statementGuardedWithSuccess: (self pop: fullArgs size + 1
+ 																			thenReturnExpr: returnExpr))]]
- 				ersStream
- 					nextPut: (self assign: (self oopVariable: '_return_value') expression: expr);
- 					nextPut: (self statementGuardedWithSuccess: (self pop: fullArgs size + 1
- 																		thenReturnExpr: (self oopVariable: '_return_value')))]
  				["t := 2."
  				 ersStream nextPut: (self pop: fullArgs size + 1 thenReturnExpr: expr)]].
  		sStream isEmpty "No statements to cause failure, therefore no need for an initial failure guard."
  			ifTrue: [sStream nextPutAll: exprRetStmts]
  				["t := t + 2."
  				 sStream nextPut: (self statementGuardedWithSuccess: exprRetStmts)].
  	sStream nextPut: self nullReturnExpr.
  	"Them := Dictionary new"
  	"(Them at: t ifAbsentPut: [Dictionary new])
  		at: self selector
  		put: (sStream originalContents copyFrom: p + 1 to: sStream position)"!

Item was added:
+ ----- Method: SmartSyntaxPluginTMethod>>maybeTransform:assignedTo:forReturnInto: (in category 'transformations') -----
+ maybeTransform: aTParseNode assignedTo: aTVariableNode forReturnInto: aTrinaryBlock
+ 	"Evaluate aTrinaryBlock with the value to be returned via assignment to aTVariableNode.
+ 	 Transform to allow for using the most efficient form of methodReturnFoo: expression.
+ 	 For example transform
+ 			expr asBooleanObj
+ 	 *not* to
+ 			var := expr asBooleanObj. ^var
+ 	 but to
+ 			var := expr. ^var asBooleanObj
+ 	 which allows it to be returned via methodReturnBool:"
+ 	(aTParseNode isSend
+ 	 and: [#(asSmallIntegerObj asBooleanObj asFloatObj) includes: aTParseNode selector]) ifTrue:
+ 		[^aTrinaryBlock
+ 			value: aTParseNode receiver
+ 			value: (TSendNode new
+ 						setSelector: aTParseNode selector
+ 						receiver: aTVariableNode
+ 						arguments: #())
+ 			value: aTVariableNode].
+ 	^aTrinaryBlock
+ 			value: aTParseNode
+ 			value: aTVariableNode
+ 			value: aTVariableNode!

Item was changed:
  ----- Method: TSendNode>>isBinaryArithmeticOrConditional (in category 'testing') -----
+ 	^arguments size = 1
- 	^arguments size = 2
  	 and: [#(+ - * / // \\ mod: quo:
  			<< >> bitShift: bitAnd: bitOr: bitXor:
  			= == ~= ~~ > >= < <=
  			& | and: or:) includes: selector]!

Item was changed:
  ----- Method: TSendNode>>printParenthetically:on:level: (in category 'printing') -----
  printParenthetically: node on: aStream level: level
  		ifNil: [aStream print: node]
  			[(node isAssignment
+ 			  or: [node isSend and: [node selector precedence > selector precedence]])
- 			  or: [node isSend and: [node selector precedence >= 3]])
  					[aStream nextPut: $(.
  					 node printOn: aStream level: level.
  					 aStream nextPut: $)]
  				ifFalse: [node printOn: aStream level: level]]!

More information about the Vm-dev mailing list