VM Maker: VMMaker.oscog-eem.2479.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

VM Maker: VMMaker.oscog-eem.2479.mcz

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

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

Name: VMMaker.oscog-eem.2479
Author: eem
Time: 29 October 2018, 6:00:57.748695 pm
UUID: b191888c-6777-483b-82b4-121103743ebf
Ancestors: VMMaker.oscog-eem.2478

Plugins:
Fix slip in primitiveDirectoryDelimitor.
Eliminate cCode:inSmalltalk:'s from the B3DAcceleratorPlugin

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

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>loadClientState:vertices:colors:normals:texCoords: (in category 'primitives-qwaq') -----
  loadClientState: handle vertices: vertices colors: colors normals: normals texCoords: texCoords
  "Common method to set up client state for some render ops"
  | nilOop vtxSize sz colorPtr normalPtr txPtr vertexPtr ok |
  <var: #colorPtr type: 'void *'>
  <var: #normalPtr type: 'void *'>
  <var: #txPtr type: 'void *'>
  <var: #vertexPtr type: 'void *'>
 
  colorPtr := normalPtr := txPtr := vertexPtr := nil.
  sz := 0.
 
  "Verify vertex data"
  (interpreterProxy isWords: vertices) ifFalse:
  [^interpreterProxy primitiveFail].
  vtxSize := (interpreterProxy slotSizeOf: vertices) / 3.
 
  "Verify assumptions of color, normal, texCoords data"
  nilOop := interpreterProxy nilObject.
  (colors = nilOop
  or: [(interpreterProxy isWords: colors)
  and: [(interpreterProxy slotSizeOf: colors) = (vtxSize * 4)]]) ifFalse:
  [^interpreterProxy primitiveFail].
  (normals = nilOop
  or: [(interpreterProxy isWords: normals)
  and: [(interpreterProxy slotSizeOf: normals) = (vtxSize * 3)]]) ifFalse:
  [^interpreterProxy primitiveFail].
  "Don't check size for texCoords since they can be 2,3,4 elements"
  (texCoords = nilOop
  or: [(interpreterProxy isWords: texCoords)]) ifFalse:
  [^interpreterProxy primitiveFail].
 
  "Finally submit the data to OpenGL"
  colors = nilOop ifFalse:
  [colorPtr := interpreterProxy firstIndexableField: colors].
  normals = nilOop ifFalse:
  [normalPtr := interpreterProxy firstIndexableField: normals].
  texCoords = nilOop ifFalse:
  [sz := (interpreterProxy slotSizeOf: texCoords) / vtxSize.
  txPtr := interpreterProxy firstIndexableField: texCoords].
  vertexPtr := interpreterProxy firstIndexableField: vertices.
  interpreterProxy failed ifFalse:
