compiler/TSimpleType.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 }"

TType subclass:#TSimpleType
	instanceVariableNames:'name'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Tea-Compiler-Types'
!

!TSimpleType class methodsFor:'instance creation'!

named: aString
    ^ self new initializeWithName: aString

    "Created: / 21-08-2015 / 19:24:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TSimpleType methodsFor:'accessing'!

name
    ^ name
! !

!TSimpleType methodsFor:'comparing'!

= anotherType
    ^ self class = anotherType class and:[ self name = anotherType name ]

    "Created: / 25-08-2015 / 23:36:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

hash
    ^ name hash

    "Created: / 25-08-2015 / 23:34:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TSimpleType methodsFor:'conversion'!

asLLVMTypeInModule: aLLVMModule
    "Return the type as LLVMType"

    "/ Q&D hack for builtin types, sigh...
    name = 'i1' ifTrue:[ 
        ^ LLVMType int1
    ].
    name = 'i8' ifTrue:[ 
        ^ LLVMType int1
    ].
    name = 'i32' ifTrue:[ 
        ^ LLVMType int32
    ].
    name = 'i64' ifTrue:[ 
        ^ LLVMType int64
    ].
    name = 'iptr' ifTrue:[ 
        ^ LLVMType intptr
    ].
    name = 'tSmallInteger' ifTrue:[ 
        ^ LLVMType intptr
    ].                  
    ^ LLVMType void pointer

    "Created: / 31-08-2015 / 09:06:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-09-2015 / 16:31:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TSimpleType methodsFor:'initialization'!

initializeWithName: aString
    name := aString

    "Created: / 21-08-2015 / 19:23:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TSimpleType methodsFor:'printing & storing'!

printOn:aStream
    aStream nextPut: $<; space.
    self printWithoutAnglesOn:aStream.
    aStream space; nextPut: $>.

    "Created: / 25-08-2015 / 23:22:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

printWithoutAnglesOn:aStream
    aStream nextPutAll: name

    "Modified: / 21-08-2015 / 17:08:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TSimpleType methodsFor:'testing'!

isSimpleType
    ^ true
!

isSubtypeOf: anotherType
    "/ Hack for now - types must match exactly...
    ^ anotherType class == self class and:[ anotherType name = name ]

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