mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-12 04:58:18 +03:00
cleaned up in shared.h
This commit is contained in:
parent
f431fe72b5
commit
068caedd23
@ -25,10 +25,6 @@
|
||||
(while true
|
||||
(println "eternal")))
|
||||
|
||||
(defn nullf ()
|
||||
(let [x (fake)]
|
||||
(null? x)))
|
||||
|
||||
(defn slimmer (x s)
|
||||
(+ x (* (strlen s) (- x 1))))
|
||||
|
||||
|
@ -1,4 +1,47 @@
|
||||
|
||||
;; typedef string* string_array;
|
||||
|
||||
;; EXPORT string_array string_array_new(int size) {
|
||||
;; string_array a = calloc(size + 1, sizeof(string));
|
||||
;; for(int i = 0; i < size; i++) {
|
||||
;; a[i] = strdup("");
|
||||
;; }
|
||||
;; return a;
|
||||
;; }
|
||||
|
||||
;; EXPORT int string_array_count(string_array array) {
|
||||
;; int i = 0;
|
||||
;; string_array p = array;
|
||||
;; while(*p) {
|
||||
;; i++;
|
||||
;; p++;
|
||||
;; }
|
||||
;; return i;
|
||||
;; }
|
||||
|
||||
;; EXPORT string string_array_get(string_array array, int pos) {
|
||||
;; return strdup(array[pos]);
|
||||
;; }
|
||||
|
||||
;; EXPORT string_array string_array_set(string_array array, int pos, string new_value) {
|
||||
;; array[pos] = strdup(new_value);
|
||||
;; return array;
|
||||
;; }
|
||||
|
||||
;; typedef string (*string_to_string_fn)(string);
|
||||
|
||||
;; EXPORT string_array string_array_map(string_to_string_fn f, string_array array) {
|
||||
;; string_array p = array;
|
||||
;; while(*p) {
|
||||
;; string old_string = *p;
|
||||
;; string new_string = f(old_string);
|
||||
;; *p = new_string;
|
||||
;; p++;
|
||||
;; }
|
||||
;; return array;
|
||||
;; }
|
||||
|
||||
|
||||
(register-builtin "string_array_new" '(:int) ':string-array)
|
||||
(register-builtin "string_array_count" '((:ref :string-array)) :int)
|
||||
(register-builtin "string_array_get" '((:ref :string-array) :int) :string)
|
||||
|
@ -61,22 +61,11 @@ EXPORT void println(string msg) {
|
||||
printf("%s\n", msg);
|
||||
}
|
||||
|
||||
EXPORT int* fake() {
|
||||
return (int*)123;
|
||||
}
|
||||
|
||||
EXPORT void fake2(string *s) {
|
||||
|
||||
}
|
||||
|
||||
// This function is used for testing of the ownership system
|
||||
EXPORT void eat_string(char *s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
EXPORT void eat_void(void *nothing) {
|
||||
// nothing!
|
||||
}
|
||||
|
||||
EXPORT char *string_copy(char *s) {
|
||||
return strdup(s);
|
||||
}
|
||||
@ -98,56 +87,14 @@ EXPORT bool file_existsQMARK(char *filename) {
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef string* string_array;
|
||||
|
||||
EXPORT string_array string_array_new(int size) {
|
||||
string_array a = calloc(size + 1, sizeof(string));
|
||||
for(int i = 0; i < size; i++) {
|
||||
a[i] = strdup("");
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
EXPORT int string_array_count(string_array array) {
|
||||
int i = 0;
|
||||
string_array p = array;
|
||||
while(*p) {
|
||||
i++;
|
||||
p++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
EXPORT string string_array_get(string_array array, int pos) {
|
||||
return strdup(array[pos]);
|
||||
}
|
||||
|
||||
EXPORT string_array string_array_set(string_array array, int pos, string new_value) {
|
||||
array[pos] = strdup(new_value);
|
||||
return array;
|
||||
}
|
||||
|
||||
typedef string (*string_to_string_fn)(string);
|
||||
|
||||
EXPORT string_array string_array_map(string_to_string_fn f, string_array array) {
|
||||
string_array p = array;
|
||||
while(*p) {
|
||||
string old_string = *p;
|
||||
string new_string = f(old_string);
|
||||
*p = new_string;
|
||||
p++;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
EXPORT int inc(x) { return x + 1; }
|
||||
EXPORT int dec(x) { return x - 1; }
|
||||
|
||||
EXPORT void async(void *f) {
|
||||
printf("Async starting.\n");
|
||||
//printf("Async starting.\n");
|
||||
carp_thread_t th = carp_thread_create(f, "Async");
|
||||
carp_thread_destroy(th);
|
||||
printf("Async done.\n");
|
||||
//printf("Async done.\n");
|
||||
}
|
||||
|
||||
EXPORT int last_index_of(string s, char c) {
|
||||
@ -179,23 +126,6 @@ EXPORT string get_input() {
|
||||
return strdup(in);
|
||||
}
|
||||
|
||||
EXPORT void call(void *f()) {
|
||||
f();
|
||||
}
|
||||
|
||||
EXPORT void call1(void *f(int)) {
|
||||
f(1);
|
||||
}
|
||||
|
||||
EXPORT void calls(void *f(char*)) {
|
||||
f("hejsan");
|
||||
}
|
||||
|
||||
EXPORT void printret(int (*f)()) {
|
||||
int x = f();
|
||||
printf("ret = %d\n", x);
|
||||
}
|
||||
|
||||
EXPORT int mod(int x, int y) {
|
||||
return x % y;
|
||||
}
|
||||
@ -206,18 +136,6 @@ EXPORT void sleep(int millis) {
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} FauxVec2;
|
||||
|
||||
FauxVec2 *position() {
|
||||
FauxVec2 *v2 = malloc(sizeof(FauxVec2));
|
||||
v2->x = 100.0f;
|
||||
v2->y = 200.0f;
|
||||
return v2;
|
||||
}
|
||||
|
||||
EXPORT CARP_PLATFORM platform() {
|
||||
return carp_get_platform();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user