1; Part of Scheme 48 1.9. See file COPYING for notices and license. 2 3; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber, Robert Ransom, Marcel Turino 4 5; Various data structures used by the compiler, module system, etc. 6 7; Type system 8 9(define-structure meta-types meta-types-interface 10 (open scheme-level-2 11 define-record-types tables bitwise 12 features ;make-immutable! 13 util low-exceptions) 14 (files (bcomp mtype)) 15 (optimize auto-integrate)) 16 17; Bindings 18 19(define-structure bindings bindings-interface 20 (open scheme-level-2 21 define-record-types 22 meta-types 23 locations) 24 (files (bcomp binding)) 25 (optimize auto-integrate)) 26 27; Names & Transforms 28 29(define-structures ((names names-interface) 30 (transforms transforms-interface)) 31 (open scheme-level-2 32 define-record-types tables 33 low-exceptions 34 meta-types ;sexp->type 35 bindings ;same-denotation? 36 features ;make-immutable! string-hash 37 syntax-transformers 38 compiler-envs) 39 (files (bcomp name) 40 (bcomp transform)) 41 (optimize auto-integrate)) 42 43; A thingie (placecard?) is used to hold a spot for a location that is to be 44; found later. The compiler sticks them in templates and the module system 45; later replaces them with locations. 46; 47; We can't use (BEGIN ...) for this trivial package because it is loaded 48; by flatload, which can't handle them. 49 50(define-structure thingies (export make-thingie 51 thingie? 52 thingie-binding 53 thingie-name 54 thingie-assigned? 55 set-thingie-assigned?!) 56 (open scheme-level-2 define-record-types) 57 (optimize auto-integrate) 58 (files (bcomp thingie))) 59 60; Nodes 61 62(define-structure compiler-envs compiler-envs-interface 63 (open scheme-level-2 define-record-types 64 meta-types bindings) 65 (files (bcomp cenv)) 66 (optimize auto-integrate)) 67 68(define-structure nodes nodes-interface 69 (open scheme-level-2 70 meta-types names packages packages-internal 71 compiler-envs bindings transforms 72 low-exceptions define-record-types tables 73 util) 74 (files (bcomp node) 75 (bcomp schemify)) 76 (optimize auto-integrate)) 77 78;-------------------------------- 79; Macros 80 81(define-structure syntactic syntactic-interface 82 (open scheme-level-2 util 83 meta-types names bindings 84 nodes compiler-envs 85 low-exceptions tables fluids 86 var-utilities 87 transforms 88 code-vectors 89 features) ;make-immutable! 90 (files (bcomp syntax)) 91 (optimize auto-integrate)) 92 93(define-structure syntax-rules-compiler (export compile-rules) 94 (open scheme-level-2 (subset util (receive)) names syntax-rules-data) 95 (files (bcomp syntax-rules-compiler))) 96 97(define-structure usual-macros usual-macros-interface 98 (open scheme-level-2 99 names ;name? 100 fluids ;used in definition of %file-name% 101 code-quotation 102 syntax-rules-compiler 103 util 104 tables 105 low-exceptions 106 syntax-transformers) 107 (files (bcomp usual) 108 (bcomp syntax-rules))) 109 110; Little utilities to be phased out by changing the format of lambda var lists 111; in nodes. 112 113(define-structure var-utilities (export n-ary? 114 normalize-formals 115 number-of-required-args) 116 (open scheme-level-2) 117 (files (bcomp var-util))) ; can't use (BEGIN ...) because this is flatloaded 118 119;-------------------------------- 120; Byte-code compiler 121 122; Lexical environment layout info for debugging 123 124(define-structures ((debug-data debug-data-interface) 125 (debug-data-internal debug-data-internal-interface)) 126 (open scheme-level-2 127 define-record-types 128 tables 129 fluids 130 record-types ;for debug-flags randomness 131 features) ;make-immutable! 132 (files (bcomp ddata) 133 (bcomp state)) 134 (optimize auto-integrate)) 135 136; Determining stack usage. No longer used. 137; 138;(define-structure stack-check (export maximum-stack-use) 139; (open scheme-level-2 architecture code-vectors low-exceptions) 140; (files (bcomp stack-check)) 141; (optimize auto-integrate)) 142 143; Compiler back end 144 145(define-structure segments segments-interface 146 (open scheme-level-2 util tables low-exceptions fluids 147 define-record-types 148 bitwise vm-data 149 code-vectors 150 templates 151 architecture 152 features ;make-immutable! 153 debug-data debug-data-internal 154 frames) 155 (files (bcomp segment)) 156 (optimize auto-integrate)) 157 158; Primops 159 160(define-structure primops primops-interface 161 (open scheme-level-2 tables define-record-types 162 meta-types 163 low-exceptions) 164 (files (bcomp primop)) 165 (optimize auto-integrate)) 166 167; Type reconstruction. 168 169(define-structure reconstruction (export node-type reconstruct-type) 170 (open scheme-level-2 tables 171 meta-types nodes names bindings 172 primops 173 var-utilities ;n-ary? 174 util ;last 175 low-exceptions) 176 (files (bcomp recon))) 177 178; The compiler itself. 179 180(define-structures ((compiler compiler-interface) 181 (bc-generation bc-generation-interface)) 182 (open scheme-level-2 util low-exceptions 183 features ;force-output 184 enumerated ;enumerand->name 185 ascii 186 architecture 187 meta-types names bindings 188 transforms 189 nodes var-utilities 190 primops 191 segments 192 debug-data-internal ; keep-source-code? 193 flat-environments 194 frames 195 reconstruction) 196 (files (bcomp comp-exp) 197 (bcomp comp-lambda) 198 (bcomp comp-prim) 199 (bcomp comp)) 200 (optimize auto-integrate)) 201 202(define-structure frames frames-interface 203 (open scheme-level-2 204 define-record-types 205 names 206 architecture ; two-byte-limit 207 templates ; template-overhead 208 debug-data-internal ; new-debug-data 209 low-exceptions ; error 210 thingies) 211 (files (bcomp frame)) 212 (optimize auto-integrate)) 213 214;---------------- 215; Reading the forms in a file. 216; This is used by scan-package and rts/eval.scm. 217 218(define-structure reading-forms (export read-forms $note-file-package) 219 (open scheme-level-2 220 fluids filenames cells 221 features ;current-noise-port force-output 222 low-exceptions ;error 223 (subset packages-internal (package-reader)) 224 ) 225 (files (bcomp read-form))) 226 227;---------------- 228; Live-variable analysis for closures. 229 230(define-structure flat-environments (export flatten-form) 231 (open scheme-level-2 nodes low-exceptions 232 optimizer primops 233 util ;every 234 var-utilities) 235 (files (bcomp flatten))) 236 237;---------------- 238; Module system 239 240(define-structure interfaces interfaces-interface 241 (open scheme-level-2 242 define-record-types tables 243 util ;filter every receive symbol-append 244 low-exceptions ;error 245 weak ;populations 246 meta-types) 247 (files (bcomp interface)) 248 (optimize auto-integrate)) 249 250(define-structures ((packages packages-interface) 251 (packages-internal packages-internal-interface) 252 (undefined undefined-interface)) 253 (open scheme-level-2 254 define-record-types tables fluids low-exceptions cells 255 util features locations weak 256 meta-types interfaces 257 names bindings 258 compiler-envs 259 templates 260 thingies) 261 (files (bcomp package) 262 (bcomp package-undef)) 263 (optimize auto-integrate)) 264 265(define-structure scan-package scan-package-interface 266 (open scheme-level-2 util 267 packages packages-internal 268 meta-types bindings 269 compiler-envs 270 reading-forms 271 filenames 272 low-exceptions 273 features ;current-noise-port force-output 274 ) 275 (files (bcomp scan-package))) 276 277(define-structure optimizer optimizer-interface 278 (open scheme-level-2 279 low-exceptions tables 280 util) 281 (files (bcomp optimize))) 282 283(define-structure compile-packages (export compile-package) 284 (open scheme-level-2 util tables 285 syntactic 286 packages 287 packages-internal ;package-name 288 optimizer 289 compiler 290 primops ;walk-primops 291 compiler-envs 292 nodes 293 scan-package 294 usual-macros ;for usual-transforms 295 transforms ;for usual-transforms 296 meta-types) ;for usual-transforms and define-all-operators 297 (files (bcomp comp-package))) 298 299;---------------- 300; DEFINE-STRUCTURE and friends 301 302(define-structure defpackage defpackage-interface 303 (open scheme-level-2 304 packages 305 (subset packages-internal (set-package-reader!)) 306 syntactic usual-macros types 307 interfaces 308 source-file-names ;%file-name% 309 low-exceptions ;error 310 tables) 311 (files (bcomp module-language) 312 (bcomp config))) 313 314(define-structure types types-interface ;Typing language 315 (open scheme-level-2 meta-types syntactic loopholes) 316 (files (bcomp type)) 317 ;; (optimize auto-integrate) - doesn't work 318 ) 319 320(define-structure module-system (compound-interface defpackage-interface 321 types-interface) 322 (open defpackage types)) 323 324;---------------- 325; Code analysis and inlining 326 327(define-structure usages usages-interface 328 (open scheme-level-2 329 meta-types names nodes 330 packages 331 packages-internal ;package-refine-type! 332 reconstruction 333 var-utilities 334 define-record-types 335 util low-exceptions tables strong) 336 (files (opt usage) 337 (opt sort))) 338 339(define-structure analysis (export analyze-forms) 340 (open scheme-level-2 341 meta-types bindings nodes primops 342 packages-internal ;package-add-static! 343 inline 344 usages 345 reconstruction 346 var-utilities 347 transforms 348 syntactic ;static-value 349 packages 350 low-exceptions 351 features ;force-output 352 optimizer ;set-optimizer! 353 util) 354 (files (opt analyze))) 355 356(define-structure inline inline-interface 357 (open scheme-level-2 util var-utilities 358 meta-types names bindings nodes 359 compiler-envs 360 transforms 361 packages 362 usages 363 low-exceptions) 364 (files (opt inline))) 365 366(define-structure strong (export strongly-connected-components) 367 (open scheme-level-2 define-record-types low-exceptions) 368 (files (big strong))) ;! 369 370 371;---------------- 372; Two basic structures needed to support the compiler. 373 374(define-structure tables general-tables-interface 375 (open scheme-level-1 376 define-record-types 377 low-exceptions 378 features) ; string-hash, make-immutable! 379 (files (big general-table)) 380 (optimize auto-integrate)) 381 382(define-structure filenames filenames-interface 383 (open scheme-level-1 low-exceptions fluids cells) 384 (files (big filename))) 385