+ [ok := self b3dLoadClientState: handle _: vertexPtr _: 3 _: colorPtr _: 4 _: normalPtr _: 3 _: txPtr _: sz.
- [ok := self
- cCode:'b3dLoadClientState(handle, vertexPtr, 3, colorPtr, 4, normalPtr, 3, txPtr, sz)'
- inSmalltalk: [vertexPtr. colorPtr. normalPtr. txPtr. sz touch].
  ok ifFalse: [interpreterProxy primitiveFail]].
  ^nil "keep compiler quiet"
  !

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveAllocateTexture (in category 'primitives-textures') -----
  primitiveAllocateTexture
  | h w d result renderer |
  <export: true>
  interpreterProxy methodArgumentCount = 4
  ifFalse:[^interpreterProxy primitiveFail].
  h := interpreterProxy stackIntegerValue: 0.
  w := interpreterProxy stackIntegerValue: 1.
  d := interpreterProxy stackIntegerValue: 2.
  renderer := interpreterProxy stackIntegerValue: 3.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxAllocateTexture: renderer _: w _: h _: d.
- result := self cCode:'b3dxAllocateTexture(renderer, w, h, d)' inSmalltalk:[-1].
  result = -1 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 5. "args+rcvr"
  ^interpreterProxy pushInteger: result.!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveCompositeTexture (in category 'primitives-textures') -----
  primitiveCompositeTexture
  | result translucent y x w h texHandle rendererHandle |
  <export: true>
  interpreterProxy methodArgumentCount = 7
  ifFalse:[^interpreterProxy primitiveFail].
  translucent := interpreterProxy booleanValueOf: (interpreterProxy stackValue: 0).
  h := interpreterProxy stackIntegerValue: 1.
  w := interpreterProxy stackIntegerValue: 2.
  y := interpreterProxy stackIntegerValue: 3.
  x := interpreterProxy stackIntegerValue: 4.
  texHandle := interpreterProxy stackIntegerValue: 5.
  rendererHandle := interpreterProxy stackIntegerValue: 6.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxCompositeTexture: rendererHandle _: texHandle _: x _: y _: w _: h _: translucent.
- result := self cCode:'b3dxCompositeTexture(rendererHandle, texHandle, x, y, w, h, translucent)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 7. "args"
  !

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveDestroyRenderer (in category 'primitives-renderer') -----
  primitiveDestroyRenderer
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxDestroyRenderer: handle.
- result := self cCode:'b3dxDestroyRenderer(handle)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 1. "pop arg; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveDestroyTexture (in category 'primitives-textures') -----
  primitiveDestroyTexture
  | handle result renderer |
  <export: true>
  interpreterProxy methodArgumentCount = 2
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  renderer := interpreterProxy stackIntegerValue: 1.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxDestroyTexture: renderer _: handle.
- result := self cCode:'b3dxDestroyTexture(renderer, handle)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 2. "pop arg; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveDrawArrays (in category 'primitives-qwaq') -----
  primitiveDrawArrays
  "Primitive. Setup non-VBO client state and call drawRangeElements in one go to avoid
  garbage collection to move the buffers underneith."
  | maxIdx minIdx mode texCoords normals colors vertices handle vtxSize ok |
  <export: true>
 
  interpreterProxy methodArgumentCount = 8 ifFalse:
  [^interpreterProxy primitiveFail].
 
  maxIdx := interpreterProxy stackIntegerValue: 0.
  minIdx := interpreterProxy stackIntegerValue: 1.
  mode := interpreterProxy stackIntegerValue: 2.
  texCoords := interpreterProxy stackValue: 3.
  normals := interpreterProxy stackValue: 4.
  colors := interpreterProxy stackValue: 5.
  vertices := interpreterProxy stackValue: 6.
  handle := interpreterProxy stackIntegerValue: 7.
 
  self loadClientState: handle vertices: vertices colors: colors normals: normals texCoords: texCoords.
  interpreterProxy failed ifTrue:[^nil].
  doRangeChecks ifTrue:
  ["Verify the vertex data itself"
  self checkVertexData: vertices.
 
  "Verify min-max range in bounds for given vertex array"
  vtxSize := (interpreterProxy slotSizeOf: vertices) / 3.
  (minIdx < 0 or:[minIdx > maxIdx or:[maxIdx > vtxSize]]) ifTrue:
  [interpreterProxy primitiveFail]].
  interpreterProxy failed ifFalse:
+ [ok := self b3dDrawArrays: handle _: mode _: minIdx _: maxIdx.
- [ok := self cCode: 'b3dDrawArrays(handle, mode, minIdx, maxIdx)'
- inSmalltalk:[mode. false].
  ok ifTrue:
  [interpreterProxy pop: interpreterProxy methodArgumentCount]].
  ^nil "keep compiler quiet"
  !

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveDrawElements (in category 'primitives-qwaq') -----
  primitiveDrawElements
  "Primitive. Setup non-VBO client state and call drawElements in one go to avoid
  garbage collection to move the buffers underneith."
  | faces mode texCoords normals colors vertices handle ok facePtr faceSize |
  <export: true>
  <var: #facePtr type: 'unsigned int *'>
 
  interpreterProxy methodArgumentCount = 7 ifFalse:
  [^interpreterProxy primitiveFail].
 
  faces := interpreterProxy stackValue: 0.
  (interpreterProxy isWords: faces) ifFalse:
  [^interpreterProxy primitiveFail].
  faceSize := interpreterProxy slotSizeOf: faces.
  facePtr := interpreterProxy firstIndexableField: faces.
 
  mode := interpreterProxy stackIntegerValue: 1.
  texCoords := interpreterProxy stackValue: 2.
  normals := interpreterProxy stackValue: 3.
  colors := interpreterProxy stackValue: 4.
  vertices := interpreterProxy stackValue: 5.
  handle := interpreterProxy stackIntegerValue: 6.
 
  self loadClientState: handle vertices: vertices colors: colors normals: normals texCoords: texCoords.
  interpreterProxy failed ifTrue:[^nil].
 
  doRangeChecks ifTrue:
  ["Verify the vertex data itself"
  self checkVertexData: vertices.
  "Change bounds range to make sure the data is valid"
  self checkBoundsRange: vertices faces: facePtr count: faceSize].
 
  interpreterProxy failed ifFalse:
+ [ok := self b3dDrawElements: handle _: mode _: faceSize _: facePtr.
- [ok := self cCode: 'b3dDrawElements(handle, mode, faceSize, facePtr)'
- inSmalltalk:[mode. facePtr. false].
  ok ifTrue:
  [interpreterProxy pop: interpreterProxy methodArgumentCount]].
  ^nil "keep compiler quiet"
  !

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveDrawRangeElements (in category 'primitives-qwaq') -----
  primitiveDrawRangeElements
  "Primitive. Setup non-VBO client state and call drawRangeElements in one go to avoid
  garbage collection to move the buffers underneith."
  | faces maxIdx minIdx mode texCoords normals colors vertices handle vtxSize ok facePtr faceSize |
  <export: true>
  <var: #facePtr type: 'unsigned int *'>
 
  interpreterProxy methodArgumentCount = 9 ifFalse:
  [^interpreterProxy primitiveFail].
 
  faces := interpreterProxy stackValue: 0.
  (interpreterProxy isWords: faces) ifFalse:
  [^interpreterProxy primitiveFail].
  faceSize := interpreterProxy slotSizeOf: faces.
  facePtr := interpreterProxy firstIndexableField: faces.
 
  maxIdx := interpreterProxy stackIntegerValue: 1.
  minIdx := interpreterProxy stackIntegerValue: 2.
  mode := interpreterProxy stackIntegerValue: 3.
  texCoords := interpreterProxy stackValue: 4.
  normals := interpreterProxy stackValue: 5.
  colors := interpreterProxy stackValue: 6.
  vertices := interpreterProxy stackValue: 7.
  handle := interpreterProxy stackIntegerValue: 8.
 
  self loadClientState: handle vertices: vertices colors: colors normals: normals texCoords: texCoords.
  interpreterProxy failed ifTrue:[^nil].
 
  doRangeChecks ifTrue:
  ["Verify the vertex data itself"
  self checkVertexData: vertices.
  "Change bounds range to make sure the data is valid"
  self checkBoundsRange: vertices faces: facePtr count: faceSize.
  "Verify min-max range in bounds for given vertex array"
  vtxSize := (interpreterProxy slotSizeOf: vertices) / 3.
  (minIdx < 0 or:[minIdx > maxIdx or:[maxIdx > vtxSize]]) ifTrue:
  [interpreterProxy primitiveFail]].
 
  interpreterProxy failed ifFalse:
+ [ok := self b3dDrawRangeElements: handle _: mode _: minIdx _: maxIdx _: faceSize _: facePtr.
- [ok := self cCode: 'b3dDrawRangeElements(handle, mode, minIdx, maxIdx, faceSize,  facePtr)'
- inSmalltalk:[mode. facePtr. false].
  ok ifTrue:
  [interpreterProxy pop: interpreterProxy methodArgumentCount]].
  ^nil "keep compiler quiet"
  !

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveFinishRenderer (in category 'primitives-renderer') -----
  primitiveFinishRenderer
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxFinishRenderer: handle.
- result := self cCode:'b3dxFinishRenderer(handle)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 1. "pop arg; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveFlushRenderer (in category 'primitives-renderer') -----
  primitiveFlushRenderer
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxFlushRenderer: handle.
- result := self cCode:'b3dxFlushRenderer(handle)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 1. "pop arg; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveGetRendererColorMasks (in category 'primitives-renderer') -----
  primitiveGetRendererColorMasks
  | handle masks array |
  <export: true>
  <var: #masks declareC:'unsigned int masks[4]'>
  interpreterProxy methodArgumentCount = 2
  ifFalse:[^interpreterProxy primitiveFail].
  array := interpreterProxy stackObjectValue: 0.
  handle := interpreterProxy stackIntegerValue: 1.
  interpreterProxy failed ifTrue:[^nil].
  ((interpreterProxy isArray: array)
  and: [(interpreterProxy slotSizeOf: array) = 4
+ and: [self b3dxGetRendererColorMasks: handle _: masks]])
- and: [self cCode:'b3dxGetRendererColorMasks(handle, masks)' inSmalltalk:[false]]])
  ifFalse:[^interpreterProxy primitiveFail].
  interpreterProxy pushRemappableOop: array.
  0 to: 3 do: [:i|
  interpreterProxy
  storePointer: i
  ofObject: interpreterProxy topRemappableOop
  withValue: (interpreterProxy positive32BitIntegerFor: (masks at: i))].
  interpreterProxy popRemappableOop.
  ^interpreterProxy pop: 2 "pop args return receiver"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveGetRendererSurfaceDepth (in category 'primitives-renderer') -----
  primitiveGetRendererSurfaceDepth
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxGetRendererSurfaceDepth: handle.
- result := self cCode:'b3dxGetRendererSurfaceDepth(handle)' inSmalltalk:[-1].
  result < 0 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 2. "args+rcvr"
  ^interpreterProxy pushInteger: result!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveGetRendererSurfaceHandle (in category 'primitives-renderer') -----
  primitiveGetRendererSurfaceHandle
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxGetRendererSurfaceHandle: handle.
- result := self cCode:'b3dxGetRendererSurfaceHandle(handle)' inSmalltalk:[-1].
  result < 0 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 2. "args+rcvr"
  ^interpreterProxy pushInteger: result!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveGetRendererSurfaceHeight (in category 'primitives-renderer') -----
  primitiveGetRendererSurfaceHeight
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxGetRendererSurfaceHeight: handle.
- result := self cCode:'b3dxGetRendererSurfaceHeight(handle)' inSmalltalk:[-1].
  result < 0 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 2. "args+rcvr"
  ^interpreterProxy pushInteger: result!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveGetRendererSurfaceWidth (in category 'primitives-renderer') -----
  primitiveGetRendererSurfaceWidth
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxGetRendererSurfaceWidth: handle.
- result := self cCode:'b3dxGetRendererSurfaceWidth(handle)' inSmalltalk:[-1].
  result < 0 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 2. "args+rcvr"
  ^interpreterProxy pushInteger: result!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveIsOverlayRenderer (in category 'primitives-renderer') -----
  primitiveIsOverlayRenderer
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxIsOverlayRenderer: handle.
- result := self cCode:'b3dxIsOverlayRenderer(handle)' inSmalltalk:[false].
  interpreterProxy pop: 2. "args+rcvr"
  ^interpreterProxy pushBool: result.!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveRenderVertexBuffer (in category 'primitives-renderer') -----
  primitiveRenderVertexBuffer
  | idxCount vtxCount vtxArray idxArray texHandle primType result flags handle |
  <export: true>
  <var: #idxArray type: 'int *'>
  <var: #vtxArray type: 'float *'>
 
  interpreterProxy methodArgumentCount = 8
  ifFalse:[^interpreterProxy primitiveFail].
  idxCount := interpreterProxy stackIntegerValue: 0.
  vtxCount := interpreterProxy stackIntegerValue: 2.
  texHandle := interpreterProxy stackIntegerValue: 4.
  flags := interpreterProxy stackIntegerValue: 5.
  primType := interpreterProxy stackIntegerValue: 6.
  handle := interpreterProxy stackIntegerValue: 7.
 
  interpreterProxy failed ifTrue:[^nil].
  vtxArray := self stackPrimitiveVertexArray: 3 ofSize: vtxCount.
  idxArray := self stackPrimitiveIndexArray: 1 ofSize: idxCount validate: true forVertexSize: vtxCount.
 
  (vtxArray == nil or:[idxArray == nil
  or:[primType < 1 or:[primType > 6
  or:[interpreterProxy failed]]]])
  ifTrue:[^interpreterProxy primitiveFail].
 
+ result := self b3dxRenderVertexBuffer: handle _: primType _: flags _: texHandle _: vtxArray _: vtxCount _: idxArray _: idxCount.
- result := self cCode:'b3dxRenderVertexBuffer(handle, primType, flags, texHandle, vtxArray, vtxCount, idxArray, idxCount)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 8. "pop args; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveSetLights (in category 'primitives-renderer') -----
  primitiveSetLights
  | lightArray lightCount light handle |
  <export: true>
+ <var: #light type: #'void *'>
- <inline: false>
- <var: #light type: 'void*'>
 
  interpreterProxy methodArgumentCount = 2
  ifFalse:[^interpreterProxy primitiveFail].
 
  lightArray := self stackLightArrayValue: 0.
  handle := interpreterProxy stackIntegerValue: 1.
  interpreterProxy failed ifTrue:[^nil].
  (self b3dxDisableLights: handle)
  ifFalse:[^interpreterProxy primitiveFail].
+ lightArray ifNil: [^nil].
- lightArray == nil ifTrue:[^nil].
  lightCount := interpreterProxy slotSizeOf: lightArray.
  "For each enabled light source"
  0 to: lightCount-1 do:[:i|
  light := self fetchLightSource: i ofObject: lightArray.
+ (self b3dxLoadLight: handle _: i _: light) ifFalse:
+ [^interpreterProxy primitiveFail].
- (self cCode:'b3dxLoadLight(handle, i, light)' inSmalltalk:[false])
- ifFalse:[^interpreterProxy primitiveFail].
  ].
  ^interpreterProxy pop: 2. "args; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveSetMaterial (in category 'primitives-renderer') -----
  primitiveSetMaterial
  | material handle |
  <export: true>
  <inline: false>
  <var: #material type: 'void*'>
 
  interpreterProxy methodArgumentCount = 2
  ifFalse:[^interpreterProxy primitiveFail].
  material := self stackMaterialValue: 0.
  handle := interpreterProxy stackIntegerValue: 1.
+ (self b3dxLoadMaterial: handle _: material)
- (self cCode:'b3dxLoadMaterial(handle, material)' inSmalltalk:[false])
  ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 2. "args; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveSwapRendererBuffers (in category 'primitives-renderer') -----
  primitiveSwapRendererBuffers
  | handle result |
  <export: true>
  interpreterProxy methodArgumentCount = 1
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxSwapRendererBuffers: handle.
- result := self cCode:'b3dxSwapRendererBuffers(handle)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 1. "pop arg; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveTextureByteSex (in category 'primitives-textures') -----
  primitiveTextureByteSex
  | handle result renderer |
  <export: true>
  interpreterProxy methodArgumentCount = 2
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  renderer := interpreterProxy stackIntegerValue: 1.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxTextureByteSex: renderer _: handle.
- result := self cCode:'b3dxTextureByteSex(renderer, handle)' inSmalltalk:[-1].
  result < 0 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 3.
  ^interpreterProxy pushBool: result.!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveTextureDepth (in category 'primitives-textures') -----
  primitiveTextureDepth
  | handle result renderer |
  <export: true>
  interpreterProxy methodArgumentCount = 2
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  renderer := interpreterProxy stackIntegerValue: 1.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxActualTextureDepth: renderer _: handle.
- result := self cCode:'b3dxActualTextureDepth(renderer, handle)' inSmalltalk:[-1].
  result < 0 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 3.
  ^interpreterProxy pushInteger: result.!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveTextureGetColorMasks (in category 'primitives-textures') -----
  primitiveTextureGetColorMasks
  | handle masks array renderer |
  <export: true>
  <var: #masks declareC:'unsigned int masks[4]'>
  interpreterProxy methodArgumentCount = 3
  ifFalse:[^interpreterProxy primitiveFail].
  array := interpreterProxy stackObjectValue: 0.
  handle := interpreterProxy stackIntegerValue: 1.
  renderer := interpreterProxy stackIntegerValue: 2.
  interpreterProxy failed ifTrue:[^nil].
  ((interpreterProxy isArray: array)
  and: [(interpreterProxy slotSizeOf: array) = 4
+ and: [self b3dxTextureColorMasks: renderer _: handle _: masks]])
- and: [self cCode:'b3dxTextureColorMasks(renderer, handle, masks)' inSmalltalk:[false]]])
  ifFalse:[^interpreterProxy primitiveFail].
  interpreterProxy pushRemappableOop: array.
  0 to: 3 do: [:i|
  interpreterProxy
  storePointer: i
  ofObject: interpreterProxy topRemappableOop
  withValue: (interpreterProxy positive32BitIntegerFor: (masks at: i))].
  interpreterProxy popRemappableOop.
  ^interpreterProxy pop: 3 "pop args return receiver"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveTextureSurfaceHandle (in category 'primitives-textures') -----
  primitiveTextureSurfaceHandle
  | handle result renderer |
  <export: true>
  interpreterProxy methodArgumentCount = 2
  ifFalse:[^interpreterProxy primitiveFail].
  handle := interpreterProxy stackIntegerValue: 0.
  renderer := interpreterProxy stackIntegerValue: 1.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxTextureSurfaceHandle: renderer _: handle.
