/
hal.c
146 lines (114 loc) · 2.3 KB
/
hal.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#if 0
COMPILE PRINTF getenv isatty tcgetattr tcsetattr malloc realloc strcasecmp \
atexit memmove strdup strncpy memset memcmp fgetc fgets strcmp fopen \
ipowui strchr feof fclose fstream sscanf fstream itobin nwrite \
nread _snprintf MLVALIST
DUMMYHEADER
MALLOC brk
#GLOBALS
OPTFLAG -Os
STRIPFLAG
#FULLDEBUG
return
#endif
#define error(exp,number,fmt, ...) \
{ fprintf(stderr,"\x1b[1;5;31m" fmt "\x1b[0m" __VA_OPT__(,) __VA_ARGS__);return 0; }
#include "linenoise/linenoise.c"
#include "libcalc.c"
/* since this is sort of retro,
I'm eager to use some retro programming style.
*/
// todo: enter "programs" with linenumbers.
// enter functions also in more lines.
// ( 3*5 RET +7 RET ..)
// nest functions
//
// "config" system: output, base, ..
typedef struct {
char* cmd;
void (*callback)(void);
} _cmd;
void quit(){
printf("Quit\n");
exit(0);
}
void help(){
printsl("\nHelp.\n"
"h - help\n"
"q - quit\n"
);
}
/*
_cmd _commands[] = {
{"q",&quit},
{"h",&_help},
{0,0}
};
*/
typedef struct {
char* cmd;
void (*label)(void);
} cmd;
int main(int argc,char**argv){
static int erg;
static char *l;
static int b;
static expression *exp[32];
static int cf = 0;
static int lf = 0;
argc ? prints(AC_LGREEN"HAL 300 rev.1\nREADY:\n(type help for help)\n\n") :0;
exp[0] = exp[0] ? exp[0]
:new_exp ();
goto HOP;
HOP: // damned gcc
l = 0;
static cmd commands[] = {
{"q",quit},
{"quit",quit},
{"h",help},
{"help",help},
{0,0}
};
while( argc&&main(0,0) );
// replace ret of main with _RET
/*
asm volatile("pop %%rax\n"
".global _RET\n"
"_RET:\n"
"leaq (_RET),%%rax\n"
"push %%rax\n" ::: "rax");
(segfault with optimizing) */
// ********************************** LOOP //
LOOP:
free(l);
l= linenoise("> ");
*l? linenoiseHistoryAdd(l):0;
for ( cmd *c = commands; c->cmd; c++ ){
if ( strcmp(l,c->cmd) == 0 ){
printf("cmd\n");
c->label();
//goto *(c->label);
goto LOOP;
}
}
if ( *l == 'f' ){
if ( *(l+1) == '=' ){
lf++;
cf = lf;
exp[cf] = new_exp();
printf("STORE: f%d\n",cf);
l+=2;
}
}
printf("l: %s\ncf %d\n",l,cf);
parse(l,exp[cf]);
printf("1\n");
erg= calculate( exp[cf] );
printf(AC_LCYAN"\n%d\n0%o\n0x%x\n%b\n"AC_LGREEN, erg,erg,erg,erg);
free(l);
//asm("retq");
//goto LOOP;
return(1);
// childish laughter...
// how not to loop - once.
}