@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -I$(SRC) $(OBJECTS) $(LIBS) -o $@
-.PHONY: parsedebug optimized dev
+.PHONY: parsedebug optimized dev profile
parsedebug: CFLAGS += -DPARSEDEBUG
parsedebug: clean build/a.out
optimized: CFLAGS=-Wall -O3 -flto
optimized: clean build/a.out
+profile: CFLAGS=-Wall -O3 -flto -pg
+profile: clean build/a.out
+
dev: clean build/a.out
$(OBJ)/%.o: $(SRC)/%.c
#include <stdarg.h>
-#define BY_LET 1
-#define BY_DEF 2
-#define BY_PARAM 3
-
typedef struct varmapentry {
const char *name;
usize name_len;
}
}
+void sbInteger_retain(hInteger a) {
+ if (is_bigint(a)) {
+ bigint *big = find_bigint_for_handle(a);
+ big->gcinfo.refcount ++;
+ }
+}
+
+void sbInteger_release(hInteger a) {
+ if (is_bigint(a)) {
+ bigint *big = find_bigint_for_handle(a);
+ big->gcinfo.refcount --;
+ }
+}
+
hInteger sbInteger_sum(hInteger a, hInteger b) {
if (!is_bigint(a) && !is_bigint(b)) {
return sbInteger_new(a + b);
hInteger sbInteger_new(i64 value);
+void sbInteger_retain(hInteger a);
+
+void sbInteger_release(hInteger a);
+
hInteger sbInteger_sum(hInteger a, hInteger b);
hInteger sbInteger_diff(hInteger a, hInteger b);
#include "data/string.h"
#include "data/list.h"
#include "data/hashtable.h"
+#include "data/integer.h"
#define FLAG_NONINTRINSIC (1ULL << 63)
* because they are trivially copiable. some classes (integer, string) need
* to sometimes be retained but sometimes not, so we delegate to them to
* figure out if they need to or not. */
- if (a->type == IT_STRING) {
- sbString_clone(a->string);
+ switch (a->type) {
+ case IT_STRING:
+ sbString_clone(a->string);
+ break;
+ case IT_INTEGER:
+ sbInteger_retain(a->string);
+ break;
+ default:
+ /* nothing */
}
}
void sbV_release(const hV *a) {
- if (a->type == IT_STRING) {
- sbString_release(a->string);
+ switch (a->type) {
+ case IT_STRING:
+ sbString_release(a->string);
+ break;
+ case IT_INTEGER:
+ sbInteger_release(a->string);
+ break;
+ default:
+ /* nothing */
}
}
}
void push_stack(hVm vm, hV *value) {
- sbV_retain(value);
*(hV**)vm->vsp = value;
vm->vsp += sizeof(hV*);
vm->xsp += sizeof(hV);
void push_stack_immediate(hVm vm, const hV *value) {
/* save it on our own stack */
- sbV_retain(value);
*(hV*)vm->xsp = *value;
*(hV**)vm->vsp = (hV*)vm->xsp;
vm->vsp += sizeof(hV*);
hV *pop_stack(hVm vm) {
vm->vsp -= sizeof(hV*);
vm->xsp -= sizeof(hV);
- sbV_release(*(hV**)vm->vsp);
return *(hV**)vm->vsp;
}
hV *npop_stack(hVm vm, usize count) {
vm->vsp -= count * sizeof(hV*);
vm->xsp -= count * sizeof(hV);
- for (usize i = 0; i < count; i++) {
- sbV_release(((hV**)vm->vsp)[i]);
- }
return *(hV**)vm->vsp;
}