- result := self cCode:'b3dxTextureSurfaceHandle(renderer, handle)' inSmalltalk:[-1].
  result < 0 ifTrue:[^interpreterProxy primitiveFail].
  interpreterProxy pop: 3.
  ^interpreterProxy pushInteger: result!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveTextureUpload (in category 'primitives-textures') -----
  primitiveTextureUpload
  | h w d result form bits ppw bitsPtr handle renderer |
  <export: true>
  <var: #bitsPtr type: 'void*'>
  interpreterProxy methodArgumentCount = 3
  ifFalse:[^interpreterProxy primitiveFail].
  form := interpreterProxy stackValue: 0.
  ((interpreterProxy isPointers: form) and:[(interpreterProxy slotSizeOf: form) >= 4])
  ifFalse:[^interpreterProxy primitiveFail].
  bits := interpreterProxy fetchPointer: 0 ofObject: form.
  w := interpreterProxy fetchInteger: 1 ofObject: form.
  h := interpreterProxy fetchInteger: 2 ofObject: form.
  d := interpreterProxy fetchInteger: 3 ofObject: form.
  ppw := 32 // d.
  (interpreterProxy isWords: bits)
  ifFalse:[^interpreterProxy primitiveFail].
  (interpreterProxy slotSizeOf: bits) = (w + ppw - 1 // ppw * h)
  ifFalse:[^interpreterProxy primitiveFail].
  bitsPtr := interpreterProxy firstIndexableField: bits.
  handle := interpreterProxy stackIntegerValue: 1.
  renderer := interpreterProxy stackIntegerValue: 2.
  interpreterProxy failed ifTrue:[^nil].
+ result := self b3dxUploadTexture: renderer _: handle _: w _: h _: d _: bitsPtr.
- result := self cCode:'b3dxUploadTexture(renderer, handle, w, h, d, bitsPtr)' inSmalltalk:[false].
  result ifFalse:[^interpreterProxy primitiveFail].
  ^interpreterProxy pop: 3. "args; return rcvr"!

Item was changed:
  ----- Method: B3DAcceleratorPlugin>>stackLightArrayValue: (in category 'primitive support') -----
  stackLightArrayValue: stackIndex
  "Load an Array of B3DPrimitiveLights from the given stack index"
  | oop array arraySize |
  <inline: false>
+ array := interpreterProxy stackValue: stackIndex.
- array := interpreterProxy stackObjectValue: stackIndex.
- array = nil ifTrue:[^nil]. "really??"
  array = interpreterProxy nilObject ifTrue:[^nil].
+ (interpreterProxy isArray: array) ifFalse:
+ [^interpreterProxy primitiveFail].
- (interpreterProxy isArray: array)
- ifFalse:[^interpreterProxy primitiveFail].
  arraySize := interpreterProxy slotSizeOf: array.
  0 to: arraySize-1 do:[:i|
  oop := interpreterProxy fetchPointer: i ofObject: array.
  ((interpreterProxy isWords: oop) and:[(interpreterProxy slotSizeOf: oop) = 32])
  ifFalse:[^interpreterProxy primitiveFail].
  ].
  ^array!

Item was changed:
  ----- Method: FilePlugin>>primitiveDirectoryDelimitor (in category 'directory primitives') -----
  primitiveDirectoryDelimitor
  <export: true>
  interpreterProxy minorVersion >= 13
  ifTrue:
  [interpreterProxy
  pop: 1
  thenPush: (interpreterProxy characterObjectOf: self dir_Delimitor)]
  ifFalse:
  [| ascii |
+ ascii := self dir_Delimitor.
- ascii := self asciiDirectoryDelimiter.
  (ascii >= 0 and: [ascii <= 255])
  ifTrue:
  [interpreterProxy
  pop: 1
  thenPush: (interpreterProxy
  fetchPointer: ascii
  ofObject: interpreterProxy characterTable)]
  ifFalse:
  [interpreterProxy primitiveFail]]!

Reply | Threaded
Open this post in threaded view
|

Eliminating cCode:inSmalltalk:'s

Ben Coman
 
I'm sure this was explained somewhere before (even recently), 
but I forget, and can't find anything in my usual search places.

On Tue, 30 Oct 2018 at 09:02, <[hidden email]> wrote:
 
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2479.mcz

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

Name: VMMaker.oscog-eem.2479
Author: eem
Time: 29 October 2018, 6:00:57.748695 pm
UUID: b191888c-6777-483b-82b4-121103743ebf
Ancestors: VMMaker.oscog-eem.2478

Plugins:
Fix slip in primitiveDirectoryDelimitor.
Eliminate cCode:inSmalltalk:'s from the B3DAcceleratorPlugin

=============== Diff against VMMaker.oscog-eem.2478 ===============
<snip>
Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveAllocateTexture (in category 'primitives-textures') -----
  primitiveAllocateTexture
        | h w d result renderer |
        <export: true>
        interpreterProxy methodArgumentCount = 4
                ifFalse:[^interpreterProxy primitiveFail].
        h := interpreterProxy stackIntegerValue: 0.
        w := interpreterProxy stackIntegerValue: 1.
        d := interpreterProxy stackIntegerValue: 2.
        renderer := interpreterProxy stackIntegerValue: 3.
        interpreterProxy failed ifTrue:[^nil].
+       result := self b3dxAllocateTexture: renderer _: w _: h _: d.
-       result := self cCode:'b3dxAllocateTexture(renderer, w, h, d)' inSmalltalk:[-1].
        result = -1 ifTrue:[^interpreterProxy primitiveFail].
        interpreterProxy pop: 5. "args+rcvr"
        ^interpreterProxy pushInteger: result.!


What is the mechanism that allows cCode:inSmalltalk:'s to be replaced like above?
I half expected  "b3dxAllocateTexture:_:_:_:"
to be newly defined somewhere else in that commit.

cheers -ben 
Reply | Threaded
Open this post in threaded view
|

Re: Eliminating cCode:inSmalltalk:'s

Eliot Miranda-2
 
Hi Ben,

On Oct 30, 2018, at 4:57 AM, Ben Coman <[hidden email]> wrote:

I'm sure this was explained somewhere before (even recently), 
but I forget, and can't find anything in my usual search places.

On Tue, 30 Oct 2018 at 09:02, <[hidden email]> wrote:
 
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2479.mcz

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

Name: VMMaker.oscog-eem.2479
Author: eem
Time: 29 October 2018, 6:00:57.748695 pm
UUID: b191888c-6777-483b-82b4-121103743ebf
Ancestors: VMMaker.oscog-eem.2478

Plugins:
Fix slip in primitiveDirectoryDelimitor.
Eliminate cCode:inSmalltalk:'s from the B3DAcceleratorPlugin

=============== Diff against VMMaker.oscog-eem.2478 ===============
<snip>
Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveAllocateTexture (in category 'primitives-textures') -----
  primitiveAllocateTexture
        | h w d result renderer |
        <export: true>
        interpreterProxy methodArgumentCount = 4
                ifFalse:[^interpreterProxy primitiveFail].
        h := interpreterProxy stackIntegerValue: 0.
        w := interpreterProxy stackIntegerValue: 1.
        d := interpreterProxy stackIntegerValue: 2.
        renderer := interpreterProxy stackIntegerValue: 3.
        interpreterProxy failed ifTrue:[^nil].
+       result := self b3dxAllocateTexture: renderer _: w _: h _: d.
-       result := self cCode:'b3dxAllocateTexture(renderer, w, h, d)' inSmalltalk:[-1].
        result = -1 ifTrue:[^interpreterProxy primitiveFail].
        interpreterProxy pop: 5. "args+rcvr"
        ^interpreterProxy pushInteger: result.!


What is the mechanism that allows cCode:inSmalltalk:'s to be replaced like above?
I half expected  "b3dxAllocateTexture:_:_:_:"
to be newly defined somewhere else in that commit.

Those implementations can come later.  Right now the plugin doesn’t simulate anyway.  You’re right I could have written them then and there, but I would rather do real o es than simple failing stubs.  If I find that I can’t simulate without stubs I’ll add them.  Feel free to provide them if you’re motivated.  I should have just fixed the digitCompare: issue but got carried away...

cheers -ben 

_,,,^..^,,,_ (phone)
Reply | Threaded
Open this post in threaded view
|

Re: Eliminating cCode:inSmalltalk:'s

Ben Coman
 


On Tue, 30 Oct 2018 at 20:22, Eliot Miranda <[hidden email]> wrote:
 
Hi Ben,

On Oct 30, 2018, at 4:57 AM, Ben Coman <[hidden email]> wrote:

I'm sure this was explained somewhere before (even recently), 
but I forget, and can't find anything in my usual search places.

On Tue, 30 Oct 2018 at 09:02, <[hidden email]> wrote:
 
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2479.mcz

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

Name: VMMaker.oscog-eem.2479
Author: eem
Time: 29 October 2018, 6:00:57.748695 pm
UUID: b191888c-6777-483b-82b4-121103743ebf
Ancestors: VMMaker.oscog-eem.2478

Plugins:
Fix slip in primitiveDirectoryDelimitor.
Eliminate cCode:inSmalltalk:'s from the B3DAcceleratorPlugin

=============== Diff against VMMaker.oscog-eem.2478 ===============
<snip>
Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveAllocateTexture (in category 'primitives-textures') -----
  primitiveAllocateTexture
        | h w d result renderer |
        <export: true>
        interpreterProxy methodArgumentCount = 4
                ifFalse:[^interpreterProxy primitiveFail].
        h := interpreterProxy stackIntegerValue: 0.
        w := interpreterProxy stackIntegerValue: 1.
        d := interpreterProxy stackIntegerValue: 2.
        renderer := interpreterProxy stackIntegerValue: 3.
        interpreterProxy failed ifTrue:[^nil].
+       result := self b3dxAllocateTexture: renderer _: w _: h _: d.
-       result := self cCode:'b3dxAllocateTexture(renderer, w, h, d)' inSmalltalk:[-1].
        result = -1 ifTrue:[^interpreterProxy primitiveFail].
        interpreterProxy pop: 5. "args+rcvr"
        ^interpreterProxy pushInteger: result.!


What is the mechanism that allows cCode:inSmalltalk:'s to be replaced like above?
I half expected  "b3dxAllocateTexture:_:_:_:"
to be newly defined somewhere else in that commit.

Those implementations can come later.  Right now the plugin doesn’t simulate anyway.  You’re right I could have written them then and there, but I would rather do real o es than simple failing stubs.  If I find that I can’t simulate without stubs I’ll add them.  Feel free to provide them if you’re motivated.  I should have just fixed the digitCompare: issue but got carried away...

I'm still missing something basic, but guessing... the "inSmalltalk:" part is what is performed by the simulator?

and the "cCode:" is generated into a C-code-call that expects that function linked in from a library?

and now there is no simulation and "b3dxAllocateTexture:_:_:_:" is generated to C-code-call?

So is there a mechanism that any unknown message (i.e. "b3dxAllocateTexture:_:_:_:") is generated to a C-code-call?

cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: Eliminating cCode:inSmalltalk:'s

Eliot Miranda-2
 
Hi Ben,

On Oct 30, 2018, at 6:26 AM, Ben Coman <[hidden email]> wrote:

On Tue, 30 Oct 2018 at 20:22, Eliot Miranda <[hidden email]> wrote:
 
Hi Ben,

On Oct 30, 2018, at 4:57 AM, Ben Coman <[hidden email]> wrote:

I'm sure this was explained somewhere before (even recently), 
but I forget, and can't find anything in my usual search places.

On Tue, 30 Oct 2018 at 09:02, <[hidden email]> wrote:
 
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2479.mcz

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

Name: VMMaker.oscog-eem.2479
Author: eem
Time: 29 October 2018, 6:00:57.748695 pm
UUID: b191888c-6777-483b-82b4-121103743ebf
Ancestors: VMMaker.oscog-eem.2478

Plugins:
Fix slip in primitiveDirectoryDelimitor.
Eliminate cCode:inSmalltalk:'s from the B3DAcceleratorPlugin

=============== Diff against VMMaker.oscog-eem.2478 ===============
<snip>
Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveAllocateTexture (in category 'primitives-textures') -----
  primitiveAllocateTexture
        | h w d result renderer |
        <export: true>
        interpreterProxy methodArgumentCount = 4
                ifFalse:[^interpreterProxy primitiveFail].
        h := interpreterProxy stackIntegerValue: 0.
        w := interpreterProxy stackIntegerValue: 1.
        d := interpreterProxy stackIntegerValue: 2.
        renderer := interpreterProxy stackIntegerValue: 3.
        interpreterProxy failed ifTrue:[^nil].
+       result := self b3dxAllocateTexture: renderer _: w _: h _: d.
-       result := self cCode:'b3dxAllocateTexture(renderer, w, h, d)' inSmalltalk:[-1].
        result = -1 ifTrue:[^interpreterProxy primitiveFail].
        interpreterProxy pop: 5. "args+rcvr"
        ^interpreterProxy pushInteger: result.!


What is the mechanism that allows cCode:inSmalltalk:'s to be replaced like above?
I half expected  "b3dxAllocateTexture:_:_:_:"
to be newly defined somewhere else in that commit.

Those implementations can come later.  Right now the plugin doesn’t simulate anyway.  You’re right I could have written them then and there, but I would rather do real o es than simple failing stubs.  If I find that I can’t simulate without stubs I’ll add them.  Feel free to provide them if you’re motivated.  I should have just fixed the digitCompare: issue but got carried away...

I'm still missing something basic, but guessing... the "inSmalltalk:" part is what is performed by the simulator?

I’m sorry; yes.  Given
    self cCode: stringOrBlock inSmalltalk: block
the C translator will either emit stringOrBlock verbatim if stringOrBlock is a string, or emit the translation of stringOrBlock’s statements if it is a block.  The simulator simply evaluates block.  And the value of the expression is, effectively, the value of either block.

and the "cCode:" is generated into a C-code-call that expects that function linked in from a library?

More accurately stringOrBlock is arbitrary code.  Look for uses in BirBltSimulation and you’ll see the code for invoking the fast bitblt code for the Raspberry Pi.  This assigns parameters for a bitblt invocation to a struct.  One can define a struct in Smalltalk (VMStructType ? an approach I take for Cog method headers, stack pages, spur memory segments, etc) but Tim took the short cut of merely writing the verbatim C.

One stereotypical use was to write the invocation of some platform support function and have the inSmalltalk: either simulate or answer a default value, and sometimes to reference variables used in the call but unused elsewhere, to avoid Smalltalk compiler earnings.  This is what we see here in the B3DAcceleratorPlugin.  But using a default value precludes simulation, and the code is ugly.  So I’ve started replacing as many cCode:inSmalltalk:’s with a message send where stringOrBlock is simply a call.  This is dependent on _: keyword support and the <doNotGenerate> pragma to instruct Slang not to generate the simulator implementation.  I added <doNotGenerate> several years ago; I added _: support a few weeks ago.


and now there is no simulation and "b3dxAllocateTexture:_:_:_:" is generated to C-code-call?

That would generate a call of b3dxAllocateTexture with the given arguments.

So is there a mechanism that any unknown message (i.e. "b3dxAllocateTexture:_:_:_:") is generated to a C-code-call?

Yes.  Look for VMMaker.oscog-eem.2440 and VMMaker.oscog-eem.2452.  And in general one can use 
    self foo: expr bar: rpxe 
to generate a call of foobar.  I simply added stripping out of _:, which means not having to split a call across several keywords; much more readable.


cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: Eliminating cCode:inSmalltalk:'s

Eliot Miranda-2
 
Hi Ben, Hi All,

On Oct 30, 2018, at 7:34 AM, Eliot Miranda <[hidden email]> wrote:

Hi Ben,

On Oct 30, 2018, at 6:26 AM, Ben Coman <[hidden email]> wrote:

On Tue, 30 Oct 2018 at 20:22, Eliot Miranda <[hidden email]> wrote:
 
Hi Ben,

On Oct 30, 2018, at 4:57 AM, Ben Coman <[hidden email]> wrote:

I'm sure this was explained somewhere before (even recently), 
but I forget, and can't find anything in my usual search places.

On Tue, 30 Oct 2018 at 09:02, <[hidden email]> wrote:
 
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2479.mcz

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

Name: VMMaker.oscog-eem.2479
Author: eem
Time: 29 October 2018, 6:00:57.748695 pm
UUID: b191888c-6777-483b-82b4-121103743ebf
Ancestors: VMMaker.oscog-eem.2478

Plugins:
Fix slip in primitiveDirectoryDelimitor.
Eliminate cCode:inSmalltalk:'s from the B3DAcceleratorPlugin

=============== Diff against VMMaker.oscog-eem.2478 ===============
<snip>
Item was changed:
  ----- Method: B3DAcceleratorPlugin>>primitiveAllocateTexture (in category 'primitives-textures') -----
  primitiveAllocateTexture
        | h w d result renderer |
        <export: true>
        interpreterProxy methodArgumentCount = 4
                ifFalse:[^interpreterProxy primitiveFail].
        h := interpreterProxy stackIntegerValue: 0.
        w := interpreterProxy stackIntegerValue: 1.
        d := interpreterProxy stackIntegerValue: 2.
        renderer := interpreterProxy stackIntegerValue: 3.
        interpreterProxy failed ifTrue:[^nil].
+       result := self b3dxAllocateTexture: renderer _: w _: h _: d.
-       result := self cCode:'b3dxAllocateTexture(renderer, w, h, d)' inSmalltalk:[-1].
        result = -1 ifTrue:[^interpreterProxy primitiveFail].
        interpreterProxy pop: 5. "args+rcvr"
        ^interpreterProxy pushInteger: result.!


What is the mechanism that allows cCode:inSmalltalk:'s to be replaced like above?
I half expected  "b3dxAllocateTexture:_:_:_:"
to be newly defined somewhere else in that commit.

Those implementations can come later.  Right now the plugin doesn’t simulate anyway.  You’re right I could have written them then and there, but I would rather do real o es than simple failing stubs.  If I find that I can’t simulate without stubs I’ll add them.  Feel free to provide them if you’re motivated.  I should have just fixed the digitCompare: issue but got carried away...

I'm still missing something basic, but guessing... the "inSmalltalk:" part is what is performed by the simulator?

I’m sorry; yes.  Given
    self cCode: stringOrBlock inSmalltalk: block
the C translator will either emit stringOrBlock verbatim if stringOrBlock is a string, or emit the translation of stringOrBlock’s statements if it is a block.  The simulator simply evaluates block.  And the value of the expression is, effectively, the value of either block.

and the "cCode:" is generated into a C-code-call that expects that function linked in from a library?

More accurately stringOrBlock is arbitrary code.  Look for uses in BirBltSimulation and you’ll see the code for invoking the fast bitblt code for the Raspberry Pi.  This assigns parameters for a bitblt invocation to a struct.  One can define a struct in Smalltalk (VMStructType ? an approach I take for Cog method headers, stack pages, spur memory segments, etc) but Tim took the short cut of merely writing the verbatim C.

One stereotypical use was to write the invocation of some platform support function and have the inSmalltalk: either simulate or answer a default value, and sometimes to reference variables used in the call but unused elsewhere, to avoid Smalltalk compiler earnings.  This is what we see here in the B3DAcceleratorPlugin.  But using a default value precludes simulation, and the code is ugly.  So I’ve started replacing as many cCode:inSmalltalk:’s with a message send where stringOrBlock is simply a call.  This is dependent on _: keyword support and the <doNotGenerate> pragma to instruct Slang not to generate the simulator implementation.  I added <doNotGenerate> several years ago; I added _: support a few weeks ago.


and now there is no simulation and "b3dxAllocateTexture:_:_:_:" is generated to C-code-call?

That would generate a call of b3dxAllocateTexture with the given arguments.

So is there a mechanism that any unknown message (i.e. "b3dxAllocateTexture:_:_:_:") is generated to a C-code-call?

Yes.  Look for VMMaker.oscog-eem.2440 and VMMaker.oscog-eem.2452.  And in general one can use 
    self foo: expr bar: rpxe 
to generate a call of foobar.  I simply added stripping out of _:, which means not having to split a call across several keywords; much more readable.

It might be useful to capture this “documentation” and the documentation elsewhere (eg on the Squeak wiki) and include it in help in the package.  Anyone who has energy for this is very welcome to help.

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Eliminating cCode:inSmalltalk:'s

alistairgrant
In reply to this post by Ben Coman
 
Hi Ben,

Disclaimer: I haven't gone through the code, but this is my understanding.




On Tue., 30 Oct. 2018, 14:26 Ben Coman, <[hidden email]> wrote:
 


On Tue, 30 Oct 2018 at 20:22, Eliot Miranda <[hidden email]> wrote:
 
Hi Ben,

On Oct 30, 2018, at 4:57 AM, Ben Coman <[hidden email]> wrote:



Those implementations can come later.  Right now the plugin doesn’t simulate anyway.  You’re right I could have written them then and there, but I would rather do real o es than simple failing stubs.  If I find that I can’t simulate without stubs I’ll add them.  Feel free to provide them if you’re motivated.  I should have just fixed the digitCompare: issue but got carried away...

I'm still missing something basic, but guessing... the "inSmalltalk:" part is what is performed by the simulator?

and the "cCode:" is generated into a C-code-call that expects that function linked in from a library?

and now there is no simulation and "b3dxAllocateTexture:_:_:_:" is generated to C-code-call?

So is there a mechanism that any unknown message (i.e. "b3dxAllocateTexture:_:_:_:") is generated to a C-code-call?

Not quite.  There is a table of special messages, e.g ifTrue:ifFalse: is converted to the normal C if else statement.

Every other message send is converted to a function call.  The function is either internal, i.e. Supplied by another method, or external (which the linker should find).


Cheers,
Alistair
(on phone)

Reply | Threaded
Open this post in threaded view
|

Re: Eliminating cCode:inSmalltalk:'s

Eliot Miranda-2
 
Hi Alistair,

On Tue, Oct 30, 2018 at 7:48 AM Alistair Grant <[hidden email]> wrote:
Hi Ben,

Disclaimer: I haven't gone through the code, but this is my understanding.

On Tue., 30 Oct. 2018, 14:26 Ben Coman, <[hidden email]> wrote:
 


On Tue, 30 Oct 2018 at 20:22, Eliot Miranda <[hidden email]> wrote:
 
Hi Ben,

On Oct 30, 2018, at 4:57 AM, Ben Coman <[hidden email]> wrote:



Those implementations can come later.  Right now the plugin doesn’t simulate anyway.  You’re right I could have written them then and there, but I would rather do real o es than simple failing stubs.  If I find that I can’t simulate without stubs I’ll add them.  Feel free to provide them if you’re motivated.  I should have just fixed the digitCompare: issue but got carried away...

I'm still missing something basic, but guessing... the "inSmalltalk:" part is what is performed by the simulator?

and the "cCode:" is generated into a C-code-call that expects that function linked in from a library?

and now there is no simulation and "b3dxAllocateTexture:_:_:_:" is generated to C-code-call?

So is there a mechanism that any unknown message (i.e. "b3dxAllocateTexture:_:_:_:") is generated to a C-code-call?

Not quite.  There is a table of special messages, e.g ifTrue:ifFalse: is converted to the normal C if else statement.

Every other message send is converted to a function call.  The function is either internal, i.e. Supplied by another method, or external (which the linker should find).

Very close!  This is TSendNode>>emitCCodeOn: aStream level: level generator: aCodeGen
"Emit the receiver as a statement."

"If the selector is a built-in construct, translate it and return"
(aCodeGen emitBuiltinConstructFor: self on: aStream level: level) ifFalse:
["If it is a pointer dereference generate it"
(self emitCCodeAsFieldReferenceOn: aStream level: level generator: aCodeGen) ifFalse:
["Otherwise generate the vanilla C function call."
self emitCCodeAsFunctionCallOn: aStream level: level generator: aCodeGen]]

The built-in constructs are many, but the ones that aren't arithmetic or a function call, or control (ifTrue: => if () { ...) are
1. cCode: stringOrBlock [inSmalltalk: ] => emit stringOrBlock
2. cPreprocessorDirective: => emit whatever the argument is literally (very similar to 1. but not indented)
3. cppIf:ifTrue:ifFalse: => #if EXPR ... #else ... #endif
4. addressOf: expr [put: block] => &expr
5. touch => nothing (allows referencing variables for 1.)
6. some unusual translations for shouldNotImplement, asInteger et al (see CCodeGenerator>>#initializeCTranslationDictionary)

Then field references are inst var accessors of instances of subclasses of VMStructType, which get translated into
    foo.bar
    foo.bar = expr
    foo->bar
    foo->bar = expr
depending on the type of foo.

Only after this do sends get mapped to function calls.



Cheers,
Alistair
(on phone)



--
_,,,^..^,,,_
best, Eliot