Skip to content

Commit

Permalink
Compiles but has dublicated definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nickik committed Jul 14, 2016
1 parent 1a13875 commit db8ab22
Show file tree
Hide file tree
Showing 19 changed files with 1,276 additions and 1,208 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ OBJS+= loader.o
OBJS+= stack.o
OBJS+= slots.o
OBJS+= mps.o
OBJS+= execute.o
OBJS+= vm.o
OBJS+= print.o

all: main

Expand Down
30 changes: 30 additions & 0 deletions alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#include "alloc.h"

// caller needs to make sure to root addr_o before calling this!
// size is the size in bytes (including header)
mps_res_t mps_alloc_obj(mps_addr_t *addr_o,
mps_ap_t ap,
uint32_t size,
uint16_t cljtype,
uint8_t mpstype) {
assert(addr_o != NULL);
assert(size > HEADER_SIZE);
mps_res_t res;

do {
res = mps_reserve(addr_o, ap, size);
if (res != MPS_RES_OK) return res;
struct obj_stub *obj = *addr_o;

obj->type = mpstype;
obj->cljtype = cljtype;
obj->size = size;

// zero all fields
memset(obj->ref, 0, size - HEADER_SIZE);

} while (!mps_commit(ap, *addr_o, size));

return res;
}
19 changes: 19 additions & 0 deletions alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _ALLOC_H_
#define _ALLOC_H_

struct obj_stub {
uint8_t type;
uint8_t _;
uint16_t cljtype;
uint32_t size; // incl. header
mps_addr_t ref[];
} __attribute__((packed));


mps_res_t mps_alloc_obj(mps_addr_t *addr_o,
mps_ap_t ap,
uint32_t size,
uint16_t cljtype,
uint8_t mpstype);

#endif
Loading

0 comments on commit db8ab22

Please sign in to comment.