annotate keiko/obcommon.h @ 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 * obcommon.h
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 #ifndef EXTERN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 #define EXTERN extern
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 typedef unsigned char uchar;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 typedef int mybool;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 #define TRUE 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 #define FALSE 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 #ifndef min
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 #define min(x, y) ((x) <= (y) ? (x) : (y))
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 #ifndef max
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 #define max(x, y) ((x) <= (y) ? (y) : (x))
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 #define align(x, k) (((x)+((k)-1)) & ~((k)-1))
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 #ifdef WORDS_BIGENDIAN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 #define align_byte(x) (((unsigned) (x))>>24)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 #define align_short(x) ((x)>>16)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 #else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 #define align_byte(x) (x)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 #define align_short(x) (x)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 #include <stdint.h>
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 typedef int64_t longint;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 typedef union {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 #ifdef WORDS_BIGENDIAN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 struct { int hi, lo; } n;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 #else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 struct { int lo, hi; } n;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 #endif
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 double d;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 longint q;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 } dblbuf;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 /* Stack frame layout */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 #define BP 0 /* Saved base pointer */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 #define PC 1 /* Saved program counter */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 #define CP 2 /* Saved context pointer */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 #define SL -1 /* Static link */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 #define HEAD 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 #define FRAME_SHIFT 16 /* Shift for pointer map of stack frame */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 /* Constant pool layout */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 #define CP_PRIM 0 /* Primitive address (64 bits) */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 #define CP_CODE 1 /* Bytecode address */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 #define CP_SIZE 2 /* Size of bytecode */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 #define CP_FRAME 3 /* Frame size */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 #define CP_STACK 4 /* Stack size */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 #define CP_MAP 5 /* Frame map */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 #define CP_STKMAP 6 /* Stack map table */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 #define CP_CONST 7 /* First constant */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 /* Descriptor layout */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 #define DESC_MAP 0 /* Pointer map */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93 #define DESC_DEPTH 1 /* Inheritance depth of record */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 #define DESC_ANCES 2 /* Ancestor list of record */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 #define DESC_BOUND 1 /* First bound for flex array */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 /* Tokens used in pointer maps: all must be congruent to 2 modulo 4 */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
98 #define GC_BASE 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
99 #define GC_REPEAT 6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
100 #define GC_END 10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
101 #define GC_MAP 14
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
102 #define GC_FLEX 18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
103 #define GC_BLOCK 22
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
104 #define GC_MARK 26
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
105 #define GC_POINTER 30
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
106
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
107 /* Error codes */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
108 #define E_CAST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
109 #define E_ASSIGN 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
110 #define E_CASE 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
111 #define E_WITH 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
112 #define E_ASSERT 5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
113 #define E_RETURN 6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
114 #define E_BOUND 7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
115 #define E_NULL 8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
116 #define E_DIV 9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
117 #define E_FDIV 10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
118 #define E_STACK 11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
119 #define E_GLOB 12