├── .gitignore ├── LICENSE ├── README.org ├── bigloo-swank.scm ├── bigloo.sh ├── chez-swank.sls ├── chez.sh ├── chibi-swank.sld ├── chibi.sh ├── chicken-swank.scm ├── chicken.sh ├── common ├── base.scm └── handlers.scm ├── cyclone-swank.sld ├── cyclone.sh ├── gambit-swank.sld ├── gambit.sh ├── gauche-swank.sld ├── gauche.sh ├── gerbil-build.ss ├── gerbil-r7rs.sh ├── gerbil-swank.ss ├── gerbil.pkg ├── gerbil.sh ├── guile-swank.scm ├── guile.sh ├── kawa-swank.sld ├── kawa.sh ├── larceny-swank.sld ├── larceny.sh ├── mit-swank.sld ├── mit.sh ├── racket-swank.sld ├── racket.sh └── specific ├── bigloo.scm ├── chez.ss ├── chibi.scm ├── chicken.scm ├── cyclone.ss ├── gambit.scm ├── gauche.scm ├── gerbil.scm ├── guile.scm ├── kawa.scm ├── larceny.scm ├── mit.scm └── racket.ss /.gitignore: -------------------------------------------------------------------------------- 1 | gerbil-build-deps 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * Swankish, a SLIME swank for Schemes 2 | ** Schemes 3 | Support for various Schemes varies in quality. Not everything works on every Scheme. 4 | 5 | See each Schemes entry for how to configure it in your Emacs configuration. 6 | *** Chibi Scheme 7 | #+BEGIN_SRC elisp 8 | (defun chibi-scheme-start-swank (file encoding) 9 | (format "%S\n\n" `(start-swank ,file))) 10 | (setq slime-lisp-implementations 11 | (cons '(chibi-scheme ("chibi-scheme" "-A/path/to/r7rs-swank" "-m" "(chibi-swank)") 12 | :init chibi-scheme-start-swank) 13 | slime-lisp-implementations)) 14 | #+END_SRC 15 | *** Gerbil Scheme 16 | #+BEGIN_SRC elisp 17 | (defun gerbil-scheme-start-swank (file encoding) 18 | (format "%S\n\n" `(begin (import (ecraven gerbil-swank)) (start-swank ,file)))) 19 | (setq slime-lisp-implementations 20 | (cons '(gerbil-scheme ("gxi" "-:d-" "--lang" "r7rs") 21 | :init gerbil-scheme-start-swank 22 | :env "GERBIL_LOADPATH=/path/to/r7rs-swank/") 23 | slime-lisp-implementations)) 24 | #+END_SRC 25 | *** Chez Scheme 26 | You'll also need https://github.com/ecraven/chez-scheme-libraries. 27 | #+BEGIN_SRC elisp 28 | (defun chez-scheme-start-swank (file encoding) 29 | (format "%S\n\n" `(begin (import (chez-swank)) (start-swank ,file)))) 30 | (setq slime-lisp-implementations 31 | (cons '(chez-scheme ("chez-scheme" "--libdirs" "/path/to/r7rs-swank:/path/to/chez/libs") 32 | :init chez-scheme-start-swank) 33 | slime-lisp-implementations)) 34 | #+END_SRC 35 | *** Gauche 36 | #+BEGIN_SRC elisp 37 | (defun gauche-scheme-start-swank (file encoding) 38 | (format "%S\n\n" `(begin (import (gauche-swank)) (start-swank ,file)))) 39 | (setq slime-lisp-implementations 40 | (cons '(gauche-scheme ("gosh" "-r7" "-A/path/to/r7rs-swank" "-l" "gauche-swank.sld") 41 | :init gauche-scheme-start-swank 42 | :env "GAUCHE_KEYWORD_IS_SYMBOL=T") 43 | slime-lisp-implementations)) 44 | #+END_SRC 45 | #+BEGIN_SRC elisp 46 | (defun guile-scheme-start-swank (file encoding) 47 | (format "%S\n\n" `(begin (import (guile-swank)) (start-swank ,file)))) 48 | (setq slime-lisp-implementations 49 | (cons '(guile-scheme ("guile" "-l" "/path/to/guile-swank.scm") 50 | :init guile-scheme-start-swank 51 | :directory "/path/to/r7rs-swank") 52 | slime-lisp-implementations)) 53 | #+END_SRC 54 | 55 | *** Chicken Scheme 56 | #+BEGIN_SRC elisp 57 | (defun chicken-scheme-start-swank (file encoding) 58 | (format "%S\n\n" `(begin (load "chicken-swank") (start-swank ,file)))) 59 | (setq slime-lisp-implementations 60 | (cons '(chicken-scheme ("csi" "-R" "r7rs") 61 | :init chicken-scheme-start-swank 62 | :directory "/path/to/r7rs-swank/") 63 | slime-lisp-implementations)) 64 | #+END_SRC 65 | *** Kawa 66 | #+BEGIN_SRC elisp 67 | (defun kawa-start-swank (file encoding) 68 | (format "%S\n\n" `(begin (import (kawa-swank)) (start-swank ,file)))) 69 | (setq slime-lisp-implementations 70 | (cons '(kawa ("kawa" "-f" "kawa-swank.sld" "-e" "(eval (read) (interaction-environment))") 71 | :init kawa-start-swank 72 | :directory "/path/to/r7rs-swank/") 73 | slime-lisp-implementations)) 74 | #+END_SRC 75 | ** TODO [3/6] 76 | - [ ] proper information about the current Scheme 77 | - [X] redirect output to Slime 78 | - [X] inspector 79 | - [ ] debugger 80 | - [ ] tracing 81 | - [X] image support 82 | -------------------------------------------------------------------------------- /bigloo-swank.scm: -------------------------------------------------------------------------------- 1 | (module bigloo-swank 2 | (include "specific/bigloo.scm") 3 | (include "common/base.scm") 4 | (include "common/handlers.scm") 5 | (main main)) 6 | 7 | (define (main argv::pair) 8 | (display "starting") (newline) (flush-output-port) 9 | (start-swank "/tmp/bigloo-port.txt")) 10 | -------------------------------------------------------------------------------- /bigloo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | bigloo -call/cc bigloo-swank.scm 3 | echo does not work yet 4 | -------------------------------------------------------------------------------- /chez-swank.sls: -------------------------------------------------------------------------------- 1 | (library (chez-swank) 2 | (export start-swank 3 | swank:get-last-exception 4 | swank:lookup-presented-object-or-lose 5 | swank:lookup-presented-object 6 | make-swank-image 7 | swank-register-image-converter 8 | inspect-in-emacs 9 | swank-present 10 | tracing 11 | trace-let trace-let* trace-letrec trace-letrec* trace-define) 12 | (import (socket net) 13 | (srfi :69) 14 | (except (rename (chezscheme) 15 | (bytevector-copy! %bytevector-copy!) 16 | (load %load) 17 | (error %error) 18 | (with-output-to-string %with-output-to-string)) 19 | string-ci-hash make-hash-table hash-table? string-hash define-record-type trace-let trace-define) 20 | (only (scheme base) define-record-type bytevector-append)) 21 | (include "specific/chez.ss") 22 | (include "common/base.scm") 23 | (include "common/handlers.scm") 24 | 25 | ;; print everything possible 26 | (print-extended-identifiers #t)) 27 | -------------------------------------------------------------------------------- /chez.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo '(import (chez-swank)) (start-swank)' | chez-scheme --libdirs '.:/home/nex/scheme/chez' 3 | 4 | -------------------------------------------------------------------------------- /chibi-swank.sld: -------------------------------------------------------------------------------- 1 | (define-library (chibi-swank) 2 | (export start-swank 3 | swank:lookup-presented-object-or-lose 4 | swank:lookup-presented-object 5 | inspect-in-emacs 6 | make-swank-image 7 | swank-register-image-converter 8 | swank-present 9 | tracing trace-define trace-let trace-let* trace-letrec trace-letrec*) 10 | (import (scheme base) (scheme eval) (scheme read) (scheme write) 11 | (scheme file) (scheme case-lambda) (scheme process-context) (scheme cxr) 12 | (chibi process) (chibi) (chibi string) (srfi 39) (srfi 1) 13 | (chibi repl) (chibi ast) (srfi 18) (srfi 95) (chibi net server) 14 | (chibi show) (chibi show pretty) 15 | (meta) (srfi 69) (chibi io) (chibi modules) 16 | (only (srfi 27) random-integer) 17 | (only (srfi 130) string-replace string-contains string-cursor->index)) 18 | (include "specific/chibi.scm") 19 | (include "common/base.scm") 20 | (include "common/handlers.scm")) 21 | -------------------------------------------------------------------------------- /chibi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chibi-scheme -A . -m '(chibi-swank)' -e '(start-swank)' 3 | -------------------------------------------------------------------------------- /chicken-swank.scm: -------------------------------------------------------------------------------- 1 | (import (chicken file) 2 | (chicken format) 3 | (chicken pretty-print) 4 | (chicken random) 5 | (chicken syntax) 6 | (chicken tcp) 7 | (chicken random) 8 | (srfi-1) 9 | (srfi-13) 10 | (srfi-69)) 11 | (begin 12 | (load "specific/chicken.scm") 13 | (load "common/base.scm") 14 | (load "common/handlers.scm")) 15 | -------------------------------------------------------------------------------- /chicken.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # needs chicken 5 3 | # chicken-install r7rs srfi-1 srfi-13 srfi-14 srfi-69 4 | csi -R r7rs chicken-swank.scm -b -e '(start-swank)' 5 | -------------------------------------------------------------------------------- /common/base.scm: -------------------------------------------------------------------------------- 1 | (define debug? #f) 2 | 3 | (define (debug-log . rest) 4 | (when debug? 5 | (for-each (lambda (r) 6 | (if (string? r) 7 | (display r log-port) 8 | (write r log-port))) 9 | rest) 10 | (newline log-port) 11 | (flush-output-port log-port))) 12 | 13 | (define (hash-table-clear! table) 14 | "Remove all entries from TABLE." 15 | (hash-table-walk table 16 | (lambda (key value) 17 | (hash-table-delete! table key)))) 18 | 19 | (define (read-all port) 20 | "Read forms from port until eof, return a list" 21 | (let loop ((result '()) 22 | (form (read port))) 23 | (if (eof-object? form) 24 | (reverse result) 25 | (loop (cons form result) 26 | (read port))))) 27 | (define (read-packet port) 28 | "Read 6 byte ascii hex length, then length bytes, all utf-8" 29 | (let* ((length (string->number (utf8->string (read-bytevector 6 port)) 16)) 30 | (result (make-bytevector length))) 31 | (let loop ((result-index 0) 32 | (to-read length)) 33 | (if (zero? to-read) 34 | (let ((res (utf8->string result))) 35 | (debug-log "from slime> " res) 36 | (message->scheme res)) 37 | (let* ((tmp (read-bytevector to-read port)) 38 | (len (bytevector-length tmp))) 39 | (bytevector-copy! result result-index tmp) 40 | (loop (+ result-index len) 41 | (- to-read len))))))) 42 | 43 | (define (message->scheme string) 44 | (read (open-input-string string))) 45 | 46 | (define (scheme->message form) 47 | (let ((o (open-output-string))) 48 | (write form o) 49 | (get-output-string o))) 50 | 51 | (define param:slime-in-port (make-parameter #f)) 52 | (define param:slime-out-port (make-parameter #f)) 53 | (define param:environment (make-parameter (interaction-environment))) 54 | (define param:current-id (make-parameter #f)) 55 | (define param:condition:msg (make-parameter "nil")) 56 | (define param:active-continuations (make-parameter #f)) 57 | (define param:active-condition (make-parameter #f)) 58 | (define log-port (current-output-port)) 59 | 60 | (define (process-one-message) 61 | (let ((form (read-packet (param:slime-in-port)))) 62 | (write-message (process-form form #f)))) 63 | 64 | (define (write-message sexp) 65 | (write-packet (scheme->message sexp) (param:slime-out-port))) 66 | 67 | (define param:abort (make-parameter #f)) 68 | 69 | (define (swank/abort message) 70 | ((param:abort) message)) 71 | 72 | (define (process-form form env-name) 73 | (let ((key (car form))) 74 | (let ((h (find-handler key))) 75 | (if h 76 | (with-exception-handler 77 | (lambda (condition) 78 | ($handle-condition condition) 79 | (swank/abort ($error-description condition))) 80 | (lambda () (apply h (cdr form)))) 81 | `(:return (:abort "no handler found") nil))))) 82 | (define start-swank 83 | (case-lambda (() (start-swank 4005)) 84 | ((port-or-file) (cond ((number? port-or-file) 85 | (server-loop port-or-file #f)) 86 | ((string? port-or-file) 87 | (server-loop #f port-or-file)) 88 | (else 89 | (error "Please call with port number or filename to which the automatically chosen port number will be written.")))))) 90 | (define (server-loop port-number port-file) 91 | ($open-tcp-server 92 | port-number port-file 93 | (lambda (actual-port-number data) 94 | (unless port-file 95 | (debug-log "swank listening on port " actual-port-number)) 96 | (when port-file 97 | (when (file-exists? port-file) 98 | (delete-file port-file)) 99 | (with-output-to-file port-file 100 | (lambda () 101 | (display actual-port-number)))) 102 | ($tcp-server-accept data 103 | (lambda (in out) 104 | (parameterize ((param:slime-in-port in) 105 | (param:slime-out-port out)) 106 | (let loop () 107 | (process-one-message) 108 | (loop)))))))) 109 | 110 | (define (string-pad-left string size pad) 111 | (let* ((s-len (string-length string)) 112 | (missing (max 0 (- size s-len)))) 113 | (if (zero? missing) 114 | string 115 | (string-append (make-string missing pad) string)))) 116 | 117 | (define (write-packet str port) 118 | (let* ((bv (string->utf8 str)) 119 | (len (bytevector-length bv)) 120 | (hex-len (number->string len 16))) 121 | (when (> (string-length hex-len) 6) 122 | (error "Expression length exceeds 24 bits" hex-len)) 123 | (debug-log "to slime< " str) 124 | (write-bytevector (string->utf8 (string-pad-left hex-len 6 #\0)) port) 125 | (write-bytevector bv port) 126 | (flush-output-port port))) 127 | 128 | (define *handlers* (make-hash-table)) 129 | 130 | (define (register-slime-handler! name function) 131 | ;; kawa returns non-equal for symbols with :, so we force the registered ones through READ as well 132 | (let ((name (read (open-input-string (symbol->string name))))) 133 | (hash-table-set! *handlers* name function))) 134 | 135 | (define (find-handler name) 136 | (hash-table-ref/default *handlers* name #f)) 137 | 138 | (define (interactive-eval sexp) 139 | (let-values ((vals (eval sexp (param:environment)))) ;; TODO environment 140 | vals)) 141 | 142 | (define *presentations* (make-hash-table)) 143 | 144 | (define (swank:lookup-presented-object id) 145 | "Retrieve the object corresponding to ID. 146 | The secondary value indicates the absence of an entry." 147 | ;; it seems we often get (list 'quote id) 148 | (if (list? id) 149 | (swank:lookup-presented-object (cadr id)) 150 | (let* ((nope (list #f)) 151 | (val (hash-table-ref/default 152 | *presentations* 153 | ;; emacs seems to ask for a number with a decimal, 154 | ;; aka inexact 155 | (exact id) nope))) 156 | (values (if (eq? nope val) #f val) 157 | (if (eq? nope val) 'nil 't))))) 158 | 159 | (define (swank:lookup-presented-object-or-lose id) 160 | "Get the result of the previous REPL evaluation with ID." 161 | (call-with-values (lambda () (swank:lookup-presented-object id)) 162 | (lambda (object found?) 163 | (if (eq? found? 'nil) 164 | (swank/abort 165 | (string-append "Attempt to access unrecorded object (id " 166 | (number->string id)")")) 167 | object)))) 168 | 169 | (define (replace-readtime-lookup-presented-object-or-lose string) 170 | "For presentations, emacs passes something that common lisp evals at read time. The resulting object is very different than what gerbil or gambits #. tries to do, so we do everything at run time" 171 | (let* ((pattern "#.(swank:lookup-presented-object-or-lose ") 172 | (start (string-contains string pattern))) 173 | (if start 174 | (replace-readtime-lookup-presented-object-or-lose 175 | (string-replace string "" start (+ 2 start))) 176 | string))) 177 | 178 | (define last-presentation-id 0) 179 | (define (next-presentation-id) 180 | (set! last-presentation-id (+ last-presentation-id 1)) 181 | last-presentation-id) 182 | 183 | ;; based on https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64 184 | (define (base64-encode bv) 185 | (let* ((chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") 186 | (c (remainder (bytevector-length bv) 3)) 187 | ;; padding at end 188 | (p (if (> c 0) (make-string (- 3 c) #\=) "")) 189 | (r (open-output-string)) 190 | ;; add trailing zeros 191 | (s (bytevector-append bv (if (> c 0) (make-bytevector (- 3 c) 0) (bytevector))))) 192 | 193 | (do ((i 0 (+ i 3))) 194 | ((>= i (bytevector-length s))) 195 | (if (and (> i 0) 196 | (zero? (remainder (* 4 (/ i 3)) 76))) 197 | (display "\n" r)) ;; "\r\n" ? 198 | (let* ((n (+ (* (bytevector-u8-ref s i) 256 256) 199 | (* (bytevector-u8-ref s (+ i 1)) 256) 200 | (bytevector-u8-ref s (+ i 2)))) 201 | (n0 (remainder (quotient n 262144) 64)) 202 | (n1 (remainder (quotient n 4096) 64)) 203 | (n2 (remainder (quotient n 64) 64)) 204 | (n3 (remainder n 64))) 205 | (display (string-ref chars n0) r) 206 | (display (string-ref chars n1) r) 207 | (display (string-ref chars n2) r) 208 | (display (string-ref chars n3) r))) 209 | (let ((out (get-output-string r))) 210 | (string-append (substring out 0 (- (string-length out) (string-length p))) p)))) 211 | (define (encode-swank-image-data bytevector) 212 | (base64-encode bytevector)) 213 | (define (presentations?) #t) 214 | (define (present value type) 215 | (or (swank-convert-to-image value type) 216 | (let ((id (next-presentation-id))) 217 | (hash-table-set! *presentations* id value) 218 | (write-message `(:presentation-start ,id ,type)) 219 | (swank/write-string (write-to-string value) type) 220 | (write-message `(:presentation-end ,id ,type)) 221 | (swank/write-string "\n" type) 222 | 'nil))) 223 | 224 | (define (swank-convert-to-image value type) 225 | (let loop ((cs *image-converters*)) 226 | (if (null? cs) 227 | (if (swank-image? value) 228 | (if (swank-image-filename value) 229 | (write-message `(:write-image ((:type ,(swank-image-type value) 230 | ,@(list ':file (swank-image-filename value)))) 231 | ,(swank-image-string value))) 232 | (write-message `(:write-image ((:type ,(swank-image-type value) 233 | ,@(list ':data (encode-swank-image-data (swank-image-data value))))) 234 | ,(swank-image-string value)))) 235 | #f) 236 | (let ((c (car cs))) 237 | (if ((car c) value) 238 | (swank-convert-to-image ((cdr c) value) type) 239 | (loop (cdr cs))))))) 240 | 241 | (define (write-to-string val) 242 | (let ((o (open-output-string))) 243 | (write val o) 244 | (get-output-string o))) 245 | 246 | (define (read-from-string str) 247 | (read (open-input-string str))) 248 | 249 | (define (display-to-string val) 250 | (let ((o (open-output-string))) 251 | (display val o) 252 | (get-output-string o))) 253 | 254 | (define (unquote-number n) 255 | "If N is '17, return 17. Otherwise return N." 256 | (if (and (pair? n) 257 | (eq? (car n) 'quote) 258 | (pair? (cdr n)) 259 | (number? (cadr n))) 260 | (cadr n) 261 | n)) 262 | 263 | (define (unquote-string x) 264 | (if (and (list? x) 265 | (eq? (car x) 'quote)) 266 | (cond ((string? (cadr x)) 267 | (cadr x)) 268 | ((eq? (cadr x) 'nil) 269 | "(user)") 270 | (else ;; TODO 271 | "(user")) 272 | x)) 273 | (define (swank/write-string val type) 274 | (write-message `(:write-string ,(if (string? val) val (write-to-string val)) ,@(if type (list type) '())))) 275 | 276 | ;;;; autodoc 277 | (define (improper->proper-list lst) 278 | (if (pair? lst) 279 | (cons (car lst) 280 | (improper->proper-list (cdr lst))) 281 | (if (null? lst) 282 | '() 283 | (list '!rest lst)))) 284 | 285 | (define (find-expression-containing-swank-cursor-marker expr) 286 | (define (f expr exit) 287 | (if (list? expr) 288 | (if (member '|swank::%cursor-marker%| expr) 289 | expr 290 | (let ((res (find (lambda (ex) 291 | (f ex exit)) 292 | expr))) 293 | (if res (exit res) res))) 294 | #f)) 295 | (call-with-current-continuation (lambda (exit) (f expr exit)))) 296 | 297 | (define (highlight-at-cursor signature expr) 298 | (let* ((form (find-expression-containing-swank-cursor-marker (cdr expr))) 299 | (index (list-index (lambda (el) (eq? el '|swank::%cursor-marker%|)) form))) 300 | (if index 301 | (wrap-item/index (improper->proper-list signature) (- index 1) '===> '<===) 302 | '()))) 303 | 304 | (define (find-string-before-swank-cursor-marker expr) 305 | (let ((ex (find-expression-containing-swank-cursor-marker expr))) 306 | (if ex 307 | (if (string? (car ex)) 308 | (car ex) 309 | #f)))) 310 | 311 | (define (wrap-item/index lst index before-marker after-marker) 312 | (let loop ((i 0) 313 | (lst lst)) 314 | (cond ((null? (cdr lst)) 315 | (list before-marker (car lst) after-marker)) 316 | ((member (car lst) '(!rest !optional)) 317 | (cons (car lst) (loop i (cdr lst)))) 318 | ((= i index) 319 | (append (list before-marker (car lst) after-marker) (cdr lst))) 320 | (else 321 | (cons (car lst) 322 | (loop (+ i 1) (cdr lst))))))) 323 | 324 | (define (with-output-to-string thunk) 325 | (let ((o (open-output-string))) 326 | (parameterize ((current-output-port o)) 327 | (thunk)) 328 | (get-output-string o))) 329 | 330 | (define *throw-to-top-level* #f) 331 | (define (sldb-loop) 332 | (if *throw-to-top-level* 333 | (begin 334 | (set! *throw-to-top-level* #f) 335 | (write-message `(:debug-return 1 1 nil))) 336 | (begin 337 | (process-one-message) 338 | (sldb-loop)))) 339 | (define *last-exception* #f) 340 | (define (swank:get-last-exception) 341 | *last-exception*) 342 | (define (invoke-sldb exception) 343 | (set! *last-exception* exception) 344 | (let ((msg ($condition-msg exception)) 345 | (trace ($condition-trace exception)) 346 | (links ($condition-links exception))) 347 | (write-message `(:debug 1 1 (,msg ,(write-to-string exception) nil) 348 | (("ABORT" "abort")) 349 | (,@(map (lambda (c t i) 350 | `(,i ,t)) 351 | links 352 | trace 353 | (iota (length trace)))) 354 | ,(let ((id (param:current-id))) 355 | (if id 356 | (list id) 357 | 'nil)))) 358 | (write-message `(:debug-activate 1 1)) 359 | (parameterize ((param:condition:msg msg) 360 | (param:active-continuations links) 361 | (param:active-condition exception)) 362 | (sldb-loop)))) 363 | 364 | (define inspector-state #f) 365 | 366 | ;; see specific for the record type definition of istate 367 | 368 | (define (reset-inspector) 369 | (set! inspector-state #f)) 370 | 371 | (define (inspect-object object) 372 | (let ((previous inspector-state) 373 | (content (swank/inspect object)) 374 | (parts (make-hash-table)) 375 | (actions (make-hash-table))) 376 | (set! inspector-state (make-istate object parts actions #f previous content)) 377 | (if previous (set-istate-next! previous inspector-state)) 378 | (istate->elisp inspector-state))) 379 | 380 | (define (ellipsize str) 381 | (if (> (string-length str) 100) 382 | (string-append (substring str 0 97) "...") 383 | str)) 384 | 385 | (define (istate->elisp inspector-state) 386 | `(:title ,(ellipsize (write-to-string (istate-object inspector-state))) 387 | :id ,(assign-istate-index (istate-object inspector-state) (istate-parts inspector-state)) 388 | :content ,(prepare-inspector-range (istate-parts inspector-state) 389 | (istate-actions inspector-state) 390 | (istate-content inspector-state) 391 | 0 392 | 100))) 393 | 394 | (define (assign-istate-index object parts) 395 | (let ((i (hash-table-size parts))) 396 | (hash-table-set! parts i object) 397 | i)) 398 | 399 | (define (assign-istate-action-index fun actions) 400 | (let ((i (hash-table-size actions))) 401 | (hash-table-set! actions i fun) 402 | i)) 403 | 404 | (define (prepare-inspector-range parts actions content from to) 405 | (let* ((cs (substream content from to)) 406 | (ps (prepare-inspector-parts cs parts actions))) 407 | (list ps 408 | (if (< (length cs) (- to from)) 409 | (+ from (length cs)) 410 | (+ to 1000)) 411 | from to))) 412 | 413 | (define (prepare-inspector-parts ps parts actions) 414 | (define (line label value . others) 415 | `(,(string-append (display-to-string label) ": ") 416 | (:value ,(ellipsize (write-to-string value)) ,(assign-istate-index value parts)) 417 | "\n")) 418 | (define (action label action) 419 | `((:action ,label ,(assign-istate-action-index action actions)))) 420 | (define (value val) 421 | `((:value ,(ellipsize (write-to-string val)) ,(assign-istate-index val parts)))) 422 | (apply append (map (lambda (p) 423 | (cond ((string? p) (list p)) 424 | ((symbol? p) (list (symbol->string p))) 425 | (else 426 | (case (car p) 427 | ((line) (apply line (cdr p))) 428 | ((action) (apply action (cdr p))) 429 | ((value) (apply value (cdr p))) 430 | ((newline) (list "\n")) 431 | (else (error "Invalid part:" p)))))) 432 | ps))) 433 | 434 | (define (swank/inspect object) 435 | (cond ((boolean? object) (inspect-boolean object)) 436 | ((symbol? object) (inspect-symbol object)) 437 | ((char? object) (inspect-char object)) 438 | ((integer? object) (inspect-integer object)) 439 | ((pair? object) (inspect-pair object)) 440 | ((hash-table? object) (inspect-hash-table object)) 441 | ((vector? object) (inspect-vector object)) 442 | ((bytevector? object) (inspect-bytevector object)) 443 | ((string? object) (inspect-string object)) 444 | (else 445 | (inspect-unknown object)))) 446 | 447 | (define (inspector-line label value . values) 448 | `(line ,label ,value ,@values)) 449 | 450 | (define (inspect-char object) 451 | (stream (inspector-line "Character code" (char->integer object)) 452 | (inspector-line "Lower case" (char-downcase object)) 453 | (inspector-line "Upper case" (char-upcase object)))) 454 | 455 | (define (inspect-integer object) 456 | (stream "Value: " (number->string object) 457 | " = #x" (number->string object 16) 458 | " = #o" (number->string object 8) 459 | " = #b" (number->string object 2) 460 | "\n" 461 | (inspector-line "Character" (integer->char object)))) 462 | 463 | (define (inspect-pair pair) 464 | (if (or (pair? (cdr pair)) 465 | (null? (cdr pair))) 466 | (let loop ((l1 pair) (l2 pair) (i 0)) 467 | (cond ((pair? l1) 468 | (stream-cons (inspector-line i (car l1)) 469 | (let ((l1 (cdr l1))) 470 | (if (eq? l1 l2) 471 | (stream "{circular list detected}") 472 | (loop l1 473 | (if (odd? i) (cdr l2) l2) 474 | (+ i 1)))))) 475 | ((null? l1) (stream)) 476 | (else (stream (inspector-line "tail" (cdr l1)))))) 477 | (stream (inspector-line "car" (car pair)) 478 | (inspector-line "cdr" (cdr pair))))) 479 | 480 | (define (inspect-boolean object) 481 | (stream (inspector-line "Boolean" object))) 482 | 483 | (define (inspect-symbol object) 484 | (stream (inspector-line "Symbol" object))) 485 | 486 | (define (inspect-unknown object) 487 | (let ((specific ($inspect-fallback object))) 488 | (if specific 489 | specific 490 | (stream (inspector-line "Object" object))))) 491 | 492 | (define (inspect-vector object) 493 | (stream-cons (inspector-line "Length" (vector-length object)) 494 | (let ((len (vector-length object))) 495 | (let loop ((i 0)) 496 | (if (< i len) 497 | (stream-cons (inspector-line i (vector-ref object i)) 498 | (loop (+ i 1))) 499 | (stream)))))) 500 | 501 | (define (inspect-hash-table object) 502 | (let ((elements '())) 503 | (hash-table-walk object 504 | (lambda (key value) 505 | (set! elements (cons* `(value ,key) " => " `(value ,value) " " `(action "[remove entry]" ,(lambda () (hash-table-delete! object key))) '(newline) elements)))) 506 | (stream-cons (inspector-line "Length" (hash-table-size object)) 507 | (stream-cons `(action "[clear hash table]" ,(lambda () (hash-table-clear! object))) 508 | (stream-cons '(newline) 509 | (apply stream elements)))))) 510 | 511 | (define (inspect-bytevector object) 512 | (stream-cons (inspector-line "Length" (bytevector-length object)) 513 | (let ((len (bytevector-length object))) 514 | (let loop ((i 0)) 515 | (if (< i len) 516 | (stream-cons (inspector-line i (bytevector-u8-ref object i)) 517 | (loop (+ i 1))) 518 | (stream)))))) 519 | 520 | (define (inspect-string object) 521 | (stream-cons (inspector-line "Length" (string-length object)) 522 | (let ((len (string-length object))) 523 | (let loop ((i 0)) 524 | (if (< i len) 525 | (stream-cons (inspector-line i (string-ref object i)) 526 | (loop (+ i 1))) 527 | (stream)))))) 528 | 529 | (define (binding-value symbol) 530 | (call/cc (lambda (k) (with-exception-handler (lambda (c) (k #f)) (lambda () (eval symbol (param:environment))))))) 531 | 532 | (define (object-documentation name object) 533 | (let ((doc ($binding-documentation object))) 534 | (string-append name "\n" 535 | (if doc doc "") 536 | "\n" 537 | "It is bound to:\n" (write-to-string object)))) 538 | 539 | (define (describe-symbol name) 540 | (let* ((value (binding-value (string->symbol name)))) 541 | (object-documentation name value))) 542 | 543 | ;;;; streams 544 | (define-syntax swank/delay 545 | (syntax-rules () 546 | ((swank/delay expr) 547 | (lambda () expr)))) 548 | 549 | (define (swank/force promise) (promise)) 550 | 551 | (define (stream-cons a b) 552 | (cons a (swank/delay b))) 553 | 554 | (define (stream-car p) 555 | (car p)) 556 | 557 | (define (stream-cdr p) 558 | (swank/force (cdr p))) 559 | 560 | (define (stream . rest) 561 | (list->stream rest)) 562 | 563 | (define (list->stream list) 564 | (if (pair? list) 565 | (stream-cons (car list) (list->stream (cdr list))) 566 | '())) 567 | 568 | (define (substream s from to) 569 | (let loop ((i 0) 570 | (l '()) 571 | (s s)) 572 | (cond ((or (if (null? to) #f (= i to)) (null? s)) (reverse l)) 573 | ((< i from) (loop (+ i 1) l (stream-cdr s))) 574 | (else (loop (+ i 1) (cons (stream-car s) l) (stream-cdr s)))))) 575 | 576 | (define (intersperse lst sep) 577 | (let loop ((rem lst) 578 | (result '())) 579 | (cond ((null? rem) 580 | (reverse result)) 581 | ((null? (cdr rem)) 582 | (reverse (cons (car rem) result))) 583 | (else (loop (cdr rem) 584 | (cons sep 585 | (cons (car rem) 586 | result))))))) 587 | 588 | (define (build-multi-value vals) 589 | (intersperse (map (lambda (val) 590 | (cons 'value (list val))) 591 | vals) 592 | ", ")) 593 | 594 | (define *traces* '()) 595 | (define-record-type trace-entry 596 | (%make-trace-entry id spec parent children arguments return-values) 597 | trace-entry? 598 | (id trace-entry-id) 599 | (spec trace-entry-spec) 600 | (parent trace-entry-parent) 601 | (children trace-entry-children set-trace-entry-children!) 602 | (arguments trace-entry-arguments) 603 | (return-values trace-entry-return-values set-trace-entry-return-values!)) 604 | 605 | (define (make-trace-entry id spec parent arguments) 606 | (let ((te (%make-trace-entry id spec parent '() arguments '()))) 607 | (set! *traces* (cons te *traces*)) 608 | te)) 609 | 610 | (define (trace-entry-add-child! trace-entry child) 611 | (set-trace-entry-children! trace-entry (cons child (trace-entry-children trace-entry))) 612 | trace-entry) 613 | 614 | (define *param:current-trace* (make-parameter #f)) 615 | 616 | (define *next-trace-id* -1) 617 | (define (next-trace-id) 618 | (set! *next-trace-id* (+ *next-trace-id* 1)) 619 | *next-trace-id*) 620 | (define (reset-trace-ids!) 621 | (set! *next-trace-id* -1)) 622 | (define (traces) *traces*) 623 | (define (clear-traces!) 624 | (set! *traces* '())) 625 | (define (tracing fun spec) 626 | (lambda args 627 | (let* ((ct (*param:current-trace*)) 628 | (te (make-trace-entry (next-trace-id) spec ct args))) 629 | (when ct 630 | (trace-entry-add-child! ct te)) 631 | (parameterize ((*param:current-trace* te)) 632 | (let-values ((retvals (apply fun args))) 633 | (set-trace-entry-return-values! te retvals) 634 | (apply values retvals)))))) 635 | 636 | (define (add-index+to-string lst) 637 | (let loop ((l lst) 638 | (i 0) 639 | (result '())) 640 | (if (null? l) 641 | (reverse result) 642 | (loop (cdr l) 643 | (+ i 1) 644 | (cons (list i (write-to-string (car l))) result))))) 645 | 646 | (define (describe-trace-for-emacs trace-entry) 647 | `(,(trace-entry-id trace-entry) 648 | ,(if (trace-entry-parent trace-entry) 649 | (trace-entry-id (trace-entry-parent trace-entry)) 650 | 'nil) 651 | ,(if (symbol? (trace-entry-spec trace-entry)) 652 | (symbol->string (trace-entry-spec trace-entry)) 653 | (trace-entry-spec trace-entry)) 654 | ,(add-index+to-string (trace-entry-arguments trace-entry)) 655 | ,(add-index+to-string (trace-entry-return-values trace-entry)))) 656 | 657 | (define (find-trace trace-index) 658 | (let loop ((t (traces))) 659 | (cond ((null? t) 660 | #f) 661 | ((= (trace-entry-id (car t)) trace-index) 662 | (car t)) 663 | (else 664 | (loop (cdr t)))))) 665 | (define *pre-trace-values* '()) 666 | (define (add-pre-tracing-value! sym value) 667 | (set! *pre-trace-values* (cons (cons sym value) *pre-trace-values*))) 668 | (define (pre-trace-values) 669 | *pre-trace-values*) 670 | (define (%pre-tracing-value symbol) 671 | (let loop ((t *pre-trace-values*)) 672 | (cond ((null? t) 673 | #f) 674 | ((eq? symbol (caar t)) 675 | (cdar t)) 676 | (else 677 | (loop (cdr t)))))) 678 | (define (untrace! sym) 679 | (interactive-eval `(set! ,sym (%pre-tracing-value ',sym))) 680 | (remove-pre-tracing-value! sym) 681 | (remove-active-trace! sym) 682 | (string-append (symbol->string sym) " is now untraced for trace dialog.")) 683 | (define (trace! sym) 684 | (let ((value (car (interactive-eval sym)))) 685 | (if (procedure? value) 686 | (begin 687 | (add-pre-tracing-value! sym value) 688 | (interactive-eval `(set! ,sym (tracing ,sym ',sym))) 689 | (add-active-trace! sym) 690 | (string-append (symbol->string sym) " is now traced for trace dialog.")) 691 | (string-append (symbol->string sym) " is not bound to a procedure, not tracing " (write-to-string value))))) 692 | (define (remove-pre-tracing-value! sym) 693 | (set! *pre-trace-values* (let loop ((lst *pre-trace-values*)) 694 | (if (null? lst) 695 | lst 696 | (if (eq? (caar lst) sym) 697 | (cdr lst) 698 | (cons (car lst) (loop (cdr lst)))))))) 699 | (define (add-active-trace! sym) 700 | (set! *active-traces* (cons sym *active-traces*))) 701 | (define (traced-symbol? sym) 702 | (memq sym *active-traces*)) 703 | (define (remove-active-trace! sym) 704 | (set! *active-traces* (let loop ((lst *active-traces*)) 705 | (if (null? lst) 706 | lst 707 | (if (eq? (car lst) sym) 708 | (cdr lst) 709 | (cons (car lst) (loop (cdr lst)))))))) 710 | (define (find-trace-arg trace index) 711 | (list-ref (trace-entry-arguments trace) index)) 712 | (define (find-trace-retval trace index) 713 | (list-ref (trace-entry-return-values trace) index)) 714 | (define-syntax trace-let 715 | (syntax-rules () 716 | ((trace-let loop ((name value) ...) body0 body ...) 717 | (let loop ((name value) ...) 718 | (let* ((ct (*param:current-trace*)) 719 | (te (make-trace-entry (next-trace-id) (string-append "let " (symbol->string 'loop)) ct (list name ...)))) 720 | (when ct 721 | (trace-entry-add-child! ct te)) 722 | (parameterize ((*param:current-trace* te)) 723 | (let-values ((retvals (begin 724 | body0 body ...))) 725 | (set-trace-entry-return-values! te retvals) 726 | (apply values retvals)))))) 727 | ((trace-let ((name value) ...) body0 body ...) 728 | (let ((name value) ...) 729 | (let* ((ct (*param:current-trace*)) 730 | (te (make-trace-entry (next-trace-id) (string-append "let") ct (list name ...)))) 731 | (when ct 732 | (trace-entry-add-child! ct te)) 733 | (parameterize ((*param:current-trace* te)) 734 | (let-values ((retvals (begin 735 | body0 body ...))) 736 | (set-trace-entry-return-values! te retvals) 737 | (apply values retvals)))))))) 738 | (define-syntax trace-let* 739 | (syntax-rules () 740 | ((trace-let* ((name value) ...) body0 body ...) 741 | (let* ((name value) ...) 742 | (let* ((ct (*param:current-trace*)) 743 | (te (make-trace-entry (next-trace-id) (string-append "let*") ct (list name ...)))) 744 | (when ct 745 | (trace-entry-add-child! ct te)) 746 | (parameterize ((*param:current-trace* te)) 747 | (let-values ((retvals (begin 748 | body0 body ...))) 749 | (set-trace-entry-return-values! te retvals) 750 | (apply values retvals)))))))) 751 | 752 | (define-syntax trace-letrec 753 | (syntax-rules () 754 | ((trace-letrec ((name value) ...) body0 body ...) 755 | (letrec ((name value) ...) 756 | (let* ((ct (*param:current-trace*)) 757 | (te (make-trace-entry (next-trace-id) (string-append "letrec") ct (list name ...)))) 758 | (when ct 759 | (trace-entry-add-child! ct te)) 760 | (parameterize ((*param:current-trace* te)) 761 | (let-values ((retvals (begin 762 | body0 body ...))) 763 | (set-trace-entry-return-values! te retvals) 764 | (apply values retvals)))))))) 765 | 766 | (define-syntax trace-letrec* 767 | (syntax-rules () 768 | ((trace-letrec* ((name value) ...) body0 body ...) 769 | (letrec* ((name value) ...) 770 | (let* ((ct (*param:current-trace*)) 771 | (te (make-trace-entry (next-trace-id) (string-append "letrec*") ct (list name ...)))) 772 | (when ct 773 | (trace-entry-add-child! ct te)) 774 | (parameterize ((*param:current-trace* te)) 775 | (let-values ((retvals (begin 776 | body0 body ...))) 777 | (set-trace-entry-return-values! te retvals) 778 | (apply values retvals)))))))) 779 | (define-syntax trace-define 780 | (syntax-rules () 781 | ((trace-define (name . args) body0 body ...) 782 | (define name (tracing (lambda args body0 body ...) 'name))) 783 | ((trace-define name (lambda args body0 body ...)) 784 | (define name (tracing (lambda args body0 body ...) 'name))))) 785 | ;;;; convenience 786 | (define (inspect-in-emacs object) 787 | (write-message `(:inspect ,(inspect-object object) nil nil)) 788 | #t) 789 | 790 | ;;;; swank image support 791 | (define-record-type swank-image 792 | (make-swank-image type filename data string) 793 | swank-image? 794 | (type swank-image-type) 795 | (filename swank-image-filename) 796 | (data swank-image-data) 797 | (string swank-image-string)) 798 | 799 | (define *image-converters* '()) 800 | 801 | (define (swank-present thing) 802 | (present thing 'nil)) 803 | 804 | (define (swank-register-image-converter predicate converter) 805 | (unless (procedure? predicate) 806 | (error "swank-register-image-converter: predicate must be a procedure" predicate)) 807 | (unless (procedure? converter) 808 | (error "swank-register-image-converter: converter must be a procedure" converter)) 809 | (set! *image-converters* (cons (cons predicate converter) *image-converters*))) 810 | 811 | -------------------------------------------------------------------------------- /common/handlers.scm: -------------------------------------------------------------------------------- 1 | (define *listener-value* #f) 2 | (define *active-traces* '()) 3 | 4 | (define (unquote* sym) 5 | (if (and (list? sym) 6 | (not (null? (cdr sym))) 7 | (eq? (car sym) 'quote)) 8 | (cadr sym))) 9 | 10 | (define-syntax define-slime-handler 11 | (syntax-rules () 12 | ((define-slime-handler (name . params) body0 body1 ...) 13 | (register-slime-handler! 'name (lambda params body0 body1 ...))))) 14 | 15 | (define-slime-handler (:emacs-rex sexp env-name thread id) 16 | (call-with-current-continuation 17 | (lambda (exit) 18 | (parameterize ((param:abort (lambda (message) 19 | (exit `(:return (:abort ,message) 20 | ,id)))) 21 | (param:environment ($environment env-name)) 22 | (param:current-id id)) 23 | `(:return (:ok ,(process-form sexp env-name)) 24 | ,id))))) 25 | 26 | (define-slime-handler (swank:connection-info) 27 | `(:pid 123 28 | :style :spawn 29 | :encoding (:coding-systems ("utf-8-unix")) 30 | :lisp-implementation (:type "Scheme" :name ,($scheme-name) :version 123 :program "/usr/bin/scheme") 31 | :machine (:instance "host" :type "X86-64") 32 | :features (:swank) 33 | :modules ("SWANK-ARGLISTS" "SWANK-REPL" "SWANK-PRESENTATIONS") 34 | :package (:name "(user)" :prompt "(user)") 35 | :version "2.28")) 36 | 37 | (define-slime-handler (swank:swank-require packages) 38 | '()) 39 | 40 | (define-slime-handler (swank:init-presentations) 41 | '()) 42 | 43 | (define-slime-handler (cl:nth-value num form) 44 | (call-with-values 45 | (lambda () (process-form form (param:environment))) 46 | (lambda values (list-ref values num)))) 47 | 48 | (define-slime-handler (swank:lookup-presented-object num) 49 | (swank:lookup-presented-object num)) 50 | 51 | (define-slime-handler (swank-repl:create-repl . args) 52 | (list "(user)" "(user)")) 53 | 54 | (define-slime-handler (swank-repl:listener-eval form) 55 | (let* ((form (replace-readtime-lookup-presented-object-or-lose form)) 56 | (results ($output-to-repl (lambda () (interactive-eval (cons 'begin (read-all (open-input-string form)))))))) 57 | (for-each (lambda (val) 58 | (if (presentations?) 59 | (present val ':repl-result) 60 | (swank/write-string val 'repl-result))) 61 | results) 62 | '())) 63 | 64 | (define-slime-handler (swank:quit-lisp) 65 | (exit 0)) 66 | 67 | (define-slime-handler (swank:list-all-package-names . args) 68 | ($all-package-names)) 69 | 70 | (define-slime-handler (swank:completions prefix env-name) 71 | (let ((completions+prefix ($completions prefix (unquote-string env-name)))) 72 | (list (car completions+prefix) 73 | (cdr completions+prefix)))) 74 | 75 | (define-slime-handler (swank:simple-completions prefix env-name) 76 | ;; TODO: for now, just copy swank:completions 77 | (let ((completions+prefix ($completions prefix (unquote-string env-name)))) 78 | (list (car completions+prefix) 79 | (cdr completions+prefix)))) 80 | 81 | (define-slime-handler (swank:compile-string-for-emacs form buffer position filename policy) 82 | ;; TODO: for now, just evaluate, copy of listener-eval 83 | (let ((results ($output-to-repl (lambda () (interactive-eval (cons 'begin (read-all (open-input-string form)))))))) 84 | (for-each (lambda (val) 85 | (swank/write-string val 'repl-result)) 86 | results) 87 | `(:compilation-result nil t 0.001 nil nil))) 88 | 89 | (define-slime-handler (swank:load-file filename) 90 | (let ((results ($output-to-repl (lambda () (load filename (param:environment)))))) 91 | 'loaded)) 92 | 93 | (define-slime-handler (swank:set-package name) 94 | ($set-package name)) 95 | 96 | (define-slime-handler (swank:operator-arglist op-string env-name) 97 | (let* ((signature+doc ($function-parameters-and-documentation op-string)) 98 | (signature (car signature+doc))) 99 | (if signature 100 | (write-to-string signature) 101 | ""))) 102 | 103 | (define-slime-handler (swank:autodoc expr . params) 104 | (let* ((op-string (find-string-before-swank-cursor-marker expr))) 105 | (if op-string 106 | (let* ((signature+doc ($function-parameters-and-documentation op-string)) 107 | (signature (car signature+doc)) 108 | (doc (cdr signature+doc))) 109 | (let ((answer (if signature (let* ((signature (highlight-at-cursor signature expr))) 110 | (with-output-to-string (lambda () 111 | (write signature) 112 | (if (and doc 113 | (not (string=? "" doc))) 114 | (begin 115 | (display " -- ") 116 | (display doc)))))) 117 | ':not-available))) 118 | (list answer 't))) 119 | (list ':not-available 't)))) 120 | 121 | (define-slime-handler (swank:frame-locals-and-catch-tags nr) 122 | ;; (:return 123 | ;; (:ok 124 | ;; (((:name "X" :id 0 :value "1") 125 | ;; (:name "Y" :id 0 :value "0")) 126 | ;; nil)) 127 | ;; 8) 128 | ($frame-locals-and-catch-tags nr)) 129 | 130 | (define-slime-handler (swank:throw-to-toplevel) 131 | (set! *throw-to-top-level* #t) 132 | (swank/abort (param:condition:msg))) 133 | 134 | (define-slime-handler (swank:backtrace from to) 135 | ;; (:return 136 | ;; (:ok 137 | ;; (((:name "X" :id 0 :value "1") 138 | ;; (:name "Y" :id 0 :value "0")) 139 | ;; nil)) 140 | ;; 8) 141 | (let ((trace ($condition-trace (param:active-condition)))) 142 | (let ((from (min from (length trace))) 143 | (to (min to (length trace)))) 144 | (take (list-tail trace from) (- to from))))) 145 | 146 | (define-slime-handler (swank:init-inspector string-form) 147 | (reset-inspector) 148 | (let ((vals (interactive-eval (cons 'begin (read-all (open-input-string string-form)))))) 149 | (inspect-object (car vals)))) 150 | 151 | (define-slime-handler (swank:inspector-range from to) 152 | (prepare-inspector-range (istate-parts inspector-state) 153 | (istate-actions inspector-state) 154 | (istate-content inspector-state) 155 | from to)) 156 | 157 | (define-slime-handler (swank:inspect-nth-part index) 158 | (inspect-object (hash-table-ref/default (istate-parts inspector-state) index 'no-such-part))) 159 | 160 | (define-slime-handler (swank:inspector-call-nth-action index) 161 | ((hash-table-ref/default (istate-actions inspector-state) index (lambda () #f))) 162 | (inspect-object (istate-object inspector-state))) 163 | 164 | (define-slime-handler (swank:inspector-pop) 165 | (if (and inspector-state (istate-previous inspector-state)) 166 | ;; bug in chibi with begin 167 | (let () 168 | (set! inspector-state (istate-previous inspector-state)) 169 | (istate->elisp inspector-state)) 170 | 'nil)) 171 | 172 | (define-slime-handler (swank:inspector-next) 173 | (if (istate-next inspector-state) 174 | (let () 175 | (set! inspector-state (istate-next inspector-state)) 176 | (istate->elisp inspector-state)) 177 | 'nil)) 178 | 179 | (define-slime-handler (swank:inspector-reinspect) 180 | (istate->elisp inspector-state)) 181 | 182 | (define-slime-handler (swank:inspector-toggle-verbose) 183 | ;; seems to toggle how the title is shown in sbcl 184 | (istate->elisp inspector-state)) 185 | 186 | (define-slime-handler (swank:inspector-history) 187 | ;; (:return 188 | ;; (:ok "--- next/prev chain --- 189 | ;; @2 # 190 | ;; @1 # 191 | ;; *@0 #<(SIMPLE-VECTOR 3) {1001AF0EAF}> 192 | 193 | ;; --- all visited objects --- 194 | ;; 0 #<(SIMPLE-VECTOR 3) {1001AF0EAF}> 195 | ;; 1 # 196 | ;; 2 #") 197 | ;; 14) 198 | (define (add-line current i result) 199 | (string-append result 200 | " " (if (eq? current inspector-state) "*" " ") 201 | "@" (number->string i) 202 | " " (ellipsize (write-to-string (istate-object current))) 203 | "\n")) 204 | (let ((first (let loop ((start inspector-state)) 205 | (if (istate-previous start) 206 | (loop (istate-previous start)) 207 | start)))) 208 | (let loop ((result "--- next/prev chain ---\n") 209 | (i 0) 210 | (current first)) 211 | (if (istate-next current) 212 | (loop (add-line current i result) 213 | (+ i 1) 214 | (istate-next current)) 215 | (add-line current i result))))) 216 | 217 | (define-slime-handler (swank:pprint-inspector-part index) 218 | (with-output-to-string 219 | (lambda () 220 | ($pretty-print (hash-table-ref/default (istate-parts inspector-state) index 'no-such-part))))) 221 | 222 | ;; inspector, M-RET 223 | ;; (define-slime-handler (swank:listener-save-value type index) 224 | ;; 'todo) 225 | 226 | ;; (define-slime-handler (swank:listener-get-value) 227 | ;; 'todo) 228 | (define-slime-handler (swank:inspect-presentation id reset?) 229 | (when reset? 230 | (reset-inspector)) 231 | (inspect-object (hash-table-ref/default *presentations* (unquote-number id) #f))) 232 | 233 | (define-slime-handler (swank:inspect-frame-var frame index) 234 | (reset-inspector) 235 | (inspect-object ($frame-var-value frame index))) 236 | 237 | (define-slime-handler (swank:frame-source-location index) 238 | ;; (:location 239 | ;; (:file "/usr/share/sbcl-source/src/code/numbers.lisp") 240 | ;; (:position 14095) 241 | ;; (:line line column) 242 | ;; (:snippet "(define-arith + 0\n \"Return the sum of its arguments. With no args, returns 0.\")\n (define-arith * 1\n \"Return the product of its arguments. With no args, returns 1.\"))\n\n(defun - (number &rest more-numbers)\n \"Subtract the second and all subsequent arg")) 243 | (let ((loc ($condition-location (list-ref (param:active-continuations) index)))) 244 | (if loc 245 | (let ((file (list-ref loc 0)) 246 | (position (list-ref loc 1)) 247 | (line (list-ref loc 2)) 248 | (column (list-ref loc 3))) 249 | `(:location 250 | (:file ,file) 251 | ,@(if position `((:position ,position)) '()) 252 | ,@(if line `((:line ,line ,column)) '()) 253 | (:snippet ""))) 254 | `(:error "No location found.")))) 255 | 256 | (define-slime-handler (swank:interactive-eval form) 257 | (let* ((results ($output-to-repl (lambda () (interactive-eval (cons 'begin (read-all (open-input-string form))))))) 258 | (count (length results))) 259 | (cond ((= count 1) 260 | (string-append "=> " (display-to-string (car results)))) 261 | ((= count 0) 262 | "; No value") 263 | (else 264 | (let ((vs (map display-to-string results))) 265 | (let loop ((vals (cdr vs)) 266 | (result (string-append "=> " (car vs)))) 267 | (if (null? vals) 268 | result 269 | (loop (cdr vals) 270 | (string-append result ", " (car vals)))))))))) 271 | 272 | (define-slime-handler (swank:buffer-first-change filename) 273 | 'nil) 274 | 275 | (define-slime-handler (swank:apropos-list-for-emacs name external-only? case-sensitive? package) 276 | (map (lambda (el) 277 | (let ((name (car el)) 278 | (type (cadr el)) 279 | (documentation (or (caddr el) ':not-documented))) 280 | `(:designator ,(write-to-string name) ,type ,documentation))) 281 | ($apropos name))) 282 | 283 | (define-slime-handler (swank:describe-definition-for-emacs name type) 284 | (describe-symbol name)) 285 | 286 | (define-slime-handler (swank:describe-symbol name) 287 | (describe-symbol name)) 288 | 289 | (define-slime-handler (swank:describe-function name) 290 | (describe-symbol name)) 291 | 292 | (define-slime-handler (swank:list-threads) 293 | `((:id :name :status) 294 | (1 "repl-thread" "Running"))) 295 | 296 | (define-slime-handler (swank:clear-repl-results) 297 | ;; don't do anything, CL clears all presentations 298 | (set! *presentations* (make-hash-table)) 299 | 't) 300 | 301 | (define-slime-handler (swank-repl:clear-repl-variables) 302 | ;; don't do anything, CL clears *** ** * /// // / +++ ++ + here 303 | 'nil) 304 | 305 | (define-slime-handler (swank-repl:listener-save-value fun . args) 306 | ;; fun is (quote ...) 307 | (set! fun (cadr fun)) 308 | (case fun 309 | ((swank:inspector-nth-part) 310 | (let ((index (car args))) 311 | (set! *listener-value* (hash-table-ref/default (istate-parts inspector-state) index 'no-such-part)) 312 | 't)) 313 | (else 314 | (swank/abort (string-append "Unknown swank-repl:listener-save-value function: " (symbol->string fun)))))) 315 | 316 | (define-slime-handler (swank-repl:listener-get-value) 317 | (if (presentations?) 318 | (present *listener-value* ':repl-result) 319 | (swank/write-string *listener-value* 'repl-result))) 320 | 321 | (define-slime-handler (swank:complete-form expr) 322 | (let* ((op-string (find-string-before-swank-cursor-marker expr)) 323 | (form (filter (lambda (el) (not (and (string? el) (string=? "" el)))) (find-expression-containing-swank-cursor-marker expr)))) 324 | (if op-string 325 | (let* ((signature+doc ($function-parameters-and-documentation op-string)) 326 | (signature (car signature+doc)) 327 | (provided-param-count (- (length form) 1))) 328 | (let loop ((os (open-output-string)) 329 | (lst (list-tail signature provided-param-count)) 330 | (space? #f)) 331 | (cond ((null? lst) 332 | (get-output-string os)) 333 | ((symbol? lst) 334 | (when space? 335 | (display " " os)) 336 | (display lst os) 337 | (display "..." os) 338 | (get-output-string os)) 339 | ((list? lst) 340 | (when space? 341 | (display " " os)) 342 | (display (car lst) os) 343 | (loop os (cdr lst) #t))))) 344 | ':not-available))) 345 | 346 | (define-slime-handler (swank:value-for-editing name) 347 | (write-to-string (binding-value (string->symbol name)))) 348 | 349 | (define-slime-handler (swank:commit-edited-value name value-string) 350 | (let ((v (read-from-string value-string))) 351 | (interactive-eval `(set! ,(string->symbol name) ',v)) 352 | 't)) 353 | 354 | (define-slime-handler (swank:swank-expand-1 form) 355 | (let ((v (read-from-string form))) 356 | (write-to-string ($macroexpand-1 v)))) 357 | 358 | (define-slime-handler (swank:swank-macroexpand-all form) 359 | (let ((v (read-from-string form))) 360 | (write-to-string ($macroexpand-all v)))) 361 | 362 | (define-slime-handler (swank:inspect-current-condition) 363 | (inspect-object (param:active-condition))) 364 | 365 | (define-slime-handler (swank::menu-choices-for-presentation-id id) 366 | 'nil) 367 | 368 | (define-slime-handler (swank::describe-to-string object) 369 | (object-documentation (write-to-string object) (interactive-eval object))) 370 | 371 | ;;;; Tracing 372 | (define-slime-handler (swank-trace-dialog:report-total) 373 | "Return the total count of traces." ;; e.g. 5 374 | (length (traces))) 375 | 376 | (define-slime-handler (swank-trace-dialog:report-specs) 377 | "Return a list of traced functions." ;; e.g. (common-lisp-user::fac) 378 | (if (null? *active-traces*) 379 | '() 380 | *active-traces*)) 381 | 382 | (define-slime-handler (swank-trace-dialog:dialog-toggle-trace symbol) ;; e.g. symbol = (swank::from-string "FAC") 383 | (let ((sym (if (and (list? symbol) 384 | (not (null? (cdr symbol))) 385 | (eq? (car symbol) 'swank::from-string)) 386 | (string->symbol (cadr symbol)) 387 | 'ERROR))) 388 | (if (traced-symbol? sym) 389 | (untrace! sym) 390 | (trace! sym)))) 391 | 392 | (define-slime-handler (swank-trace-dialog:report-partial-tree key) ;; e.g. key = 'slime-trace-dialog-fetch-key-16 393 | (let ((remaining-count 0) 394 | (traces (map describe-trace-for-emacs (reverse (traces))))) 395 | (list traces remaining-count (unquote* key)))) 396 | 397 | (define-slime-handler (swank-trace-dialog:dialog-untrace sym) 398 | (let ((sym (unquote* sym))) 399 | (untrace! sym)) 400 | 'nil) 401 | (define-slime-handler (swank-trace-dialog:dialog-untrace-all) 402 | (set! *active-traces* '()) 403 | (for-each untrace! (map car *pre-trace-values*)) 404 | 'nil) 405 | 406 | (define-slime-handler (cl:progn . rest) 407 | (let loop ((rest rest)) 408 | (if (null? (cdr rest)) 409 | (process-form (car rest) (param:environment)) 410 | (begin 411 | (unless (eq? (car rest) 'nil) 412 | (process-form (car rest) (param:environment))) 413 | (loop (cdr rest)))))) 414 | 415 | (define-slime-handler (swank-trace-dialog:report-trace-detail trace-index) 416 | (let ((t (find-trace trace-index))) 417 | (if t 418 | (append (describe-trace-for-emacs t) 419 | (list 'nil ;; backtrace 420 | (trace-entry-spec t))) 421 | 'nil))) 422 | 423 | (define-slime-handler (swank-trace-dialog:inspect-trace-part trace-index index type) 424 | ;; type = :arg | :retval 425 | (let ((t (find-trace trace-index))) 426 | (case type 427 | ((:arg) 428 | (inspect-object (find-trace-arg t index))) 429 | ((:retval) 430 | (inspect-object (find-trace-retval t index))) 431 | (else 432 | 'nil)))) 433 | 434 | (define-slime-handler (swank-trace-dialog:clear-trace-tree) 435 | (clear-traces!) 436 | (reset-trace-ids!) 437 | 'nil) 438 | -------------------------------------------------------------------------------- /cyclone-swank.sld: -------------------------------------------------------------------------------- 1 | (define-library (cyclone-swank) 2 | (export start-swank) 3 | (import (scheme base) (scheme eval) (scheme read) (scheme write) (scheme file) (scheme case-lambda) (scheme process-context) 4 | (scheme load) (scheme char) ;; (scheme repl) 5 | (srfi 106) (srfi 69) (srfi 1)) 6 | (include "specific/cyclone.ss") 7 | (include "common/base.scm") 8 | (include "common/handlers.scm") 9 | (begin 10 | (start-swank "/tmp/cyclone-port.txt"))) 11 | 12 | -------------------------------------------------------------------------------- /cyclone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cyclone cyclone-swank.sld 3 | icyc -p '(import (cyclone-swank))' # (start-swank "/tmp/cyclone-port.txt") 4 | -------------------------------------------------------------------------------- /gambit-swank.sld: -------------------------------------------------------------------------------- 1 | ;; (import (scheme base) (scheme file) (scheme write) (scheme read) (scheme eval) (scheme repl) (scheme process-context) 2 | ;; (std srfi |13|) (std srfi |1|) 3 | ;; (only (gerbil/gambit) open-tcp-server) 4 | ;; (only (gerbil/core) hash-ref hash-put! make-hash-table exit values->list hash->list filter) 5 | ;; (only (gerbil/expander) module-context? module-context-ns expander-context-id expander-context-table current-expander-module-registry) 6 | ;; (only (gerbil/gambit/exceptions) display-exception)) 7 | 8 | ;; values->list should go when let-values works 9 | (include "specific/gambit.scm") 10 | (include "common/base.scm") 11 | (include "common/handlers.scm") 12 | -------------------------------------------------------------------------------- /gambit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gsi gambit-swank.sld 3 | -------------------------------------------------------------------------------- /gauche-swank.sld: -------------------------------------------------------------------------------- 1 | (define-library (gauche-swank) 2 | (export start-swank 3 | swank:lookup-presented-object 4 | swank:lookup-presented-object-or-lose 5 | inspect-in-emacs 6 | make-swank-image 7 | swank-register-image-converter 8 | swank-present 9 | tracing trace-define trace-let trace-let* trace-letrec trace-letrec*) 10 | (import (scheme base) (scheme eval) (scheme read) (scheme write) (scheme file) (scheme case-lambda) (scheme process-context) (scheme repl) (scheme load) (scheme char) (scheme cxr) 11 | (srfi-69) 12 | (srfi-27) 13 | (only (gauche base) 14 | keyword? keyword->string module-name all-modules module-table module-imports module-precedence-list ref class-of 15 | hash-table-for-each 16 | macroexpand-1 macroexpand-all) 17 | (rename (scheme base) (symbol->string scheme:symbol->string)) 18 | (only (gauche net) make-server-socket socket-accept socket-input-port socket-output-port) 19 | (gauche pputil) 20 | (only (srfi-13) string-contains string-prefix? string-replace) 21 | (only (srfi-1) find fold list-index cons* filter)) 22 | 23 | (include "specific/gauche.scm") 24 | (include "common/base.scm") 25 | (include "common/handlers.scm")) 26 | -------------------------------------------------------------------------------- /gauche.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | GAUCHE_KEYWORD_IS_SYMBOL=T gosh -r7 -A . -l gauche-swank.sld -e '(begin (import (gauche-swank)) (start-swank))' 3 | -------------------------------------------------------------------------------- /gerbil-build.ss: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gxi 2 | ;; -*- Gerbil -*- 3 | 4 | (import :std/make) 5 | 6 | (def build-spec 7 | '("gerbil-swank")) 8 | 9 | (def srcdir 10 | (path-normalize (path-directory (this-source-file)))) 11 | 12 | (def (main . args) 13 | (match args 14 | (["meta"] 15 | (write '("spec" "deps" "compile")) 16 | (newline)) 17 | (["spec"] 18 | (pretty-print build-spec)) 19 | (["deps"] 20 | (let (build-deps (make-depgraph/spec build-spec)) 21 | (call-with-output-file "gerbil-build-deps" (cut write build-deps <>)))) 22 | (["compile"] 23 | (let (depgraph (call-with-input-file "gerbil-build-deps" read)) 24 | (make srcdir: srcdir 25 | depgraph: depgraph 26 | optimize: #t 27 | static: #f 28 | debug: 'src 29 | prefix: "ecraven" 30 | build-spec))) 31 | ([] 32 | (displayln "... make deps") 33 | (main "deps") 34 | (displayln "... compile") 35 | (main "compile")))) 36 | -------------------------------------------------------------------------------- /gerbil-r7rs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | dir=$(dirname "$0") 3 | export GERBIL_LOADPATH=${GERBIL_LOADPATH:-$dir} 4 | gxi --lang r7rs -e '(import (ecraven gerbil-swank))' -e '(start-swank)' 5 | -------------------------------------------------------------------------------- /gerbil-swank.ss: -------------------------------------------------------------------------------- 1 | (define-library (ecraven gerbil-swank) 2 | (export start-swank 3 | swank:lookup-presented-object swank:lookup-presented-object-or-lose 4 | repl-result-history-ref) 5 | (import (scheme base) (scheme file) (scheme write) (scheme read) (scheme eval) (scheme repl) (scheme process-context) (scheme load) (scheme cxr) (scheme char) 6 | (std srfi |13|) (std srfi |1|) 7 | (only (gerbil/gambit) open-tcp-server pp random-integer) 8 | (only (gerbil/core) hash-ref hash-put! hash-table? hash-for-each hash-length 9 | make-hash-table exit hash->list filter hash-remove! 10 | values->list ;; values->list should go when let-values works 11 | ) 12 | (only (gerbil/expander) module-context? module-context-ns expander-context-id expander-context-table current-expander-module-registry) 13 | (only (gerbil/gambit/exceptions) display-exception)) 14 | (include "specific/gerbil.scm") 15 | (include "common/base.scm") 16 | (include "common/handlers.scm")) 17 | -------------------------------------------------------------------------------- /gerbil.pkg: -------------------------------------------------------------------------------- 1 | (package: ecraven prelude: :scheme/r7rs build: "gerbil-build.ss") 2 | -------------------------------------------------------------------------------- /gerbil.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | dir=$(dirname "$0") 3 | export GERBIL_LOADPATH=${GERBIL_LOADPATH:-$dir} 4 | gxi $GERBIL_HOME/lib/gxi-interactive -e '(import :ecraven/gerbil-swank)' -e '(start-swank)' 5 | -------------------------------------------------------------------------------- /guile-swank.scm: -------------------------------------------------------------------------------- 1 | (define-library (guile-swank) 2 | (import (scheme base) 3 | (scheme write) 4 | (scheme case-lambda) 5 | (scheme read) 6 | (scheme char) 7 | (scheme eval) 8 | (scheme repl) 9 | (scheme file) 10 | (scheme load) 11 | (scheme process-context) 12 | (ice-9 match) 13 | (ice-9 binary-ports) 14 | (ice-9 documentation) 15 | (only (ice-9 ports) with-output-to-port with-error-to-port) 16 | (srfi srfi-69) 17 | (srfi srfi-11) ;; let-values 18 | (srfi srfi-1) 19 | (srfi srfi-9) 20 | (only (srfi srfi-13) string-contains-ci string-contains string-replace string-prefix?) 21 | (except (guile) 22 | error 23 | exit 24 | include 25 | load 26 | vector->list) 27 | (ice-9 exceptions) 28 | (ice-9 pretty-print) 29 | (system vm frame) 30 | (system vm program) 31 | (only (system repl debug) 32 | narrow-stack->vector 33 | print-frame 34 | stack->vector) 35 | (oop goops)) 36 | (export start-swank swank:lookup-presented-object 37 | swank:lookup-presented-object-or-lose 38 | make-swank-image 39 | swank-register-image-converter 40 | inspect-in-emacs 41 | swank-present 42 | tracing 43 | trace-let trace-let* trace-letrec trace-letrec* trace-define) 44 | 45 | (include "specific/guile.scm") 46 | (include "common/base.scm") 47 | (include "common/handlers.scm") 48 | ) 49 | -------------------------------------------------------------------------------- /guile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # for dev, force recompile 3 | touch guile-swank.scm 4 | guile -l guile-swank.scm -c "(import (guile-swank)) (start-swank)" 5 | -------------------------------------------------------------------------------- /kawa-swank.sld: -------------------------------------------------------------------------------- 1 | (define-library (kawa-swank) 2 | (export start-swank inspect-in-emacs) 3 | (import (scheme base) (scheme eval) (scheme read) (scheme write) (scheme file) (scheme case-lambda) (scheme process-context) (scheme repl) (scheme load) (scheme char) (scheme cxr) 4 | (srfi :69) (srfi :1) (only (srfi :13) string-contains-ci string-contains string-replace) 5 | (kawa pprint) 6 | (only (rnrs hashtables) hashtable-clear!)) 7 | (include "specific/kawa.scm") 8 | (include "common/base.scm") 9 | (include "common/handlers.scm")) 10 | -------------------------------------------------------------------------------- /kawa.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | kawa -f kawa-swank.sld -e '(import (kawa-swank)) (start-swank 4005)' 3 | -------------------------------------------------------------------------------- /larceny-swank.sld: -------------------------------------------------------------------------------- 1 | (define-library (larceny-swank) 2 | (export start-swank) 3 | (import (scheme base) (scheme eval) (scheme read) (scheme write) (scheme file) 4 | (scheme case-lambda) (scheme process-context) (scheme repl) (scheme load) (scheme char) 5 | (srfi 69) 6 | (srfi 1) 7 | (srfi 9) 8 | (only (srfi 13) string-contains string-replace string-prefix?) 9 | (only (larceny compiler) require) 10 | (primitives pretty-print r5rs:require)) 11 | (import (primitives server-socket-accept socket-output-port socket-input-port make-server-socket make-client-socket random)) 12 | (begin 13 | (r5rs:require 'Standard/socket)) 14 | (include "specific/larceny.scm") 15 | (include "common/base.scm") 16 | (include "common/handlers.scm") 17 | ) 18 | -------------------------------------------------------------------------------- /larceny.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo '(begin (import (larceny-swank)) (start-swank))' | larceny -r7rs -A . 3 | -------------------------------------------------------------------------------- /mit-swank.sld: -------------------------------------------------------------------------------- 1 | (define (load-relative filename) 2 | (with-working-directory-pathname 3 | (directory-namestring (current-load-pathname)) 4 | (lambda () (load filename)))) 5 | 6 | (load-relative "specific/mit.scm") 7 | (load-relative "common/base.scm") 8 | (load-relative "common/handlers.scm") 9 | -------------------------------------------------------------------------------- /mit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mit-scheme --heap 300000 --load $(pwd)/mit-swank.sld --eval '(start-swank 4005)' 3 | -------------------------------------------------------------------------------- /racket-swank.sld: -------------------------------------------------------------------------------- 1 | #lang r7rs 2 | ;(define-library (racket-swank) 3 | (import (scheme base) (scheme eval) (scheme read) (scheme write) (scheme file) (scheme case-lambda) (scheme process-context) (scheme repl) (scheme load) (scheme char) (scheme cxr) 4 | (only (srfi 1) fold filter fold-right find list-index iota take cons*) 5 | (only (compatibility/mlist) mlist->list list->mlist) 6 | (only (srfi 13) string-prefix? string-contains string-replace) 7 | (only (racket/base) namespace? make-base-namespace namespace-require current-namespace directory-exists? current-directory build-path namespace-mapped-symbols foldr mcons mcar mcdr expand expand-once) 8 | (only (racket/file) fold-files) 9 | (only (racket/pretty) pretty-print) 10 | (racket/tcp) (srfi/69)) 11 | (export start-swank 12 | swank:get-last-exception 13 | swank:lookup-presented-object-or-lose 14 | swank:lookup-presented-object 15 | make-swank-image 16 | swank-register-image-converter 17 | inspect-in-emacs 18 | swank-present 19 | tracing 20 | trace-let trace-let* trace-letrec trace-letrec* trace-define) 21 | 22 | (include "specific/racket.ss") 23 | (include "common/base.scm") 24 | (include "common/handlers.scm") 25 | ;) 26 | (start-swank) 27 | -------------------------------------------------------------------------------- /racket.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | racket -I r7rs racket-swank.sld 3 | -------------------------------------------------------------------------------- /specific/bigloo.scm: -------------------------------------------------------------------------------- 1 | ;;;; srfi-39 2 | (define make-parameter 3 | (lambda (init . conv) 4 | (let ((converter 5 | (if (null? conv) (lambda (x) x) (car conv)))) 6 | (let ((global-cell 7 | (cons #f (converter init)))) 8 | (letrec ((parameter 9 | (lambda new-val 10 | (let ((cell (dynamic-lookup parameter global-cell))) 11 | (cond ((null? new-val) 12 | (cdr cell)) 13 | ((null? (cdr new-val)) 14 | (set-cdr! cell (converter (car new-val)))) 15 | (else ; this case is needed for parameterize 16 | (converter (car new-val)))))))) 17 | (set-car! global-cell parameter) 18 | parameter))))) 19 | 20 | (define-syntax parameterize 21 | (syntax-rules () 22 | ((parameterize ((expr1 expr2) ...) body ...) 23 | (dynamic-bind (list expr1 ...) 24 | (list expr2 ...) 25 | (lambda () body ...))))) 26 | 27 | (define dynamic-bind 28 | (lambda (parameters values body) 29 | (let* ((old-local 30 | (dynamic-env-local-get)) 31 | (new-cells 32 | (map (lambda (parameter value) 33 | (cons parameter (parameter value #f))) 34 | parameters 35 | values)) 36 | (new-local 37 | (append new-cells old-local))) 38 | (dynamic-wind 39 | (lambda () (dynamic-env-local-set! new-local)) 40 | body 41 | (lambda () (dynamic-env-local-set! old-local)))))) 42 | 43 | (define dynamic-lookup 44 | (lambda (parameter global-cell) 45 | (or (assq parameter (dynamic-env-local-get)) 46 | global-cell))) 47 | 48 | (define dynamic-env-local '()) 49 | 50 | (define dynamic-env-local-get 51 | (lambda () dynamic-env-local)) 52 | 53 | (define dynamic-env-local-set! 54 | (lambda (new-env) (set! dynamic-env-local new-env))) 55 | ;;;; end srfi-39 56 | (define ($scheme-name) 57 | "bigloo") 58 | (define-syntax case-lambda 59 | (syntax-rules () 60 | ((case-lambda (params body0 body1 ...) ...) 61 | (lambda args 62 | (cond ((= (length args) (length 'params)) 63 | (apply (lambda params body0 body1 ...) args)) 64 | ...))))) 65 | (define-syntax let-values 66 | (syntax-rules () 67 | ((let-values ((vals form)) body0 body ...) 68 | (receive vals form 69 | (begin body0 body ...))))) 70 | (define make-hash-table make-hashtable) 71 | (define hash-table-set! hashtable-put!) 72 | (define (hash-table-ref/default table key default) (hashtable-get table key)) ; ignore default 73 | (define hash-table-size hashtable-size) 74 | (define hash-table-delete! hashtable-remove!) 75 | (define hash-table-walk hashtable-for-each) 76 | (define hash-table? hashtable?) 77 | 78 | (define ($macroexpand-1 form) 79 | form) 80 | 81 | (define ($macroexpand-all form) 82 | form) 83 | 84 | (define ($error-description error) 85 | error) 86 | (define ($environment name) 87 | (interaction-environment)) 88 | (define $pretty-print pp) 89 | (define string->utf8 (lambda (x) x)) 90 | (define utf8->string (lambda (x) x)) 91 | (define (bytevector . rest) 92 | (apply string (map integer->char rest))) 93 | (define bytevector-length string-length) 94 | (define (bytevector-u8-ref bv n) (char->integer (string-ref bv n))) 95 | (define (bytevector? object) #f) 96 | (define (bytevector-append a b) 97 | (string-append a b)) 98 | (define write-bytevector write-string) 99 | (define (error . args) args) ;;TODO 100 | (define ($open-tcp-server port-number port-file handler) 101 | (let* ((n (or port-number (+ 10000 (random 50000)))) 102 | (server (make-server-socket n))) 103 | (handler n server))) 104 | (define ($tcp-server-accept server handler) 105 | (let ((socket (socket-accept server ':inbuf #t ':outbuf #t))) 106 | (handler (socket-input socket) (socket-output socket)))) 107 | (define ($output-to-repl thunk) 108 | ;; basic implementation, print all output at the end, this should 109 | ;; be replaced with a custom output port 110 | (let ((o (open-output-string))) 111 | (parameterize ((current-output-port o)) 112 | (let-values ((x (thunk))) 113 | (swank/write-string (get-output-string o) #f) 114 | (apply values x))))) 115 | (define fop flush-output-port) 116 | (define (flush-output-port . args) 117 | (if (null? args) 118 | (fop (current-output-port)) 119 | (fop (car args)))) 120 | (define (read-bytevector size port) 121 | (read-chars size port)) 122 | (define ($all-package-names) 123 | '()) 124 | (define (make-bytevector size . default) 125 | (if (null? default) 126 | (make-string size) 127 | (make-string size (char->integer (car default))))) 128 | (define exact inexact->exact) 129 | 130 | (define (bytevector-copy! to at from) 131 | (let ((len (string-length from))) 132 | (let loop ((i 0)) 133 | (if (= i len) 134 | 'done 135 | (begin 136 | (string-set! to (+ at i) (string-ref from i)) 137 | (loop (+ i 1))))))) 138 | (define ($frame-var-value frame index) 139 | #f) 140 | (define ($binding-documentation name) 141 | #f) 142 | (define ($inspect-fallback object) 143 | #f) 144 | (define (symbol->string s) 145 | (cond ((keyword? s) 146 | (keyword->string s)) 147 | (else 148 | (symbol->string s)))) 149 | (define ($condition-msg condition) 150 | "UNKNOWN") 151 | 152 | (define ($condition-links condition) 153 | '()) 154 | 155 | (define ($handle-condition exception) 156 | #f) 157 | 158 | (define ($condition-trace condition) 159 | '()) 160 | 161 | (define ($completions prefix env-name) 162 | '()) 163 | 164 | (define ($set-package env-name) 165 | (list "(user)" "(user)")) 166 | 167 | (define ($function-parameters-and-documentation name) 168 | (cons #f #f)) 169 | 170 | (define ($frame-locals-and-catch-tags nr) 171 | '()) 172 | 173 | (define ($apropos name) 174 | '()) 175 | 176 | (define-record-type 177 | (make-istate object parts actions next previous content) 178 | istate? 179 | (object istate-object) 180 | (parts istate-parts) 181 | (actions istate-actions) 182 | (next istate-next set-istate-next!) 183 | (previous istate-previous) 184 | (content istate-content)) 185 | 186 | (define (list-index predicate list) 187 | (let loop ((i 0) 188 | (l list)) 189 | (if (null? l) 190 | #f 191 | (if (predicate (car l)) 192 | i 193 | (loop (+ i 1) (cdr l)))))) 194 | (define ($condition-location condition) 195 | #f) 196 | ;;;; HACK! 197 | (define (string-replace string replacement start end) 198 | (string-append (substring string 0 start) (substring string end (string-length string)))) 199 | -------------------------------------------------------------------------------- /specific/chibi.scm: -------------------------------------------------------------------------------- 1 | ;;;; srfi 13 2 | (define %string-contains string-contains) 3 | (define (string-contains string pattern) 4 | (let ((x (%string-contains string pattern))) 5 | (if x 6 | (string-cursor->index string x) 7 | x))) 8 | (define ($scheme-name) 9 | "chibi-scheme") 10 | 11 | (define ($macroexpand-1 form) 12 | (macroexpand form)) 13 | 14 | (define ($macroexpand-all form) 15 | (macroexpand form)) 16 | ;; chibi does not allow running code between opening the socket 17 | ;; and accepting with (chibi net server) :-/ 18 | (define ($open-tcp-server port-number port-file handler) 19 | (let ((n (or port-number (+ 10000 (random-integer 50000))))) 20 | ;; HACK: the port should be printed by base.scm, but as commented 21 | ;; above, chibi does not let us run code there 22 | (display "listening on port ") (display n) (newline) (flush-output-port) 23 | (when port-file 24 | (when (file-exists? port-file) 25 | (delete-file port-file)) 26 | (with-output-to-file port-file 27 | (lambda () 28 | (display n)))) 29 | ;; end of HACK 30 | (run-net-server n (lambda (in out sock addr) 31 | (handler n (list in out sock)))))) 32 | 33 | (define ($tcp-server-accept lst handler) 34 | (handler (car lst) (cadr lst))) 35 | 36 | (define ($all-package-names) 37 | (map display-to-string (map car *modules*))) 38 | 39 | (define (display-to-string val) 40 | (let ((out (open-output-string))) 41 | (display val out) 42 | (get-output-string out))) 43 | 44 | (define ($error-description error) 45 | (apply string-append (error-object-message error) 46 | ": " 47 | (map write-to-string (error-object-irritants error)))) 48 | 49 | (define ($output-to-repl thunk) 50 | ;; basic implementation, print all output at the end, this should 51 | ;; be replaced with a custom output port 52 | (let ((o (open-output-string))) 53 | (parameterize ((current-output-port o)) 54 | (let-values ((x (thunk))) 55 | (swank/write-string (get-output-string o) #f) 56 | (apply values x))))) 57 | (define (all-exports env) 58 | (delete-duplicates 59 | (let lp ((env env) (res '())) 60 | (if (not env) 61 | res 62 | (lp (env-parent env) (append (env-exports env) res)))))) 63 | (define (longest-common-prefix strings) 64 | 65 | (cond ((null? strings) 66 | "") 67 | ((= (length strings) 1) 68 | (car strings)) 69 | (else 70 | (let ((max-length (apply min (map string-length strings)))) 71 | (let loop ((i 1)) 72 | (if (all-string=? (map (lambda (el) 73 | (substring el 0 i)) 74 | strings)) 75 | (if (= i max-length) 76 | (substring (car strings) 0 i) 77 | (loop (+ i 1))) 78 | (substring (car strings) 0 (- i 1)))))))) 79 | (define *active-package-name* '(user)) 80 | (define (all-string=? lst) 81 | (let loop ((first (car lst)) 82 | (rest (cdr lst))) 83 | (if (null? rest) 84 | #t 85 | (if (not (string=? first (car rest))) 86 | #f 87 | (loop first (cdr rest)))))) 88 | (define (find-module name) 89 | ;; (display "find-module ") 90 | ;; (write name) 91 | ;; (newline) 92 | ;; TODO: fix this 93 | (if (eq? 'COMMON-LISP-USER name) 94 | (set! name '(chibi swank))) 95 | (let ((res (assoc name *modules*))) 96 | res)) 97 | (define ($completions prefix env-name) 98 | (if (not (find-module '(user))) 99 | (add-module! '(user) (make-module '() ($environment env-name) '()))) 100 | (let* ((package (if (not (string? env-name)) *active-package-name* (let ((in (open-input-string env-name))) (read in))))) 101 | (display "package: ") (display package) (newline) 102 | (let* ((env (module-env (cdr (find-module package))))) 103 | (let* ((bindings (all-exports env))) 104 | (let ((completions (sort (map symbol->string (filter (lambda (el) 105 | (string-prefix? prefix (symbol->string el))) 106 | bindings)) 107 | string 146 | (make-istate object parts actions next previous content) 147 | istate? 148 | (object istate-object) 149 | (parts istate-parts) 150 | (actions istate-actions) 151 | (next istate-next set-istate-next!) 152 | (previous istate-previous) 153 | (content istate-content)) 154 | 155 | (define ($inspect-fallback object) 156 | #f) 157 | 158 | (define ($apropos name) 159 | "Return a list of (name type documentation) for all matches for NAME." 160 | '()) 161 | 162 | (define ($binding-documentation p) 163 | #f) 164 | -------------------------------------------------------------------------------- /specific/chicken.scm: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "chicken-scheme") 3 | (define ($macroexpand-1 form) 4 | (##sys#expand form)) 5 | (define ($macroexpand-all form) 6 | (##sys#expand form)) 7 | (define ($open-tcp-server port-number port-file handler) 8 | (parameterize ((tcp-read-timeout #f)) 9 | (let* ((n (or port-number (+ 10000 (pseudo-random-integer 50000)))) 10 | (listener (tcp-listen n))) 11 | (handler n listener)))) 12 | 13 | (define-record-type 14 | (make-istate object parts actions next previous content) 15 | istate? 16 | (object istate-object) 17 | (parts istate-parts) 18 | (actions istate-actions) 19 | (next istate-next set-istate-next!) 20 | (previous istate-previous) 21 | (content istate-content)) 22 | 23 | (define ($tcp-server-accept listener handler) 24 | (let-values (((in out) (tcp-accept listener))) 25 | (handler in out))) 26 | 27 | (define ($output-to-repl thunk) 28 | ;; basic implementation, print all output at the end, this should 29 | ;; be replaced with a custom output port 30 | (let ((o (open-output-string))) 31 | (parameterize ((current-output-port o)) 32 | (let-values ((x (thunk))) 33 | (swank/write-string (get-output-string o) #f) 34 | (apply values x))))) 35 | 36 | ;; from chicken-core/csi.scm 37 | (define ($error-description error) 38 | (if (##sys#structure? error 'condition) 39 | (let ((out (open-output-string))) 40 | (fprintf out "condition: ~s~%" (##sys#slot error 1)) 41 | (for-each 42 | (lambda (k) 43 | (fprintf out " ~s~%" k) 44 | (let loop ((props (##sys#slot error 2))) 45 | (unless (null? props) 46 | (when (eq? k (caar props)) 47 | (##sys#with-print-length-limit 48 | 100 49 | (lambda () 50 | (fprintf out "\t~s: ~s" (cdar props) (cadr props)) )) 51 | (newline out)) 52 | (loop (cddr props))))) 53 | (##sys#slot error 1)) 54 | (get-output-string out)) 55 | "unknown")) 56 | 57 | (define ($completions prefix env-name) 58 | (cons '() 59 | prefix)) 60 | 61 | (define ($function-parameters-and-documentation name) 62 | (cons #f #f)) 63 | 64 | (define ($set-package name) 65 | (list "(user)" "(user)")) 66 | 67 | (define ($environment name) 68 | (interaction-environment)) 69 | 70 | (define ($condition-trace condition) 71 | '()) 72 | 73 | (define ($frame-locals-and-catch-tags nr) 74 | '()) 75 | 76 | (define ($condition-msg condition) 77 | "UNKNOWN") 78 | 79 | (define ($condition-links condition) 80 | '()) 81 | 82 | (define ($handle-condition exception) 83 | #f) 84 | 85 | (define ($apropos name) 86 | "Return a list of (name type documentation) for all matches for NAME." 87 | '()) 88 | 89 | (define ($inspect-fallback object) 90 | #f) 91 | -------------------------------------------------------------------------------- /specific/cyclone.ss: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "cyclone-scheme") 3 | (define ($open-tcp-server/accept port-number handler) 4 | (let ((server (make-server-socket (number->string port-number)))) 5 | (let ((socket (socket-accept server))) 6 | (handler port-number (socket-input-port socket) (socket-output-port socket))))) 7 | 8 | (define ($all-package-names) 9 | '()) 10 | 11 | (define ($error-description error) 12 | (let ((o (open-output-string))) 13 | (write error o) 14 | (get-output-string o))) 15 | 16 | (define env (setup-environment)) 17 | (define (interaction-environment) env) ;; *global-environment* ? 18 | 19 | (define (read-bytevector k port) 20 | (string->utf8 (read-string k port))) 21 | 22 | ;; (scheme cyclone util) env:all-variables 23 | 24 | (define ($output-to-repl thunk) 25 | ;; basic implementation, print all output at the end, this should 26 | ;; be replaced with a custom output port 27 | (let ((o (open-output-string))) 28 | (parameterize ((current-output-port o) 29 | (current-error-port o)) 30 | (let-values ((x (thunk))) 31 | (swank/write-string (get-output-string o) #f) 32 | (apply values x))))) 33 | 34 | (define ($function-parameters-and-documentation name) 35 | (cons #f #f)) 36 | 37 | (define ($set-package name) 38 | (list "(user)" "(user)")) 39 | 40 | (define ($environment name) 41 | (interaction-environment)) 42 | 43 | (define ($condition-trace condition) 44 | '()) 45 | 46 | (define ($frame-locals-and-catch-tags nr) 47 | '()) 48 | 49 | (define ($condition-msg condition) 50 | "UNKNOWN") 51 | 52 | (define ($condition-links condition) 53 | '()) 54 | 55 | (define ($handle-condition exception) 56 | #f) 57 | 58 | (define-record-type 59 | (make-istate object parts actions next previous content) 60 | istate? 61 | (object istate-object) 62 | (parts istate-parts) 63 | (actions istate-actions) 64 | (next istate-next set-istate-next!) 65 | (previous istate-previous) 66 | (content istate-content)) 67 | 68 | (define ($apropos name) 69 | '()) 70 | 71 | (define ($completions prefix env-name) 72 | (cons '() prefix)) 73 | 74 | (define ($condition-location condition) 75 | #f) 76 | 77 | (define ($frame-var-value frame index) 78 | #f) 79 | 80 | (define $pretty-print display) 81 | 82 | (define ($binding-documentation p) 83 | #f) 84 | 85 | (define ($inspect-fallback object) 86 | #f) 87 | -------------------------------------------------------------------------------- /specific/gambit.scm: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "gambit") 3 | -------------------------------------------------------------------------------- /specific/gauche.scm: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "gauche-scheme") 3 | 4 | (define ($macroexpand-1 form) 5 | (macroexpand-1 form)) 6 | 7 | (define ($macroexpand-all form) 8 | (macroexpand-all form)) 9 | 10 | (define ($open-tcp-server port-number port-file handler) 11 | (let* ((n (or port-number (+ 10000 (random-integer 50000)))) 12 | (socket (make-server-socket 'inet n ':reuse-addr? #t))) 13 | (handler n socket))) 14 | 15 | (define ($tcp-server-accept socket handler) 16 | (let ((cs (socket-accept socket))) 17 | (handler (socket-input-port cs) (socket-output-port cs)))) 18 | 19 | (define ($all-package-names) 20 | (map module-name (all-modules))) 21 | 22 | (define (display-to-string val) 23 | (let ((out (open-output-string))) 24 | (display val out) 25 | (get-output-string out))) 26 | 27 | (define ($error-description error) 28 | (apply string-append (error-object-message error) 29 | ": " 30 | (map write-to-string (error-object-irritants error)))) 31 | 32 | ;; required for older gauche which treats keywords distinct from symbols 33 | (define (symbol->string x) 34 | (cond ((keyword? x) 35 | (string-append ":" (keyword->string x))) 36 | ((symbol? x) 37 | (scheme:symbol->string x)) 38 | (error "not symbol or keyword" x))) 39 | 40 | (define ($output-to-repl thunk) 41 | ;; basic implementation, print all output at the end, this should 42 | ;; be replaced with a custom output port 43 | (let ((o (open-output-string))) 44 | (parameterize ((current-output-port o)) 45 | (let-values ((x (thunk))) 46 | (swank/write-string (get-output-string o) #f) 47 | (apply values x))))) 48 | 49 | (define ($function-parameters-and-documentation name) 50 | (let* ((binding (car (interactive-eval (string->symbol name)))) 51 | (parameters (if (and binding 52 | (eq? (class-of binding))) 53 | (ref binding 'info) 54 | #f))) 55 | (cons parameters #f))) 56 | 57 | (define ($set-package name) 58 | (list "(user)" "(user)")) 59 | 60 | (define env (interaction-environment)) 61 | (define ($environment name) 62 | env) 63 | 64 | (define ($condition-trace condition) 65 | '()) 66 | 67 | (define ($frame-locals-and-catch-tags nr) 68 | '()) 69 | 70 | (define ($frame-var-value frame index) 71 | #f) 72 | 73 | (define ($condition-msg condition) 74 | "UNKNOWN") 75 | 76 | (define ($condition-links condition) 77 | '()) 78 | 79 | (define ($handle-condition exception) 80 | #f) 81 | 82 | (define (string-match-forward a b) 83 | (let* ((a-len (string-length a)) 84 | (b-len (string-length b)) 85 | (min-len (min a-len b-len))) 86 | (let loop ((i 0)) 87 | (if (> i min-len) 88 | (- i 1) 89 | (if (string=? (substring a 0 i) (substring b 0 i)) 90 | (loop (+ i 1)) 91 | (- i 1)))))) 92 | (define (longest-common-prefix strings) 93 | (if (null? strings) 94 | "" 95 | (fold (lambda (s1 s2) (substring s2 0 (string-match-forward s1 s2))) (car strings) (cdr strings)))) 96 | (define ($completions prefix env-name) 97 | (let ((result '())) 98 | (define (search m) 99 | (hash-table-for-each (module-table m) 100 | (lambda (symbol value) 101 | (if (string-prefix? prefix (symbol->string symbol)) 102 | (set! result (cons (symbol->string symbol) result)))))) 103 | (let ((mod ($environment env-name))) 104 | (for-each (lambda (m) (for-each search (module-precedence-list m))) 105 | (module-imports mod)) 106 | (for-each search 107 | (module-precedence-list mod)) 108 | 109 | (cons result 110 | (longest-common-prefix result))))) 111 | 112 | (define-record-type 113 | (make-istate object parts actions next previous content) 114 | istate? 115 | (object istate-object) 116 | (parts istate-parts) 117 | (actions istate-actions) 118 | (next istate-next set-istate-next!) 119 | (previous istate-previous) 120 | (content istate-content)) 121 | 122 | (define ($inspect-fallback object) 123 | #f) 124 | 125 | (define $pretty-print pprint) 126 | 127 | 128 | (define ($binding-documentation name) 129 | #f) 130 | 131 | (define ($apropos name) 132 | (let ((result '())) 133 | (define (search m) 134 | (hash-table-for-each (module-table m) 135 | (lambda (symbol value) 136 | (if (string-contains (symbol->string symbol) name) 137 | (set! result (cons (list symbol ':function #f) result)))))) 138 | (let ((mod (param:environment))) 139 | (for-each (lambda (m) (for-each search (module-precedence-list m))) 140 | (module-imports mod)) 141 | (for-each search 142 | (module-precedence-list mod)) 143 | 144 | result))) 145 | 146 | -------------------------------------------------------------------------------- /specific/gerbil.scm: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "gerbil-scheme") 3 | 4 | (define (remove-underscores-and-trailing-numbers str) 5 | (define last (- (string-length str) 1)) 6 | (cond ((char-numeric? (string-ref str last)) 7 | (remove-underscores-and-trailing-numbers (substring str 0 last))) 8 | ((char=? (string-ref str last) #\_) 9 | (remove-underscores-and-trailing-numbers (substring str 0 last))) 10 | ((char=? (string-ref str 0) #\_) 11 | (remove-underscores-and-trailing-numbers (substring str 1 (+ last 1)))) 12 | (else 13 | (string->symbol str)))) 14 | 15 | (define (xmap fun lst) 16 | (if (null? lst) 17 | '() 18 | (if (not (pair? lst)) 19 | (fun lst) 20 | (cons (fun (car lst)) (xmap fun (cdr lst)))))) 21 | 22 | (define (unsyntax-bindings lst) 23 | (xmap (lambda (sym) 24 | (let ((s (symbol->string sym))) 25 | (remove-underscores-and-trailing-numbers s))) 26 | lst)) 27 | 28 | (define ($function-parameters-and-documentation name) 29 | (let* ((binding (call/cc (lambda (k) (with-exception-handler (lambda (c) (k #f)) (lambda () (eval (string->symbol name) (param:environment))))))) 30 | (source (if binding (##decompile binding) #f))) 31 | (if (and source 32 | (pair? source) 33 | (not (null? source))) 34 | (let ((s (car source))) 35 | (case s 36 | ((lambda ##lambda) 37 | (cons (cons (string->symbol name) (unsyntax-bindings (cadr source))) 38 | (if (string? (caddr source)) (caddr source) #f))) 39 | (else 40 | (cons #f #f)))) 41 | (cons #f #f)))) 42 | 43 | (define ($set-package name) 44 | (list name name)) 45 | 46 | (define ($open-tcp-server port-number port-file handler) 47 | (let ((n (or port-number (+ 10000 (random-integer 40000))))) 48 | (let* ((p (open-tcp-server n))) 49 | (handler n p)))) 50 | 51 | (define ($tcp-server-accept p handler) 52 | (let ((c (read p))) 53 | (handler c c))) 54 | 55 | (define hash-table-set! hash-put!) 56 | (define hash-table-ref/default hash-ref) 57 | (define hash-table-size hash-length) 58 | ;;(define hash-table? hash-table?) 59 | (%#extern (hash-table? table?)) 60 | (define (hash-table-walk table fun) (hash-for-each fun table)) 61 | (define hash-table-delete! hash-remove!) 62 | 63 | ;; TODO remove when let-values works correctly 64 | (define-syntax let-values 65 | (syntax-rules () 66 | ((let-values ((vals form)) body0 body ...) 67 | (call-with-values (lambda () form) (lambda vals body0 body ...))))) 68 | 69 | (define ($all-package-names) 70 | (cons "(user)" (map expander-context-id (filter module-context? (map cdr (hash->list (current-expander-module-registry))))))) 71 | 72 | (define ($error-description error) 73 | (let ((o (open-output-string))) 74 | (display-exception error o) 75 | (get-output-string o))) 76 | 77 | (define ($output-to-repl thunk) 78 | ;; basic implementation, print all output at the end, this should 79 | ;; be replaced with a custom output port 80 | (let ((o (open-output-string))) 81 | (parameterize ((current-output-port o) 82 | (current-error-port o)) 83 | (let-values ((x (thunk))) 84 | (swank/write-string (get-output-string o) #f) 85 | (apply values x))))) 86 | (define (env-name->environment env-name) 87 | (cond ((or (and (string? env-name) (string=? env-name "(user)")) 88 | (and (symbol? env-name) (eq? env-name 'nil))) 89 | (gx#current-expander-context)) 90 | (else 91 | (let ((name (string->symbol env-name))) 92 | (find (lambda (e) (eq? (expander-context-id e) name)) 93 | (filter module-context? (map cdr (hash->list (current-expander-module-registry))))))))) 94 | (define $environment env-name->environment) 95 | 96 | (define (environment-bindings env-name) 97 | (let ((env (env-name->environment env-name))) 98 | (if env 99 | (map car (hash->list (expander-context-table env))) 100 | '()))) 101 | 102 | (define (string-match-forward a b) 103 | (let* ((a-len (string-length a)) 104 | (b-len (string-length b)) 105 | (min-len (min a-len b-len))) 106 | (let loop ((i 0)) 107 | (if (> i min-len) 108 | (- i 1) 109 | (if (string=? (substring a 0 i) (substring b 0 i)) 110 | (loop (+ i 1)) 111 | (- i 1)))))) 112 | 113 | (define (longest-common-prefix strings) 114 | (if (null? strings) 115 | "" 116 | (fold (lambda (s1 s2) (substring s2 0 (string-match-forward s1 s2))) (car strings) (cdr strings)))) 117 | 118 | (define ($completions prefix env-name) 119 | (let ((matches (filter (lambda (el) (string-prefix? prefix el)) 120 | (map symbol->string (environment-bindings env-name))))) 121 | (cons matches 122 | (longest-common-prefix matches)))) 123 | 124 | (define ($condition-trace condition) 125 | '()) 126 | 127 | (define ($frame-locals-and-catch-tags nr) 128 | '()) 129 | 130 | (define ($frame-var-value frame index) 131 | #f) 132 | 133 | (define ($condition-msg condition) 134 | "UNKNOWN") 135 | 136 | (define ($condition-links condition) 137 | '()) 138 | 139 | (define ($handle-condition exception) 140 | #f) 141 | 142 | (define ($pretty-print object) 143 | (pp object (current-output-port))) 144 | 145 | (define ($inspect-fallback object) 146 | #f) 147 | 148 | (define-record-type 149 | (make-istate object parts actions next previous content) 150 | istate? 151 | (object istate-object) 152 | (parts istate-parts) 153 | (actions istate-actions) 154 | (next istate-next set-istate-next!) 155 | (previous istate-previous) 156 | (content istate-content)) 157 | 158 | (define %repl-result-history-ref ##repl-result-history-ref) 159 | (define (repl-result-history-ref id) 160 | ;; If we are swanky 161 | (if (param:environment) 162 | (call-with-values 163 | (lambda () (swank:lookup-presented-object 164 | (- last-presentation-id id))) 165 | (lambda (value exists?) 166 | (unless (eq? 'nil exists?) 167 | value))) 168 | ;;otherwise, back to normal 169 | (%repl-result-history-ref id))) 170 | 171 | (define ($binding-documentation name) 172 | #f) 173 | 174 | (define ($apropos name) 175 | '()) 176 | 177 | (define ($condition-location condition) 178 | #f) 179 | 180 | (define ($macroexpand-1 form) 181 | form) 182 | 183 | (define ($macroexpand-all form) 184 | form) 185 | -------------------------------------------------------------------------------- /specific/guile.scm: -------------------------------------------------------------------------------- 1 | ;;(use-modules (srfi srfi-11)) 2 | (define ($scheme-name) 3 | "guile") 4 | 5 | (define ($macroexpand-1 form) 6 | (macroexpand form)) 7 | 8 | (define ($macroexpand-all form) 9 | (macroexpand form)) 10 | 11 | (define (make-server-socket port) 12 | (let ((sock (socket PF_INET SOCK_STREAM 0))) 13 | (setsockopt sock SOL_SOCKET SO_REUSEADDR 1) 14 | (bind sock AF_INET INADDR_LOOPBACK port) 15 | sock)) 16 | 17 | (define (accept-new-client server-socket) 18 | (match (accept server-socket) 19 | ((client-socket . _) client-socket))) 20 | 21 | (define ($open-tcp-server port-number port-file handler) 22 | (let* ((n (or port-number (+ 10000 (random 50000)))) 23 | (server-socket (make-server-socket n)) 24 | (dummy (listen server-socket 1))) 25 | (handler n server-socket))) 26 | 27 | (define ($tcp-server-accept socket handler) 28 | (let ((port (accept-new-client socket))) 29 | (handler port port))) 30 | 31 | (define fop flush-output-port) 32 | ;;(define (flush-output-port . port) (fop (if (null? port) (current-output-port) (car port)))) 33 | 34 | ;;(define (read-bytevector count port) (get-bytevector-n port count)) 35 | ;; (define bvc! bytevector-copy!) 36 | ;; (define (bytevector-copy! to to-index from) 37 | ;; (bvc! from 0 to to-index (bytevector-length from))) 38 | 39 | ;;(define write-string display) 40 | 41 | (define ($all-package-names) 42 | (all-modules)) 43 | 44 | ;; (define (with-exception-handler handler thunk) 45 | ;; (catch #t 46 | ;; thunk 47 | ;; (lambda p 48 | ;; (handler p)))) 49 | 50 | (define ($error-description error) 51 | (let ((o (open-output-string))) 52 | (write error o) 53 | (get-output-string o))) 54 | 55 | (define ($output-to-repl thunk) 56 | ;; basic implementation, print all output at the end, this should 57 | ;; be replaced with a custom output port 58 | (let ((o (open-output-string))) 59 | (with-output-to-port o (lambda () 60 | (with-error-to-port o (lambda () 61 | (let-values ((x (thunk))) 62 | (swank/write-string (get-output-string o) #f) 63 | (apply values x)))))))) 64 | 65 | (define (env-name->environment env-name) 66 | ;; TODO 67 | (interaction-environment)) 68 | (define (environment-bindings env) 69 | (define (env-binds env) 70 | (let ((results '())) 71 | (module-for-each (lambda (k v) (set! results (cons k results))) env) 72 | results)) 73 | (append (env-binds env) 74 | (append-map env-binds (module-uses env)))) 75 | (define (string-match-forward a b) 76 | (let* ((a-len (string-length a)) 77 | (b-len (string-length b)) 78 | (min-len (min a-len b-len))) 79 | (let loop ((i 0)) 80 | (if (> i min-len) 81 | (- i 1) 82 | (if (string=? (substring a 0 i) (substring b 0 i)) 83 | (loop (+ i 1)) 84 | (- i 1)))))) 85 | (define (longest-common-prefix strings) 86 | (if (null? strings) 87 | "" 88 | (fold (lambda (s1 s2) (substring s2 0 (string-match-forward s1 s2))) (car strings) (cdr strings)))) 89 | (define ($completions prefix env-name) 90 | (let ((matches (filter (lambda (el) (string-prefix? prefix el)) 91 | (map symbol->string (environment-bindings (env-name->environment env-name)))))) 92 | (cons matches 93 | (longest-common-prefix matches)))) 94 | ;;;; taken from geiser 95 | (define (submodules mod) 96 | (hash-map->list (lambda (k v) v) (module-submodules mod))) 97 | 98 | (define (root-modules) 99 | (submodules (resolve-module '() #f))) 100 | 101 | (define (all-modules) 102 | (define (maybe-name m) 103 | (and (module-kind m) (format #f "~A" (module-name m)))) 104 | (let* ((guile (resolve-module '(guile))) 105 | (roots (remove (lambda (m) (eq? m guile)) (root-modules))) 106 | (children (append-map all-child-modules roots))) 107 | (cons "(user)" (filter-map maybe-name children)))) 108 | 109 | (define (all-child-modules mod . seen) 110 | (let ((cs (filter (lambda (m) (not (member m (if (null? seen) seen (car seen))))) (submodules mod)))) 111 | (fold (lambda (m all) (append (all-child-modules m all) all)) 112 | (list mod) 113 | cs))) 114 | 115 | (define stack-offset 3) 116 | 117 | 118 | ;; we keep the frames returned by $condition-trace, so that frame-locals-and-catch-tags 119 | ;; can access the same frames with the same ordering 120 | (define stored-frames 121 | #()) 122 | 123 | (define ($condition-trace condition) 124 | ;; we ignore condition for now, since I didn't find a way of getting 125 | ;; stack information out of it. 126 | (let ((frames (let* ((tag %start-stack) 127 | (frames (narrow-stack->vector 128 | (make-stack #t) 129 | stack-offset 130 | tag 131 | 0 132 | tag)) 133 | (n-frames (vector-length frames))) 134 | (let loop ((i (- n-frames 1)) 135 | (result #())) 136 | (if (< i 0) 137 | result 138 | (let ((fr (vector-ref frames i))) 139 | (if (frame-procedure-name fr) 140 | (loop (- i 1) 141 | (vector-append (vector fr) result)) 142 | (loop (- i 1) result)))))))) 143 | (set! stored-frames frames) 144 | (vector->list 145 | (vector-map (lambda (fr) 146 | (format #f "~a" (frame-procedure-name fr))) 147 | frames)))) 148 | 149 | 150 | (define ($frame-locals-and-catch-tags nr) 151 | (let* ((tag %start-stack) 152 | (frames stored-frames) 153 | (bindings (frame-bindings (vector-ref frames nr))) 154 | (entries (map (lambda (i b) 155 | `(:name ,(format #f "~a" (binding-name b)) 156 | :id ,i 157 | :value ,(format #f "~a" (binding-ref b)))) 158 | (iota (length bindings)) 159 | bindings))) 160 | (list entries (list 'nil)))) 161 | 162 | (define ($frame-var-value frame index) 163 | #f) 164 | 165 | (define ($condition-msg condition) 166 | (apply format 167 | `(#f 168 | ,(exception-message condition) 169 | ,@(exception-irritants condition)))) 170 | 171 | (define ($condition-links condition) 172 | (vector->list 173 | (vector-map (lambda (fr) 174 | (let ((src (frame-source fr))) 175 | (if src 176 | (let ((file (source:file src)) 177 | (line (source:line src)) 178 | (col (source:column src))) 179 | (list file #f line col)) 180 | #f))) 181 | stored-frames))) 182 | 183 | (define ($handle-condition exception) 184 | (invoke-sldb exception)) 185 | 186 | (define ($function-parameters-and-documentation name) 187 | (cons #f #f)) 188 | 189 | (define (get-valid-module-name name) 190 | (with-input-from-string name read)) 191 | 192 | (define ($set-package name) 193 | (let ((mod (resolve-module (get-valid-module-name name) #t #:ensure #f))) 194 | (when mod 195 | (set-current-module mod))) 196 | (list name name)) 197 | 198 | (define ($environment name) 199 | (interaction-environment)) 200 | 201 | (define $pretty-print pretty-print) 202 | 203 | (define-record-type 204 | (make-istate object parts actions next previous content) 205 | istate? 206 | (object istate-object) 207 | (parts istate-parts) 208 | (actions istate-actions) 209 | (next istate-next set-istate-next!) 210 | (previous istate-previous) 211 | (content istate-content)) 212 | 213 | (define (inspect-class obj) 214 | (apply stream 215 | `(,(inspector-line "Name" (class-name obj)) 216 | 217 | "Super classes: " 218 | ,@(build-multi-value (class-direct-supers obj)) 219 | (newline) 220 | 221 | "Direct Slots: " 222 | ,@(build-multi-value (class-direct-slots obj)) 223 | (newline) 224 | 225 | "Sub classes: " 226 | ,@(build-multi-value 227 | (let ((subs (class-direct-subclasses obj))) 228 | (if (null? subs) 229 | (list 'nil) 230 | subs))) 231 | (newline) 232 | 233 | "Precedence List: " 234 | ,@(build-multi-value 235 | (let ((subs (class-precedence-list obj))) 236 | (if (null? subs) 237 | (list 'nil) 238 | subs))) 239 | (newline) 240 | (newline) 241 | "All Slots:" 242 | (newline) 243 | ,@(all-slots-for-inspector obj) 244 | ))) 245 | 246 | (define (inspect-instance obj) 247 | (let ((cls (class-of obj))) 248 | (apply stream 249 | `(,(inspector-line "Class" cls) 250 | "--------------------" 251 | (newline) 252 | ,@(fold (lambda (s acc) 253 | (let ((sname (slot-definition-name s))) 254 | (if (slot-bound? obj sname) 255 | (cons (inspector-line sname 256 | (slot-ref obj sname)) 257 | acc) 258 | acc))) 259 | '() 260 | (class-slots cls)))))) 261 | 262 | (define (inspect-record r) 263 | (let* ((rtd (record-type-descriptor r)) 264 | (fields (record-type-fields rtd))) 265 | (apply stream 266 | `(,(format #f "The object is a Record of type ~a." 267 | (record-type-name rtd)) 268 | (newline) 269 | ,@(map (lambda (f) 270 | (let ((proc (record-accessor rtd f))) 271 | (inspector-line (format #f "~a" f) 272 | (proc r)))) 273 | fields))))) 274 | 275 | (define ($inspect-fallback obj) 276 | (cond ((is-a? obj ) 277 | (inspect-class obj)) 278 | ((instance? obj) 279 | (inspect-instance obj)) 280 | ((record? obj) 281 | (inspect-record obj)) 282 | (else #f))) 283 | 284 | (define (all-slots-for-inspector obj) 285 | (map (lambda (s) 286 | (inspector-line (slot-definition-name s) 287 | (slot-definition-init-value s))) 288 | (class-slots obj))) 289 | 290 | (define ($apropos name) 291 | ;; based on guile's ice-9/session.scm 292 | (let* ((pattern name) 293 | (uses (module-uses (current-module))) 294 | (modules (cons (current-module) 295 | (if (and (not (null? uses)) 296 | (eq? (module-name (car uses)) 297 | 'duplicates)) 298 | (cdr uses) 299 | uses)))) 300 | (let ((results '())) 301 | (for-each 302 | (lambda (module) 303 | (let* ((name (module-name module)) 304 | (obarray (module-obarray module))) 305 | ;; XXX - should use hash-fold here 306 | (hash-for-each 307 | (lambda (symbol variable) 308 | (if (string-contains-ci (symbol->string symbol) pattern) 309 | (let* ((binding 310 | (if (variable-bound? variable) 311 | (variable-ref variable) 312 | #f)) 313 | (documentation ($binding-documentation binding)) 314 | (type (if (procedure? binding) ':function ':variable))) 315 | (set! results (cons (list symbol type documentation) results))))) 316 | obarray))) 317 | modules) 318 | results))) 319 | 320 | (define ($binding-documentation value) 321 | (cond ((procedure? value) (procedure-documentation value)) 322 | (else "No documentation."))) 323 | 324 | (define ($condition-location condition) 325 | ;; a hack. Since in Guile we can't get a backtrace out of a condition 326 | ;; object, $condition-links returns directly a list of locations. So 327 | ;; we just pass it further. See swank:frame-source-location 328 | condition) 329 | -------------------------------------------------------------------------------- /specific/kawa.scm: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "kawa") 3 | ;; not sure how to express this require as an r7rs import :-/ 4 | ;; (require 'syntax-utils) 5 | ;; (define ($macroexpand-1 form) 6 | ;; (expand form)) 7 | ;; (define ($macroexpand-all form) 8 | ;; (expand form)) 9 | 10 | ;; kawa reads foo:bar as ($lookup$ foo (quasiquote bar)), this leads to many problems :-/ 11 | 12 | (define (random n) 13 | ((java.util.concurrent.ThreadLocalRandom:current):nextInt 0 (+ n 1))) 14 | 15 | (define ($open-tcp-server port-number port-file handler) 16 | (display port-number) (newline) 17 | (let* ((n (or port-number (+ 10000 (random 50000)))) 18 | (socket (java.net.ServerSocket n))) 19 | (handler n socket))) 20 | 21 | (define ($tcp-server-accept socket handler) 22 | (let ((connection-socket (socket:accept))) 23 | (handler (connection-socket:getInputStream) (gnu.kawa.io.OutPort (connection-socket:getOutputStream))))) 24 | 25 | (define ($error-description error) 26 | (error:toString)) 27 | 28 | (define ($all-package-names) 29 | ;; TODO 30 | '("(user)")) 31 | 32 | (define (environment-bindings env :: gnu.mapping.SimpleEnvironment) 33 | (let loop ((enum :: gnu.mapping.LocationEnumeration (env:enumerateAllLocations)) 34 | (result '())) 35 | (if (enum:hasMoreElements) 36 | (let ((current :: gnu.mapping.NamedLocation (enum:nextElement))) 37 | (loop enum (cons (current:getKeySymbol) result))) 38 | (reverse result)))) 39 | 40 | (define ($output-to-repl thunk) 41 | ;; basic implementation, print all output at the end, this should 42 | ;; be replaced with a custom output port 43 | (let ((o (open-output-string))) 44 | (parameterize ((current-output-port o)) 45 | (let-values ((x (thunk))) 46 | (swank/write-string (get-output-string o) #f) 47 | (apply values x))))) 48 | 49 | (define (string-match-forward a b) 50 | (let* ((a-len (string-length a)) 51 | (b-len (string-length b)) 52 | (min-len (min a-len b-len))) 53 | (let loop ((i 0)) 54 | (if (> i min-len) 55 | (- i 1) 56 | (if (string=? (substring a 0 i) (substring b 0 i)) 57 | (loop (+ i 1)) 58 | (- i 1)))))) 59 | 60 | (define (longest-common-prefix strings) 61 | (if (null? strings) 62 | "" 63 | (fold (lambda (s1 s2) (substring s2 0 (string-match-forward s1 s2))) (car strings) (cdr strings)))) 64 | 65 | (define (env-name->environment env-name) 66 | (cond ((string=? env-name "(user)") 67 | (interaction-environment)) 68 | (else 69 | (error "not implemented yet")))) 70 | 71 | (define (find-java-matches prefix env-name) 72 | (if (prefix:contains ":") 73 | (let* ((parts (prefix:split ":")) 74 | (first (parts 0)) 75 | (rest (substring prefix (+ (string-length first) 1) (string-length prefix)))) 76 | (define (filter-relevant names) 77 | (filter-map (lambda (name) 78 | (let ((p :: String (string-append first ":" name))) 79 | (if (p:startsWith prefix) 80 | p 81 | #f))) 82 | names)) 83 | (let ((binding (call/cc (lambda (k) (with-exception-handler (lambda (condition) (k #f)) 84 | (lambda () 85 | (eval (string->symbol first) (env-name->environment env-name)))))))) 86 | (if binding 87 | (let ((c :: java.lang.Class (if (instance? binding java.lang.Class) binding (binding:getClass)))) 88 | (let ((methods (*:getMethods c)) 89 | (fields (*:getFields c))) 90 | (append (filter-relevant (map *:getName methods)) 91 | (filter-relevant (map *:getName fields))))) 92 | '()))) 93 | '())) 94 | 95 | (define ($completions prefix env-name) 96 | (let* ((matches (filter (lambda (el :: java.lang.String) (el:startsWith prefix)) 97 | (map symbol->string (environment-bindings (env-name->environment env-name))))) 98 | (java-matches (find-java-matches prefix env-name)) 99 | (all (append matches java-matches))) 100 | (cons all 101 | (longest-common-prefix all)))) 102 | 103 | (define ($function-parameters-and-documentation name) 104 | (cons #f #f)) 105 | 106 | (define ($set-package name) 107 | (list "(user)" "(user)")) 108 | 109 | (define ($environment name) 110 | (interaction-environment)) 111 | 112 | (define ($condition-trace condition) 113 | (map *:toString ($condition-links condition))) 114 | 115 | (define ($condition-location stack-trace-element) 116 | "Return (PATH POSITION LINE COLUMN) for CONDITION." 117 | (let ((file (stack-trace-element:getFileName)) 118 | (line (stack-trace-element:getLineNumber))) 119 | `(,file #f ,line 0))) 120 | 121 | (define ($frame-locals-and-catch-tags nr) 122 | 'nil) 123 | 124 | (define ($frame-var-value frame index) 125 | #f) 126 | 127 | (define ($condition-msg condition) 128 | (condition:toString)) 129 | 130 | (define ($condition-links condition) 131 | (let ((st (as vector (condition:getStackTrace)))) 132 | (vector->list st))) 133 | 134 | (define ($handle-condition exception) 135 | (when (instance? exception java.lang.Exception) 136 | (invoke-sldb exception))) 137 | 138 | (define $pretty-print pprint) 139 | 140 | (define ($inspect-fallback object) 141 | #f) 142 | 143 | (define-record-type 144 | (make-istate object parts actions next previous content) 145 | istate? 146 | (object istate-object) 147 | (parts istate-parts) 148 | (actions istate-actions) 149 | (next istate-next set-istate-next!) 150 | (previous istate-previous) 151 | (content istate-content)) 152 | 153 | (define ($apropos name) 154 | (let ((env ($environment (param:environment)))) 155 | (environment-fold env 156 | (lambda (key accumulator) 157 | (if (and (symbol? key) 158 | (string-contains-ci (symbol->string key) name)) 159 | (let ((value (eval key env))) 160 | (cons (list key (if (procedure? value) ':function ':variable) ($binding-documentation value)) accumulator)) 161 | accumulator)) 162 | '()))) 163 | 164 | (define ($binding-documentation value) 165 | "") 166 | 167 | (define ($macroexpand-1 form) 168 | form) 169 | 170 | (define ($macroexpand-all form) 171 | form) 172 | -------------------------------------------------------------------------------- /specific/larceny.scm: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "larceny") 3 | (define ($all-package-names) 4 | '()) 5 | 6 | (define ($error-description error) 7 | (let ((o (open-output-string))) 8 | (display error o) 9 | (get-output-string o))) 10 | 11 | (define ($open-tcp-server/accept port-number handler) 12 | (display "$open-tcp-server/accept ") (write port-number) (newline) (flush-output-port) 13 | (let ((s (make-server-socket port-number 'blocking))) 14 | (display "server socket: ") (write s) (newline) (flush-output-port) 15 | (let-values (((ns addr) (server-socket-accept s))) 16 | (display "accepted: ") (write ns) (display " ") (write addr) (newline) (flush-output-port) 17 | (let ((in (socket-input-port ns 'blocking 'char)) 18 | (out (socket-output-port ns 'blocking 'char 'flush))) 19 | (handler port-number in out))))) 20 | 21 | (define ($open-tcp-server port-number port-file handler) 22 | (let ((n (or port-number (+ 10000 (random 50000))))) 23 | (display "$open-tcp-server/accept ") (write n) (newline) (flush-output-port) 24 | (let ((s (make-server-socket n 'blocking))) 25 | (display "server socket: ") (write s) (newline) (flush-output-port) 26 | (handler n s)))) 27 | 28 | (define ($tcp-server-accept socket handler) 29 | (display "accepting on socket: ") (write socket) (newline) (flush-output-port) 30 | (let-values (((ns addr) (server-socket-accept socket))) 31 | (display "accepted: ") (write ns) (display " ") (write addr) (newline) (flush-output-port) 32 | (let ((in (socket-input-port ns 'blocking 'char)) 33 | (out (socket-output-port ns 'blocking 'char 'flush))) 34 | (handler in out)))) 35 | 36 | (define ($output-to-repl thunk) 37 | ;; basic implementation, print all output at the end, this should 38 | ;; be replaced with a custom output port 39 | (let ((o (open-output-string))) 40 | (parameterize ((current-output-port o)) 41 | (let-values ((x (thunk))) 42 | (swank/write-string (get-output-string o) #f) 43 | (apply values x))))) 44 | 45 | (define ($completions prefix env-name) 46 | (cons '() 47 | prefix)) 48 | 49 | (define ($function-parameters-and-documentation name) 50 | (cons #f #f)) 51 | 52 | (define ($set-package name) 53 | (list "(user)" "(user)")) 54 | 55 | (define ($environment name) 56 | (interaction-environment)) 57 | 58 | (define ($condition-trace condition) 59 | '()) 60 | 61 | (define ($frame-locals-and-catch-tags nr) 62 | '()) 63 | 64 | (define ($frame-var-value frame index) 65 | #f) 66 | 67 | (define ($condition-msg condition) 68 | "UNKNOWN") 69 | 70 | (define ($condition-links condition) 71 | '()) 72 | 73 | (define ($condition-location condition) 74 | "Return (PATH POSITION LINE COLUMN) for CONDITION." 75 | #f) 76 | 77 | (define ($handle-condition exception) 78 | #f) 79 | 80 | (define $pretty-print pretty-print) 81 | 82 | (define-record-type 83 | (make-istate object parts actions next previous content) 84 | istate? 85 | (object istate-object) 86 | (parts istate-parts) 87 | (actions istate-actions) 88 | (next istate-next set-istate-next!) 89 | (previous istate-previous) 90 | (content istate-content)) 91 | 92 | (define ($inspect-fallback object) 93 | #f) 94 | 95 | (define ($apropos name) 96 | '()) 97 | 98 | (define ($binding-documentation value) 99 | "") 100 | -------------------------------------------------------------------------------- /specific/mit.scm: -------------------------------------------------------------------------------- 1 | (declare (usual-integrations)) 2 | ;;;; srfi 13 3 | (define (string-start+end str start end) 4 | (let ((s (if (eq? #!default start) 5 | 0 start)) 6 | (e (if (eq? #!default end) 7 | (string-length str) end))) 8 | (values s e))) 9 | 10 | (define (string-start+end+start+end s1 start1 end1 s2 start2 end2) 11 | (let ((s (if (eq? #!default start1) 12 | 0 start1)) 13 | (e (if (eq? #!default end1) 14 | (string-length s1) end1)) 15 | (sx (if (eq? #!default start2) 16 | 0 start2)) 17 | (ex (if (eq? #!default end2) 18 | (string-length s2) end2))) 19 | (values s e sx ex))) 20 | 21 | (define (string-map proc s #!optional start end) 22 | (receive (start end) 23 | (string-start+end s start end) 24 | (let* ((len (- end start)) 25 | (ans (make-string len))) 26 | (do ((i (- end 1) (- i 1)) 27 | (j (- len 1) (- j 1))) 28 | ((< j 0)) 29 | (string-set! ans j (proc (string-ref s i)))) 30 | ans))) 31 | 32 | (define (string-map! proc s #!optional start end) 33 | (receive (start end) 34 | (string-start+end s start end) 35 | (do ((i (- end 1) (- i 1))) 36 | ((< i start)) 37 | (string-set! s i (proc (string-ref s i)))))) 38 | 39 | (define (string-fold kons knil s #!optional start end) 40 | (receive (start end) 41 | (string-start+end s start end) 42 | (let lp ((v knil) (i start)) 43 | (if (< i end) (lp (kons (string-ref s i) v) (+ i 1)) 44 | v)))) 45 | 46 | (define (string-fold-right kons knil s #!optional start end) 47 | (receive (start end) 48 | (string-start+end s start end) 49 | (let lp ((v knil) (i (- end 1))) 50 | (if (>= i start) (lp (kons (string-ref s i) v) (- i 1)) 51 | v)))) 52 | 53 | (define (string-tabulate proc len) 54 | (let ((s (make-string len))) 55 | (do ((i (- len 1) (- i 1))) 56 | ((< i 0)) 57 | (string-set! s i (proc i))) 58 | s)) 59 | 60 | (define (string-for-each proc s #!optional start end) 61 | (receive (start end) 62 | (string-start+end s start end) 63 | (let lp ((i start)) 64 | (if (< i end) 65 | (begin (proc (string-ref s i)) 66 | (lp (+ i 1))))))) 67 | 68 | (define (string-for-each-index proc s #!optional start end) 69 | (receive (start end) 70 | (string-start+end s start end) 71 | (let lp ((i start)) 72 | (if (< i end) (begin (proc i) (lp (+ i 1))))))) 73 | 74 | 75 | 76 | 77 | ;;(define string-hash-ci string-ci-hash) 78 | (define string= string=?) 79 | (define string< string string>?) 81 | (define string<= string<=?) 82 | (define string>= string>=?) 83 | (define (string<> a b) (not (string= a b))) 84 | 85 | (define string-ci= string-ci=?) 86 | (define string-ci< string-ci string-ci>?) 88 | (define string-ci<= string-ci<=?) 89 | (define string-ci>= string-ci>=?) 90 | (define (string-ci<> a b) (not (string-ci= a b))) 91 | 92 | (define (substring/shared s #!optional start end) 93 | (receive (start end) 94 | (string-start+end s start end) 95 | (if (and (zero? start) (= end (string-length s))) s 96 | (substring s start end)))) 97 | 98 | (define (string-take s n) 99 | (substring/shared s 0 n)) 100 | 101 | (define (string-take-right s n) 102 | (let ((len (string-length s))) 103 | (substring/shared s (- len n) len))) 104 | 105 | (define (string-drop s n) 106 | (let ((len (string-length s))) 107 | (substring/shared s n len))) 108 | 109 | (define (string-drop-right s n) 110 | (let ((len (string-length s))) 111 | (substring/shared s 0 (- len n)))) 112 | 113 | (define (string-pad s n #!optional char start end) 114 | (receive (start end) 115 | (string-start+end s start end) 116 | (let ((char (if (eq? #!default char) #\space char))) 117 | (let ((len (- end start))) 118 | (if (<= n len) 119 | (substring/shared s (- end n) end) 120 | (let ((ans (make-string n char))) 121 | (string-copy! ans (- n len) s start end) 122 | ans)))))) 123 | 124 | (define (string-copy! to tstart from #!optional fstart fend) 125 | (receive (fstart fend) 126 | (string-start+end from fstart fend) 127 | (if (> fstart tstart) 128 | (do ((i fstart (+ i 1)) 129 | (j tstart (+ j 1))) 130 | ((>= i fend)) 131 | (string-set! to j (string-ref from i))) 132 | (do ((i (- fend 1) (- i 1)) 133 | (j (+ -1 tstart (- fend fstart)) (- j 1))) 134 | ((< i fstart)) 135 | (string-set! to j (string-ref from i)))))) 136 | 137 | (define (string-skip str criterion #!optional start end) 138 | (receive (start end) 139 | (string-start+end str start end) 140 | (cond ((char? criterion) 141 | (let lp ((i start)) 142 | (and (< i end) 143 | (if (char=? criterion (string-ref str i)) 144 | (lp (+ i 1)) 145 | i)))) 146 | ((char-set? criterion) 147 | (let lp ((i start)) 148 | (and (< i end) 149 | (if (char-in-set? (string-ref str i) criterion) 150 | (lp (+ i 1)) 151 | i)))) 152 | ((procedure? criterion) 153 | (let lp ((i start)) 154 | (and (< i end) 155 | (if (criterion (string-ref str i)) (lp (+ i 1)) 156 | i)))) 157 | (else (error "Second param is neither char-set, char, or predicate procedure." 158 | string-skip criterion))))) 159 | 160 | (define (string-skip-right str criterion #!optional start end) 161 | (receive (start end) 162 | (string-start+end str start end) 163 | (cond ((char? criterion) 164 | (let lp ((i (- end 1))) 165 | (and (>= i start) 166 | (if (char=? criterion (string-ref str i)) 167 | (lp (- i 1)) 168 | i)))) 169 | ((char-set? criterion) 170 | (let lp ((i (- end 1))) 171 | (and (>= i start) 172 | (if (char-in-set? (string-ref str i) criterion) 173 | (lp (- i 1)) 174 | i)))) 175 | ((procedure? criterion) 176 | (let lp ((i (- end 1))) 177 | (and (>= i start) 178 | (if (criterion (string-ref str i)) (lp (- i 1)) 179 | i)))) 180 | (else (error "CRITERION param is neither char-set or char." 181 | string-skip-right criterion))))) 182 | 183 | (define (string-trim-both s #!optional criterion start end) 184 | (receive (start end) 185 | (string-start+end s start end) 186 | (let ((criterion (if (eq? #!default criterion) char-set:whitespace criterion))) 187 | (cond ((string-skip s criterion start end) => 188 | (lambda (i) 189 | (substring/shared s i (+ 1 (string-skip-right s criterion i end))))) 190 | (else ""))))) 191 | 192 | 193 | (define (string-filter criterion s #!optional start end) 194 | (receive (start end) 195 | (string-start+end s start end) 196 | (if (procedure? criterion) 197 | (let* ((slen (- end start)) 198 | (temp (make-string slen)) 199 | (ans-len (string-fold (lambda (c i) 200 | (if (criterion c) 201 | (begin (string-set! temp i c) 202 | (+ i 1)) 203 | i)) 204 | 0 s start end))) 205 | (if (= ans-len slen) temp (substring temp 0 ans-len))) 206 | 207 | (let* ((cset (cond ((char-set? criterion) criterion) 208 | ((char? criterion) (char-set criterion)) 209 | (else (error "string-delete criterion not predicate, char or char-set" criterion)))) 210 | 211 | (len (string-fold (lambda (c i) (if (char-in-set? c cset) 212 | (+ i 1) 213 | i)) 214 | 0 s start end)) 215 | (ans (make-string len))) 216 | (string-fold (lambda (c i) (if (char-in-set? c cset) 217 | (begin (string-set! ans i c) 218 | (+ i 1)) 219 | i)) 220 | 0 s start end) 221 | ans)))) 222 | 223 | (define (string-count s criterion #!optional start end) 224 | (receive (start end) 225 | (string-start+end s start end) 226 | (cond ((char? criterion) 227 | (do ((i start (+ i 1)) 228 | (count 0 (if (char=? criterion (string-ref s i)) 229 | (+ count 1) 230 | count))) 231 | ((>= i end) count))) 232 | 233 | ((char-set? criterion) 234 | (do ((i start (+ i 1)) 235 | (count 0 (if (char-in-set? (string-ref s i) criterion) 236 | (+ count 1) 237 | count))) 238 | ((>= i end) count))) 239 | 240 | ((procedure? criterion) 241 | (do ((i start (+ i 1)) 242 | (count 0 (if (criterion (string-ref s i)) (+ count 1) count))) 243 | ((>= i end) count))) 244 | 245 | (else (error "CRITERION param is neither char-set or char." 246 | string-count criterion))))) 247 | 248 | (define (reverse-list->string clist) 249 | (let* ((len (length clist)) 250 | (s (make-string len))) 251 | (do ((i (- len 1) (- i 1)) (clist clist (cdr clist))) 252 | ((not (pair? clist))) 253 | (string-set! s i (car clist))) 254 | s)) 255 | 256 | (define (string-index str criterion #!optional start end) 257 | (receive (start end) 258 | (string-start+end str start end) 259 | (cond ((char? criterion) 260 | (let lp ((i start)) 261 | (and (< i end) 262 | (if (char=? criterion (string-ref str i)) i 263 | (lp (+ i 1)))))) 264 | ((char-set? criterion) 265 | (let lp ((i start)) 266 | (and (< i end) 267 | (if (char-in-set? (string-ref str i) criterion) i 268 | (lp (+ i 1)))))) 269 | ((procedure? criterion) 270 | (let lp ((i start)) 271 | (and (< i end) 272 | (if (criterion (string-ref str i)) i 273 | (lp (+ i 1)))))) 274 | (else (error "Second param is neither char-set, char, or predicate procedure." 275 | string-index criterion))))) 276 | 277 | (define (string-index-right str criterion #!optional start end) 278 | (receive (start end) 279 | (string-start+end str start end) 280 | (cond ((char? criterion) 281 | (let lp ((i (- end 1))) 282 | (and (>= i start) 283 | (if (char=? criterion (string-ref str i)) i 284 | (lp (- i 1)))))) 285 | ((char-set? criterion) 286 | (let lp ((i (- end 1))) 287 | (and (>= i start) 288 | (if (char-in-set? (string-ref str i) criterion) i 289 | (lp (- i 1)))))) 290 | ((procedure? criterion) 291 | (let lp ((i (- end 1))) 292 | (and (>= i start) 293 | (if (criterion (string-ref str i)) i 294 | (lp (- i 1)))))) 295 | (else (error "Second param is neither char-set, char, or predicate procedure." 296 | string-index-right criterion))))) 297 | 298 | (define (string-concatenate strings) 299 | (let* ((total (do ((strings strings (cdr strings)) 300 | (i 0 (+ i (string-length (car strings))))) 301 | ((not (pair? strings)) i))) 302 | (ans (make-string total))) 303 | (let lp ((i 0) (strings strings)) 304 | (if (pair? strings) 305 | (let* ((s (car strings)) 306 | (slen (string-length s))) 307 | (string-copy! ans i s 0 slen) 308 | (lp (+ i slen) (cdr strings))))) 309 | ans)) 310 | 311 | (define (string-concatenate-reverse string-list #!optional final end) 312 | (let* ((final (if (string? final) final "")) 313 | (end (if (and (integer? end) 314 | (exact? end) 315 | (<= 0 end (string-length final))) 316 | end 317 | (string-length final)))) 318 | (let ((len (let lp ((sum 0) (lis string-list)) 319 | (if (pair? lis) 320 | (lp (+ sum (string-length (car lis))) (cdr lis)) 321 | sum)))) 322 | 323 | (%finish-string-concatenate-reverse len string-list final end)))) 324 | 325 | (define (%finish-string-concatenate-reverse len string-list final end) 326 | (let ((ans (make-string (+ end len)))) 327 | (string-copy! ans len final 0 end) 328 | (let lp ((i len) (lis string-list)) 329 | (if (pair? lis) 330 | (let* ((s (car lis)) 331 | (lis (cdr lis)) 332 | (slen (string-length s)) 333 | (i (- i slen))) 334 | (string-copy! ans i s 0 slen) 335 | (lp i lis)))) 336 | ans)) 337 | 338 | (define char-set:graphic-no-whitespace 339 | (char-set-difference char-set:graphic char-set:whitespace)) 340 | 341 | (define (string-tokenize s #!optional token-chars start end) 342 | (receive (start end) 343 | (string-start+end s start end) 344 | (let ((token-chars (if (char-set? token-chars) token-chars char-set:graphic-no-whitespace))) 345 | (let lp ((i end) (ans '())) 346 | (cond ((and (< start i) (string-index-right s token-chars start i)) => 347 | (lambda (tend-1) 348 | (let ((tend (+ 1 tend-1))) 349 | (cond ((string-skip-right s token-chars start tend-1) => 350 | (lambda (tstart-1) 351 | (lp tstart-1 352 | (cons (substring s (+ 1 tstart-1) tend) 353 | ans)))) 354 | (else (cons (substring s start tend) ans)))))) 355 | (else ans)))))) 356 | 357 | (define (string-contains text pattern #!optional start1 end1 start2 end2) 358 | (receive (t-start t-end p-start p-end) 359 | (string-start+end+start+end text start1 end1 pattern start2 end2) 360 | (%kmp-search pattern text char=? p-start p-end t-start t-end))) 361 | 362 | (define (string-contains-ci text pattern #!optional start1 end1 start2 end2) 363 | (receive (t-start t-end p-start p-end) 364 | (string-start+end+start+end text start1 end1 pattern start2 end2) 365 | (%kmp-search pattern text char-ci=? p-start p-end t-start t-end))) 366 | 367 | (define (%kmp-search pattern text c= p-start p-end t-start t-end) 368 | (let ((plen (- p-end p-start)) 369 | (rv (make-kmp-restart-vector pattern c= p-start p-end))) 370 | 371 | ;; The search loop. TJ & PJ are redundant state. 372 | (let lp ((ti t-start) (pi 0) 373 | (tj (- t-end t-start)) ; (- tlen ti) -- how many chars left. 374 | (pj plen)) ; (- plen pi) -- how many chars left. 375 | 376 | (if (= pi plen) 377 | (- ti plen) ; Win. 378 | (and (<= pj tj) ; Lose. 379 | (if (c= (string-ref text ti) ; Search. 380 | (string-ref pattern (+ p-start pi))) 381 | (lp (+ 1 ti) (+ 1 pi) (- tj 1) (- pj 1)) ; Advance. 382 | (let ((pi (vector-ref rv pi))) ; Retreat. 383 | (if (= pi -1) 384 | (lp (+ ti 1) 0 (- tj 1) plen) ; Punt. 385 | (lp ti pi tj (- plen pi)))))))))) 386 | 387 | (define (make-kmp-restart-vector pattern #!optional c= start end) 388 | (receive (start end) 389 | (string-start+end pattern start end) 390 | (let ((c= (if (procedure? c=) c= char=?))) 391 | (let* ((rvlen (- end start)) 392 | (rv (make-vector rvlen -1))) 393 | (if (> rvlen 0) 394 | (let ((rvlen-1 (- rvlen 1)) 395 | (c0 (string-ref pattern start))) 396 | 397 | ;; Here's the main loop. We have set rv[0] ... rv[i]. 398 | ;; K = I + START -- it is the corresponding index into PATTERN. 399 | (let lp1 ((i 0) (j -1) (k start)) 400 | (if (< i rvlen-1) 401 | ;; lp2 invariant: 402 | ;; pat[(k-j) .. k-1] matches pat[start .. start+j-1] 403 | ;; or j = -1. 404 | (let lp2 ((j j)) 405 | (cond ((= j -1) 406 | (let ((i1 (+ 1 i))) 407 | (if (not (c= (string-ref pattern (+ k 1)) c0)) 408 | (vector-set! rv i1 0)) 409 | (lp1 i1 0 (+ k 1)))) 410 | ;; pat[(k-j) .. k] matches pat[start..start+j]. 411 | ((c= (string-ref pattern k) (string-ref pattern (+ j start))) 412 | (let* ((i1 (+ 1 i)) 413 | (j1 (+ 1 j))) 414 | (vector-set! rv i1 j1) 415 | (lp1 i1 j1 (+ k 1)))) 416 | 417 | (else (lp2 (vector-ref rv j))))))))) 418 | rv)))) 419 | 420 | (define (string-xreplace s1 s2 start1 end1 #!optional start2 end2) 421 | (receive (start2 end2) 422 | (string-start+end s2 start2 end2) 423 | (let* ((slen1 (string-length s1)) 424 | (sublen2 (- end2 start2)) 425 | (alen (+ (- slen1 (- end1 start1)) sublen2)) 426 | (ans (make-string alen))) 427 | (%string-copy! ans 0 s1 0 start1) 428 | (%string-copy! ans start1 s2 start2 end2) 429 | (%string-copy! ans (+ start1 sublen2) s1 end1 slen1) 430 | ans))) 431 | 432 | (define (%string-copy! to tstart from fstart fend) 433 | (if (> fstart tstart) 434 | (do ((i fstart (+ i 1)) 435 | (j tstart (+ j 1))) 436 | ((>= i fend)) 437 | (string-set! to j (string-ref from i))) 438 | 439 | (do ((i (- fend 1) (- i 1)) 440 | (j (+ -1 tstart (- fend fstart)) (- j 1))) 441 | ((< i fstart)) 442 | (string-set! to j (string-ref from i))))) 443 | 444 | (define (string-delete criterion s #!optional start end) 445 | (receive (start end) 446 | (string-start+end s start end) 447 | (if (procedure? criterion) 448 | (let* ((slen (- end start)) 449 | (temp (make-string slen)) 450 | (ans-len (string-fold (lambda (c i) 451 | (if (criterion c) i 452 | (begin (string-set! temp i c) 453 | (+ i 1)))) 454 | 0 s start end))) 455 | (if (= ans-len slen) temp (substring temp 0 ans-len))) 456 | 457 | (let* ((cset (cond ((char-set? criterion) criterion) 458 | ((char? criterion) (char-set criterion)) 459 | (else (error "string-delete criterion not predicate, char or char-set" criterion)))) 460 | (len (string-fold (lambda (c i) (if (char-in-set? c cset) 461 | i 462 | (+ i 1))) 463 | 0 s start end)) 464 | (ans (make-string len))) 465 | (string-fold (lambda (c i) (if (char-in-set? c cset) 466 | i 467 | (begin (string-set! ans i c) 468 | (+ i 1)))) 469 | 0 s start end) 470 | ans)))) 471 | ;; added 472 | (define (string-subst str from to) 473 | (let ((from-len (string-length from)) 474 | (to-len (string-length to))) 475 | (let loop ((str str) 476 | (start 0)) 477 | (let ((pos (string-contains str from start))) 478 | (if (not pos) str 479 | (loop (string-xreplace str to pos (+ pos from-len)) 480 | (+ pos to-len))))))) 481 | 482 | ;;;; end of srfi-13 483 | ;; still no proper multiple values :-/ 484 | (define-syntax let-values 485 | (syntax-rules () 486 | ((let-values ((vals form)) body0 body ...) 487 | (receive vals (let ((r form)) 488 | ;; TODO this is a total hack, which doesn't even work well... 489 | (if (and (compiled-closure? r) 490 | (let ((di (compiled-code-block/debugging-info (compiled-entry/block (compiled-closure->entry r))))) 491 | (if (and di (vector? di) (eq? (vector-ref di 0) 'debugging-info-wrapper)) 492 | (string=? "runtime/global.inf" (vector-ref di 3)) 493 | #t ;; hm... anything simpler to do? 494 | ))) 495 | r 496 | (apply values (list r)))) 497 | (begin body0 body ...))))) 498 | 499 | 500 | 501 | (define ($scheme-name) 502 | "mit-scheme") 503 | (define (fluid a) 504 | (a)) 505 | 506 | (define ($open-tcp-server port-number port-file handler) 507 | (let* ((n (or port-number (+ 10000 (random-integer 50000)))) ;; TODO: pass 0, then somehow read the actual port from the socket 508 | (socket (open-tcp-server-socket n (host-address-loopback)))) 509 | (handler n socket))) 510 | 511 | (define ($tcp-server-accept socket handler) 512 | (let ((p (tcp-server-binary-connection-accept socket #t #f))) 513 | (handler p p))) 514 | 515 | (define hash-table-set! hash-table/put!) 516 | 517 | (define hash-table-ref/default hash-table/get) 518 | 519 | (define ($all-package-names) 520 | (map (lambda (package) (env->pstring (package/environment package))) 521 | (all-packages))) 522 | 523 | (define ($handle-condition exception) 524 | (invoke-sldb exception)) 525 | 526 | (define ($condition-msg condition) 527 | (condition/report-string condition)) 528 | 529 | (define ($condition-location condition) 530 | "Return (PATH POSITION LINE COLUMN) for CONDITION." 531 | #f) 532 | 533 | (define ($condition-links condition) 534 | ;; TODO 535 | (map (lambda (x) 'foo) ($condition-trace condition))) 536 | 537 | (define (pp-to-string o) 538 | (string-trim (with-output-to-string (lambda () (pp o))))) 539 | 540 | (define debugger-hide-system-code? #f) 541 | 542 | (define (system-frame? stack-frame) 543 | (stack-frame/repl-eval-boundary? stack-frame)) 544 | 545 | (define (stack-frame->subproblem frame number) 546 | (receive (expression environment subexpression) 547 | (stack-frame/debugging-info frame) 548 | (make-subproblem frame expression environment subexpression number))) 549 | (define-record-type 550 | (make-subproblem stack-frame expression environment subexpression number) 551 | subproblem? 552 | (stack-frame subproblem/stack-frame) 553 | (expression subproblem/expression) 554 | (environment subproblem/environment) 555 | (subexpression subproblem/subexpression) 556 | (number subproblem/number)) 557 | (define-record-type 558 | (%make-bline start-mark object type parent depth next prev offset 559 | properties) 560 | bline? 561 | 562 | ;; Index of this bline within browser lines vector. #F if line is 563 | ;; invisible. 564 | (index bline/index set-bline/index!) 565 | 566 | ;; Line start within browser buffer. #F if line is invisible. 567 | (start-mark bline/start-mark set-bline/start-mark!) 568 | 569 | ;; Object that this line represents. 570 | (object bline/object) 571 | 572 | ;; Type of OBJECT. This type is specific to the browser; it tells 573 | ;; the browser how to manipulate OBJECT. 574 | (type bline/type) 575 | 576 | ;; BLINE representing the object that this object is a component of, 577 | ;; or #F if none. 578 | (parent bline/parent) 579 | 580 | ;; Nonnegative integer indicating the depth of this object in the 581 | ;; component nesting. 582 | (depth bline/depth) 583 | 584 | ;; BLINEs representing the objects that are adjacent to this one in 585 | ;; the component ordering, or #F if none. 586 | (next bline/next set-bline/next!) 587 | (prev bline/prev) 588 | 589 | ;; Nonnegative integer indicating the position of this object in the 590 | ;; component ordering. 591 | (offset bline/offset) 592 | 593 | (properties bline/properties)) 594 | (define (make-bline object type parent prev) 595 | (let ((bline 596 | (%make-bline #f 597 | object 598 | type 599 | parent 600 | (if parent (+ (bline/depth parent) 1) 0) 601 | #f 602 | prev 603 | (if prev (+ (bline/offset prev) 1) 0) 604 | (make-1d-table)))) 605 | (if prev 606 | (set-bline/next! prev bline)) 607 | bline)) 608 | (define-record-type 609 | (make-reduction subproblem expression environment number) 610 | reduction? 611 | (subproblem reduction/subproblem) 612 | (expression reduction/expression) 613 | (environment reduction/environment) 614 | (number reduction/number)) 615 | (define (subproblem/reductions subproblem) 616 | (let ((frame (subproblem/stack-frame subproblem))) 617 | (let loop ((reductions (stack-frame/reductions frame)) (n 0)) 618 | (if (pair? reductions) 619 | (cons (make-reduction subproblem 620 | (caar reductions) 621 | (cadar reductions) 622 | n) 623 | (loop (cdr reductions) (+ n 1))) 624 | '())))) 625 | 626 | (define (continuation->blines continuation) 627 | (let ((beyond-system-code #f)) 628 | (let loop ((frame (continuation/first-subproblem continuation)) 629 | (prev #f) 630 | (n 0)) 631 | (if (not frame) 632 | '() 633 | (let* ((next-subproblem 634 | (lambda (bline) 635 | (loop (stack-frame/next-subproblem frame) 636 | bline 637 | (+ n 1)))) 638 | (walk-reductions 639 | (lambda (bline reductions) 640 | (cons bline 641 | (let loop ((reductions reductions) (prev #f)) 642 | (if (null? reductions) 643 | (next-subproblem bline) 644 | (let ((bline 645 | (make-bline (car reductions) 646 | 'bline-type:reduction 647 | bline 648 | prev))) 649 | (cons bline 650 | (loop (cdr reductions) bline)))))))) 651 | (continue 652 | (lambda () 653 | (let* ((subproblem (stack-frame->subproblem frame n))) 654 | (if debugger:student-walk? 655 | (let ((reductions 656 | (subproblem/reductions subproblem))) 657 | (if (null? reductions) 658 | (let ((bline 659 | (make-bline subproblem 660 | 'bline-type:subproblem 661 | #f 662 | prev))) 663 | (cons bline 664 | (next-subproblem bline))) 665 | (let ((bline 666 | (make-bline (car reductions) 667 | 'bline-type:reduction 668 | #f 669 | prev))) 670 | (walk-reductions bline 671 | (if (> n 0) 672 | '() 673 | (cdr reductions)))))) 674 | (walk-reductions 675 | (make-bline subproblem 676 | 'bline-type:subproblem 677 | #f 678 | prev) 679 | (subproblem/reductions subproblem))))))) 680 | (cond ((and (not debugger-hide-system-code?) 681 | (system-frame? frame)) 682 | (loop (stack-frame/next-subproblem frame) 683 | prev 684 | n)) 685 | ((or ;; (and limit (>= n limit)) 686 | (if (system-frame? frame) 687 | (begin (set! beyond-system-code #t) #t) 688 | #f) 689 | beyond-system-code) 690 | (list (make-continuation-bline continue #f prev))) 691 | (else (continue)))))))) 692 | 693 | (define ($condition-trace condition) 694 | (define from 0) 695 | (define (combination->list c) 696 | (read-from-string (pp-to-string c))) 697 | (let* ((blines (drop (continuation->blines (condition/continuation condition)) from)) 698 | (blines-count (length blines)) 699 | (count (take (iota blines-count from) blines-count))) 700 | (append (map (lambda (i bline) 701 | (let ((o (bline/object bline))) 702 | (cond ((reduction? o) (string "R" (reduction/number o) ": " (pp-to-string (reduction/expression o)))) 703 | ((subproblem? o) (string "S" (subproblem/number o) ": " (pp-to-string (subproblem/subexpression o)) "\nin " (pp-to-string (subproblem/expression o)))) 704 | (else (pp-to-string o))))) 705 | count 706 | blines)))) 707 | (define (procedure-parameters symbol env) 708 | (let ((type (environment-reference-type env symbol))) 709 | (let ((ans (if (eq? type 'normal) 710 | (let ((binding (environment-lookup env symbol))) 711 | (if (and binding 712 | (procedure? binding)) 713 | (cons symbol (read-from-string (string-trim (with-output-to-string 714 | (lambda () (pa binding)))))) 715 | #f)) 716 | #f))) 717 | ans))) 718 | (define ($binding-documentation p) 719 | ;; same as (inspect object), then hitting c 720 | #f) 721 | (define ($function-parameters-and-documentation name) 722 | ;; TODO 723 | (let ((binding #f)) 724 | (cons (procedure-parameters (string->symbol name) ($environment param:environment)) 725 | ($binding-documentation binding)))) 726 | 727 | (define (string-replace s1 s2 start1 end1) ;; . start2+end2 728 | (let* ((s1-before (substring s1 0 start1)) 729 | (s1-after (substring s1 end1 (string-length s1)))) 730 | (string-append s1-before s2 s1-after))) 731 | 732 | (define ($inspect-fallback object) 733 | (cond ((record? object) 734 | (let* ((type (record-type-descriptor object)) 735 | (field-names (record-type-field-names type)) 736 | (len (length field-names)) 737 | (field-values (map (lambda (i) ((record-accessor type i) object)) field-names))) 738 | (let loop ((n field-names) 739 | (v field-values)) 740 | (if (null? n) 741 | (stream) 742 | (stream-cons (inspector-line (car n) (car v)) 743 | (loop (cdr n) (cdr v))))))) 744 | (else #f))) 745 | 746 | (define ($environment env-name) 747 | ;; TODO 748 | (interaction-environment)) 749 | 750 | (define ($error-description condition) 751 | (condition/report-string condition)) 752 | 753 | (define (all-packages) 754 | (let loop ((package (name->package '()))) ;; system-global-package 755 | (cons package 756 | (append-map loop (package/children package))))) 757 | 758 | (define anonymous-package-prefix "environment-") 759 | 760 | (define unknown-environment (cons 'unknown 'environment)) 761 | 762 | (define (env->pstring env) 763 | (if (eq? unknown-environment env) 764 | "unknown environment" 765 | (let ((package (environment->package env))) 766 | (if package 767 | (write-to-string (package/name package)) 768 | (string anonymous-package-prefix (object-hash env)))))) 769 | 770 | (define (with-exception-handler handler thunk) 771 | (bind-condition-handler (list condition-type:serious-condition) 772 | handler 773 | thunk)) 774 | 775 | (define ($output-to-repl thunk) 776 | ;; basic implementation, print all output at the end, this should 777 | ;; be replaced with a custom output port 778 | (let ((o (open-output-string))) 779 | (parameterize ((current-output-port o)) 780 | (begin0 781 | (thunk) 782 | (swank/write-string (get-output-string o) #f))))) 783 | 784 | (define ($completions prefix env-name) 785 | (let ((strings (all-completions prefix (pstring->env env-name)))) 786 | (cons (sort strings stringenv pstring) 798 | (cond ((or (not (string? pstring)) 799 | (not (string? (fluid *buffer-pstring*))) 800 | (string-ci=? (fluid *buffer-pstring*) "COMMON-LISP-USER")) 801 | (nearest-repl/environment)) 802 | ((string-prefix? anonymous-package-prefix pstring) 803 | (let ((object 804 | (object-unhash 805 | (string->number (string-tail pstring 806 | (string-length 807 | anonymous-package-prefix)) 808 | 10 809 | #t)))) 810 | (if (not (environment? object)) 811 | (error:wrong-type-datum object "environment")) 812 | object)) 813 | (else 814 | (package/environment (find-package (read-from-string pstring) #t))))) 815 | 816 | (define (all-completions prefix environment) 817 | (let ((prefix 818 | (if (fluid (environment-lookup environment 'PARAM:PARSER-CANONICALIZE-SYMBOLS?)) 819 | (string-downcase prefix) 820 | prefix)) 821 | (completions '())) 822 | (for-each-interned-symbol 823 | (lambda (symbol) 824 | (if (and (string-prefix? prefix (symbol-name symbol)) 825 | (environment-bound? environment symbol)) 826 | (set! completions (cons (symbol-name symbol) completions))) 827 | unspecific)) 828 | completions)) 829 | 830 | (define-record-type 831 | (make-istate object parts actions next previous content) 832 | istate? 833 | (object istate-object) 834 | (parts istate-parts) 835 | (actions istate-actions) 836 | (next istate-next set-istate-next!) 837 | (previous istate-previous) 838 | (content istate-content)) 839 | 840 | (define ($frame-locals-and-catch-tags nr) 841 | `(nil 842 | nil)) 843 | -------------------------------------------------------------------------------- /specific/racket.ss: -------------------------------------------------------------------------------- 1 | (define ($scheme-name) 2 | "racket") 3 | (define ($macroexpand-1 form) 4 | (expand-once form)) 5 | (define ($macroexpand-all form) 6 | (expand form)) 7 | (define ($open-tcp-server port-number port-file handler) 8 | (let ((n (or port-number 0)) 9 | (server (tcp-listen port-number))) 10 | (handler n server))) 11 | (define ($tcp-server-accept server handler) 12 | (let-values (((in out) (tcp-accept server))) 13 | (handler in out))) 14 | 15 | (define env (let ((n (make-base-namespace))) 16 | (parameterize ((current-namespace n)) 17 | (namespace-require 'r7rs) 18 | (namespace-require 'r7rs/base) 19 | (namespace-require 'r7rs/read) 20 | (namespace-require 'r7rs/write)) 21 | n)) 22 | (define (interaction-environment) env) 23 | 24 | 25 | (define ($all-package-names) 26 | '()) ;; (module-list) from geiser 27 | 28 | ;; 29 | 30 | (define ($error-description error) 31 | (let ((o (open-output-string))) 32 | (display error o) 33 | (get-output-string o))) 34 | 35 | (define ($output-to-repl thunk) 36 | ;; basic implementation, print all output at the end, this should 37 | ;; be replaced with a custom output port 38 | (let ((o (open-output-string))) 39 | (parameterize ((current-output-port o)) 40 | (let-values ((x (thunk))) 41 | (swank/write-string (get-output-string o) #f) 42 | (apply values x))))) 43 | 44 | (define (env-name->environment env-name) 45 | env) 46 | (define (environment-bindings env) 47 | (namespace-mapped-symbols env)) 48 | (define (string-match-forward a b) 49 | (let* ((a-len (string-length a)) 50 | (b-len (string-length b)) 51 | (min-len (min a-len b-len))) 52 | (let loop ((i 0)) 53 | (if (> i min-len) 54 | (- i 1) 55 | (if (string=? (substring a 0 i) (substring b 0 i)) 56 | (loop (+ i 1)) 57 | (- i 1)))))) 58 | (define (longest-common-prefix strings) 59 | (if (null? strings) 60 | "" 61 | (fold (lambda (s1 s2) (substring s2 0 (string-match-forward s1 s2))) (mcar strings) (mlist->list (mcdr strings))))) 62 | (define ($completions prefix env-name) 63 | (let ((matches (list->mlist (filter (lambda (el) (string-prefix? prefix el)) 64 | (mlist->list (map symbol->string (list->mlist (environment-bindings (env-name->environment env-name))))))))) 65 | (cons (mlist->list matches) 66 | (longest-common-prefix matches)))) 67 | 68 | (define ($function-parameters-and-documentation name) 69 | (cons #f #f)) 70 | 71 | (define ($set-package name) 72 | (list "(user)" "(user)")) 73 | 74 | (define ($environment name) 75 | (interaction-environment)) 76 | 77 | (define ($condition-trace condition) 78 | '()) 79 | 80 | (define ($frame-locals-and-catch-tags nr) 81 | '()) 82 | 83 | (define ($frame-var-value frame index) 84 | #f) 85 | 86 | (define ($condition-msg condition) 87 | "UNKNOWN") 88 | 89 | (define ($condition-links condition) 90 | '()) 91 | 92 | (define ($handle-condition exception) 93 | #f) 94 | 95 | (define-record-type 96 | (make-istate object parts actions next previous content) 97 | istate? 98 | (object istate-object) 99 | (parts istate-parts) 100 | (actions istate-actions) 101 | (next istate-next set-istate-next!) 102 | (previous istate-previous) 103 | (content istate-content)) 104 | 105 | (define ($inspect-fallback object) 106 | #f) 107 | 108 | (define $pretty-print pretty-print) 109 | 110 | (define ($binding-documentation binding) 111 | #f) 112 | 113 | (define ($condition-location condition) 114 | "Return (PATH POSITION LINE COLUMN) for CONDITION." 115 | #f) 116 | 117 | (define ($apropos name) 118 | '()) 119 | --------------------------------------------------------------------------------