home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / little-st2 / part05 < prev    next >
Encoding:
Internet Message Format  |  1988-01-30  |  20.6 KB

  1. Subject:  v17i053:  New release of little smalltalk, Part05/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Tim Budd <budd@MIST.CS.ORST.EDU>
  7. Posting-number: Volume 13, Issue 57
  8. Archive-name: little-st2/part05
  9.  
  10. #!/bin/sh
  11. #
  12. # This is version 2.02 of Little Smalltalk, distributed in five parts.
  13. # This version is dated 12/25/87
  14. # Several bugs and many features and improvements have been made since the
  15. # first posting to comp.src.unix.  See the file ``todo'' for a partial list.
  16. # Comments, bug reports, and the like should be submitted to:
  17. #     Tim Budd
  18. #     Smalltalk Distribution
  19. #     Department of Computer Science
  20. #     Oregon State University
  21. #     Corvallis, Oregon
  22. #     97330
  23. #     budd@cs.orst.edu
  24. #     {hp-pcd, tektronix}!orstcs!budd
  25. #
  26. echo 'Start of small.v2, part 05 of 05:'
  27. echo 'x - Bugs'
  28. sed 's/^X//' > Bugs << '/'
  29. Xobjects are limited to size 256 
  30. X    this mostly limits the text (char) size of methods - to 512 chars.
  31. X    this could be fixed by changing memory.c.
  32. X
  33. Xradices other than 10 aren't implemented.
  34. X
  35. XThe parser doesn always do literal arrays correctly, in particular, I
  36. X    think negation signs on numbers aren't recognized within arrays.
  37. X    (should be reorganized in the parser).
  38. X
  39. Xparser should leave method text in method, so it can be edited dynamically
  40. X(does this now, but it should be an option, to save space on small
  41. Xsystems).
  42. X
  43. XThe collection hierarchy has been completely reorginized (this isn't a bug)
  44. X    many of the more obscure messages are left unimplmented.
  45. X    many of the abstract classes are eliminated
  46. X    Bags have been eliminated (they can be replaced by lists)
  47. X    collections are now magnitudes (set subset relations)
  48. X
  49. XThe basic classes are somewhat incomplete, in particular
  50. X    points aren't implemented
  51. X    radians are implemented (neither are trig functions)
  52. X
  53. XBytearrays are a bit odd.  In particular,
  54. X    converting to bytearrays gives something too big (by twice)
  55. X    converting bytearrays to strings can cause bugs if the last
  56. X    byte is not zero (causing non null terminated strings)
  57. X
  58. XSemaphores and processes aren't implemented yet - even in the multiprocess
  59. X    version
  60. X    initial experiments aren't encouraging - 
  61. X    they seem to be too slow.
  62. X    
  63. XPROJECTS______________________________________________________________
  64. XFor those with time on their hands and nothing to do, here is a list
  65. Xof several projects that need doing.
  66. X
  67. X1. Profiling indicates that about 45% of execution time is spent in the
  68. Xroutine ``execute'', in interp.c.  Rewrite this in your favorite assembly
  69. Xlanguage to speed it up.
  70. X
  71. X2. Rewrite the memory manager.  Possible changes
  72. X    a. use garbage collection of some sort
  73. X    b. allow big objects (bigger than 256 words)
  74. X
  75. X3. Rewrite the process manager in assembly language, permitting the
  76. X    Smalltalk process stack to exist intermixed with the C
  77. X    execution stack.
  78. X
  79. X4. Port to your favorite machine, making the interface fit the machine.
  80. X    Make sure you send me a diff script of any changes you made,
  81. X    so I can incorporate them into the next release
  82. X
  83. X5. Lots of extensions could stand implementing, such as
  84. X    infinite precision numbers
  85. X    semaphores and processes
  86. /
  87. echo 'x - Makefile'
  88. sed 's/^X//' > Makefile << '/'
  89. X#
  90. X# Makefile for Little Smalltalk, version 2
  91. X#
  92. XCFLAGS = -g
  93. X
  94. XCOMMONc = memory.c names.c lex.c parser.c
  95. XCOMMONo = memory.o names.o lex.o parser.o
  96. XPARSEc  = comp.c $(COMMONc) image.c
  97. XPARSEo  = comp.o $(COMMONo) image.o
  98. XSTc     = main.c $(COMMONc) process.c primitive.c interp.c
  99. XSTo     = main.o $(COMMONo) process.o primitive.o interp.o
  100. Xclasses = basic.st unix.st mult.st munix.st test.st
  101. Xallfiles = READ_ME Bugs Makefile todo *.ms *.h *.c *.st *.ini
  102. X
  103. Xinstall: stest sunix
  104. X    echo "created single process version, see docs for more info"
  105. X
  106. X#
  107. X# parse - the object image parser.  
  108. X# used to build the initial object image
  109. X#
  110. Xparse: $(PARSEo)
  111. X    cc -o parse $(CFLAGS) $(PARSEo)
  112. X
  113. Xparseprint:
  114. X    pr *.h $(PARSEc) | lpr
  115. X
  116. Xparselint:
  117. X    lint $(PARSEc)
  118. X
  119. X#
  120. X# st - the actual bytecode interpreter
  121. X# runs bytecodes from the initial image, or another image
  122. X#
  123. Xst: $(STo)
  124. X    cc $(CFLAGS) -o st $(STo) -lm
  125. X
  126. Xstlint: 
  127. X    lint $(STc)
  128. X
  129. Xstprint:
  130. X    pr *.h $(STc) | lpr
  131. X
  132. X#
  133. X# image - build the initial object image
  134. X#
  135. Xclasslpr:
  136. X    pr $(classes) | lpr
  137. X
  138. Xsunix: parse st
  139. X    parse basic.st unix.st
  140. X    st - - <script.ini
  141. X
  142. Xmunix: parse st
  143. X    parse basic.st unix.st mult.st munix.st
  144. X    st - - <script.ini
  145. X
  146. Xstest: parse st
  147. X    parse -s basic.st unix.st test.st
  148. X    st - - <script.ini
  149. X    st <test.ini
  150. X
  151. Xmtest: parse st
  152. X    parse -s basic.st unix.st mult.st munix.st test.st mtest.st
  153. X    st - - <script.ini
  154. X    st <test.ini
  155. X
  156. X#
  157. X# include file dependencies
  158. X#
  159. Xcomp.o: env.h memory.h names.h
  160. Ximage.o: env.h memory.h names.h lex.h
  161. Xinterp.o: env.h memory.h names.h process.h interp.h
  162. Xlex.o: env.h memory.h lex.h
  163. Xmain.o: env.h memory.h names.h interp.h process.h
  164. Xmemory.o: env.h memory.h
  165. Xnames.o: env.h memory.h names.h
  166. Xparser.o: env.h memory.h names.h interp.h lex.h
  167. Xprimitive.o: env.h memory.h names.h process.h
  168. Xprocess.o: env.h memory.h names.h process.h
  169. X
  170. X#
  171. X# distribution bundles
  172. X#
  173. X
  174. Xtar:
  175. X    tar cvf ../smalltalk.v2.tar .
  176. X    compress -c ../smalltalk.v2.tar >../smalltalk.v2.tar.Z
  177. X
  178. Xpack:
  179. X    packmail -o'small.v2' -h'head' $(allfiles)
  180. /
  181. echo 'x - comp.c'
  182. sed 's/^X//' > comp.c << '/'
  183. X/*
  184. X    Little Smalltalk, version 2
  185. X    Written by Tim Budd, Oregon State University, July 1987
  186. X
  187. X    Unix specific front end for the initial object image maker
  188. X    (parse utility)
  189. X*/
  190. X
  191. X# include <stdio.h>
  192. X# include "env.h"
  193. X# include "memory.h"
  194. X# include "names.h"
  195. X
  196. Xmain(argc, argv) 
  197. Xint argc;
  198. Xchar **argv;
  199. X{ FILE *fp;
  200. X    int i;
  201. X    boolean printit = true;
  202. X
  203. X    initMemoryManager();
  204. X
  205. X    buildInitialNameTables();
  206. X
  207. X    if (argc == 1)
  208. X        readFile(stdin, printit);
  209. X    else
  210. X        for (i = 1; i < argc; i++) {
  211. X            if (argv[i][0] == '-') {
  212. X                switch(argv[i][1]) {
  213. X                    case 's': printit = false; break;
  214. X                    case 'v': printit = true; break;
  215. X                    }
  216. X                }
  217. X            else {
  218. X                fp = fopen(argv[i], "r");
  219. X                if (fp == NULL) {
  220. X                    ignore fprintf(stderr,
  221. X                        "can't open file %s", argv[i]);
  222. X                    exit(1);
  223. X                    }
  224. X                else {
  225. X                    readFile(fp, printit);
  226. X                    ignore fclose(fp);
  227. X                    }
  228. X                }
  229. X            }
  230. X
  231. X# ifndef BINREADWRITE
  232. X    fp = fopen(INITIALIMAGE, "w");
  233. X# endif
  234. X# ifdef BINREADWRITE
  235. X    fp = fopen(INITIALIMAGE, "wb");
  236. X# endif
  237. X    if (fp == NULL) sysError("error during image file open",INITIALIMAGE);
  238. X    imageWrite(fp);
  239. X    ignore fclose(fp);
  240. X    exit(0);
  241. X}
  242. /
  243. echo 'x - interp.h'
  244. sed 's/^X//' > interp.h << '/'
  245. X/*
  246. X    Little Smalltalk, version 2
  247. X    Written by Tim Budd, Oregon State University, July 1987
  248. X*/
  249. X/*
  250. X    symbolic definitions for the bytecodes
  251. X*/
  252. X
  253. X# define Extended 0
  254. X# define PushInstance 1
  255. X# define PushArgument 2
  256. X# define PushTemporary 3
  257. X# define PushLiteral 4
  258. X# define PushConstant 5
  259. X# define PushGlobal 6
  260. X# define PopInstance 7
  261. X# define PopTemporary 8
  262. X# define SendMessage 9
  263. X# define SendUnary 10
  264. X# define SendBinary 11
  265. X# define SendKeyword 12
  266. X# define DoPrimitive 13
  267. X# define CreateBlock 14
  268. X# define DoSpecial 15
  269. X
  270. X/* types of special instructions (opcode 15) */
  271. X
  272. X# define SelfReturn 1
  273. X# define StackReturn 2
  274. X# define BlockReturn 3
  275. X# define Duplicate 4
  276. X# define PopTop 5
  277. X# define Branch 6
  278. X# define BranchIfTrue 7
  279. X# define BranchIfFalse 8
  280. X# define AndBranch 9
  281. X# define OrBranch 10
  282. X# define SendToSuper 11
  283. /
  284. echo 'x - lex.h'
  285. sed 's/^X//' > lex.h << '/'
  286. X/*
  287. X    Little Smalltalk, version 2
  288. X    Written by Tim Budd, Oregon State University, July 1987
  289. X*/
  290. X/*
  291. X    values returned by the lexical analyzer
  292. X*/
  293. X
  294. X# ifndef NOENUMS
  295. X
  296. Xtypedef enum tokensyms { nothing, nameconst, namecolon, 
  297. X    intconst, floatconst, charconst, symconst,
  298. X    arraybegin, strconst, binary, closing, inputend} tokentype;
  299. X# endif
  300. X
  301. X# ifdef NOENUMS
  302. X# define tokentype int
  303. X# define nothing 0
  304. X# define nameconst 1
  305. X# define namecolon 2
  306. X# define intconst 3
  307. X# define floatconst 4
  308. X# define charconst 5
  309. X# define symconst 6
  310. X# define arraybegin 7
  311. X# define strconst 8
  312. X# define binary 9
  313. X# define closing 10
  314. X# define inputend 11
  315. X
  316. X# endif
  317. X
  318. Xextern tokentype nextToken(NOARGS);
  319. X
  320. Xextern tokentype token;        /* token variety */
  321. Xextern char tokenString[];    /* text of current token */
  322. Xextern int tokenInteger;    /* integer (or character) value of token */
  323. Xextern double tokenFloat;    /* floating point value of token */
  324. Xextern noreturn lexinit();    /* initialization routine */
  325. /
  326. echo 'x - main.c'
  327. sed 's/^X//' > main.c << '/'
  328. X/*
  329. X    Little Smalltalk, version 2
  330. X    Written by Tim Budd, Oregon State University, July 1987
  331. X
  332. X    unix specific driver (front-end) for bytecode interpreter.
  333. X*/
  334. X# include <stdio.h>
  335. X
  336. X# include "env.h"
  337. X# include "memory.h"
  338. X# include "names.h"
  339. X# include "interp.h"
  340. X# include "process.h"
  341. X
  342. X# ifdef STRING
  343. X# include <string.h>
  344. X# endif
  345. X# ifdef STRINGS
  346. X# include <strings.h>
  347. X# endif
  348. X# ifdef SIGNALS
  349. X# include <signal.h>
  350. X# include <setjmp.h>
  351. Xjmp_buf intenv;
  352. X# endif
  353. X# ifdef SSIGNALS
  354. X# include <signal.h>
  355. X# include <setjmp.h>
  356. Xjmp_buf intenv;
  357. X# endif
  358. X
  359. Xextern int processStackTop;
  360. Xextern object processStack[];
  361. X
  362. X# ifdef SIGNALS
  363. Xbrkfun() { longjmp(intenv, 1); }
  364. X# endif
  365. X# ifdef SSIGNALS
  366. Xbrkfun() { longjmp(intenv, 1); }
  367. X# endif
  368. X
  369. Xmain(argc, argv) 
  370. Xint argc;
  371. Xchar **argv;
  372. X{
  373. XFILE *fp;
  374. Xchar fileName[120];
  375. X
  376. XinitMemoryManager();
  377. X
  378. Xif ((argc == 1) || ((argc > 1) && streq(argv[1],"-"))){
  379. X# ifdef BINREADWRITE
  380. X    fp = fopen(INITIALIMAGE,"rb");
  381. X# endif
  382. X# ifndef BINREADWRITE
  383. X    fp = fopen(INITIALIMAGE,"r");
  384. X# endif
  385. X    if (fp == NULL)
  386. X        sysError("cannot read image file",INITIALIMAGE);
  387. X    }
  388. Xelse {
  389. X# ifdef BINREADWRITE
  390. X    fp = fopen(argv[1], "rb");
  391. X# endif
  392. X# ifndef BINREADWRITE
  393. X    fp = fopen(argv[1], "r");
  394. X# endif
  395. X    if (fp == NULL)
  396. X        sysError("cannot read image file", argv[1]);
  397. X    }
  398. XimageRead(fp);
  399. Xignore fclose(fp);
  400. X
  401. XinitCommonSymbols();
  402. X
  403. Xignore fprintf(stderr,"initially %d objects\n", objcount());
  404. X
  405. X/* now we are ready to start */
  406. X
  407. X# ifdef SIGNALS
  408. Xignore signal(SIGINT, brkfun);
  409. Xignore setjmp(intenv);
  410. X# endif
  411. X# ifdef SSIGNALS
  412. Xignore ssignal(SIGINT, brkfun);
  413. Xignore setjmp(intenv);
  414. X# endif
  415. X
  416. Xprpush(smallobj);
  417. XsendMessage(newSymbol("commandLoop"), getClass(smallobj), 0);
  418. Xflushstack();
  419. X
  420. Xignore fprintf(stderr,"finally %d objects\n", objcount());
  421. X
  422. Xif (argc > 2) {
  423. X    if (streq(argv[2],"-"))
  424. X        ignore strcpy(fileName, INITIALIMAGE);
  425. X    else
  426. X        ignore strcpy(fileName, argv[2]);
  427. X# ifdef BINREADWRITE
  428. X    fp = fopen(fileName,"wb");
  429. X# endif
  430. X# ifndef BINREADWRITE
  431. X    fp = fopen(fileName,"w");
  432. X# endif
  433. X    if (fp == NULL)
  434. X        sysError("cannot write image file",fileName);
  435. X    else {
  436. X        ignore fprintf(stderr,"creating image file %s\n", fileName);
  437. X        imageWrite(fp);
  438. X        ignore fclose(fp);
  439. X        }
  440. X    }
  441. Xexit(0);
  442. X}
  443. /
  444. echo 'x - mtest.st'
  445. sed 's/^X//' > mtest.st << '/'
  446. X*
  447. X* tests for multiprocessing system
  448. X*
  449. XDeclare Mtest Test 
  450. XDeclare Future Object result sem
  451. XInstance Mtest test
  452. XClass Mtest
  453. X    all
  454. X        super all.
  455. X        'all multiprocessing tests passed' print.
  456. X|
  457. X    future        | a f |
  458. X        a <- List new.
  459. X        f <- Future new; eval: [(1 to: 100) do: [:x | nil]. 
  460. X            a addLast: 2. 3].
  461. X        a addLast: 1.
  462. X        a addLast: f value.
  463. X        (a asArray = #(1 2 3))
  464. X            ifFalse: [ smalltalk error: 'future error'].
  465. X        'future test passed' print
  466. X]
  467. XClass Future
  468. X    new
  469. X        sem <- Semaphore new; set: 0
  470. X|
  471. X    eval: aBlock
  472. X        [ result <- aBlock value. sem signal ] fork
  473. X|
  474. X    value
  475. X        sem wait. 
  476. X        sem signal.
  477. X        ^ result
  478. X]
  479. X
  480. /
  481. echo 'x - mult.st'
  482. sed 's/^X//' > mult.st << '/'
  483. X*
  484. X* Little Smalltalk, version 2
  485. X* Written by Tim Budd, Oregon State University, July 1987
  486. X*
  487. X* multiprocess scheduler - this is optional
  488. X*
  489. XDeclare Interpreter Object context prev creating stack stackTop byteCodePointer
  490. XDeclare Process Object interpreter yield
  491. XDeclare Scheduler Object processList atomic currentProcess
  492. XDeclare Semaphore Object count processList
  493. XInstance Scheduler scheduler
  494. XClass Block
  495. X    newProcess
  496. X        ^ (context newInterpreter: bytecodeCounter) newProcess
  497. X|
  498. X    fork
  499. X        self newProcess resume
  500. X]
  501. XClass Context
  502. X    newInterpreter: start
  503. X        ^ Interpreter new;
  504. X            context: self;
  505. X            byteCounter: start;
  506. X            stack: (Array new: 20)
  507. X]
  508. XClass Interpreter
  509. X    new
  510. X        stackTop <- 0.
  511. X        byteCodePointer <- 0
  512. X|
  513. X    execute
  514. X        ^ <19 self>
  515. X|
  516. X    byteCounter: start
  517. X        byteCodePointer <- start
  518. X|
  519. X    context: value
  520. X        context <- value
  521. X|
  522. X    stack: value
  523. X        stack <- value.
  524. X|
  525. X    newProcess
  526. X        ^ Process new; interpreter: self
  527. X]
  528. XClass Method
  529. X    executeWith: arguments
  530. X        ( ( Context new ; method: self ; 
  531. X            temporaries: ( Array new: temporarySize) ;
  532. X            arguments: arguments ) newInterpreter: 0 )
  533. X                newProcess resume
  534. X]
  535. XClass Process
  536. X    execute     | i |
  537. X        yield <- true.
  538. X        i <- 0.
  539. X        [ interpreter notNil and: [ yield ]]
  540. X            whileTrue: [ interpreter <- interpreter execute.
  541. X                    i <- i + 1.
  542. X                    (i > 200) ifTrue: [yield <- false ]].
  543. X        (interpreter isNil)
  544. X            ifTrue: [ self terminate ]
  545. X|
  546. X    interpreter: value
  547. X        interpreter <- value
  548. X|
  549. X    resume
  550. X        scheduler addProcess: self
  551. X|
  552. X    terminate
  553. X        scheduler removeProcess: self
  554. X|
  555. X    yield
  556. X        yield <- false
  557. X]
  558. XClass Scheduler
  559. X    new
  560. X        processList <- Set new.
  561. X        atomic <- false
  562. X|
  563. X    addProcess: aProcess
  564. X        processList add: aProcess
  565. X|
  566. X    critical: aBlock
  567. X        atomic <- true.
  568. X        aBlock value.
  569. X        atomic <- false
  570. X|
  571. X    currentProcess
  572. X        ^ currentProcess
  573. X|
  574. X    removeProcess: aProcess
  575. X        processList remove: aProcess
  576. X|
  577. X    run
  578. X        [ processList size ~= 0 ] whileTrue:
  579. X            [ processList do: 
  580. X                [ :x | currentProcess <- x. 
  581. X                    [ x execute. atomic ] whileTrue ] ]
  582. X]
  583. XClass Semaphore
  584. X    new
  585. X        count <- 0.
  586. X        processList <- List new
  587. X|
  588. X    critical: aBlock
  589. X        self wait.
  590. X        aBlock value.
  591. X        self signal
  592. X|
  593. X    set: aNumber
  594. X        count <- aNumber
  595. X|
  596. X    signal
  597. X        (processList size = 0)
  598. X            ifTrue: [ count <- count + 1]
  599. X            ifFalse: [ scheduler critical:
  600. X                [ processList first resume.
  601. X                    processList removeFirst ]]
  602. X|
  603. X    wait        | process |
  604. X        (count = 0)
  605. X            ifTrue: [ scheduler critical:
  606. X                    [ process <- scheduler currentProcess.
  607. X                      processList add: process.
  608. X                      scheduler removeProcess: process].
  609. X                  scheduler currentProcess yield ]
  610. X            ifFalse: [ count <- count - 1]
  611. X]
  612. /
  613. echo 'x - munix.st'
  614. sed 's/^X//' > munix.st << '/'
  615. X*
  616. X* Little Smalltalk, version 2
  617. X* Written by Tim Budd, Oregon State University, July 1987
  618. X*
  619. X* unix specific routines for the multiprocess front end
  620. X*
  621. X*
  622. XClass Smalltalk
  623. X    commandLoop        | string |
  624. X        self openFiles.
  625. X        scheduler new.
  626. X        [ string <- stdin getPrompt: '>    '. string notNil ]
  627. X            whileTrue: [ (string size strictlyPositive)
  628. X                    ifTrue: [ self doIt: string ] ]
  629. X|
  630. X    doIt: aString        | method |
  631. X        method <- Method new.
  632. X        method text: ( 'proceed ', aString ).
  633. X        (method compileWithClass: Object)
  634. X            ifTrue: [ method executeWith: #( 1 ). 
  635. X                  scheduler run ]
  636. X|
  637. X    error: aString        | process |
  638. X        stderr print: 'Error: ', aString.
  639. X        scheduler critical:
  640. X            [ process <- scheduler currentProcess.
  641. X              scheduler removeProcess: process].
  642. X        " flush out current process "
  643. X        scheduler currentProcess yield.
  644. X        " could we do traceback here?"
  645. X]
  646. /
  647. echo 'x - names.h'
  648. sed 's/^X//' > names.h << '/'
  649. X/*
  650. X    Little Smalltalk, version 2
  651. X    Written by Tim Budd, Oregon State University, July 1987
  652. X*/
  653. X/*
  654. X    names and sizes of internally object used internally in the system
  655. X*/
  656. X
  657. X# define classSize 6
  658. X# define nameInClass 1
  659. X# define sizeInClass 2
  660. X# define methodsInClass 3
  661. X# define superClassInClass 4
  662. X# define variablesInClass 5
  663. X
  664. X# define methodSize 6
  665. X# define textInMethod 1
  666. X# define messageInMethod 2
  667. X# define bytecodesInMethod 3
  668. X# define literalsInMethod 4
  669. X# define stackSizeInMethod 5
  670. X# define temporarySizeInMethod 6
  671. X
  672. X# define contextSize 6
  673. X# define methodInContext 1
  674. X# define methodClassInContext 2
  675. X# define argumentsInContext 3
  676. X# define temporariesInContext 4
  677. X
  678. X# define blockSize 6
  679. X# define contextInBlock 1
  680. X# define argumentCountInBlock 2
  681. X# define argumentLocationInBlock 3
  682. X# define bytecountPositionInBlock 4
  683. X# define creatingInterpreterInBlock 5
  684. X
  685. X# define InterpreterSize 6
  686. X# define contextInInterpreter 1
  687. X# define previousInterpreterInInterpreter 2
  688. X# define creatingInterpreterInInterpreter 3
  689. X# define stackInInterpreter 4
  690. X# define stackTopInInterpreter 5
  691. X# define byteCodePointerInInterpreter 6
  692. X
  693. Xextern object nameTableLookup(OBJ X OBJ);
  694. X
  695. X# define globalSymbol(s) nameTableLookup(globalNames, newSymbol(s))
  696. X
  697. Xextern object trueobj;        /* the pseudo variable true */
  698. Xextern object falseobj;        /* the pseudo variable false */
  699. Xextern object smallobj;        /* the pseudo variable smalltalk */
  700. Xextern object blockclass;    /* the class ``Block'' */
  701. Xextern object contextclass;    /* the class ``Context'' */
  702. Xextern object intclass;        /* the class ``Integer'' */
  703. Xextern object intrclass;    /* the class ``Interpreter'' */
  704. Xextern object symbolclass;    /* the class ``Symbol'' */
  705. Xextern object stringclass;    /* the class ``String'' */
  706. X
  707. Xextern object getClass(OBJ);    /* get class of an object */
  708. Xextern object newSymbol(STR);    /* new smalltalk symbol */
  709. Xextern object newArray(INT);    /* new array */
  710. Xextern object newStString(STR);    /* new smalltalk string */
  711. Xextern object newFloat(FLOAT);    /* new floating point number */
  712. Xextern noreturn initCommonSymbols();    /* common symbols */
  713. /
  714. echo 'x - process.h'
  715. sed 's/^X//' > process.h << '/'
  716. X/*
  717. X    Little Smalltalk, version 2
  718. X    Written by Tim Budd, Oregon State University, July 1987
  719. X*/
  720. X/*
  721. X    constants and types used by process manager. 
  722. X    See process.c and interp.c for more details.
  723. X*/
  724. X/*
  725. X    if there are no enumerated types, make tasks simply integer constants
  726. X*/
  727. X# ifdef NOENUMS
  728. X# define taskType int
  729. X
  730. X# define sendMessageTask 1
  731. X# define sendSuperTask   2
  732. X# define ReturnTask     3
  733. X# define BlockReturnTask 4
  734. X# define BlockCreateTask 5
  735. X# define ContextExecuteTask 6
  736. X
  737. X#endif
  738. X
  739. X# ifndef NOENUMS
  740. X
  741. Xtypedef enum {sendMessageTask, sendSuperTask, ReturnTask, BlockReturnTask,
  742. X        BlockCreateTask, ContextExecuteTask} taskType;
  743. X
  744. X# endif
  745. X
  746. Xextern int finalStackTop;    /* stack top when finished with interpreter */
  747. Xextern int finalByteCounter;    /* bytecode counter when finished with interpreter */
  748. Xextern int argumentsOnStack;    /* position of arguments on stack for mess send */
  749. Xextern object messageToSend;    /* message to send */
  750. Xextern object returnedObject;    /* object returned from message */
  751. Xextern taskType  finalTask;        /* next task to do (see below) */
  752. Xextern object creator;
  753. X
  754. X
  755. Xextern noreturn sendMessage(OBJ X OBJ X INT);
  756. Xextern noreturn prpush(OBJ);
  757. /
  758. echo 'x - test.st'
  759. sed 's/^X//' > test.st << '/'
  760. X*
  761. X*
  762. X* Little Smalltalk, version 2
  763. X* Written by Tim Budd, Oregon State University, July 1987
  764. X*
  765. X*  a few test cases.
  766. X* invoke by messages to global variable ``test'', i.e.
  767. X*        test collection
  768. X*
  769. X* all test cases can be run by sending the message all to test
  770. X*         test all
  771. X*
  772. XDeclare Test Object
  773. XDeclare One Object
  774. XDeclare Two One
  775. XDeclare Three Two
  776. XDeclare Four Three
  777. XInstance Test test
  778. XClass One
  779. X        test
  780. X                ^ 1
  781. X|
  782. X    result1
  783. X                ^ self test
  784. X]
  785. XClass Two
  786. X        test
  787. X                ^ 2
  788. X]
  789. XClass Three
  790. X        result2
  791. X                ^ self result1
  792. X|
  793. X    result3
  794. X                ^ super test
  795. X]
  796. XClass Four
  797. X        test
  798. X                ^ 4
  799. X]
  800. XClass Test
  801. X    all
  802. X        self super.
  803. X        self conversions.
  804. X        self collections.
  805. X        self factorial.
  806. X        self filein.
  807. X        'all tests completed' print
  808. X|
  809. X    conversions
  810. X        " test a few conversion routines "
  811. X        ( (#abc == #abc asString asSymbol) and: [
  812. X        ($A == $A asInteger asCharacter) and: [
  813. X        (12 == 12 asDigit digitValue) and: [
  814. X        (237 == 237 asString asInteger) and: [
  815. X        (43 = 43 asFloat truncated) and: [
  816. X        $A == ($A asString at: 1) ] ] ] ] ] )
  817. X            ifFalse: [^ smalltalk error: 'conversion failure'].
  818. X        'conversion test passed' print.
  819. X|
  820. X    collections
  821. X        " test the collection classes a little"
  822. X        ( (#(1 2 3 3 2 4 2) asSet = #(1 2 3 4) asSet) and: [
  823. X        (#(1 5 3 2 4) sort asArray = #(1 2 3 4 5)) and: [
  824. X        ((#+ respondsTo occurrencesOf: Float) = 1) and: [
  825. X        ('First' < 'last') ] ] ] )
  826. X            ifFalse: [^smalltalk error: 'collection failure'].
  827. X        'collection test passed' print.
  828. X|
  829. X    factorial    | t |
  830. X        t <- [:x | (x = 1) ifTrue: [ 1 ] 
  831. X                ifFalse: [ x * (t value: x - 1) ] ].
  832. X        ((t value: 5) = 5 factorial)
  833. X            ifFalse: [ smalltalk error: 'factorial failure'].
  834. X        'factorial test passed' print
  835. X        
  836. X|
  837. X    filein
  838. X        File new; name: 'queen.st'; open: 'r'; fileIn.
  839. X        (globalNames includesKey: #Queen )
  840. X            ifFalse: [ smalltalk error: 'fileIn failure'].
  841. X        'file in test passed' print.
  842. X        self queen
  843. X|
  844. X    super2         | x1 x2 x3 x4 |
  845. X                x1 <- One new.
  846. X                x2 <- Two new.
  847. X                x3 <- Three new.
  848. X                x4 <- Four new.
  849. X        ^ List new; addLast: x1 test;
  850. X            addLast: x1 result1;
  851. X            addLast: x2 test;
  852. X            addLast: x2 result1;
  853. X            addLast: x3 test;
  854. X                    addLast: x4 result1;
  855. X                    addLast: x3 result2;
  856. X            addLast: x4 result2;
  857. X                    addLast: x3 result3;
  858. X                    addLast: x4 result3
  859. X|
  860. X    super
  861. X        (self super2 asArray = #(1 1 2 2 2 4 2 4 2 2) )
  862. X            ifTrue: ['super test passed' print]
  863. X            ifFalse: [ smalltalk error: 'super test failed']
  864. X]
  865. /
  866. echo 'Part 05 of small.v2 complete.'
  867. exit
  868.