comparison interps/egobch/src/optimize.c @ 996:859f9b4339e6

<Gregor> tar xf egobot.tar.xz
author HackBot
date Sun, 09 Dec 2012 19:30:08 +0000
parents
children
comparison
equal deleted inserted replaced
995:6883f5911eb7 996:859f9b4339e6
1 /*
2 * Copyright (C) 2005 Gregor Richards
3 *
4 * This file is part of EgoBCh.
5 *
6 * EgoBCh is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * EgoBCh is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with EgoBCh; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "egobch.h"
22 #include "optimize.h"
23
24 void optimize()
25 {
26 /* optimize a segment of code */
27 int a;
28 struct bchi *cur;
29
30 while (iprog[ipptr]) {
31 cur = prog + pptr;
32
33 switch (iprog[ipptr]) {
34 case '}':
35 cur->cmd = RTGL;
36 ipptr++;
37 pptr++;
38 break;
39
40 case '<':
41 cur->cmd = LFT;
42 ipptr++;
43 pptr++;
44 break;
45
46 case '[':
47 a = pptr;
48 ipptr++;
49 pptr++;
50
51 /* run a suboptimize */
52 optimize();
53
54 cur->cmd = LPO;
55 cur->arg1 = pptr;
56
57 cur = prog + pptr;
58 cur->cmd = LPC;
59 cur->arg1 = a;
60
61 ipptr++;
62 pptr++;
63 break;
64
65 case ']':
66 /* let the above run */
67 return;
68
69 case '.':
70 if (lazy_io) {
71 cur->cmd = OUT;
72 pptr++;
73 }
74 ipptr++;
75 break;
76
77 case ',':
78 if (lazy_io) {
79 cur->cmd = INP;
80 pptr++;
81 }
82 ipptr++;
83 break;
84
85 case '#':
86 if (debug) {
87 cur->cmd = DBG;
88 pptr++;
89 }
90 ipptr++;
91 break;
92
93 default:
94 ipptr++;
95 break;
96 }
97 }
98
99 /* we're done, make a fin */
100 prog[pptr].cmd = FIN;
101 pptr = 0;
102 }