diff --git a/.idea/tyche.iml b/.idea/tyche.iml
index c52a66d..9f4c130 100644
--- a/.idea/tyche.iml
+++ b/.idea/tyche.iml
@@ -1,6 +1,2 @@
-
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 03371ea..5a625cf 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,14 @@
+#
# user overwritable variables
+#
+# install prefix
PREFIX=/usr/local
+#
+# internal flags/options
+#
+
# version
VERSION_MAJOR=0
@@ -9,10 +16,6 @@ VERSION_MINOR=1
VERSION=${VERSION_MAJOR}.${VERSION_MINOR}
-#
-# flags/options
-#
-
IS_CLANG := $(shell $(CC) -dM -E - < /dev/null | grep -c __clang__)
WARNINGS=@config/WARNINGS
@@ -25,13 +28,14 @@ else
endif
DEBUG_CFLAGS=-Og -ggdb3 ${WARNINGS} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=leak \
- -fno-sanitize-recover=all -fstack-protector-strong -fstack-clash-protection -fno-common ${ADD_DBG_FLAGS}
+ -fno-sanitize-recover=all -fstack-protector-strong -fstack-clash-protection -fno-common ${ADD_DBG_FLAGS} \
+ -DCHECK_TYCHE_BUGS=1
DEBUG_LDFLAGS=-fsanitize=address
RELEASE_CFLAGS=-O3 -flto=auto -march=native -mtune=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong
RELEASE_LDFLAGS=-flto=auto
-CFLAGS+=-std=c99 -fPIC -fvisibility=hidden -MMD -MP
+CFLAGS+=-std=c11 -fPIC -fvisibility=hidden
LDFLAGS+=
#
@@ -60,6 +64,13 @@ uninstall:
.PHONY: all check clean install uninstall
+#
+# intermediate rules
+#
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
#
# executable files
#
@@ -68,6 +79,7 @@ tyche: CFLAGS += ${RELEASE_CFLAGS}
tyche: LDFLAGS += ${RELEASE_LDFLAGS}
tyche: src/tyche.o libtyche.a
$(CC) -o $@ $^ ${LDFLAGS}
+ strip $@
tyche-test: CFLAGS += ${DEBUG_CFLAGS}
tyche-test: LDFLAGS += ${DEBUG_LDFLAGS}
@@ -79,6 +91,4 @@ libtyche.a: lib/vm.o
libtyche.so.${VERSION}: LDFLAGS += ${RELEASE_LDFLAGS}
libtyche.so.${VERSION}: lib/vm.o
- $(CC) -shared -o $@ -Wl,-soname,libfoo.so.${VERSION_MAJOR} $^ ${LDFLAGS}
-
--include $(wildcard src/*.d lib/*.d)
\ No newline at end of file
+ $(CC) -shared -o $@ -Wl,-soname,libfoo.so.${VERSION_MAJOR} $^ ${LDFLAGS}
\ No newline at end of file
diff --git a/TODO.md b/TODO.md
index f7d3955..b0995c6 100644
--- a/TODO.md
+++ b/TODO.md
@@ -6,10 +6,11 @@ Decisions:
- Transparency and log levels
- [ ] Makefile
-- [ ] Value and stack value
+- [ ] VALUE
- [ ] Stack
- [ ] Test application (C++?)
- [ ] Heap
+ - [ ] Heap value
- [ ] VM
- [ ] (Lua interface) call assembler
- [ ] (Lua) generate bytecode
diff --git a/lib/stack.c b/lib/stack.c
new file mode 100644
index 0000000..67c0f4b
--- /dev/null
+++ b/lib/stack.c
@@ -0,0 +1,2 @@
+#include "value.c"
+
diff --git a/lib/tyche.h b/lib/tyche.h
index a2307cd..f730485 100644
--- a/lib/tyche.h
+++ b/lib/tyche.h
@@ -1,4 +1,8 @@
#ifndef TYCHE_TYCHE_H
#define TYCHE_TYCHE_H
+typedef enum {
+ TT_NIL, TT_INTEGER, TT_REAL, TT_STRING, TT_STRING_CONST, TT_ARRAY, TT_TABLE, TT_FUNCTION, TT_NATIVE_PTR,
+} TYC_TYPE;
+
#endif //TYCHE_TYCHE_H
diff --git a/lib/value.c b/lib/value.c
new file mode 100644
index 0000000..3a1e178
--- /dev/null
+++ b/lib/value.c
@@ -0,0 +1,62 @@
+#include "tyche.h"
+
+#include
+#include
+#include
+
+typedef struct {
+ TYC_TYPE type;
+ union {
+ int32_t i;
+ float f;
+ uint32_t idx;
+ };
+} VALUE;
+
+static_assert(sizeof(VALUE) <= 8, "VALUE must be < 8 bytes");
+
+static int32_t value_integer(VALUE v)
+{
+#ifdef CHECK_TYCHE_BUGS
+ if (v.type != TT_INTEGER)
+ abort();
+#endif
+ return v.i;
+}
+
+static float value_real(VALUE v)
+{
+#ifdef CHECK_TYCHE_BUGS
+ if (v.type != TT_REAL)
+ abort();
+#endif
+ return v.f;
+}
+
+static uint32_t value_idx(VALUE v)
+{
+#ifdef CHECK_TYCHE_BUGS
+ if (v.type != TT_FUNCTION && v.type != TT_NATIVE_PTR && v.type != TT_ARRAY && v.type != TT_TABLE && v.type != TT_STRING && v.type != TT_STRING_CONST)
+ abort();
+#endif
+ return v.idx;
+}
+
+VALUE create_value_integer(int32_t v)
+{
+ return (VALUE) { .type = TT_INTEGER, .i = v };
+}
+
+VALUE create_value_real(float f)
+{
+ return (VALUE) { .type = TT_INTEGER, .f = f };
+}
+
+VALUE create_value_idx(TYC_TYPE type, uint32_t idx)
+{
+#ifdef CHECK_TYCHE_BUGS
+ if (type != TT_FUNCTION && type != TT_NATIVE_PTR && type != TT_ARRAY && type != TT_TABLE && type != TT_STRING && type != TT_STRING_CONST)
+ abort();
+#endif
+ return (VALUE) { .type = type, .idx = idx };
+}
\ No newline at end of file