annotate keiko/iskel.c @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 /*
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 * iskel.c
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 * This file is part of the Oxford Oberon-2 compiler
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 * Copyright (c) 2006--2016 J. M. Spivey
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 * All rights reserved
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 * modification, are permitted provided that the following conditions are met:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 * 1. Redistributions of source code must retain the above copyright notice,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 * this list of conditions and the following disclaimer.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 * this list of conditions and the following disclaimer in the documentation
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 * and/or other materials provided with the distribution.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 * 3. The name of the author may not be used to endorse or promote products
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 * derived from this software without specific prior written permission.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 /* This file is the skeleton of the bytecode interpreter; the parts
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 specific to each instruction are inserted from the file
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 'keiko.iset' by the script 'iset.tcl'. There are three places that
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 code is inserted, each marked by two dollar signs. In order of
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 appearance, they are:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 1. A jump table for quick dispatching (used if JTABLE is defined).
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 2. Macro definitions used in the action routines.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 3. Action routines for each instruction, forming the cases in a big
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 switch. */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 #include <math.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 #include "obx.h"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 #include "keiko.h"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 #ifdef HAVE_INDEXED_JUMPS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 #define JTABLE 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 #ifdef TRACE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 #define DISASS 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 #undef JTABLE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 #define do_find_proc if (dflag > 1) thisproc = find_proc(cp)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 #else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 #define do_find_proc
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 #ifdef PROFILE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 #undef JTABLE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 $$ macro definitions
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 /* interp -- main loop of the interpreter */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 void interp(value *sp0) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 register value *cp = valptr(sp0[CP]);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 uchar *pc = pointer(cp[CP_CODE]);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 register uchar *pc0 = NULL;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 register value *sp = sp0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 register uchar ir = 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 #ifdef PROFILE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 register counter ticks = 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 register value *bp = NULL;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 value *base = sp0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 #ifdef TRACE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 proc thisproc = NULL;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 #ifdef JTABLE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 /* Save time by using gcc's label array feature */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 static void *jtable[256] = {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 $$ jump table
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 };
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 #ifdef JTABLE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 /* Each action ends with an indexed jump to the next */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 #define ACTION(op) lbl_ ## op:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 #define ALSO(op)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93 #define DEFAULT
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 #define NEXT goto *jtable[ir = *(pc0 = pc)]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 #else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 /* Actions are just cases in a big switch */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 #define ACTION(op) case K_ ## op:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
98 #define ALSO(op) case K_ ## op:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
99 #define DEFAULT default:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
100 #define NEXT break
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
101 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
102
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
103 level++;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
104 do_find_proc;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
105
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
106 #ifdef PROFILE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
107 prof_enter(cp, 0, PROF_CALL);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
108 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
109
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
110 frame();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
111
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
112 #ifdef JTABLE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
113 NEXT;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
114 #else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
115 while (TRUE) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
116 #ifdef TRACE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
117 if (dflag > 1) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
118 printf("pc=%s+%ld(%p) sp=%p bp=%p cp=%p",
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
119 thisproc->p_name,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
120 (long) (pc - (uchar *) pointer(cp[CP_CODE])),
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
121 pc, sp, bp, cp);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
122 fflush(stdout);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
123 for (int i = 0; i < 8; i++) printf(" %x", sp[i].i);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
124 printf("\n");
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
125 printf("%6ld: %s\n", (long) (pc-imem), fmt_inst(pc));
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
126 fflush(stdout);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
127 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
128 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
129
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
130 #ifdef PROFILE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
131 ticks++;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
132 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
133
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
134 switch (ir = *(pc0 = pc)) {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
135 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
137 $$ action routines
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
138
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
139 ACTION(ILLEGAL)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
140 DEFAULT
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
141 panic("*illegal instruction %d", ir);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
142 #ifndef JTABLE
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
143 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
144 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
145 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
146 }