FFI: FFI-Tools-mt.36.mcz

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

FFI: FFI-Tools-mt.36.mcz

commits-2
Marcel Taeumel uploaded a new version of FFI-Tools to project FFI:
http://source.squeak.org/FFI/FFI-Tools-mt.36.mcz

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

Name: FFI-Tools-mt.36
Author: mt
Time: 26 May 2021, 3:32:10.751346 pm
UUID: 8e4974c2-b56b-ce43-835a-63b50d879ece
Ancestors: FFI-Tools-mt.35

Complements FFI-Kernel-mt.170.

Simplifies Shout styling by re-using standard range-types such as #pragmaKeyword and #comment. No need for #externalFunctionCallingConvention or #module.

Even #externalCallTypePointerIndicator might not be necessary. Yet, #externalCallType seems to be a useful range type, though.

=============== Diff against FFI-Tools-mt.35 ===============

Item was changed:
  ----- Method: SHParserST80>>callback (in category '*FFI-Tools') -----
  callback
  <pragmaParser>
 
+ self scanPast: #pragmaKeyword.
+ self failUnless: currentToken notNil.
- self scanPast: #externalFunctionCallingConvention.
 
+ "1) Return type"
+ currentToken = 'const'
+ ifTrue: [self scanPast: #comment].
  self scanPast: #externalCallType.
  currentToken = '*'
  ifTrue: [self scanPast: #externalCallTypePointerIndicator].
 
+ "2) Placeholder for function pointer"
+ currentTokenFirst == $( ifFalse: [^ self fail]. self scanPast: #string.
+ currentTokenFirst == $* ifFalse: [^ self fail]. self scanPast: #string.
+ currentTokenFirst == $) ifFalse: [^ self fail]. self scanPast: #string.
+
+ "3) Argument types"
- currentTokenFirst == $( ifFalse: [^ self fail]. self scanNext.
- currentTokenFirst == $* ifFalse: [^ self fail]. self scanNext.
- currentTokenFirst == $) ifFalse: [^ self fail]. self scanNext.
-
  self failUnless: currentTokenFirst == $(.
  self scanPast: #leftParenthesis.
  [currentTokenFirst ~= $)]
  whileTrue: [
  self failUnless: currentToken notNil.
+ currentToken = 'const'
+ ifTrue: [self scanPast: #comment]
+ ifFalse: [self scanPast: #externalCallType].
- self scanPast: #externalCallType.
  currentToken = '*'
  ifTrue: [self scanPast: #externalCallTypePointerIndicator]].
  self scanPast: #rightParenthesis.
+
- currentToken = 'module:'
- ifTrue: [
- self scanPast: #module.
- self parseStringOrSymbol ].
- currentToken = 'error:' ifTrue: [
- self scanPast: #primitive. "there's no rangeType for error"
- self currentTokenType == #name
- ifTrue: [ self parseTemporary: #patternTempVar ]
- ifFalse: [ self parseStringOrSymbol ] ].
  self failUnless: currentToken = '>'.
  self scanPast: #primitiveOrExternalCallEnd!

Item was changed:
  ----- Method: SHParserST80>>parseExternalCall (in category '*FFI-Tools') -----
  parseExternalCall
 
+ "0) First keyword of pragma e.g., <cdecl: ... module: ... error: ...>"
+ self addRangeType: #pragmaKeyword.
+
+ "1) Call flags such as 'threaded' "
- self addRangeType: #externalFunctionCallingConvention.
-
  [self scanNext.
  ((Smalltalk at: #ExternalFunction) callingConventionModifierFor: currentToken) notNil]
  whileTrue.
+
+ "2) Return type"
  self failUnless: currentToken notNil.
+ currentToken = 'const'
+ ifTrue: [self scanPast: #comment].
  self scanPast: #externalCallType.
  currentToken = '*'
  ifTrue: [self scanPast: #externalCallTypePointerIndicator].
  currentToken = '['
  ifTrue: ["array types return"
  self scanPast: #externalCallType.
  [currentTokenFirst ~= $]]
  whileTrue: [
  self failUnless: currentTokenFirst isDigit.
  self scanPast: #externalCallType].
  self scanPast: #externalCallType].
+
+ "3) Function name or index"
  currentTokenFirst isDigit
+ ifTrue: [self scanPast: #string]
+ ifFalse: [currentTokenFirst == $'
+ ifTrue: [self parseString]
+ ifFalse: [self scanPast: #string]].
+
+ "4) Argument types"
- ifTrue: [self scanPast: #integer]
- ifFalse: [
- self failUnless: currentTokenFirst == $'.
- self parseString].
  self failUnless: currentTokenFirst == $(.
  self scanPast: #leftParenthesis.
  [currentTokenFirst ~= $)]
  whileTrue: [
  self failUnless: currentToken notNil.
+ currentToken = 'const'
+ ifTrue: [self scanPast: #comment]
+ ifFalse: [self scanPast: #externalCallType].
- self scanPast: #externalCallType.
  currentToken = '*'
  ifTrue: [self scanPast: #externalCallTypePointerIndicator]].
  self scanPast: #rightParenthesis.
+
+ "5) Module name"
  currentToken = 'module:'
  ifTrue: [
+ self scanPast: #pragmaKeyword.
- self scanPast: #module.
  self parseStringOrSymbol ].
+
+ "6) Error code"
  currentToken = 'error:' ifTrue: [
+ self scanPast: #pragmaKeyword.
- self scanPast: #primitive. "there's no rangeType for error"
  self currentTokenType == #name
  ifTrue: [ self parseTemporary: #patternTempVar ]
  ifFalse: [ self parseStringOrSymbol ] ].
  self failUnless: currentToken = '>'.
  self scanPast: #primitiveOrExternalCallEnd!