-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[language binding] add c-api, java-api and python-api
- Loading branch information
Showing
25 changed files
with
470 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,5 @@ pscm-build-bin | |
#coverage | ||
cov/ | ||
/build-* | ||
|
||
.aswb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cc_library( | ||
name = "pscm_c_api", | ||
srcs = ["pscm_c_api.cpp"], | ||
hdrs = ["pscm_c_api.h"], | ||
copts = ["-std=c++20"], | ||
implementation_deps = ["//:pscm"], | ||
includes = ["."], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "pscm_c_api.h" | ||
#include <pscm/Scheme.h> | ||
using namespace pscm; | ||
|
||
void *pscm_create_scheme() { | ||
return new Scheme(); | ||
} | ||
|
||
void pscm_destroy_scheme(void *scm) { | ||
auto p = (Scheme *)scm; | ||
delete p; | ||
} | ||
|
||
void *pscm_eval(void *scm, const char *code) { | ||
auto p = (Scheme *)scm; | ||
auto ret = p->eval(code); | ||
return new Cell(ret); | ||
} | ||
|
||
const char *pscm_to_string(void *value) { | ||
auto p = (Cell *)value; | ||
auto s = p->to_std_string(); | ||
char *c_str = new char[s.size() + 1]; | ||
strcpy(c_str, s.c_str()); | ||
c_str[s.size()] = '\0'; | ||
return c_str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
extern "C" { | ||
void *pscm_create_scheme(); | ||
void pscm_destroy_scheme(void *scm); | ||
void *pscm_eval(void *scm, const char *code); | ||
const char *pscm_to_string(void *value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
java_library( | ||
name = "pscm_java_api", | ||
srcs = ["dev/pscm/PSCMScheme.java"], | ||
visibility = ["//visibility:public"], | ||
deps = select({ | ||
"@platforms//os:android": [], | ||
"//conditions:default": [":pscm-jni"], | ||
}), | ||
) | ||
|
||
cc_library( | ||
name = "pscm_java_binding", | ||
srcs = ["pscm_java_binding.cpp"], | ||
copts = ["-std=c++20"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":copy_jni_hdr_lib", | ||
"//binding/c:pscm_c_api", | ||
], | ||
alwayslink = True, | ||
) | ||
|
||
cc_binary( | ||
name = "pscm-jni", | ||
linkshared = True, | ||
deps = [":pscm_java_binding"], | ||
) | ||
|
||
java_test( | ||
name = "pscm_java_api_test", | ||
srcs = ["test/PSCMSchemeTest.java"], | ||
test_class = "test.PSCMSchemeTest", | ||
deps = [ | ||
":pscm_java_api", | ||
"@maven//:junit_junit", | ||
], | ||
) | ||
|
||
java_binary( | ||
name = "pscm_java_api_example", | ||
srcs = ["example/PSCMSchemeExample.java"], | ||
main_class = "PSCMSchemeExample", | ||
deps = [ | ||
":pscm_java_api", | ||
], | ||
) | ||
|
||
genrule( | ||
name = "copy_link_jni_md_header", | ||
srcs = select({ | ||
"@platforms//os:macos": ["@bazel_tools//tools/jdk:jni_md_header-darwin"], | ||
"@platforms//os:linux": ["@bazel_tools//tools/jdk:jni_md_header-linux"], | ||
"//conditions:default": [], | ||
}), | ||
outs = ["jni_md.h"], | ||
cmd = "cp -f $< $@", | ||
) | ||
|
||
genrule( | ||
name = "copy_link_jni_header", | ||
srcs = ["@bazel_tools//tools/jdk:jni_header"], | ||
outs = ["jni.h"], | ||
cmd = "cp -f $< $@", | ||
) | ||
|
||
cc_library( | ||
name = "copy_jni_hdr_lib", | ||
hdrs = [ | ||
":copy_link_jni_header", | ||
":copy_link_jni_md_header", | ||
], | ||
includes = ["."], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dev.pscm; | ||
|
||
public class PSCMScheme { | ||
|
||
private long scm = 0; | ||
|
||
public PSCMScheme() { | ||
init(); | ||
} | ||
|
||
public void init() { | ||
if (scm == 0) { | ||
scm = createScheme(); | ||
} | ||
} | ||
|
||
public String eval(String code) { | ||
return evalSchemeCode(scm, code); | ||
} | ||
|
||
/** | ||
* A native method that is implemented by the 'native-lib' native library, | ||
* which is packaged with this application. | ||
*/ | ||
public native long createScheme(); | ||
public native String evalSchemeCode(long scm, String code); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import dev.pscm.PSCMScheme; | ||
|
||
public class PSCMSchemeExample { | ||
|
||
static { | ||
// load shared library | ||
System.loadLibrary("pscm-jni"); | ||
} | ||
|
||
public static void main(String args[]) { | ||
System.out.println("Hello World"); | ||
PSCMScheme scm = new PSCMScheme(); | ||
// eval (version) | ||
String ret = scm.eval("(version)"); | ||
System.out.println(ret); | ||
} | ||
} |
Oops, something went wrong.