Advertisement
shahak

OOP3 part 1

Dec 9th, 2017
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. compile: aSourceCode where: anOrderedCollection
  2. (anOrderedCollection size = (self argumentsInMethod: aSourceCode) size)
  3. ifFalse: [
  4.     ^self error: 'Can not compile method, number of arguments is not equal to the number of constraints!'.
  5. ] ifTrue: [
  6.     |fixedSorceCode lines|
  7.     lines := aSourceCode subStrings: '
  8. '.
  9.     fixedSorceCode := (lines at: 1),'
  10.     '.
  11.     ((lines size > 1) and: [((lines at: 2) at: 1) = $|])
  12.     ifFalse: [
  13.         1 to: (anOrderedCollection size) do: [:i |
  14.             ((anOrderedCollection at: i) = nil)
  15.             ifFalse: [
  16.                 fixedSorceCode := fixedSorceCode,'(', ((self argumentsInMethod: aSourceCode) at: i),
  17.                 ' isKindOf: ', ((anOrderedCollection at: i)), ')',
  18.                     ' ifFalse: [
  19.                         ^self error: ''Type mismatch! Argument ', (i printString) ,
  20.                         ' should be ', ((anOrderedCollection at: i)), '''
  21.                      ].
  22.                      '
  23.             ]
  24.         ].
  25.         2 to: (lines size) do: [:i | fixedSorceCode := fixedSorceCode , (lines at: i), '
  26.         '].
  27.     ] ifTrue: [
  28.         fixedSorceCode := fixedSorceCode, (lines at: 2),'
  29.     '.
  30.         1 to: (anOrderedCollection size) do: [:i |
  31.             ((anOrderedCollection at: i) = nil)
  32.             ifFalse: [
  33.                 fixedSorceCode := fixedSorceCode,'(', ((self argumentsInMethod: aSourceCode) at: i),
  34.                 ' isKindOf: ', ((anOrderedCollection at: i)), ')',
  35.                     ' ifFalse: [
  36.                         ^self error: ''Type mismatch! Argument ', (i printString) ,
  37.                         ' should be ', ((anOrderedCollection at: i)), '''
  38.                      ].
  39.                      '
  40.             ]
  41.         ].
  42.         3 to: (lines size) do: [:i | fixedSorceCode := fixedSorceCode , (lines at: i), '
  43.         '].
  44.     ].
  45.    
  46.     self compile: fixedSorceCode.  
  47. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement