The Trunk: Compiler-ar.143.mcz

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

The Trunk: Compiler-ar.143.mcz

commits-2
Andreas Raab uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-ar.143.mcz

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

Name: Compiler-ar.143
Author: ar
Time: 24 May 2010, 8:42:36.032 pm
UUID: af1d9aa9-96ff-9e4f-9df9-94e11682c0b4
Ancestors: Compiler-ar.142

Verify the number of arguments in FFI calls.

=============== Diff against Compiler-ar.142 ===============

Item was changed:
  ----- Method: Parser>>externalFunctionDeclaration (in category 'primitives') -----
  externalFunctionDeclaration
  "Parse the function declaration for a call to an external library."
  | descriptorClass callType retType externalName args argType module |
  descriptorClass := Smalltalk at: #ExternalFunction ifAbsent:[nil].
  descriptorClass == nil ifTrue:[^false].
  callType := descriptorClass callingConventionFor: here.
  callType == nil ifTrue:[^false].
  "Parse return type"
  self advance.
  retType := self externalType: descriptorClass.
  retType == nil ifTrue:[^self expected:'return type'].
  "Parse function name or index"
  externalName := here.
  (self match: #string)
  ifTrue:[externalName := externalName asSymbol]
  ifFalse:[(self match:#number) ifFalse:[^self expected:'function name or index']].
  (self matchToken: #'(') ifFalse:[^self expected:'argument list'].
  args := WriteStream on: Array new.
  [here == #')'] whileFalse:[
  argType := self externalType: descriptorClass.
  argType == nil ifTrue:[^self expected:'argument'].
  argType isVoid & argType isPointerType not ifFalse:[args nextPut: argType].
  ].
+ (args position = self properties selector numArgs) ifFalse:[
+ ^self expected: 'Matching number of arguments'
+ ].
  (self matchToken:#')') ifFalse:[^self expected:')'].
  (self matchToken: 'module:') ifTrue:[
  module := here.
  (self match: #string) ifFalse:[^self expected: 'String'].
  module := module asSymbol].
  Smalltalk at: #ExternalLibraryFunction ifPresent:[:xfn| | fn |
  fn := xfn name: externalName
  module: module
  callType: callType
  returnType: retType
  argumentTypes: args contents.
  self allocateLiteral: fn.
  ].
  self addPragma: (Pragma keyword: #primitive: arguments: #(120)).
  ^true!