w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Builtin.c
Go to the documentation of this file.
1 
2 #include "obx.h"
3 #include <ctype.h>
4 #include <math.h>
5 #include <string.h>
6 
7 char *lib_version =
8  "Oxford Oberon-2 library version 3.2beta1 [build hg-f2fdbc915d42]";
9 
11  word desc = bp[HEAD+0].a;
12  int size = bp[HEAD+1].i+4;
13  value *sp = bp;
14  word p = gc_alloc(size, bp);
15  value *q = ptrcast(value, p);
16  q[0].a = desc;
17  (*--sp).a = p+4;
18  return sp;
19 }
20 
21 /*
22 Layout for flexible arrays:
23 
24 q: desc
25 
26  element 0
27  ...
28  element n-1
29 
30 desc: map desc = q + align(n*elsize) + 4
31  dim 1
32  ...
33  dim k
34 
35 map: -4
36  desc-(q+4)
37 [ GC_REPEAT if elmap != 0
38  0
39  n
40  elsize
41  GC_MAP
42  elmap
43  GC_END ]
44  GC_END
45 
46 size = align(n*elsize) + 4*k + 20 + (28 if elmap != 0)
47 
48 Parameters NEWFLEX(elmap, elsize, k: INTEGER;
49  dim_0, ..., dim_{k-1}: INTEGER): SYSTEM.PTR
50 */
51 
53  word elmap = bp[HEAD+0].a;
54  int elsize = bp[HEAD+1].i;
55  int k = bp[HEAD+2].i;
56  value *dim = &bp[HEAD+3]; /* Array of bounds */
57  value *sp = bp;
58 
59  int size, arsize, i, n;
60  word p, desc, map;
61  value *q, *pdesc, *pmap;
62 
63  /* Compute no. of elements */
64  n = 1;
65  for (i = 0; i < k; i++) n *= dim[i].i;
66  if (n < 0) liberror("allocating negative size");
67  arsize = align(n * elsize, 4);
68  if (n == 0) elmap = 0;
69 
70  /* Allocate the space */
71  size = arsize + 4*k + 20;
72  if (elmap != 0) size += 28;
73 
74  p = gc_alloc(size, bp);
75  desc = p + arsize + 4;
76  map = desc + 4*k + 4;
77 
78  q = ptrcast(value, p);
79  pdesc = ptrcast(value, desc);
80  pmap = ptrcast(value, map);
81  q[0].a = desc;
82 
83  /* Fill in the descriptor */
84  pdesc[DESC_MAP].a = map;
85  for (i = 0; i < k; i++) pdesc[DESC_BOUND+i].i = dim[i].i;
86 
87  /* Fill in the map */
88  pmap[0].i = -4;
89  pmap[1].i = desc-(p+4);
90  if (elmap == 0)
91  pmap[2].i = GC_END;
92  else {
93  pmap[2].i = GC_REPEAT;
94  pmap[3].i = 0;
95  pmap[4].i = n;
96  pmap[5].i = elsize;
97  pmap[6].i = GC_MAP;
98  pmap[7].i = elmap;
99  pmap[8].i = GC_END;
100  pmap[9].i = GC_END;
101  }
102 
103  (*--sp).a = p+4;
104  return sp;
105 }
106 
108  uchar *s1 = pointer(bp[HEAD+0]), *s2 = pointer(bp[HEAD+2]);
109  int i = 0, n = min(bp[HEAD+1].i, bp[HEAD+3].i);
110  value *sp = bp;
111 
112  while (i < n && s1[i] != '\0' && s1[i] == s2[i]) i++;
113  if (i >= n) liberror("string is not null-terminated");
114  (*--sp).i = s1[i] - s2[i];
115  return sp;
116 }
117 
119  obcopy((char * ) pointer(bp[HEAD+2]), bp[HEAD+3].i,
120  (char * ) pointer(bp[HEAD+0]), bp[HEAD+1].i, bp);
121  return bp;
122 }
123 
125  int size = bp[HEAD+0].i;
126  int dim = bp[HEAD+1].i;
127  uchar *src = pointer(bp[HEAD+2]), *dst = pointer(bp[HEAD+dim+3]);
128  value *sbound = &bp[HEAD+3], *dbound = &bp[HEAD+dim+4];
129  int i;
130 
131  for (i = 0; i < dim; i++) {
132  int sb = sbound[i].i, db = dbound[i].i;
133  if (sb > db || (i > 0 && sb < db))
134  liberror("bound mismatch in open array assignment");
135  size *= sb;
136  }
137 
138  memmove(dst, src, size);
139  return bp;
140 }
141 
143  memmove(pointer(bp[HEAD+1]), pointer(bp[HEAD+0]), bp[HEAD+2].i);
144  return bp;
145 }
146 
148  value *bp1 = valptr(bp[BP]);
149  error_stop((char * ) pointer(bp[HEAD+0]), 0, 0, bp1, NULL);
150  return bp;
151 }
152 
154  int line = bp[HEAD+0].i;
155  int arg = bp[HEAD+1].i;
156  value *bp1 = valptr(bp[BP]);
157  uchar *pc = pointer(bp[PC]);
158  error_stop("assertion failed (%d)", arg, line, bp1, pc);
159  return bp;
160 }
value * EASSERT(value *bp)
Definition: Builtin.c:153
value * FLEXASSIGN(value *bp)
Definition: Builtin.c:124
value * sys_liberror(value *bp)
Definition: Builtin.c:147
value * NEWFLEX(value *bp)
Definition: Builtin.c:52
char * lib_version
Definition: Builtin.c:7
value * COPY(value *bp)
Definition: Builtin.c:118
value * sys_move(value *bp)
Definition: Builtin.c:142
value * NEW(value *bp)
Definition: Builtin.c:10
value * COMPARE(value *bp)
Definition: Builtin.c:107
bp
Definition: action.c:1035
q
Definition: afm2pl.c:2287
#define n
Definition: t4ht.c:1290
long pc
Definition: disdvi.c:114
#define bp1
#define a(n)
Definition: gpos-common.c:148
#define memmove(d, s, n)
Definition: gsftopk.c:65
unsigned long dim
Definition: hpcdtoppm.c:62
unsigned char uchar
Definition: unzcrash.c:37
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
#define align(x, k)
Definition: obcommon.h:49
#define GC_MAP
Definition: obcommon.h:101
#define DESC_MAP
Definition: obcommon.h:92
#define PC
Definition: obcommon.h:75
#define DESC_BOUND
Definition: obcommon.h:95
#define BP
Definition: obcommon.h:74
#define GC_REPEAT
Definition: obcommon.h:99
#define GC_END
Definition: obcommon.h:100
#define pointer(v)
Definition: obx.h:58
void error_stop(const char *msg, int val, int line, value *bp, uchar *pc)
Definition: xmain.c:222
#define ptrcast(t, a)
Definition: obx.h:69
#define valptr(v)
Definition: obx.h:57
#define liberror(msg)
Definition: obx.h:265
void obcopy(char *dst, int dlen, const char *src, int slen, value *bp)
Definition: support.c:222
int k
Definition: otp-parser.c:70
#define min(a, b)
Definition: pbmplus.h:223
unsigned short word
Definition: picttoppm.c:64
const char * desc
Definition: pkgdata.cpp:136
static int size
Definition: ppmlabel.c:24
int db
Definition: ppmqvga.c:68
#define map
Definition: tables.h:296
Definition: bdf.c:133
s1
Definition: t4ht.c:1059
char * s2
Definition: t4ht.c:1062
#define sp
Definition: stack.c:11
Definition: obx.h:51
word a
Definition: obx.h:54
int i
Definition: obx.h:52
word gc_alloc(unsigned size, value *sp)
Definition: gc.c:812