on master help sign in
Add u8/u16 fields to header, use u8 for marking null strings
7512498Jorge Acereda
config.mk+1−1
@@ -14,7 +14,7 @@ RANLIB ?=ranlib
14CABAL :=cabal
14CABAL :=cabal
15# IDRIS_ENABLE_STATS should not be set in final release
15# IDRIS_ENABLE_STATS should not be set in final release
16# Any flags defined here which alter the RTS API must also be added to src/IRTS/CodegenC.hs
16# Any flags defined here which alter the RTS API must also be added to src/IRTS/CodegenC.hs
17−CFLAGS :=-O2 -Wall -std=c99 -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
17+CFLAGS :=-O2 -Wall -g -std=c99 -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
18
18
19# CABALFLAGS :=
19# CABALFLAGS :=
20CABALFLAGS += --enable-tests
20CABALFLAGS += --enable-tests
rts/idris_rts.c+5−2
@@ -7,6 +7,10 @@
7#include "idris_bitstring.h"
7#include "idris_bitstring.h"
8#include "getline.h"
8#include "getline.h"
9
9
10+#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1]
11+
12+STATIC_ASSERT(sizeof(Hdr) == 8, condSizeOfHdr);
13+
10#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
14#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
11#include <signal.h>
15#include <signal.h>
12#endif
16#endif
@@ -264,8 +268,7 @@ VAL MKFLOAT(VM* vm, double val) {
264VAL MKSTRlen(VM* vm, const char * str, size_t len) {
268VAL MKSTRlen(VM* vm, const char * str, size_t len) {
265 String * cl = allocStr(vm, len, 0);
269 String * cl = allocStr(vm, len, 0);
266 memcpy(cl->str, str, len);
270 memcpy(cl->str, str, len);
267− if (str == NULL)
271+ cl->__null = str == NULL;
268− cl->slen = ~0;
269 return (VAL)cl;
272 return (VAL)cl;
270}
273}
271
274
rts/idris_rts.h+12−7
@@ -29,7 +29,9 @@ typedef enum {
29
29
30
30
31typedef struct Hdr {
31typedef struct Hdr {
32− ClosureType ty;
32+ uint8_t ty;
33+ uint8_t u8;
34+ uint16_t u16;
33 uint32_t sz;
35 uint32_t sz;
34} Hdr;
36} Hdr;
35
37
@@ -70,6 +72,7 @@ typedef struct Float {
70typedef struct String {
72typedef struct String {
71 Hdr hdr;
73 Hdr hdr;
72 size_t slen;
74 size_t slen;
75+#define __null hdr.u8
73 char str[0];
76 char str[0];
74} String;
77} String;
75
78
@@ -231,17 +234,17 @@ typedef void(*func)(VM*, VAL*);
231// Register access
234// Register access
232
235
233#define RVAL (vm->ret)
236#define RVAL (vm->ret)
234−#define LOC(x) (*(vm->valstack_base + (x)))
237+#define LOC(x) (vm->valstack_base[x])
235−#define TOP(x) (*(vm->valstack_top + (x)))
238+#define TOP(x) (vm->valstack_top[x])
236#define REG1 (vm->reg1)
239#define REG1 (vm->reg1)
237
240
238// Retrieving values
241// Retrieving values
239static inline char * getstr(String * x) {
242static inline char * getstr(String * x) {
240− return x->slen == ~0? NULL : x->str;
243+ return x->__null? NULL : x->str;
241}
244}
242
245
243static inline size_t getstrlen(String * x) {
246static inline size_t getstrlen(String * x) {
244− return x->slen == ~0? 0 : x->slen;
247+ return x->slen;
245}
248}
246
249
247#define GETSTR(x) (ISSTR(x) ? getstr((String*)(x)) : GETSTROFF(x))
250#define GETSTR(x) (ISSTR(x) ? getstr((String*)(x)) : GETSTROFF(x))
@@ -265,7 +268,7 @@ static inline size_t getstrlen(String * x) {
265
268
266#define CELEM(x) (((x)->hdr.sz - sizeof(Array)) / sizeof(VAL))
269#define CELEM(x) (((x)->hdr.sz - sizeof(Array)) / sizeof(VAL))
267
270
268−#define GETTY(x) (((x)->hdr.ty))
271+#define GETTY(x) ((ClosureType)((x)->hdr.ty))
269#define SETTY(x,t) ((x)->hdr.ty = t)
272#define SETTY(x,t) ((x)->hdr.ty = t)
270
273
271// Integers, floats and operators
274// Integers, floats and operators
@@ -372,7 +375,9 @@ static inline void updateConF(Con * cl, unsigned tag, unsigned arity) {
372static inline Con * allocConF(VM * vm, unsigned tag, unsigned arity, int outer) {
375static inline Con * allocConF(VM * vm, unsigned tag, unsigned arity, int outer) {
373 size_t sz = sizeof(VAL) * arity;
376 size_t sz = sizeof(VAL) * arity;
374 Con * cl = iallocate(vm, sizeof(*cl) + sz, outer);
377 Con * cl = iallocate(vm, sizeof(*cl) + sz, outer);
375− updateConF(cl, tag, arity);
378+ SETTY(cl, CT_CON);
379+ cl->tag = tag;
380+ cl->arity = arity;
376 return cl;
381 return cl;
377}
382}
378
383