mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-14 18:47:42 +03:00
Merge branch 'master' of github.com:eriksvedang/Carp
This commit is contained in:
commit
23c484a09f
@ -231,6 +231,7 @@
|
||||
(register-builtin "substring" '(:string :int) :string)
|
||||
(register-builtin "file_path_component" '(:string) :string)
|
||||
(register-builtin "get_input" '() :string)
|
||||
(register-builtin "spawn" '((:fn () :void)) :void)
|
||||
|
||||
(register-builtin "call" '((:fn () :void)) :void)
|
||||
(register-builtin "call1" '((:fn (:int) :void)) :void)
|
||||
|
@ -43,6 +43,9 @@
|
||||
(glVertex3f x y 0.0f)
|
||||
(glEnd)))
|
||||
|
||||
(defn red ()
|
||||
0.6)
|
||||
|
||||
(defn gl-demo ()
|
||||
(if (glfwInit)
|
||||
(let [window (glfwCreateWindow 640 480 "Yeah!" NULL NULL)]
|
||||
@ -52,20 +55,20 @@
|
||||
(glfwMakeContextCurrent window)
|
||||
(while (not (glfwWindowShouldClose window))
|
||||
(do
|
||||
(glClearColor 0.6f 0.85f 0.85f 1.0f)
|
||||
(glClearColor (red) 0.85f 0.85f 1.0f)
|
||||
(glClear gl-color-buffer-bit)
|
||||
(glColor3f 1.0f 0.9f 0.2f)
|
||||
(glColor3f 1.0 0.9f 0.2f)
|
||||
(draw-rect -0.5f -0.5f 1.0f 1.0f)
|
||||
(glfwSwapBuffers window)
|
||||
(glfwPollEvents)))
|
||||
(glfwTerminate))))
|
||||
(panic "Failed to initialize glfw.")))
|
||||
|
||||
(bake draw-rect)
|
||||
;;(bake draw-rect)
|
||||
|
||||
;(def app-ast (lambda-to-ast (code app)))
|
||||
;(def app-asta (annotate-ast app-ast))
|
||||
|
||||
;;(bake-gl-exe)
|
||||
(bake* gl-demo '(draw-rect))
|
||||
;;(bake* gl-demo '(draw-rect))
|
||||
|
||||
|
@ -136,6 +136,20 @@ void async(void *f) {
|
||||
printf("Async done.\n");
|
||||
}
|
||||
|
||||
void spawn(void (*f)()) {
|
||||
printf("FORK start.\n");
|
||||
int pid = fork();
|
||||
if(pid == 0) {
|
||||
printf("In parent\n");
|
||||
f();
|
||||
printf("FORK done.\n");
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
printf("In child\n");
|
||||
}
|
||||
}
|
||||
|
||||
int last_index_of(string s, char c) {
|
||||
int len = strlen(s);
|
||||
for(int i = len - 1; i >= 0; i--) {
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "eval.h"
|
||||
#include "reader.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void register_primop(char *name, Primop primop) {
|
||||
Obj *o = obj_new_primop(primop);
|
||||
env_extend(global_env, obj_new_symbol(name), o);
|
||||
@ -1395,3 +1397,18 @@ Obj *p_array_to_list(Obj** args, int arg_count) {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
Obj *p_spork(Obj** args, int arg_count) {
|
||||
printf("SPORK start.\n");
|
||||
int pid = fork();
|
||||
if(pid == 0) {
|
||||
printf("In parent\n");
|
||||
apply(args[0], NULL, 0);
|
||||
printf("SPORK done.\n");
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
printf("In child\n");
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ Obj *p_builtin_p(Obj** args, int arg_count);
|
||||
Obj *p_meta_set_BANG(Obj** args, int arg_count);
|
||||
Obj *p_meta_get(Obj** args, int arg_count);
|
||||
Obj *p_array_to_list(Obj** args, int arg_count);
|
||||
Obj *p_spork(Obj** args, int arg_count);
|
||||
|
||||
Obj *register_ffi_internal(char *name, VoidFn funptr, Obj *args, Obj *return_type_obj, bool builtin);
|
||||
|
||||
|
@ -177,6 +177,7 @@ void env_new_global() {
|
||||
register_primop("meta-set!", p_meta_set_BANG);
|
||||
register_primop("meta-get", p_meta_get);
|
||||
register_primop("array-to-list", p_array_to_list);
|
||||
register_primop("spork", p_spork);
|
||||
|
||||
Obj *abs_args = obj_list(type_int);
|
||||
register_ffi_internal("abs", (VoidFn)abs, abs_args, type_int, true);
|
||||
|
Loading…
Reference in New Issue
Block a user