home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / smalltk / src / initial.c < prev    next >
C/C++ Source or Header  |  1991-10-12  |  3KB  |  131 lines

  1. /*
  2.     Little Smalltalk, version 3
  3.     Written by Tim Budd, June 1988
  4.  
  5.     initial image maker
  6. */
  7. # include <stdio.h>
  8. # include "env.h"
  9. # include "memory.h"
  10. # include "names.h"
  11.  
  12. int initial = 1;    /* making initial image */
  13.  
  14. /* lightspeed C not using argc/argv features */
  15. # ifdef NOARGC
  16. char *argv[] = {"initial", "basic.st","mag.st","collect.st", "file.st",
  17.         "mult.st", 
  18. # ifdef STDWIN
  19.         "graphics.st", "stdwin.st", 0};
  20. int argc = 8;
  21. # endif
  22. # ifndef STDWIN
  23.         "tty.st", 0};
  24. int argc = 7;
  25. # endif
  26.  
  27. main()
  28. # endif
  29. # ifndef NOARGC
  30. main(argc, argv) 
  31. int argc;
  32. char **argv;
  33. # endif
  34. {     char methbuf[100];
  35.     int i;
  36.  
  37.     initMemoryManager();
  38.  
  39.     makeInitialImage();
  40.  
  41.     initCommonSymbols();
  42.  
  43.     for (i = 1; i < argc; i++) {
  44.         fprintf(stderr,"%s:\n", argv[i]);
  45.         ignore sprintf(methbuf, 
  46.             "x <120 1 '%s' 'r'>. <123 1>. <121 1>", 
  47.                 argv[i]);
  48.         goDoIt(methbuf);
  49.         }
  50.  
  51.     /* when we are all done looking at the arguments, do initialization */
  52.     fprintf(stderr,"initialization\n");
  53.     /*debugging = true;*/
  54.     goDoIt("x nil initialize\n");
  55.     fprintf(stderr,"finished\n");
  56.  
  57.     /* exit and return - belt and suspenders, but it keeps lint happy */
  58.     exit(0); return 0;
  59. }
  60.  
  61. static goDoIt(text)
  62. char *text;
  63. {     object process, stack, method;
  64.  
  65.     method = newMethod();
  66.     incr(method);
  67.     setInstanceVariables(nilobj);
  68.     ignore parse(method, text, false);
  69.  
  70.     process = allocObject(processSize);
  71.     incr(process);
  72.     stack = allocObject(50);
  73.     incr(stack);
  74.  
  75.     /* make a process */
  76.     basicAtPut(process, stackInProcess, stack);
  77.     basicAtPut(process, stackTopInProcess, newInteger(10));
  78.     basicAtPut(process, linkPtrInProcess, newInteger(2));
  79.  
  80.     /* put argument on stack */
  81.     basicAtPut(stack, 1, nilobj);    /* argument */
  82.     /* now make a linkage area in stack */
  83.     basicAtPut(stack, 2, nilobj);    /* previous link */
  84.     basicAtPut(stack, 3, nilobj);    /* context object (nil = stack) */
  85.     basicAtPut(stack, 4, newInteger(1));    /* return point */
  86.     basicAtPut(stack, 5, method);    /* method */
  87.     basicAtPut(stack, 6, newInteger(1));    /* byte offset */
  88.  
  89.     /* now go execute it */
  90.     while (execute(process, 15000)) fprintf(stderr,"..");
  91. }
  92.  
  93. /*
  94.     there is a sort of chicken and egg problem with regards to making
  95.     the initial image
  96. */
  97. static makeInitialImage()
  98. {    object hashTable;
  99.     object symbolObj, symbolClass, classClass;
  100.  
  101.     /* first create the table, without class links */
  102.     symbols = allocObject(1);
  103.     incr(symbols);
  104.     hashTable = allocObject(3 * 53);
  105.     basicAtPut(symbols, 1, hashTable);
  106.  
  107.     /* next create #Symbol, Symbol and Class */
  108.     symbolObj = newSymbol("Symbol");
  109.     symbolClass = newClass("Symbol");
  110.     setClass(symbolObj, symbolClass);
  111.     classClass = newClass("Class");
  112.     setClass(symbolClass, classClass);
  113.     setClass(classClass, classClass);
  114.  
  115.     /* now fix up classes for symbol table */
  116.     /* and make a couple common classes, just to hold their places */
  117.     ignore newClass("Link");
  118.     ignore newClass("ByteArray");
  119.     setClass(hashTable, newClass("Array"));
  120.     setClass(symbols, newClass("Dictionary"));
  121.     setClass(nilobj, newClass("UndefinedObject"));
  122.     ignore newClass("String");
  123.     nameTableInsert(symbols, strHash("symbols"), newSymbol("symbols"), symbols);
  124.  
  125.     /* finally at least make true and false to be distinct */
  126.     trueobj = newSymbol("true");
  127.     nameTableInsert(symbols, strHash("true"), trueobj, trueobj);
  128.     falseobj = newSymbol("false");
  129.     nameTableInsert(symbols, strHash("false"), falseobj, falseobj);
  130. }
  131.