annotate keiko/obcommon.h @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
mike@0 1 /*
mike@0 2 * obcommon.h
mike@0 3 *
mike@0 4 * This file is part of the Oxford Oberon-2 compiler
mike@0 5 * Copyright (c) 2006--2016 J. M. Spivey
mike@0 6 * All rights reserved
mike@0 7 *
mike@0 8 * Redistribution and use in source and binary forms, with or without
mike@0 9 * modification, are permitted provided that the following conditions are met:
mike@0 10 *
mike@0 11 * 1. Redistributions of source code must retain the above copyright notice,
mike@0 12 * this list of conditions and the following disclaimer.
mike@0 13 * 2. Redistributions in binary form must reproduce the above copyright notice,
mike@0 14 * this list of conditions and the following disclaimer in the documentation
mike@0 15 * and/or other materials provided with the distribution.
mike@0 16 * 3. The name of the author may not be used to endorse or promote products
mike@0 17 * derived from this software without specific prior written permission.
mike@0 18 *
mike@0 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
mike@0 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
mike@0 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
mike@0 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
mike@0 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
mike@0 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
mike@0 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
mike@0 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
mike@0 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
mike@0 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mike@0 29 */
mike@0 30
mike@0 31 #ifndef EXTERN
mike@0 32 #define EXTERN extern
mike@0 33 #endif
mike@0 34
mike@0 35 typedef unsigned char uchar;
mike@0 36
mike@0 37 typedef int mybool;
mike@0 38 #define TRUE 1
mike@0 39 #define FALSE 0
mike@0 40
mike@0 41 #ifndef min
mike@0 42 #define min(x, y) ((x) <= (y) ? (x) : (y))
mike@0 43 #endif
mike@0 44
mike@0 45 #ifndef max
mike@0 46 #define max(x, y) ((x) <= (y) ? (y) : (x))
mike@0 47 #endif
mike@0 48
mike@0 49 #define align(x, k) (((x)+((k)-1)) & ~((k)-1))
mike@0 50
mike@0 51 #ifdef WORDS_BIGENDIAN
mike@0 52 #define align_byte(x) (((unsigned) (x))>>24)
mike@0 53 #define align_short(x) ((x)>>16)
mike@0 54 #else
mike@0 55 #define align_byte(x) (x)
mike@0 56 #define align_short(x) (x)
mike@0 57 #endif
mike@0 58
mike@0 59 #include <stdint.h>
mike@0 60
mike@0 61 typedef int64_t longint;
mike@0 62
mike@0 63 typedef union {
mike@0 64 #ifdef WORDS_BIGENDIAN
mike@0 65 struct { int hi, lo; } n;
mike@0 66 #else
mike@0 67 struct { int lo, hi; } n;
mike@0 68 #endif
mike@0 69 double d;
mike@0 70 longint q;
mike@0 71 } dblbuf;
mike@0 72
mike@0 73 /* Stack frame layout */
mike@0 74 #define BP 0 /* Saved base pointer */
mike@0 75 #define PC 1 /* Saved program counter */
mike@0 76 #define CP 2 /* Saved context pointer */
mike@0 77 #define SL -1 /* Static link */
mike@0 78 #define HEAD 3
mike@0 79 #define FRAME_SHIFT 16 /* Shift for pointer map of stack frame */
mike@0 80
mike@0 81 /* Constant pool layout */
mike@0 82 #define CP_PRIM 0 /* Primitive address (64 bits) */
mike@0 83 #define CP_CODE 1 /* Bytecode address */
mike@0 84 #define CP_SIZE 2 /* Size of bytecode */
mike@0 85 #define CP_FRAME 3 /* Frame size */
mike@0 86 #define CP_STACK 4 /* Stack size */
mike@0 87 #define CP_MAP 5 /* Frame map */
mike@0 88 #define CP_STKMAP 6 /* Stack map table */
mike@0 89 #define CP_CONST 7 /* First constant */
mike@0 90
mike@0 91 /* Descriptor layout */
mike@0 92 #define DESC_MAP 0 /* Pointer map */
mike@0 93 #define DESC_DEPTH 1 /* Inheritance depth of record */
mike@0 94 #define DESC_ANCES 2 /* Ancestor list of record */
mike@0 95 #define DESC_BOUND 1 /* First bound for flex array */
mike@0 96
mike@0 97 /* Tokens used in pointer maps: all must be congruent to 2 modulo 4 */
mike@0 98 #define GC_BASE 2
mike@0 99 #define GC_REPEAT 6
mike@0 100 #define GC_END 10
mike@0 101 #define GC_MAP 14
mike@0 102 #define GC_FLEX 18
mike@0 103 #define GC_BLOCK 22
mike@0 104 #define GC_MARK 26
mike@0 105 #define GC_POINTER 30
mike@0 106
mike@0 107 /* Error codes */
mike@0 108 #define E_CAST 1
mike@0 109 #define E_ASSIGN 2
mike@0 110 #define E_CASE 3
mike@0 111 #define E_WITH 4
mike@0 112 #define E_ASSERT 5
mike@0 113 #define E_RETURN 6
mike@0 114 #define E_BOUND 7
mike@0 115 #define E_NULL 8
mike@0 116 #define E_DIV 9
mike@0 117 #define E_FDIV 10
mike@0 118 #define E_STACK 11
mike@0 119 #define E_GLOB 12