about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--premake5.lua1
-rw-r--r--src/gemma.cpp2
-rw-r--r--src/guile/examples.scm6
-rw-r--r--src/guile_api.cpp49
-rw-r--r--src/guile_api.h9
-rw-r--r--src/main.cpp4
6 files changed, 58 insertions, 13 deletions
diff --git a/premake5.lua b/premake5.lua
index 40aaa01..f966e8a 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -47,6 +47,7 @@ project "gemma"
    kind "ConsoleApp"
    defines { "OPENBLAS" }
    language "C++"
+   buildoptions { "-Wfatal-errors" }
    objdir "build/"
    targetdir "build/bin/%{cfg.buildcfg}"
 
diff --git a/src/gemma.cpp b/src/gemma.cpp
index a9038c7..5804bde 100644
--- a/src/gemma.cpp
+++ b/src/gemma.cpp
@@ -82,6 +82,8 @@ void gemma_gsl_error_handler (const char * reason,
 #include <openblas_config.h>
 #endif
 
+using namespace gemmaguile;
+
 void GEMMA::PrintHeader(void) {
 
   cout <<
diff --git a/src/guile/examples.scm b/src/guile/examples.scm
new file mode 100644
index 0000000..8855a34
--- /dev/null
+++ b/src/guile/examples.scm
@@ -0,0 +1,6 @@
+(define-module (example)
+  #:use-module (srfi srfi-4)
+  #:export (make-floats))
+
+(define (make-floats)
+  #f64( 1.0 2.2 3.3 4.0))
diff --git a/src/guile_api.cpp b/src/guile_api.cpp
index 21eb9ff..e3ef482 100644
--- a/src/guile_api.cpp
+++ b/src/guile_api.cpp
@@ -1,13 +1,44 @@
 #include <guile_api.h>
 
-void global_start_guile() {
-    scm_init_guile();
-}
+namespace gemmaguile {
+
+    void global_start_guile() {
+        scm_init_guile();
+    }
+
+    string global_guile_version() {
+        SCM version_scm = scm_version();
+        char* c_str = scm_to_utf8_string(version_scm);
+        string version_str(c_str);
+        free(c_str);  // Must free the allocated memory
+
+        return version_str;
+    }
+
+    SCM make_floats()
+    {
+        return scm_call_0(scm_c_public_ref("example", "make-floats"));
+    }
+
+    void use_floats()
+    {
+        SCM vec = make_floats();
+
+        scm_t_array_handle handle;
+        size_t len;
+        ssize_t inc;
+        const SCM *elt;
+
+        const double *ny = scm_f64vector_elements (vec,&handle,&len,&inc);
+        for (size_t i = 0; i < len; i++) {
+            printf("elem %zu = %f\n", i, ny[i]);
+        }
+        scm_array_handle_release (&handle);
+    }
+
+    void start_test() {
+        scm_c_primitive_load("src/guile/examples.scm");
+        use_floats();
+    }
 
-string global_guile_version() {
-    SCM version_scm = scm_version();
-    char* c_str = scm_to_utf8_string(version_scm);
-    string version_str(c_str);
-    free(c_str);  // Must free the allocated memory
-    return version_str;
 }
diff --git a/src/guile_api.h b/src/guile_api.h
index 1244b11..b413342 100644
--- a/src/guile_api.h
+++ b/src/guile_api.h
@@ -5,5 +5,10 @@
 
 using namespace std;
 
-void global_start_guile();
-string global_guile_version();
+namespace gemmaguile {
+
+    void global_start_guile();
+    string global_guile_version();
+    void start_test();
+
+};
diff --git a/src/main.cpp b/src/main.cpp
index 95c8fd3..ee6d597 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -32,8 +32,8 @@ int main(int argc, char *argv[]) {
 
   gsl_set_error_handler (&gemma_gsl_error_handler);
 
-  global_start_guile();
-
+  gemmaguile::global_start_guile();
+  gemmaguile::start_test();
 
   if (argc <= 1) {
     cGemma.PrintHeader();