Skip to content

Commit

Permalink
Code cleanup and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoNex committed Feb 9, 2024
1 parent 7685a0a commit 7d34193
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 20 deletions.
2 changes: 0 additions & 2 deletions internal/obj/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static struct object input_b(struct object *args, size_t len) {
tmp = getchar();
char *reinput = realloc(input, ilen + 1);
if (reinput == NULL) {
free(input);
return errorf("input: error allocating memory");
}
input = reinput;
Expand Down Expand Up @@ -528,7 +527,6 @@ static struct object bytes_b(struct object *args, size_t len) {

for (uint32_t i = 0; i < len; i++) {
if (list[i].type != obj_integer) {
free(b);
return errorf("bytes: list cannot be converted to bytes");
}
b[i] = list[i].data.i;
Expand Down
8 changes: 0 additions & 8 deletions internal/obj/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ static inline void _map_delete(struct map_node **root, struct map_node **n, stru
}
}

static inline void _map_dispose(struct map_node * restrict n) {
if (n != NULL) {
if (n->l != NULL) _map_dispose(n->l);
if (n->r != NULL) _map_dispose(n->r);
free(n);
}
}

static inline void _map_keys(struct map_node * restrict n, struct list *list) {
if (n != NULL) {
list->list[list->len++] = n->val.key;
Expand Down
6 changes: 2 additions & 4 deletions internal/obj/object.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package obj

// #cgo CFLAGS: -Ofast -Ilibffi/include
// #cgo LDFLAGS: -Llibffi/lib ${SRCDIR}/libffi/lib/libffi.a -lm
// #cgo LDFLAGS: -Llibffi/lib ${SRCDIR}/libffi/lib/libffi.a -lm -L${SRCDIR}/../vm/bdwgc/lib ${SRCDIR}/../vm/bdwgc/lib/libgc.a
// #include <stdio.h>
// #include <stdlib.h>
// #include <stdint.h>
Expand Down Expand Up @@ -130,9 +130,7 @@ func (o Object) TypeString() string {
}

func (o Object) String() string {
cstr := C.object_str(o)
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr)
return C.GoString(C.object_str(o))
}

func (o Object) Int() int64 {
Expand Down
1 change: 0 additions & 1 deletion internal/obj/pipe.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <stdlib.h>
#include <stdio.h>
#include "object.h"
#include "../vm/gc.h"
Expand Down
1 change: 0 additions & 1 deletion internal/obj/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ char *object_str(struct object o) {
void print_obj(struct object o) {
char *str = object_str(o);
puts(str);
free(str);
}
1 change: 0 additions & 1 deletion internal/tau_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (tt TauTest) run(t *testing.T) {
if err := fn(tvm.LastPoppedStackObj()); err != nil {
t.Fatal(err)
}
tvm.Free()
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/vm/gc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define GC_THREADS
#include "bdwgc/include/gc.h"
#include "bdwgc/include/gc/gc.h"

#define malloc(n) GC_MALLOC(n)
#define calloc(m, n) GC_MALLOC((m)*(n))
Expand Down
2 changes: 0 additions & 2 deletions internal/vm/vm.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <setjmp.h>
#include <threads.h>

#include "vm.h"
#include "opcode.h"
Expand Down

0 comments on commit 7d34193

Please sign in to comment.