diff --git a/Makefile b/Makefile index dff7c925..6cb818d7 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,7 @@ JANET_CORE_SOURCES=src/core/abstract.c \ src/core/io.c \ src/core/marsh.c \ src/core/math.c \ + src/core/net.c \ src/core/os.c \ src/core/parse.c \ src/core/peg.c \ diff --git a/meson.build b/meson.build index fe9a02f8..7de2916e 100644 --- a/meson.build +++ b/meson.build @@ -59,6 +59,7 @@ conf.set('JANET_NO_DOCSTRINGS', not get_option('docstrings')) conf.set('JANET_NO_SOURCEMAPS', not get_option('sourcemaps')) conf.set('JANET_NO_ASSEMBLER', not get_option('assembler')) conf.set('JANET_NO_PEG', not get_option('peg')) +conf.set('JANET_NO_NET', not get_option('net')) conf.set('JANET_REDUCED_OS', get_option('reduced_os')) conf.set('JANET_NO_TYPED_ARRAY', not get_option('typed_array')) conf.set('JANET_NO_INT_TYPES', not get_option('int_types')) @@ -112,6 +113,7 @@ core_src = [ 'src/core/io.c', 'src/core/marsh.c', 'src/core/math.c', + 'src/core/net.c', 'src/core/os.c', 'src/core/parse.c', 'src/core/peg.c', diff --git a/meson_options.txt b/meson_options.txt index 83bd25a6..1d0bd77c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -11,6 +11,7 @@ option('peg', type : 'boolean', value : true) option('typed_array', type : 'boolean', value : true) option('int_types', type : 'boolean', value : true) option('prf', type : 'boolean', value : true) +option('net', type : 'boolean', value : true) option('recursion_guard', type : 'integer', min : 10, max : 8000, value : 1024) option('max_proto_depth', type : 'integer', min : 10, max : 8000, value : 200) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index f1360943..eda66669 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2423,6 +2423,7 @@ "src/core/io.c" "src/core/marsh.c" "src/core/math.c" + "src/core/net.c" "src/core/os.c" "src/core/parse.c" "src/core/peg.c" diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index bb49a8ca..c792f0c8 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -49,6 +49,7 @@ /* Other settings */ /* #define JANET_NO_ASSEMBLER */ /* #define JANET_NO_PEG */ +/* #define JANET_NO_NET */ /* #define JANET_NO_TYPED_ARRAY */ /* #define JANET_NO_INT_TYPES */ /* #define JANET_NO_PRF */ diff --git a/src/core/corelib.c b/src/core/corelib.c index 5042ddbf..bebf49da 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -975,6 +975,9 @@ static void janet_load_libs(JanetTable *env) { #ifdef JANET_THREADS janet_lib_thread(env); #endif +#ifdef JANET_NET + janet_lib_net(env); +#endif } #ifdef JANET_BOOTSTRAP diff --git a/src/core/net.c b/src/core/net.c new file mode 100644 index 00000000..529790a9 --- /dev/null +++ b/src/core/net.c @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2020 Calvin Rose +* +* 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. +*/ + +#ifndef JANET_AMALG +#include "features.h" +#include +#include "util.h" +#endif + +/* + * C Funs + */ + +static Janet cfun_net_hello(int32_t argc, Janet *argv) { + (void) argv; + janet_fixarity(argc, 0); + janet_printf("Hello!\n"); + return janet_wrap_nil(); +} + +static const JanetReg net_cfuns[] = { + {"net/hello", cfun_net_hello, + JDOC("(net/hello)\n\n" + "Prints \"Hello!\".")}, + {NULL, NULL, NULL} +}; + +void janet_lib_net(JanetTable *env) { + janet_core_cfuns(env, NULL, net_cfuns); +} + diff --git a/src/core/util.h b/src/core/util.h index 5a3f5568..c2417014 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -126,5 +126,8 @@ void janet_lib_inttypes(JanetTable *env); #ifdef JANET_THREADS void janet_lib_thread(JanetTable *env); #endif +#ifdef JANET_NET +void janet_lib_net(JanetTable *env); +#endif #endif diff --git a/src/include/janet.h b/src/include/janet.h index cc8d7069..005602fc 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -152,6 +152,11 @@ extern "C" { #define JANET_TYPED_ARRAY #endif +/* Enable or disable networking */ +#ifndef JANET_NO_NET +#define JANET_NET +#endif + /* Enable or disable large int types (for now 64 bit, maybe 128 / 256 bit integer types) */ #ifndef JANET_NO_INT_TYPES #define JANET_INT_TYPES