Browse Source

Added C++ include support and created Makefile command to build a shared object.

Brandon Ray 8 years ago
parent
commit
b2e3aa6368
5 changed files with 30 additions and 2 deletions
  1. 1 0
      CONTRIBUTORS
  2. 5 2
      Makefile
  3. 8 0
      src/compiler/gravity_compiler.h
  4. 8 0
      src/runtime/gravity_vm.h
  5. 8 0
      src/shared/gravity_value.h

+ 1 - 0
CONTRIBUTORS

@@ -4,3 +4,4 @@
 Marco Bambini <[email protected]>
 Marco Bambini <[email protected]>
 Saša Barišić  <[email protected]>
 Saša Barišić  <[email protected]>
 Steven Hall   <[email protected]>
 Steven Hall   <[email protected]>
+Brandon Ray   <[email protected]>

+ 5 - 2
Makefile

@@ -11,7 +11,7 @@ SRC = $(wildcard $(COMPILER_DIR)*.c) \
       $(wildcard $(UTILS_DIR)/*.c)
       $(wildcard $(UTILS_DIR)/*.c)
 
 
 INCLUDE = -I$(COMPILER_DIR) -I$(RUNTIME_DIR) -I$(SHARED_DIR) -I$(UTILS_DIR)
 INCLUDE = -I$(COMPILER_DIR) -I$(RUNTIME_DIR) -I$(SHARED_DIR) -I$(UTILS_DIR)
-CFLAGS = $(INCLUDE) -O2 -std=gnu99 -fgnu89-inline
+CFLAGS = $(INCLUDE) -O2 -std=gnu99 -fgnu89-inline -fPIC
 OBJ = $(SRC:.c=.o)
 OBJ = $(SRC:.c=.o)
 
 
 ifeq ($(OS),Windows_NT)
 ifeq ($(OS),Windows_NT)
@@ -38,5 +38,8 @@ gravity:	$(OBJ) $(GRAVITY_SRC)
 
 
 .PHONY: all clean unittest gravity
 .PHONY: all clean unittest gravity
 
 
+lib: gravity
+	$(CC) -shared -o libgravity.so $(OBJ)
+
 clean:
 clean:
-	rm -f $(OBJ) unittest gravity
+	rm -f $(OBJ) unittest gravity libgravity.so

+ 8 - 0
src/compiler/gravity_compiler.h

@@ -15,6 +15,10 @@
 #include "gravity_value.h"
 #include "gravity_value.h"
 #include "gravity_ast.h"
 #include "gravity_ast.h"
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 // opaque compiler data type
 // opaque compiler data type
 typedef struct gravity_compiler_t	gravity_compiler_t;
 typedef struct gravity_compiler_t	gravity_compiler_t;
 
 
@@ -26,4 +30,8 @@ void				gravity_compiler_transfer (gravity_compiler_t *compiler, gravity_vm *vm)
 gnode_t				*gravity_compiler_ast (gravity_compiler_t *compiler);
 gnode_t				*gravity_compiler_ast (gravity_compiler_t *compiler);
 void				gravity_compiler_free (gravity_compiler_t *compiler);
 void				gravity_compiler_free (gravity_compiler_t *compiler);
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 #endif

+ 8 - 0
src/runtime/gravity_vm.h

@@ -12,6 +12,10 @@
 #include "gravity_delegate.h"
 #include "gravity_delegate.h"
 #include "gravity_value.h"
 #include "gravity_value.h"
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef bool (*vm_filter_cb) (gravity_object_t *obj);
 typedef bool (*vm_filter_cb) (gravity_object_t *obj);
 typedef void (*vm_transfer_cb) (gravity_vm *vm, gravity_object_t *obj);
 typedef void (*vm_transfer_cb) (gravity_vm *vm, gravity_object_t *obj);
 typedef void (*vm_cleanup_cb) (gravity_vm *vm);
 typedef void (*vm_cleanup_cb) (gravity_vm *vm);
@@ -65,5 +69,9 @@ gravity_value_t		gravity_vm_get (gravity_vm *vm, const char *key);
 bool				gravity_vm_set (gravity_vm *vm, const char *key, gravity_value_t value);
 bool				gravity_vm_set (gravity_vm *vm, const char *key, gravity_value_t value);
 char				*gravity_vm_anonymous (gravity_vm *vm);
 char				*gravity_vm_anonymous (gravity_vm *vm);
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 #endif
 
 

+ 8 - 0
src/shared/gravity_value.h

@@ -62,6 +62,10 @@
 // gravity_string_t			48
 // gravity_string_t			48
 // gravity_range_t			40
 // gravity_range_t			40
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define GRAVITY_VERSION						"0.2.5"
 #define GRAVITY_VERSION						"0.2.5"
 #define GRAVITY_VERSION_NUMBER				0x000205
 #define GRAVITY_VERSION_NUMBER				0x000205
 #define GRAVITY_BUILD_DATE					__DATE__
 #define GRAVITY_BUILD_DATE					__DATE__
@@ -482,4 +486,8 @@ void				gravity_hash_keyvaluefree (gravity_hash_t *table, gravity_value_t key, g
 void				gravity_hash_keyfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
 void				gravity_hash_keyfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
 void				gravity_hash_valuefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
 void				gravity_hash_valuefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 #endif