ArchWizard

DGD/

source navigation ]
diff markup ]
identifier search ]
file search ]
Version: [ 1.0.a0 ] [ 1.1 ] [ 1.2 ] [ 1.2p1 ] [ 1.2p2 ] [ 1.2p3 ] [ 1.2p4 ] [ 1.2.151 ]

  1 # include "dgd.h"
  2 # include "str.h"
  3 # include "array.h"
  4 # include "object.h"
  5 # include "xfloat.h"
  6 # include "interpret.h"
  7 # include "data.h"
  8 # include "editor.h"
  9 # include "call_out.h"
 10 # include "comm.h"
 11 # include "node.h"
 12 # include "compile.h"
 13 
 14 static uindex dindex;           /* driver object index */
 15 static Uint dcount;             /* driver object count */
 16 static sector fragment;         /* swap fragment parameter */
 17 static bool swap;               /* are objects to be swapped out? */
 18 static bool dump;               /* is the program to dump? */
 19 bool intr;                      /* received an interrupt? */
 20 static bool stop;               /* is the program to terminate? */
 21 
 22 /*
 23  * NAME:        call_driver_object()
 24  * DESCRIPTION: call a function in the driver object
 25  */
 26 bool call_driver_object(f, func, narg)
 27 frame *f;
 28 char *func;
 29 int narg;
 30 {
 31     object *driver;
 32     char *driver_name;
 33 
 34     if (dindex == UINDEX_MAX || dcount != (driver=OBJR(dindex))->count ||
 35         !(driver->flags & O_DRIVER)) {
 36         driver_name = conf_driver();
 37         driver = o_find(driver_name, OACC_READ);
 38         if (driver == (object *) NULL) {
 39             driver = c_compile(f, driver_name, (object *) NULL);
 40         }
 41         dindex = driver->index;
 42         dcount = driver->count;
 43     }
 44     if (!i_call(f, driver, func, strlen(func), TRUE, narg)) {
 45         fatal("missing function in driver object: %s", func);
 46     }
 47     return TRUE;
 48 }
 49 
 50 /*
 51  * NAME:        swapout()
 52  * DESCRIPTION: indicate that objects are to be swapped out
 53  */
 54 void swapout()
 55 {
 56     swap = TRUE;
 57 }
 58 
 59 /*
 60  * NAME:        dump_state()
 61  * DESCRIPTION: indicate that the state must be dumped
 62  */
 63 void dump_state()
 64 {
 65     dump = TRUE;
 66 }
 67 
 68 /*
 69  * NAME:        interrupt()
 70  * DESCRIPTION: register an interrupt
 71  */
 72 void interrupt()
 73 {
 74     intr = TRUE;
 75 }
 76 
 77 /*
 78  * NAME:        finish()
 79  * DESCRIPTION: indicate that the program must finish
 80  */
 81 void finish()
 82 {
 83     stop = TRUE;
 84 }
 85 
 86 /*
 87  * NAME:        endthread()
 88  * DESCRIPTION: clean up after a thread has terminated
 89  */
 90 void endthread()
 91 {
 92     comm_flush();
 93     if (ext_cleanup != (void (*) P((void))) NULL) {
 94         (*ext_cleanup)();
 95     }
 96     d_export();
 97     o_clean();
 98     i_clear();
 99     ed_clear();
100     ec_clear();
101 
102     if (fragment != 0) {
103         co_swapcount(d_swapout(fragment));
104     }
105 
106     if (stop) {
107         if (ext_finish != (void (*) P((void))) NULL) {
108             (*ext_finish)();
109         }
110         comm_finish();
111         ed_finish();
112 # ifdef DEBUG
113         swap = 1;
114 # endif
115     }
116 
117     if (swap || !m_check()) {
118         /*
119          * swap out everything and possibly extend the static memory area
120          */
121         d_swapout(1);
122         arr_freeall();
123         m_purge();
124         swap = FALSE;
125     }
126 
127     if (dump) {
128         /*
129          * create a state dump
130          */
131         d_swapsync();
132         conf_dump();
133         dump = FALSE;
134     }
135 
136     if (stop) {
137         sw_finish();
138         m_finish();
139         exit(0);
140     }
141 }
142 
143 /*
144  * NAME:        errhandler()
145  * DESCRIPTION: default error handler
146  */
147 void errhandler(f, depth)
148 frame *f;
149 Int depth;
150 {
151     i_runtime_error(f, (Int) 0);
152 }
153 
154 /*
155  * NAME:        dgd_main()
156  * DESCRIPTION: the main loop of DGD
157  */
158 int dgd_main(argc, argv)
159 int argc;
160 char **argv;
161 {
162     bool swrebuild;
163     Uint timeout;
164     unsigned short mtime;
165 
166     if (argc < 2 || argc > 3) {
167         P_message("Usage: dgd config_file [dump_file]\012");    /* LF */
168         return 2;
169     }
170 
171     /* initialize */
172     dindex = UINDEX_MAX;
173     swap = dump = intr = stop = FALSE;
174     if (!conf_init(argv[1], (argc == 3) ? argv[2] : (char *) NULL, &fragment)) {
175         return 2;       /* initialization failed */
176     }
177 
178     for (;;) {
179         /* interrupts */
180         if (intr) {
181             intr = FALSE;
182             if (ec_push((ec_ftn) errhandler)) {
183                 endthread();
184             } else {
185                 call_driver_object(cframe, "interrupt", 0);
186                 i_del_value(cframe->sp++);
187                 ec_pop();
188                 endthread();
189             }
190         }
191 
192         /* rebuild swapfile */
193         swrebuild = sw_copy();
194 
195         /* handle user input */
196         timeout = co_delay(&mtime);
197         if (swrebuild &&
198             (mtime == 0xffff || timeout > 1 || (timeout == 1 && mtime != 0))) {
199             /*
200              * wait no longer than one second if the swapfile has to be
201              * rebuilt
202              */
203             timeout = 1;
204             mtime = 0;
205         }
206         comm_receive(cframe, timeout, mtime);
207 
208         /* callouts */
209         co_call(cframe);
210     }
211 }
212 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.