lobby ensureNamespace: #C. Types ensureNamespace: #C. Types C addPrototype: #Type derivedFrom: {Types Type}. Types C Type addSlot: #dispatcher valued: (Cloneable clone removeSlot: #traits). "KLUGE: The dispatcher object is a faux-Cloneable object to avoid name clashes with the methods being defined on it. After instantiation and initialize its traits slot is removed. Any further dispatches on it must be done via sendTo:through:." t@(Types C Type traits) clone [| newT | newT: resend. newT dispatcher: (#clone sendTo: {t dispatcher} through: {Cloneable}). newT ]. t@(Types C Type traits) dependencies [| deps | deps: Set newEmpty. deps addDependency: t withVisited: Set newEmpty. deps remove: t. deps ]. c addDependency: t@(Types C Type traits) withVisited: visited [ ]. t@(Types C Type traits) byteSize [ (t bitSize + Types C Char bitSize - 1) // Types C Char bitSize ]. t@(Types C Type traits) wordSize [ (t bitSize + Types C LongInt bitSize - 1) // Types C LongInt bitSize ]. Types C addPrototype: #Pointer derivedFrom: {Types C Type}. Types C Pointer addSlot: #targetType. p@(Types C Pointer traits) to: targetType "Creates a new Pointer Type for the targetType." "TODO: Map an IdentityDictionary from types to types of pointers to those types, and unify implicitly?" [| newP | newP: p clone. newP targetType: targetType. newP ]. _@(Types C Pointer traits) bitSize [ Types C LongInt bitSize ]. t@(Types C Type traits) pointer [ Types C Pointer to: t ]. p@(Types C Pointer traits) = q@(Types C Pointer traits) [p targetType = q targetType]. c addDependency: p@(Types C Pointer traits) withVisited: visited [ (visited includes: p) ifFalse: [visited include: p. (p targetType isSameAs: Types C Synonym) ifTrue: [c addDependency: p targetType withVisited: visited]] ]. n@(Types C) addPrototype: slotName derivedFrom: parents printName: name bitSize: size "Automatically adds a method #cName which returns the lower-cased version of the given name, as well as the parent Types C Type." [| type pointer | type: (n addPrototype: slotName derivedFrom: parents). "(parents copyWith: Types C Type))." _@(type traits) cName [name]. _@(type traits) bitSize [size]. pointer: (Types C Pointer to: type). _@(type traits) pointer [pointer] ]. Types C addPrototype: #Integer derivedFrom: {Types C Type}. Types C addPrototype: #Signed derivedFrom: {Types C Integer}. Types C addPrototype: #Unsigned derivedFrom: {Types C Integer}. Types C addPrototype: #Char derivedFrom: {Types C Signed} printName: 'char' bitSize: 8. Types C addPrototype: #UnsignedChar derivedFrom: {Types C Unsigned} printName: 'unsigned char' bitSize: 8. Types C addPrototype: #ShortInt derivedFrom: {Types C Signed} printName: 'signed short int' bitSize: 16. Types C addPrototype: #UnsignedShortInt derivedFrom: {Types C Unsigned} printName: 'unsigned short int' bitSize: 16. Types C addPrototype: #LongInt derivedFrom: {Types C Signed} printName: 'signed long int' bitSize: 32. Types C addPrototype: #UnsignedLongInt derivedFrom: {Types C Unsigned} printName: 'unsigned long int' bitSize: 32. Types C addPrototype: #LongLongInt derivedFrom: {Types C Signed} printName: 'signed long long int' bitSize: 64. Types C addPrototype: #UnsignedLongLongInt derivedFrom: {Types C Unsigned} printName: 'unsigned long long int' bitSize: 64. Types C addPrototype: #Float derivedFrom: {Types C Type} printName: 'float' bitSize: 32. Types C addPrototype: #Double derivedFrom: {Types C Float} printName: 'double' bitSize: 64. Types C addPrototype: #Void derivedFrom: {Types C Type} printName: 'void' bitSize: 0. Types C addPrototype: #Modifier derivedFrom: {Types C Type}. Types C Modifier addSlot: #baseType valued: Types C Type. t@(Types C Modifier traits) cName [t modifierName ; t baseType name]. m@(Types C Modifier traits) for: b [| newM | newM: m clone. newM baseType: b. newM ]. Types C addPrototype: #Mutability derivedFrom: {Types C Modifier}. Types C addPrototype: #Const derivedFrom: {Types C Mutability}. Types C addPrototype: #Volatile derivedFrom: {Types C Mutability}. t@(Types C Const traits) modifierName ['const']. t@(Types C Volatile traits) modifierName ['volatile']. Types C addPrototype: #Storage derivedFrom: {Types C Modifier}. Types C Storage traits addSlot: #None valued: Types C Storage clone. Types C Storage traits addSlot: #Auto valued: Types C Storage clone. Types C Storage traits addSlot: #Static valued: Types C Storage clone. Types C Storage traits addSlot: #Extern valued: Types C Storage clone. Types C Storage traits addSlot: #Register valued: Types C Storage clone. t@(Types C Storage Auto traits) modifierName ['auto']. t@(Types C Storage Static traits) modifierName ['static']. t@(Types C Storage Extern traits) modifierName ['extern']. t@(Types C Storage Register traits) modifierName ['register']. Types C addPrototype: #Array derivedFrom: {Types C Type}. Types C Array addSlot: #elementType valued: Types C UnsignedLongInt. Types C Array addSlot: #size valued: Nil. t@(Types C Array traits) of: elementType size: size [| newT | newT: t clone. newT elementType: elementType. newT size: size. newT ]. t@(Types C Array traits) of: elementType [t of: elementType size: Nil]. c addDependency: t@(Types C Array traits) withVisited: visited [ (visited includes: t) ifFalse: [ visited include: t. c addDependency: t elementType withVisited: visited ] ]. t@(Types C Array traits) bitSize [ t elementType bitSize * t size ]. Types C addPrototype: #Synonym derivedFrom: {Types C Type}. Types C Synonym addSlot: #cName. Types C Synonym addSlot: #targetType. Types C Synonym addSlot: #pointer. Types C Synonym addSlot: #isExported valued: False. t@(Types C Synonym traits) newNamed: name type: type [| newT | newT: t clone. newT cName: name. newT pointer: (Types C Pointer to: newT). newT targetType: type. newT ]. t@(Types C Synonym traits) export [ t isExported: True. t ]. c addDependency: t@(Types C Synonym traits) withVisited: visited [ (visited includes: t) ifFalse: [ visited include: t. c include: t. c addDependency: t targetType withVisited: visited ] ]. t@(Types C Synonym traits) bitSize [ t targetType bitSize ]. Types C addPrototype: #Structure derivedFrom: {Types C Type}. Types C Structure addSlot: #cName. Types C Structure addSlot: #basis. Types C Structure addSlot: #pointer. Types C Structure addSlot: #isExported valued: False. Types C Structure addSlot: #elementSpecs valued: ExtensibleArray newEmpty. t@(Types C Structure traits) newNamed: name basedOn: basis [| newT | newT: t clone. newT cName: name. newT basis: basis. newT pointer: (Types C Pointer to: newT). #rawAddDelegate:valued: sendTo: {newT pointer rules. #basisPointer. basis pointer rules} through: {Cloneable. #basisPointer. Cloneable}. #rawAddDelegate:valued: sendTo: {newT pointer dispatcher. #basisPointer. basis pointer dispatcher} through: {Cloneable. #basisPointer. Cloneable}. newT elementSpecs: basis elementSpecs copy. newT elementSpecs do: [| :se | [| :_ | se type] asMethod: se cName on: {newT rules} ]. newT ]. t@(Types C Structure traits) newNamed: name [| newT | newT: t clone. newT cName: name. newT basis: Nil. newT pointer: (Types C Pointer to: newT). newT elementSpecs: t elementSpecs newEmpty. newT ]. t@(Types C Structure traits) export [ t isExported: True. t ]. c addDependency: t@(Types C Structure traits) withVisited: visited [ (visited includes: t) ifFalse: [ visited include: t. c include: t. t elementSpecs do: [| :se | c addDependency: se type withVisited: visited] ] ]. t@(Types C Structure traits) bitSize [| bits packing | bits: 0. packing: False. t elementSpecs do: [| :se | packing ifFalse: [| alignment | alignment: se type bitSize. (alignment = 0 or: [alignment > Types C LongInt bitSize]) ifTrue: [alignment: Types C LongInt bitSize]. bits: (bits / alignment) ceiling * alignment ]. bits: bits + se bitSize. packing: se packed ]. (bits / Types C LongInt bitSize) ceiling * Types C LongInt bitSize ]. Types C addPrototype: #StructureElement derivedFrom: {Types C Type}. Types C StructureElement addSlot: #cName. Types C StructureElement addSlot: #type valued: Types C UnsignedLongInt. se@(Types C StructureElement traits) newNamed: name type: type [| newSE | newSE: se clone. newSE cName: name. newSE type: type. newSE ]. t@(Types C Structure traits) addElement: se [ t elementSpecs do: [| :each | each cName = se cName ifTrue: [warn: 'Attempted Redefinition of type StructureElement.'. ^ each]]. [| :_ | se type] asMethod: se cName on: {t rules}. [| :_ | se type] asMethod: se cName on: {t pointer rules}. t elementSpecs addLast: se ]. t@(Types C Structure traits) addElementNamed: name type: type [ t addElement: (Types C StructureElement newNamed: name type: type) ]. t@(Types C Structure traits) addElementNamed: name [t addElementNamed: name type: Types C UnsignedLongInt]. t@(Types C StructureElement traits) bitSize [ t type bitSize ]. _@(Types C StructureElement traits) packed [ False ]. Types C addPrototype: #PackedStructureElement derivedFrom: {Types C StructureElement}. Types C PackedStructureElement addSlot: #bitSize valued: 0. se@(Types C PackedStructureElement traits) newNamed: name size: size [| newSE | newSE: (se newNamed: name type: Types C UnsignedLongInt). newSE bitSize: size. newSE ]. t@(Types C Structure traits) addPackedElementNamed: name size: size [ t addElement: (Types C PackedStructureElement newNamed: name size: size) ]. _@(Types C PackedStructureElement traits) packed [ True ]. Types C addPrototype: #Function derivedFrom: {Types C Type}. Types C Function addSlot: #argumentTypes valued: {}. Types C Function addSlot: #resultType valued: Types C Void. fun@(Types C Function traits) from: argumentTypes to: resultType [| newFun | newFun: fun clone. newFun argumentTypes: (argumentTypes as: newFun argumentTypes). newFun resultType: resultType. newFun ]. Types C addPrototype: #FunctionPointer derivedFrom: {Types C Pointer}. fun@(Types C Function traits) pointer [ Types C FunctionPointer to: fun ]. _@(Types C FunctionPointer traits) from: argumentTypes to: resultType [ (Types C Function from: argumentTypes to: resultType) pointer ]. Types C addPrototype: #Module derivedFrom: {Types C Type}.