From 7d5661f98adba08cf3c28ad6294cc91826de8338 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Wed, 27 May 2015 16:05:19 -0400 Subject: [PATCH] Added some base objects to the world --- Makefile | 1 + source/main.c | 2 ++ source/world.c | 43 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4bef298..e481cda 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ LD = $(CC) MAKEDEPEND = $(CPP) -M $(CPPFLAGS) -o $< CCDEPGEN = -MMD -MF $*.d CFLAGS = -Wall -Wextra -O3 --std=c99 --pedantic $(addprefix -I,$(INCLUDES)) +LDFLAGS = -static -include $(SOURCES:.c=.d) diff --git a/source/main.c b/source/main.c index fb5bcef..62fcc7a 100644 --- a/source/main.c +++ b/source/main.c @@ -219,6 +219,8 @@ static void hashmap(void) { /*****************************************************************************/ int main(int argc, char** argv) { + extern void world_init(void); + world_init(); printf(":> "); while(true) { expression(); diff --git a/source/world.c b/source/world.c index de7f18b..3f6c6f7 100644 --- a/source/world.c +++ b/source/world.c @@ -4,29 +4,56 @@ */ //#include "world.h" +#include "set.h" #include "map.h" -typedef struct { - map_t* parent; - map_t* self; - uint8_t data[]; +typedef struct object_t { + struct object_t* parent; + map_t* slots; + uint8_t value[]; } object_t; +set_t* Selectors = NULL; +object_t* Lobby = NULL; +object_t* Object = NULL; +object_t* Number = NULL; +object_t* String = NULL; +object_t* Array = NULL; +object_t* ByteArray = NULL; +object_t* HashSet = NULL; +object_t* HashMap = NULL; + void object_free(void* obj) { object_t* object = (object_t*)obj; if (object->parent) mem_release(object->parent); - if (object->self) - mem_release(object->self); + if (object->slots) + mem_release(object->slots); } object_t* object_clone(object_t* parent) { object_t* obj = (object_t*)mem_allocate(sizeof(object_t), &object_free); - obj->parent = (NULL == parent) ? NULL : mem_retain(parent->self); - obj->self = map_new(NULL, NULL); + if (NULL != parent) + mem_retain(parent); + obj->parent = parent; + obj->slots = map_new(NULL, NULL); return obj; } +void world_init(void) +{ + Selectors = set_new(NULL, NULL); + Lobby = object_clone(NULL); + Object = object_clone(Lobby); + Number = object_clone(Object); + String = object_clone(Object); + Array = object_clone(Object); + ByteArray = object_clone(Object); + HashSet = object_clone(Object); + HashMap = object_clone(Object); +} + + -- 2.54.0