Skip to content

Commit

Permalink
Merge branch 'next-etc'
Browse files Browse the repository at this point in the history
  • Loading branch information
egallesio committed Sep 23, 2024
2 parents 88c649f + a305705 commit 6c2d263
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
10 changes: 0 additions & 10 deletions etc/README

This file was deleted.

25 changes: 25 additions & 0 deletions etc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

This directory contains the following directories:

- **Docker**: A directory containing two Docker files for STklos (one
for building STklos with the sources coming from the git tree and
another one to built it from a stable release).

- **Unicode**: A directory containing some files to build the UT8 tables
needed by STklos

- **completions**: A directory which contains code for *bash(1)* and *zsh(1)*
completions.

It also contains two files, which are not complete examples (it is why
they are not in the `examples` directory). They can be used as
templates, for some advanced work in C with STklos.
- **simple-module.c** : A simple module which adds some primitives
written in C to the interpreter. This module must be compiled and
dynamically loaded with the interpreter (documentation can be
found in the source file).
- **simple-stklos.c**: A simple main program which uses the STklos
library)

**IMPORTANT**: this program must be updated to be run
on recent versions of STklos.
34 changes: 25 additions & 9 deletions etc/simple-module.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* simple-module.c -- A simple C module for STklos
*
* Copyright © 2000-2023 Erick Gallesio <eg@stklos.net>
* Copyright © 2000-2024 Erick Gallesio <eg@stklos.net>
*
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -23,8 +23,10 @@
* Creation date: 22-Jul-2000 12:10 (eg)
*/

/* This module defines two simple primitives called "test" and "add".
* - "test" takes one parameter, displays it and returns it.
/* This module defines three simple primitives called "hello", "test" and "add".
* - "hello" takes no parameter and displays a simple message
* - "test" takes one parameter, displays it and returns it (reversed if it
* is a pair, unmodified otherwise.
* - "add" returns the sum of its two (small) integer parameters
*
* New primitives are defined with the DEFINE_PRIMITIVE macro
Expand Down Expand Up @@ -54,13 +56,22 @@
#include <stklos.h>


DEFINE_PRIMITIVE("hello", hello, subr0, (void))
{
SCM msg = STk_Cstring2string("Hello from STklos.\n"); // convert C str -> SCM str
STk_display(msg, STk_current_output_port()); // call SCM display
return STk_void; // return #void
}


DEFINE_PRIMITIVE("test", tst, subr1, (SCM l))
{
SCM oport = STk_current_output_port();
STk_fprintf(oport, "Parameter is ");
STk_display(l, oport);
STk_newline(oport);
return l;
STk_putc('\n', oport);

return CONSP(l) ? STk_cons(CDR(l), CAR(l)): l; // Reverse CONSes. Keep others
}

DEFINE_PRIMITIVE("add", add, subr2, (SCM a, SCM b))
Expand All @@ -69,20 +80,25 @@ DEFINE_PRIMITIVE("add", add, subr2, (SCM a, SCM b))
if (!INTP(a)) STk_error("First parameter ~S is not an integer", a);
if (!INTP(b)) STk_error("Second parameter ~S is not an integer", b);

sum = INT_VAL(a) + INT_VAL(b);
return MAKE_INT(sum);
sum = INT_VAL(a) + INT_VAL(b); // INT_VAL returns a C int
return MAKE_INT(sum); // MAKE_INT returns a SCM int
}


/*
* The name of the module is just used to display error message. Put
* something meaningful in it. The statements beween MODULE_ENTRY_START
* and MODULE_ENTRY_END are executed when the module is loaded.
*
* ADD_PRIMITIVE_IN_MODULE adds a primitive in the given module.
*/
MODULE_ENTRY_START("simple-module")
{
SCM mod = STk_current_module();
STk_puts("Loading extension simple-module\n", STk_current_output_port());
ADD_PRIMITIVE(tst);
ADD_PRIMITIVE(add);

ADD_PRIMITIVE_IN_MODULE(hello, mod);
ADD_PRIMITIVE_IN_MODULE(tst, mod);
ADD_PRIMITIVE_IN_MODULE(add, mod);
}
MODULE_ENTRY_END
4 changes: 2 additions & 2 deletions utils/stklos-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ while test $# -gt 0; do
echo @VERSION@
;;
--compile|-c)
inc=-I${prefix}/include/@PACKAGE@
echo @CC@ @SH_COMP_FLAGS@ $inc $inc/gc
inc=-I${prefix}/include/
echo @CC@ @CFLAGS@ @CPPFLAGS@ @STKCFLAGS@ @SH_COMP_FLAGS@ @GCINC@ $inc
;;
--link|-l)
echo @SH_LOADER@ @SH_LOAD_FLAGS@
Expand Down

0 comments on commit 6c2d263

Please sign in to comment.