Table Of ContentThe Implementation
of Icon and Unicon
Ralph and Madge T. Griswold
Kenneth W. Walker
Clinton L. Jeffery
Michael D. Wilder
Anthony T. Jones
Jafar Al Gharaibeh
©2017ClintonJeffery
ThisisadraftmanuscriptdatedMay29,2019.
Sendcommentsanderratatojeffery@cs.uidaho.edu.
Contents
Preface xvii
CompendiumIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
I The Implementation of the Icon Programming Language 3
1 Introduction 7
1.1 ImplementingProgrammingLanguages . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 TheBackgroundforIcon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2 IconLanguageOverview 11
2.1 TheIconProgrammingLanguage . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.1 DataTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.2 ExpressionEvaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.3 CsetsandStrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.1.4 StringScanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.1.5 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.1.6 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.1.7 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1.8 Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1.9 InputandOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.1.10 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.1.11 Co-Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.1.12 DiagnosticFacilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.2 LanguageFeaturesandtheImplementation . . . . . . . . . . . . . . . . . . . . . 37
3 OrganizationoftheImplementation 41
3.1 TheIconVirtualMachine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.2 ComponentsoftheImplementation . . . . . . . . . . . . . . . . . . . . . . . . 42
3.3 TheTranslator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.4 TheLinker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.4.1 ScopeResolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.4.2 ConstructionofRun-TimeStructures . . . . . . . . . . . . . . . . . . . . 45
3.5 TheRun-TimeSystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4 ValuesandVariables 49
4.1 Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.1.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.1.2 TheNullValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.1.3 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.2 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.3.1 OperationsonVariables . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.3.2 SpecialVariables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.3.2.1 TrappedVariables . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.3.2.2 KeywordVariables . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.4 DescriptorsandBlocksinC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.4.1 Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.4.2 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.4.3 DefinedConstants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.4.4 RTLCoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5 StringsandCsets 67
5.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.1.1 RepresentationofStrings . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.1.2 Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.1.3 Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.1.4 AssignmenttoSubscriptedStrings . . . . . . . . . . . . . . . . . . . . . . 73
5.1.5 Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.2 Csets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6 Lists 83
6.1 StructuresforLists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
6.2 QueueandStackAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
6.3 PositionalAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
6.4 Arrays(Unicononly) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7 SetsandTables 101
7.1 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7.1.1 DataOrganizationforSets . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7.1.2 SetOperations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
7.2 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.2.1 DataOrganizationforTables . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.3 HashingFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
8 TheInterpreter 117
8.1 Stack-BasedEvaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.2 VirtualMachineInstructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
8.2.1 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
8.2.2 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
8.2.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
8.2.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.2.5 Self-ModifyingInstructions . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.3 TheInterpreterProper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
8.3.1 TheInterpreterLoop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
8.3.2 InterpreterStateVariables . . . . . . . . . . . . . . . . . . . . . . . . . . 134
9 ExpressionEvaluation 137
9.1 BoundedExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
9.1.1 ExpressionFrames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
9.2 Failure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
9.3 GeneratorsandGoal-DirectedEvaluation . . . . . . . . . . . . . . . . . . . . . . 145
9.4 GenerativeControlStructures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
9.4.1 Alternation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
9.4.2 RepeatedAlternation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.4.3 Limitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
9.5 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
9.6 StringScanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
10 Functions,Procedures,andCo-Expressions 169
10.1 InvocationExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
10.2 ProcedureBlocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
10.3 Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.3.1 ArgumentProcessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.3.2 FunctionInvocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.3.3 ProcedureInvocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.4 Co-Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11 StorageManagement 187
11.1 MemoryLayout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11.2 Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
11.2.1 TheStaticRegion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
11.2.2 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
11.2.3 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
11.3 GarbageCollection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
11.3.1 TheBasis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
11.3.2 TheLocationPhase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
11.3.3 PointerAdjustmentandCompaction . . . . . . . . . . . . . . . . . . . . . 206
11.3.4 CollectingCo-ExpressionBlocks . . . . . . . . . . . . . . . . . . . . . . 216
11.3.5 MultipleRegions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
11.3.6 StorageRequirementsduringGarbageCollection . . . . . . . . . . . . . . 218
11.4 PredictiveNeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
12 Run-TimeSupportOperations 225
12.1 TypeCheckingandConversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
12.2 DereferencingandAssignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
12.2.1 Dereferencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
12.2.2 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
12.3 InputandOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
12.3.1 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
12.3.2 ReadingandWritingData . . . . . . . . . . . . . . . . . . . . . . . . . . 240
12.4 DiagnosticFacilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
II An Optimizing Compiler for Icon 245
PrefacetoPartII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
13 TheOptimizingCompiler 249
13.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
13.2 TypeInferencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
13.3 LivenessAnalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
13.4 AnalyzingGoal-DirectedEvaluation . . . . . . . . . . . . . . . . . . . . . . . . . 252
14 TheTranslationModel 255
14.1 DataRepresentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
14.2 IntermediateResults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
14.3 ExecutableCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
15 TheTypeInferencingModel 265
15.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
15.2 AbstractInterpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
15.3 CollectingSemantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Model1: EliminatingControlFlowInformation . . . . . . . . . . . . . . . . . . . . . . 272
Model2: DecouplingVariables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Model3: AFiniteTypeSystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
16 LivenessAnalysisofIntermediateValues 281
16.1 ImplicitLoops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
16.2 LivenessAnalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
16.3 AnAttributeGrammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
16.4 PrimaryExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
16.5 OperationswithSubexpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
16.6 ControlStructures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
17 OverviewoftheCompiler 295
17.1 ComponentsoftheCompiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
17.2 TheRun-timeSystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
17.3 TheImplementationLanguage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
17.4 StandardandTailoredOperationImplementations . . . . . . . . . . . . . . . . . . 300
18 OrganizationofIconc 303
18.1 CompilerPhases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
18.2 NaiveOptimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
18.3 CodeGenerationforProcedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
19 TheImplementationofTypeInferencing 307
19.1 TheRepresentationofTypesandStores . . . . . . . . . . . . . . . . . . . . . . . 307
19.2 AFullTypeSystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
19.3 ProcedureCallsandCo-ExpressionActivations . . . . . . . . . . . . . . . . . . . 313
19.4 TheFlowGraphandTypeComputations . . . . . . . . . . . . . . . . . . . . . . . 315
20 CodeGeneration 319
20.1 TranslatingIconExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
20.2 SignalHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
20.3 TemporaryVariableAllocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
21 ControlFlowOptimizations 337
21.1 NaiveCodeGeneration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
21.2 SuccessContinuations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
21.3 Iconc’sPeepholeOptimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
22 OptimizingInvocations 345
22.1 InvocationofProcedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
22.2 InvocationandIn-liningofBuilt-inOperations . . . . . . . . . . . . . . . . . . . 346
22.3 HeuristicforDecidingtoIn-line . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
22.4 In-liningSuccessContinuations . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
22.5 ParameterPassingOptimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
22.6 AssignmentOptimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
23 PerformanceofCompiledCode 357
23.1 ExpressionOptimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
23.2 ProgramExecutionSpeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
23.3 CodeSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
24 ScalableTypeInferencing 365
24.1 TheTypeRepresentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
24.2 TypeVectorHashing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
24.3 TypeInferencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
24.4 ACopy-on-WriteTypeVectorPool . . . . . . . . . . . . . . . . . . . . . . . . . 368
24.5 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
24.5.1 BitVectorHashing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
24.5.2 HashHalving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
24.6 Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
24.6.1 Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
24.6.2 Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
24.6.3 MeasuringtheTechniques . . . . . . . . . . . . . . . . . . . . . . . . . . 376
24.6.4 CollisionRates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
24.7 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
25 OptimizingCodeGeneratedbyIconc 381
25.1 AreasWhereIconcCanBeImproved . . . . . . . . . . . . . . . . . . . . . . . . 381
25.1.1 RedundantFunctionCalls . . . . . . . . . . . . . . . . . . . . . . . . . . 382
25.1.2 ConstantPropagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
25.1.3 VariableInitialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
25.2 EnablingOptimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
25.3 IntermediateCodeRepresentation . . . . . . . . . . . . . . . . . . . . . . . . . . 382
25.3.1 HowCodeisGenerated . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
25.4 RedundantFunctionCalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
25.5 IconLiteralsandConstantPropagation . . . . . . . . . . . . . . . . . . . . . . . . 387
25.5.1 TendedDescriptorTables . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
25.5.2 AnalyzingLiteralAssignments . . . . . . . . . . . . . . . . . . . . . . . . 388
25.5.3 NewFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
25.6 VariableInitialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
25.6.1 EliminatingDeadCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
25.6.2 LoopUnrolling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
25.7 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
25.7.1 ExecutionSpeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
25.7.2 CodeSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
25.7.3 AnalysisofIntermediateCodeOptimizations . . . . . . . . . . . . . . . . 398
25.8 ConclusionandFutureOptimizations . . . . . . . . . . . . . . . . . . . . . . . . 399
26 FutureWorkontheCompiler 405
26.1 SummaryofPartII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
26.2 FutureWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
III The Implementation of Unicon 409
27 TheUniconTranslator 413
27.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
27.2 LexicalAnalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
27.2.1 Lex-compatibleAPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
27.2.2 CharacterCategories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
27.2.3 TheTokenType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
27.2.4 ErrorHandlingandDebugging . . . . . . . . . . . . . . . . . . . . . . . . 414
27.2.5 ReservedWords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
27.2.6 Big-inhaleInput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
27.2.7 SemicolonInsertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
27.2.8 TheRealLexicalAnalyzerFunction,yylex2() . . . . . . . . . . . . . . . . 418
27.3 TheUniconParser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
27.3.1 SyntaxErrorHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
27.4 TheUniconPreprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
27.5 SemanticAnalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
27.6 ObjectOrientedFacilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
27.6.1 ImplementingMultipleInheritanceinUnicon . . . . . . . . . . . . . . . . 432
27.6.2 Unicon’sProgend()revisited . . . . . . . . . . . . . . . . . . . . . . . . . 436
27.6.3 OtherOOPIssues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
27.6.4 OnPublicInterfacesandRuntimeTypeChecking . . . . . . . . . . . . . . 438
28 Networking,MessagingandthePOSIXInterface 439
28.1 NetworkingFacilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
28.1.1 SocketsintheUniconFileFunctions . . . . . . . . . . . . . . . . . . . . 439
28.1.2 SimultaneousInputfromDifferentFileTypes . . . . . . . . . . . . . . . . 439
28.2 MessagingFacilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
28.2.1 TheTransferProtocolLibrary . . . . . . . . . . . . . . . . . . . . . . . . 440
28.2.2 LibtpArchitecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
28.2.3 TheDiscipline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
28.2.4 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
29 ODBCDatabaseFacilities 445
29.1 Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
29.2 ISQLFiletype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
30 Portable2Dand3DGraphics 449
30.1 GraphicsSourceFilesSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
30.2 StructuresDefinedingraphics.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
30.3 PlatformMacrosandCodingConventions . . . . . . . . . . . . . . . . . . . . . . 452
30.4 WindowManipulationinrxwin.riandrmswin.ri . . . . . . . . . . . . . . . . . . . 452
30.4.1 WindowCreationandDestruction . . . . . . . . . . . . . . . . . . . . . . 453
30.4.2 EventProcessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
30.4.3 ResourceManagement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
30.4.4 MemoryManagementandr*rsc.riFiles . . . . . . . . . . . . . . . . . . . 454
30.4.5 ColorManagement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
30.4.6 FontManagement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
30.5 ExternalImageFilesandFormats . . . . . . . . . . . . . . . . . . . . . . . . . . 455
30.6 Implementationof3DFacilities . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
30.6.1 3DFacilitiesRequirements . . . . . . . . . . . . . . . . . . . . . . . . . . 455
30.6.2 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
30.6.3 RedrawingWindows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
30.6.4 Textures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
30.6.5 TextureCoordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
30.7 GraphicsFacilitiesPortingReference . . . . . . . . . . . . . . . . . . . . . . . . 458
30.8 TheXImplementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
30.9 TheMSWindowsImplementation . . . . . . . . . . . . . . . . . . . . . . . . . . 468