Permalink
Please sign in to comment.
Showing
with
141 additions
and 12 deletions.
- +3 −0 .gitignore
- +3 −3 src/Makefile
- +13 −2 src/evaluate.cpp
- +66 −0 src/guile.cpp
- +18 −0 src/guile.h
- +3 −1 src/main.cpp
- +3 −0 src/main.scm
- BIN src/stockfish
- +12 −4 src/thread.cpp
- +5 −2 src/thread.h
- +15 −0 src/userscripts.scm
| @@ -0,0 +1,3 @@ | ||
| *.o | ||
| *~ | ||
| src/.depend |
| @@ -0,0 +1,66 @@ | ||
| #include "guile.h" | ||
| SCM display; | ||
| SCM evaluate; | ||
| SCM get_side_to_move(SCM pos) | ||
| { | ||
| Position *rpos = (Position*)scm_to_pointer(pos); | ||
| return scm_from_int(rpos->side_to_move()); | ||
| } | ||
| void* init_guile(void* data) | ||
| { | ||
| scm_gc(); | ||
| scm_c_primitive_load("/home/user/Stockfish/src/userscripts.scm"); | ||
| display = scm_c_public_lookup("guile", "display"); | ||
| scm_call_1(scm_variable_ref(display), scm_from_stringn("from C\n", 7, NULL, SCM_FAILED_CONVERSION_ERROR)); | ||
| scm_c_define_gsubr("side-to-move", 1, 0, 0, (void*)&get_side_to_move); | ||
| evaluate = scm_c_public_lookup("userscripts", "evaluate"); | ||
| //evaluate = scm_c_public_lookup("guile-user", "evaluate"); | ||
| scm_call_1(scm_variable_ref(display), scm_variable_ref(evaluate)); | ||
| scm_c_primitive_load("/home/user/Stockfish/src/main.scm"); | ||
| // printf("thread: %d\n", std::thread::id()); | ||
| printf("init for thread: %d %d\n", std::thread::id(), std::this_thread::get_id()); | ||
| //scm_call_0(scm_variable_ref(evaluate)); | ||
| //scm_call_0(scm_variable_ref(evaluate)); | ||
| //scm_call_0(scm_variable_ref(evaluate)); | ||
| return NULL; | ||
| } | ||
| Value guile_evaluate(const Position& pos, Value v) | ||
| { | ||
| assert(evaluate != NULL); | ||
| //SCM str = scm_from_stringn("from C\n", 7, NULL, SCM_FAILED_CONVERSION_ERROR); | ||
| //SCM display = scm_c_public_lookup("", "display"); // guile | ||
| //printf("thread: %d %d\n", std::thread::id(), std::this_thread::get_id()); | ||
| //evaluate = scm_c_public_lookup("userscripts", "evaluate"); | ||
| //scm_call_1(scm_variable_ref(display), scm_variable_ref(evaluate)); | ||
| // printf("was %d\n", v); | ||
| SCM r = scm_call_2(scm_variable_ref(evaluate), | ||
| scm_from_pointer((void*)&pos, NULL), | ||
| scm_from_int(v)); | ||
| // printf("now is %d\n", (Value)scm_to_int(r)); | ||
| return (Value)scm_to_int(r); | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| #ifndef GUILE_H_INCLUDED | ||
| #define GUILE_H_INCLUDED | ||
| #define WITH_GUILE | ||
| #include <libguile.h> | ||
| #include <thread> | ||
| #include "types.h" | ||
| #include "position.h" | ||
| //extern "C" SCM get_side_to_move(SCM pos); | ||
| void* init_guile(void* data); | ||
| Value guile_evaluate(const Position& pos, Value v); | ||
| #endif |
| @@ -0,0 +1,3 @@ | ||
| (use-modules (userscripts)) | ||
| ; other glue code ... |
Binary file not shown.
| @@ -0,0 +1,15 @@ | ||
| (define-module (userscripts) | ||
| #:export (evaluate)) | ||
| (define (__evaluate pos v) | ||
| (+ (- (random 1000) 500) v)) | ||
| (define (_evaluate pos v) | ||
| v) | ||
| (define (evaluate pos v) | ||
| (if (= (side-to-move pos) 0) | ||
| v | ||
| (* -1 v))) | ||
0 comments on commit
8918cb4