Fwd: [Vm-dev] VM Maker: VMMaker-dtl.194.mcz

David T. Lewis lewis at mail.msen.com
Thu Oct 21 01:08:34 UTC 2010


On Wed, Oct 20, 2010 at 05:06:49PM -0700, Andreas Raab wrote:
> 
> On 10/20/2010 5:01 PM, Eliot Miranda wrote:
> >A change set ifs fine.  But I still don't quite understand why you need
> >the inSmalltalk: argument.  I'm assuming
> >
> >self ifDefined: aConstantName
> >       inSmalltalk: [smalltalk statements]
> >       comment: aComment
> >       ifTrue: [true statements]
> >       ifFalse: [false statements]
> >
> >then surely that's equivalent to
> >
> >self ifDefined: aConstantName
> >       comment: aComment
> >       ifTrue: [self cCode: [true statements] inSmalltalk: [smalltalk
> >statements]]
> >       ifFalse: [self cCode: [false statements] inSmalltalk: [smalltalk
> >statements]]
> >
> >which is much nicer IMO because it is orthogonal.
> 
> My understanding is that the 'inSmalltalk' is the block producing the 
> value of the ifdef, e.g.,
> 
> 	self isDefined: 'WIN32' inSmalltalk:[Smalltalk platformName = 
> 	'Win32']
> 		...
> 
> Thus it would not be equivalent at all.
> 
> Cheers,
>   - Andreas

It's patterned after the #cCode:inSmalltalk: idiom.

If you write this:

  ObjectMemory>>isIntegerValue: intValue
      ^ self isDefined: 'SQ_HOST32'
          inSmalltalk: [true]
          comment: 'cast to int for 64 bit image on 32 bit host'
          ifTrue: ((self cCoerce: intValue to: 'int')
                      bitXor: ((self cCoerce: intValue to: 'int') << 1)) >= 0
          ifFalse: (intValue >= 16r-40000000 and: [intValue <= 16r3FFFFFFF])

It will evaluate in Smalltalk to true, and is translated to C as follows:

  sqInt isIntegerValue(sqInt intValue) {
      return 
  # ifdef SQ_HOST32  // cast to int for 64 bit image on 32 bit host
          (((((int) intValue)) ^ ((((int) intValue)) << 1)) >= 0)
  # else
          ((intValue >= -1073741824)
           && (intValue <= 1073741823))
  # endif  // SQ_HOST32
      ;
  }

The inSmalltalk: block is evaluated when running in the simulator, and the
comment: adds a comment to the generated C source. Not perfect but it gets
the job done.

Dave



More information about the Vm-dev mailing list