compiler/TTypechecker.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 02 Sep 2015 18:15:44 +0100
changeset 7 7556e3d41d80
parent 6 0c806a7f1888
child 9 569bf5707c7e
permissions -rw-r--r--
Make 3 + 4 working, though the code is rather messy ...and needs a lot of cleanup. There are no checks for error cases, no debug info, etc...

"{ Package: 'jv:tea/compiler' }"

"{ NameSpace: Smalltalk }"

TCompilerPass subclass:#TTypechecker
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Tea-Compiler'
!

!TTypechecker methodsFor:'visitor-double dispatching'!

acceptMessageNode: aMessageNode 
    | receiverType receiverBinding methodBinding |

    super acceptMessageNode: aMessageNode.
    receiverType := aMessageNode receiver binding type.
    receiverType isSimpleType ifTrue:[ 
        receiverBinding := context environment binding lookupClassNamed: receiverType name.
        methodBinding := receiverBinding lookupMethodNamed: aMessageNode selector.
        1 to: aMessageNode arguments size do:[:paramIdx |  
            | actualParamType formalParamType |    
            actualParamType := (aMessageNode arguments at: paramIdx) binding type.
            formalParamType := methodBinding parameterTypes at: paramIdx.
            (actualParamType isSubtypeOf: formalParamType) ifFalse:[ 
                self error: 'Type mismatch'.
                ^ self.
            ].
        ].
        aMessageNode binding: methodBinding.
        ^ self.
    ].
    self notYetImplemented

    "Created: / 02-09-2015 / 10:34:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-09-2015 / 17:11:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !