-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucode.c
executable file
·54 lines (43 loc) · 1.47 KB
/
ucode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*************************************************************************
* ucode.c
* Driver for the uMachine emulator.
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "umach.h"
#include "uload.h"
#include "uexec.h"
#include "uconfig.h"
/* External interface to FLEX */
extern FILE *yyin;
/* External interface to the uMachine */
extern uINSTRUCTION uCode [codeSize];
extern int uLabel[labelCount];
/* Main routine */
int main(int argc, char *argv[])
{
/* Check command line parameters */
if (argc != 2) {
fprintf(stderr, "correct usage: %s <filename>\n", argv[0]);
return 1;
}
processConfigFile();
/* Open the source file (attaching to external yyin) */
if ((yyin = fopen(argv[1], "r")) == (FILE *) NULL) {
fprintf(stderr, ">>>ERROR - CANNOT OPEN SOURCE FILE\n");
fprintf(stderr, " CHECK THAT %s EXISTS\n", argv[1]);
return 2;
}
/* Attempt to load and execute the program */
fprintf(stdout, " uMachine Interpreter \n");
fprintf(stdout, " (-*-) [VERSION 2.0DV] (-*-) \n");
fprintf(stdout, "-------------------------------\n");
uReset();
if (uLoad(uCode, uLabel)) {
uExecute(uCode, uLabel);
}
fprintf(stdout, "-------------------------------\n");
fprintf(stdout, " (-*-) [VERSION 2.0DV] (-*-) \n");
fprintf(stdout, " uMachine Interpreter \n");
return 0;
}