-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.h
More file actions
103 lines (82 loc) · 1.69 KB
/
Copy pathcode.h
File metadata and controls
103 lines (82 loc) · 1.69 KB
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
#define cmdstr_len 1024
//缓存区
char cmdstr[cmdstr_len];
word *tmp_list[cmdstr_len/4];
word **tmp_lp=tmp_list;
//STACK OPERATE
void bye() {exit(0);}//结束程序
void push(){IP++;DP++;*DP=(cell)*IP;}
void dup(){DP++;*DP=*(DP-1);DEBUG("entering dup")}
void swap(){cell t=*DP; *DP=*(DP-1); *(DP-1)=t;}
void over(){*(DP+1)=*(DP-1);DP++;}
void drop(){DP--;}
//RS
void tor() {RP++;*RP=*DP;DP--;}
void rto() {DP++;*DP=*RP;RP--;}
void rat() {DP++;*DP=*RP;}
//TS
void tot() {TP++;*TP=*DP;DP--;}
void tto() {DP++;*DP=*TP;TP--;}
void tat() {DP++;*DP=*TP;}
//+-*/
void add(){ *(DP-1)=*(DP-1)+(*DP); DP--;}
void sub(){ *(DP-1)=*(DP-1)-(*DP); DP--;}
void mul(){ *(DP-1)=*(DP-1)*(*DP); DP--;}
void divv(){ *(DP-1)=*(DP-1)/(*DP); DP--;}
void words()
{ word*wtmp=dict_head;
do
{
printf("%s ",wtmp->name);
} while(wtmp=wtmp->next);
printf("\n");
}
void ret() {IP=(word**)*RP; RP--;DEBUG("entering ret")}
void dolist()
{
RP++;
*RP=(cell)IP;
IP=(*IP)->wplist-1;
DEBUG("entering dolist")
}
void showDS()
{
printf("DS> ");
for (int *i=DS;i<=DP ;i++ )
printf("%d ",*i);
printf("\n");
/*
printf("tmplist> ");
for (word **j=tmp_list;j<=tmp_lp ;j++ )
printf("%d ",*j);
printf("\n");
//*/
/*
printf("RS> ");
for (cell *k=RS;k<=RP ;k++ )
printf("%d ",*k);
printf("\n");
//*/
}
word * code(char*s, fnp fp)
{
word *w=(word*)malloc(sizeof(word));
w->next=dict_head;
dict_head=w;
w->fn=fp;
w->wplist=NULL;
w->name=s;
return w;
}
void colon(char*s)
{
word *w=(word*)malloc(sizeof(word));
w->next=dict_head;
dict_head=w;
w->fn=dolist;
w->name=(char*)malloc(strlen(s)+1);
strcpy(w->name,s);
int n=(int)tmp_lp-(int)tmp_list;
w->wplist=(word**)malloc(n);
memcpy(w->wplist,tmp_list, n);
}