From 27e400fba3de55835af9638fff3df80dbb1fa5c7 Mon Sep 17 00:00:00 2001 From: Damien Ready Date: Sat, 20 Mar 2021 10:53:51 -0500 Subject: [PATCH 1/3] Prepare the .tar distribution with folder layout --- Makefile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ec057c54..da5e1260 100644 --- a/Makefile +++ b/Makefile @@ -226,8 +226,18 @@ build/janet-%.tar.gz: $(JANET_TARGET) \ jpm.1 janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) \ build/doc.html README.md build/c/janet.c build/c/shell.c jpm $(eval JANET_DIST_DIR = "janet-$(shell basename $*)") - mkdir -p build/$(JANET_DIST_DIR) - cp -r $^ build/$(JANET_DIST_DIR)/ + mkdir -p build/$(JANET_DIST_DIR)/bin + cp $(JANET_TARGET) build/$(JANET_DIST_DIR)/bin/ + cp jpm build/$(JANET_DIST_DIR)/bin/ + mkdir -p build/$(JANET_DIST_DIR)/include + cp build/janet.h build/$(JANET_DIST_DIR)/include/ + mkdir -p build/$(JANET_DIST_DIR)/lib/ + cp $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/$(JANET_DIST_DIR)/lib/ + mkdir -p build/$(JANET_DIST_DIR)/man/man1/ + cp janet.1 jpm.1 build/$(JANET_DIST_DIR)/man/man1/ + mkdir -p build/$(JANET_DIST_DIR)/src/ + cp build/c/janet.c build/c/shell.c build/$(JANET_DIST_DIR)/src/ + cp CONTRIBUTING.md build/doc.html LICENSE README.md build/$(JANET_DIST_DIR)/ cd build && tar -czvf ../$@ $(JANET_DIST_DIR) ######################### From ec2d7bf349e2a2c8035034fe22239fe51a5e8e9d Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Wed, 24 Mar 2021 09:38:12 +0900 Subject: [PATCH 2/3] Support adding arbitrary metadata to bindings --- src/core/specials.c | 3 +++ test/suite0004.janet | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/core/specials.c b/src/core/specials.c index b3cea30a..3688eb72 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -251,6 +251,9 @@ static JanetTable *handleattr(JanetCompiler *c, int32_t argn, const Janet *argv) case JANET_STRING: janet_table_put(tab, janet_ckeywordv("doc"), attr); break; + case JANET_STRUCT: + janet_table_merge_struct(tab, janet_unwrap_struct(attr)); + break; } } return tab; diff --git a/test/suite0004.janet b/test/suite0004.janet index 208f7cc4..17b1f358 100644 --- a/test/suite0004.janet +++ b/test/suite0004.janet @@ -70,5 +70,17 @@ (assert (= ~(,defn 1 2 3) [defn 1 2 3]) "bracket tuples are never macros") (assert (= ~(,+ 1 2 3) [+ 1 2 3]) "bracket tuples are never function calls") +# Metadata + +(def foo-with-tags :a-tag :bar) +(assert (get (dyn 'foo-with-tags) :a-tag) "extra keywords in def are metadata tags") + +(def foo-with-meta {:baz :quux} :bar) +(assert (= :quux (get (dyn 'foo-with-meta) :baz)) "extra struct in def is metadata") + +(defn foo-fn-with-meta {:baz :quux} "This is a function" [x] (identity x)) +(assert (= :quux (get (dyn 'foo-fn-with-meta) :baz)) "extra struct in defn is metadata") +(assert (= "(foo-fn-with-meta x)\n\nThis is a function" (get (dyn 'foo-fn-with-meta) :doc)) "extra string in defn is docstring") + (end-suite) From 64ec9f9cb63c1b0fd7f2c13689ab906885911710 Mon Sep 17 00:00:00 2001 From: Lue Date: Thu, 25 Mar 2021 13:19:05 -0400 Subject: [PATCH 3/3] Allow .cc file extension in jpm declare-native --- jpm | 44 +++++++++++++++++++------------------ test/install/project.janet | 20 ++++++++++------- test/install/testexec.janet | 3 ++- test/install/testmod5.cc | 42 +++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 30 deletions(-) create mode 100644 test/install/testmod5.cc diff --git a/jpm b/jpm index ae1d0760..3d1a505d 100755 --- a/jpm +++ b/jpm @@ -968,17 +968,18 @@ int main(int argc, const char **argv) { (var has-cpp false) (def objects (seq [src :in sources] - (cond - (string/has-suffix? ".cpp" src) - (let [op (out-path src ".cpp" objext)] - (compile-cpp opts src op) - (set has-cpp true) - op) - (string/has-suffix? ".c" src) - (let [op (out-path src ".c" objext)] - (compile-c opts src op) - op) - (errorf "unknown source file type: %s, expected .c or .cpp" src)))) + (def suffix + (cond + (string/has-suffix? ".cpp" src) ".cpp" + (string/has-suffix? ".cc" src) ".cc" + (string/has-suffix? ".c" src) ".c" + (errorf "unknown source file type: %s, expected .c, .cc, or .cpp" src))) + (def op (out-path src suffix objext)) + (if (= suffix ".c") + (compile-c opts src op) + (do (compile-cpp opts src op) + (set has-cpp true))) + op)) (when-let [embedded (opts :embedded)] (loop [src :in embedded] @@ -1016,16 +1017,17 @@ int main(int argc, const char **argv) { # Get static objects (def sobjects (seq [src :in sources] - (cond - (string/has-suffix? ".cpp" src) - (let [op (out-path src ".cpp" sobjext)] - (compile-cpp opts src op true) - op) - (string/has-suffix? ".c" src) - (let [op (out-path src ".c" sobjext)] - (compile-c opts src op true) - op) - (errorf "unknown source file type: %s, expected .c or .cpp")))) + (def suffix + (cond + (string/has-suffix? ".cpp" src) ".cpp" + (string/has-suffix? ".cc" src) ".cc" + (string/has-suffix? ".c" src) ".c" + (errorf "unknown source file type: %s, expected .c, .cc, or .cpp" src))) + (def op (out-path src suffix sobjext)) + (if (= suffix ".c") + (compile-c opts src op true) + (compile-cpp opts src op true)) + op)) (when-let [embedded (opts :embedded)] (loop [src :in embedded] diff --git a/test/install/project.janet b/test/install/project.janet index 5f3ce572..e91ad20e 100644 --- a/test/install/project.janet +++ b/test/install/project.janet @@ -2,20 +2,24 @@ :name "testmod") (declare-native - :name "testmod" - :source @["testmod.c"]) + :name "testmod" + :source @["testmod.c"]) (declare-native - :name "testmod2" - :source @["testmod2.c"]) + :name "testmod2" + :source @["testmod2.c"]) (declare-native - :name "testmod3" - :source @["testmod3.cpp"]) + :name "testmod3" + :source @["testmod3.cpp"]) (declare-native - :name "test-mod-4" - :source @["testmod4.c"]) + :name "test-mod-4" + :source @["testmod4.c"]) + +(declare-native + :name "testmod5" + :source @["testmod5.cc"]) (declare-executable :name "testexec" diff --git a/test/install/testexec.janet b/test/install/testexec.janet index 36c91498..2e511936 100644 --- a/test/install/testexec.janet +++ b/test/install/testexec.janet @@ -2,7 +2,8 @@ (use /build/testmod2) (use /build/testmod3) (use /build/test-mod-4) +(use /build/testmod5) (defn main [&] (print "Hello from executable!") - (print (+ (get5) (get6) (get7) (get8)))) + (print (+ (get5) (get6) (get7) (get8) (get9)))) diff --git a/test/install/testmod5.cc b/test/install/testmod5.cc new file mode 100644 index 00000000..2e8ae6db --- /dev/null +++ b/test/install/testmod5.cc @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2020 Calvin Rose and contributors +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to +* deal in the Software without restriction, including without limitation the +* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +* sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +*/ + +/* A very simple native module */ + +#include +#include + +static Janet cfun_get_nine(int32_t argc, Janet *argv) { + (void) argv; + janet_fixarity(argc, 0); + std::cout << "Hello!" << std::endl; + return janet_wrap_number(9.0); +} + +static const JanetReg array_cfuns[] = { + {"get9", cfun_get_nine, NULL}, + {NULL, NULL, NULL} +}; + +JANET_MODULE_ENTRY(JanetTable *env) { + janet_cfuns(env, NULL, array_cfuns); +}