Re: GUILE_QUIET=1 guile → suppress REPL welcome message (fixed message format)

2024-05-03 Thread Matt Wette

On 3/11/24 6:50 AM, Matt Wette wrote:

On 3/10/24 6:01 PM, Dr. Arne Babenhauserheide wrote:

Hi,

It’s been two months now, did anyone get to review this patch?

It’s small and it gives an instant improvement when using Guile in Emacs
orgmode babel sourceblocks that get evaluated on export.

Best wishes,
Arne

I did look at it.  Another solution, I prefer, is generate a global 
urrent-info-port object and
provide a command-line option to make that a file or /dev/null. Send 
the welcome and

auto-compile messages to (current-info-port).

I had a patch for this at one time, but can't find it right now.


I found it.  Here is a link: 
https://github.com/mwette/guile-contrib/blob/main/patch/3.0.9/info-port.patch


If you type `guile -I` you get desired behavior.    Thinking of changing 
to make the info-port /dev/null by default.


Matt




Re: GUILE_QUIET=1 guile → suppress REPL welcome message (fixed message format)

2024-03-11 Thread Matt Wette

On 3/10/24 6:01 PM, Dr. Arne Babenhauserheide wrote:

Hi,

It’s been two months now, did anyone get to review this patch?

It’s small and it gives an instant improvement when using Guile in Emacs
orgmode babel sourceblocks that get evaluated on export.

Best wishes,
Arne

I did look at it.  Another solution, I prefer, is generate a global 
urrent-info-port object and
provide a command-line option to make that a file or /dev/null. Send the 
welcome and

auto-compile messages to (current-info-port).

I had a patch for this at one time, but can't find it right now.

Matt


speeding up Guile [was: Guix Mentor (paid) — including "speed up Guix"]

2023-12-27 Thread Matt Wette

On 12/27/23 8:17 AM, Dr. Arne Babenhauserheide wrote:

Hafeez Bana  writes:


The kind of advice you would be giving is:

…

Alternatively, if there are sysadmin shops that are interested in doing
this work - please contact me.

勺 Guix.

Out of interest: Did you already receive applications for this?

If not: ping to all who may have missed your email ☺

Speeding up Guix partially means speeding up Guile — I know there are
people here who are very interested in that.



FYI, I found that rlb's string update reduced guile compute time 20% for 
a big ffi-helper run.
I wonder if that would help guix as well.   I'm not sure how easy it 
would be to test.


ref: https://codeberg.org/rlb/guile/src/branch/utf8

Matt


guile support for multiple languages [was: [PATCH] add language/wisp to Guile?]

2023-10-02 Thread Matt Wette




On 10/2/23 7:59 AM, Christine Lemmer-Webber wrote:

"Philip McGrath"  writes:


I've sort of alluded above to my pipe dream of a grand unified future
for Racket-and-Guile-on-Chez, Guile-and-Racket-on-the-Guile-VM, and
endless other possibilities. I wrote about it in more detail on the
guix-devel list at [10]. (These thoughts were inspired by
conversations with Christine Lemmer-Webber, though she bears no
responsibility for my zany imaginings.)

It's a long email so I'm only quoting the part that mentions me.  ;)

In general I think the hash-lang idea in Racket is a neat one.  File
extensions are also possible I suppose, but ultimately, when the program
boots, there has to be some sort of way of finding the "current
configuration" of languages.

Note that #langs have an ambient authority problem, if we had a more
ocap'y system, but... we're far from that, any module can do a mess of
things, so I suppose if we're relying on the module system with ambient
authority already, the same situation may apply.

One thing that's worth noting is that languages do *two things* (or
three): they provide a reader, and they provide an execution model
(including an initial set of bindings).  It would be nice if we could
separate those two things as much as possible, when it is possible.
I think readers are the least interesting part of language design
usually.  But obviously I support Wisp here, so... ;)

  - Christine


Maybe I missed something, but I believe guile does separate these.
Languages are supported with the "spec.scm" files in which are
specified #:reader, #:evaluator and #:make-default-environment.

Matt



pull requests for guile

2023-05-06 Thread Matt Wette

Hi All,

Does the savannah git repo support `git-request-pull'?   And if so,
would that make getting patches in more efficient?   It seems the guile
project needs a way to get simple fixed, at least, merged in.  Would
this help?

Matt




ref manual errors in assembler insn descriptions

2023-03-11 Thread Matt Wette

Hi All,

I'm pretty sure the instruction desciprtions shown below in the manual
are in error.   Please let me know if my corrections are correct.

Matt

--- vm.texi-orig    2023-03-11 08:40:59.000388237 -0800
+++ vm.texi    2023-03-11 08:48:57.940061512 -0800
@@ -1468,8 +1468,8 @@
 @var{obj}, and store it to @var{dst}.
 @end deftypefn

-@deftypefn Instruction {} scm-set! s8:@var{dst} s8:@var{idx} s8:@var{obj}
-@deftypefnx Instruction {} scm-set!/immediate s8:@var{dst} c8:@var{idx} 
s8:@var{obj}

+@deftypefn Instruction {} scm-set! s8:@var{obj} s8:@var{idx} s8:@var{val}
+@deftypefnx Instruction {} scm-set!/immediate s8:@var{obj} c8:@var{idx} 
s8:@var{val}

 Store the @code{scm} local @var{val} into object @var{obj} at word
 offset @var{idx}.
 @end deftypefn
@@ -1490,8 +1490,8 @@
 the @code{u64} local @var{dst}.
 @end deftypefn

-@deftypefn Instruction {} word-set! s8:@var{dst} s8:@var{idx} s8:@var{obj}
-@deftypefnx Instruction {} word-set!/immediate s8:@var{dst} 
c8:@var{idx} s8:@var{obj}

+@deftypefn Instruction {} word-set! s8:@var{obj} s8:@var{idx} s8:@var{val}
+@deftypefnx Instruction {} word-set!/immediate s8:@var{obj} 
c8:@var{idx} s8:@var{val}

 Store the @code{u64} local @var{val} into object @var{obj} at word
 offset @var{idx}.
 @end deftypefn
@@ -1501,7 +1501,7 @@
 to the unboxed pointer local @var{dst}.
 @end deftypefn

-@deftypefn Instruction {} pointer-set!/immediate s8:@var{dst} 
c8:@var{idx} s8:@var{obj}
+@deftypefn Instruction {} pointer-set!/immediate s8:@var{obj} 
c8:@var{idx} s8:@var{val}

 Store the unboxed pointer local @var{val} into object @var{obj} at word
 offset @var{idx}.
 @end deftypefn




Re: [PATCH] add language/wisp to Guile?

2023-02-26 Thread Matt Wette

On 2/26/23 10:03 AM, Dr. Arne Babenhauserheide wrote:

Matt Wette  writes:


With respect to file extensions, guile does not use file extension:
You can name a file containing Scheme code "foo.js" and "guile foo.js"
will execute it.

The module-system uses file extensions: If you

(define-module (foo) #:export (main))
(define (main args) (display 'foo))

in foo.js, then

guile -L . -e  '(foo)' -c ''

won’t find it. But it will find it in foo.scm.



Guile does not use file extensions consistently, then?




Re: [PATCH] add language/wisp to Guile?

2023-02-26 Thread Matt Wette

With respect to file extensions, guile does not use file extension:
You can name a file containing Scheme code "foo.js" and "guile foo.js"
will execute it.

The code in the wip-load-lang branch provides file-extension support:
1) Currently emacscript, with "js" extension, elisp, with "el" extension,
    and Scheme, with "scm" extension, are supported.
2) Additional languages can be added by calling add-lang-extension,
    from (system base compile): (add-lang-extension "m" 'nx-mlang)

Matt





Re: [PATCH] add language/wisp to Guile?

2023-02-24 Thread Matt Wette

On 2/24/23 3:51 PM, Maxime Devos wrote:

On 25-02-2023 00:48, Maxime Devos wrote:

(**) For compatibility with Racket, it's not like we couldn't
implement both "#lang" and "-*- stuff: language -*-".


TBC, I mean ‘only support #lang' for values of 'lang' that Racket 
supports’, or alternatively ‘support #lang for compatibility, but 
recommend -*- ... -*- in the Guile manual.’.


The point of this is to tell the compiler what language it needs to parse,
if not the default (Scheme).  Using `#lang pascal' or `#!lang pascal' 
allows

the compiler to figure this out in the first few characters read. Using
`-*- lang: pascal -*-' might require the compiler to read a lot of text 
(not knowing
if what text is comment or not) to determine if language has been 
specified.

For the `-*-' based design, is there a maximum number of characters to be
read before deciding?

Matt




Re: [PATCH] add language/wisp to Guile?

2023-02-18 Thread Matt Wette

On 2/18/23 7:58 AM, Maxime Devos wrote:

On 18-02-2023 04:50, Philip McGrath wrote:

I haven't read the patch or this thread closely,


I'll assume you have read it non-closely.

but R6RS has an answer to any concerns about compatibility with 
`#lang`. At the beginning of Chapter 4, "Lexical and Datum Syntax" 
() 
the report specifies:


  An implementation must not extend the lexical or datum syntax in 
any way, with one exception: it need not treat the syntax 
`#!`, for any  (see section 4.2.4) that is 
not `r6rs`, as a syntax violation, and it may use specific 
`#!`-prefixed identifiers as flags indicating that subsequent input 
contains extensions to the standard lexical or datum syntax. The 
syntax `#!r6rs` may be used to signify that the input afterward is 
written with the lexical syntax and datum syntax described by this 
report. `#!r6rs` is otherwise treated as a comment; see section 4.2.3.


That is for '#!lang', not '#lang'.  R6RS allows the former, but the 
patch does the latter.  As such, R6RS does not have an answer about 
incompatibility with `#lang', unless you count ‘it's incompatible’ as 
an answer.


I just looked on the web and it appears that #! as first line is a 
comment in JavaScript also.


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#hashbang_comments




Re: [PATCH] add language/wisp to Guile?

2023-02-16 Thread Matt Wette

On 2/16/23 1:38 PM, Dr. Arne Babenhauserheide wrote:

Matt Wette  writes:


You may be interested in the load-lang patch I generated a few years ago
to allow file-extension based loading, in addition to '#lang elisp"
type hooks.

https://github.com/mwette/guile-contrib/blob/main/patch/3.0.8/load-lang.patch

@Maxime: Is this something you’d be interested in championing?

@Matt: Who needs to ack your patch for it to go into the repo?



If by repo you mean main branch, I'm guessing this is a Ludo/Andy call.
Maybe someone (you?) with write priv's could make a wip-branch for it?

Matt




Re: [PATCH] add language/wisp to Guile?

2023-02-14 Thread Matt Wette

You may be interested in the load-lang patch I generated a few years ago
to allow file-extension based loading, in addition to '#land elisp" type 
hooks.


https://github.com/mwette/guile-contrib/blob/main/patch/3.0.8/load-lang.patch

Matt




Re: patch for mmap and friends

2023-01-14 Thread Matt Wette




On 1/14/23 2:42 PM, Maxime Devos wrote:

    {
  /* Use the fd of the port under clobber protection from
 concurrency. As scm_dynwind_acquire_port assumes that
 FILE is a port, check that first. */
  SCM_VALIDATE_PORT (SCM_ARG5, file);
  scm_dynwind_acquire_port (file);
  c_fd = scm_fileno (file);
    }


Thanks.  I'll try this, modulo update to  scm_to_int (scm_fileno (file)).

Matt




Re: patch for mmap and friends

2023-01-14 Thread Matt Wette

On 1/14/23 8:31 AM, Matt Wette wrote:

On 1/14/23 7:18 AM, Maxime Devos wrote:

\
Port objects should be accepted too, as previously asked on 
<https://lists.gnu.org/archive/html/guile-user/2022-06/msg00060.html>.
As implied by later comments, using a raw fd causes problems with 
'move->fdes'.  For the remaining response, I'll assume that the 
function accepts ports as well.





To avoid this problem, you can add

  scm_remember_upto_here_1 (fd);

after the SCM_SYSCALL.
\



IIRC there is a C trick involving fields, arrays and types to check 
this at compile-time instead.  Maybe:


struct whatever {
   /* if availability of zero-length arrays can be assumed */
   int foo[sizeof(size_t) - sizeof(void*)];
   /* alternatively, a weaker but portable check */
   int foo[sizeof(size_t) - sizeof(void*) + 1];
};

Greetings,
Maxime.


Thanks for the feedback.   I'm sorry I missed you comments on the 
previous round.

I did respond to the ones I did catch.    I'll work this and resubmit.

Matt




Here is another shot.
1) added port support
2) used dynwind to protect port/fd.
3) removed the assert: I don't know why I put it in there.

Notes:
1) four other guile headers needed: atomic-internal, foreign, finalizers 
and ioext

2) had to copy/modify dynwind_acquire_port and release_port from ports.c
3) one maybe-kludge is if an fd is passed I use (car (fd->ports fd)) for 
acquire_port


Matt

static void
mmap_finalizer (void *ptr, void *data)
{
  SCM bvec;
  void *c_addr;
  size_t c_len;
  int rv;

  bvec = SCM_PACK_POINTER (ptr);
  if (!SCM_BYTEVECTOR_P (bvec))
    scm_misc_error ("mmap", "expecting bytevector", SCM_EOL);

  c_addr = SCM_BYTEVECTOR_CONTENTS (bvec);
  c_len = SCM_BYTEVECTOR_LENGTH (bvec);
  SCM_SYSCALL (rv = munmap(c_addr, c_len));
  if (rv != 0)
    scm_misc_error ("mmap", "failed to munmap memory", SCM_EOL);
}

/* Code for scm_dynwind_acquire_port and release_port sourced from 
ports.c. */


static void
release_port (SCM port)
{
  scm_t_port *pt = SCM_PORT (port);
  uint32_t cur = 1, next = 0;
  while (!scm_atomic_compare_and_swap_uint32 (>refcount, , next))
    {
  if (cur == 0)
    return;
  next = cur - 1;
    }
 if (cur > 1)
    return;

  if (SCM_PORT_TYPE (port)->close)
    SCM_PORT_TYPE (port)->close (port);

  /* Skip encoding code from ports.c! */
}

static void
scm_dynwind_acquire_port (SCM port)
{
  scm_t_port *pt = SCM_PORT (port);
  uint32_t cur = 1, next = 2;
  while (!scm_atomic_compare_and_swap_uint32 (>refcount, , next))
    {
  if (cur == 0)
    scm_wrong_type_arg_msg (NULL, 0, port, "open port");
  next = cur + 1;
    }
  scm_dynwind_unwind_handler_with_scm (release_port, port,
   SCM_F_WIND_EXPLICITLY);
}

SCM_DEFINE (scm_mmap_search, "mmap/search", 2, 4, 0,
    (SCM addr, SCM len, SCM prot, SCM flags, SCM file, SCM offset),
    "Create a memory mapping, returning a bytevector.. @var{addr},\n"
    "if non-zero, is the staring address; or, if zero, is assigned 
by\n"

    "the system.  @var{prot}, if provided, assigns protection.\n"
    "@var{file}, a port or fd, if provided associates the memory\n"
    "region with a file starting at @var{offset}, if provided.\n"
    "The region returned by mmap WILL be searched by the garbage\n"
    "collector for pointers.  See also mmap.  Note that the\n"
    "finalizer for the returned bytevector will call munmap.\n"
    "Defaults for optional arguments are\n"
    "@table @asis\n"
    "@item prot\n(logior PROT_READ PROT_WRITE)\n"
    "@item flags\n(logior MAP_ANONYMOUS MAP_PRIVATE)\n"
    "@item fd\n-1\n"
    "@item offset\n0\n"
    "@end table")
#define FUNC_NAME s_scm_mmap_search
{
  void *c_mem, *c_addr;
  size_t c_len;
  int c_prot, c_flags, c_fd;
  scm_t_off c_offset;
  SCM pointer, bvec;

  if (SCM_POINTER_P (addr))
    c_addr = SCM_POINTER_VALUE (addr);
  else if (scm_is_integer (addr))
    c_addr = (void*) scm_to_uintptr_t (addr);
  else
    scm_misc_error ("mmap", "bad addr", addr);

  c_len = scm_to_size_t (len);

  if (SCM_UNBNDP (prot))
    c_prot = PROT_READ | PROT_WRITE;
  else
    c_prot = scm_to_int (prot);

  if (SCM_UNBNDP (flags))
    c_flags = MAP_ANONYMOUS | MAP_PRIVATE;
  else
    c_flags = scm_to_int (flags);

  scm_dynwind_begin (0);

  if (SCM_UNBNDP (file))
    c_fd = -1;
  else {
    /* Use the fd under clobber protection from GC or another thread. */
    if (SCM_PORTP (file))
  c_fd = scm_to_int (scm_fileno (file));
    else {
  c_fd = scm_to_int (file);
  file = SCM_CAR (scm_fdes_to_ports (file));
    }
    scm_dynwind_acquire_port (file);
  }

  if (SCM_UNBNDP (offset))
    c_offset = 0;
  else
    c_offset 

Re: patch for mmap and friends

2023-01-14 Thread Matt Wette

On 1/14/23 7:18 AM, Maxime Devos wrote:

\
Port objects should be accepted too, as previously asked on 
.
As implied by later comments, using a raw fd causes problems with 
'move->fdes'.  For the remaining response, I'll assume that the 
function accepts ports as well.





To avoid this problem, you can add

  scm_remember_upto_here_1 (fd);

after the SCM_SYSCALL.
\



IIRC there is a C trick involving fields, arrays and types to check 
this at compile-time instead.  Maybe:


struct whatever {
   /* if availability of zero-length arrays can be assumed */
   int foo[sizeof(size_t) - sizeof(void*)];
   /* alternatively, a weaker but portable check */
   int foo[sizeof(size_t) - sizeof(void*) + 1];
};

Greetings,
Maxime.


Thanks for the feedback.   I'm sorry I missed you comments on the 
previous round.

I did respond to the ones I did catch.    I'll work this and resubmit.

Matt




Re: patch for mmap and friends

2023-01-13 Thread Matt Wette

On 1/13/23 4:49 PM, Matt Wette wrote:

Please consider this patch for adding mmap(), munmap() and msync()
 to libguile/filesys.c.  Included is update for posix.texi and test 
file mman.test.

Once included, feature 'mman should be #t.

Matt

Please add the attached file: test-suite/tests/mman.test.

I thought it was included in the patch.  It's the thought that counts, 
right?


Matt


 mman.test --- Tests for mmap API.-*- scheme -*-

 Copyright 2022 Free Software Foundation, Inc.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 3 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA

(define-module (test-mman)
  #:use-module (test-suite lib)
  #:use-module (test-suite guile-test)
  #:use-module (rnrs bytevectors)
  #:declarative? #f
  )

(define (mmap-test-file)
  (data-file-name "foo.txt"))

(define mmap-test-string "hello, world")

(define (gen-mmap-test-file)
  (with-output-to-file (mmap-test-file)
(lambda () (display mmap-test-string

(when (provided? 'mman)

  (gen-mmap-test-file)

  (with-test-prefix "mman"

(pass-if "mman 1"
  (let ((bv (mmap 0 #x100)))
(bytevector-u8-set! bv 0 34)
(= (bytevector-u8-ref bv 0) 34)))

))

;; --- last line ---


patch for mmap and friends

2023-01-13 Thread Matt Wette

Please consider this patch for adding mmap(), munmap() and msync()
 to libguile/filesys.c.  Included is update for posix.texi and test 
file mman.test.

Once included, feature 'mman should be #t.

Matt
From 6c944174d35d43f87340c8199d47f3f088fa6ca7 Mon Sep 17 00:00:00 2001
From: Matt Wette 
Date: Fri, 13 Jan 2023 16:42:06 -0800
Subject: [PATCH] Add mmap and friends (munmap, msync).

* libguile/filesys.[ch]: added scm_mmap_search, scm_mmap, scm_msync, and
  init_mman, built on availability of HAVE_MMAN_H; also provides feature
  'mman
* doc/ref/posix.texi: added documentation for mmap and friends
* test-suite/Makefile.am: updated for mman.test
* test-suite/tests/mman.test: mmap tests
---
 configure.ac   |   2 +
 doc/ref/posix.texi |  45 +++
 libguile/filesys.c | 264 +
 libguile/filesys.h |   4 +
 test-suite/Makefile.am |   1 +
 5 files changed, 316 insertions(+)

diff --git a/configure.ac b/configure.ac
index f8c12f0d7..c348d14a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1018,6 +1018,8 @@ AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,
 ])
 GUILE_STRUCT_UTIMBUF
 
+AC_CHECK_FUNCS([msync])
+
 
 #
 #
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index 5653d3758..16f3bbc49 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -1216,6 +1216,51 @@ valid separators.  Thus, programs should not assume that
 separator---e.g., when extracting the components of a file name.
 @end defvr
 
+@deffn {Scheme Procedure} mmap addr len [prot [flags [fd [offset
+@deffnx {Scheme Procedure} mmap/search addr len [prot [flags [fd [offset
+Create a memory mapping, returning a bytevector.  @var{addr}, if
+non-zero, is the staring address; or, if zero, is assigned by the
+system.  @var{prot}, if provided, assigns protection.  @var{fd},
+if provided associates the memory region with a file, starting
+at @var{offset}, if provided.
+The region returned by mmap will NOT be searched by the garbage
+ collector for pointers, while that returned by mmap/search will.
+Note that the finalizer for the returned bytevector will call munmap.
+Defaults for optional arguments are
+@table @asis
+@item prot
+(logior PROT_READ PROT_WRITE)
+@item flags
+(logior MAP_ANONYMOUS MAP_PRIVATE)
+@item fd
+-1
+@item offset
+0
+@end table
+@end deffn
+
+@deffn {Scheme Procedure} munmap bvec
+Given bytevector generated by mmap or mmap/search, unmap the
+the associated memory.  The argument will be modified to
+reflect a zero length bv.  The return value is unspecified.
+Note that munmap is called by finalizer associated with
+bytevectors returned from mmap and mmap/search.
+@end deffn
+
+@deffn {Scheme Procedure} msync addr length flag
+Flush changes made to the in-core copy of a file mapped using
+mmap or mmap/search.  This should be executed on modified memory
+before calling munmap.  The @var{flags} argument must be exactly one
+of the following:
+@table @code
+@item MS_ASYNC
+Initiate update, return immediately.
+@item MS_SYNC
+Initiate update, block until complete.
+@item MS_INVALIDATE
+Invalidate other mappings of the same file.
+@end table
+@end deffn
 
 @node User Information
 @subsection User Information
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 1f0bba556..0ddb4cfee 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -67,11 +67,17 @@
 # include 
 #endif
 
+#ifdef HAVE_SYS_MMAN_H
+# include 
+#endif
+
 #include "async.h"
 #include "boolean.h"
 #include "dynwind.h"
 #include "fdes-finalizers.h"
 #include "feature.h"
+#include "finalizers.h"
+#include "foreign.h"
 #include "fports.h"
 #include "gsubr.h"
 #include "iselect.h"
@@ -2263,6 +2269,261 @@ scm_dir_free (SCM p)
 
 
 
+#ifdef HAVE_SYS_MMAN_H
+/* see https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html */
+
+static void
+mmap_finalizer (void *ptr, void *data)
+{
+  SCM bvec;
+  void *c_addr;
+  size_t c_len;
+  int rv;
+
+  bvec = SCM_PACK_POINTER (ptr);
+  if (!SCM_BYTEVECTOR_P (bvec))
+scm_misc_error ("mmap", "expecting bytevector", SCM_EOL);
+
+  c_addr = SCM_BYTEVECTOR_CONTENTS (bvec);
+  c_len = SCM_BYTEVECTOR_LENGTH (bvec);
+  SCM_SYSCALL (rv = munmap(c_addr, c_len));
+  if (rv != 0)
+scm_misc_error ("mmap", "failed to munmap memory", SCM_EOL);
+}
+
+SCM_DEFINE (scm_mmap_search, "mmap/search", 2, 4, 0,
+(SCM addr, SCM len, SCM prot, SCM flags, SCM fd, SCM offset),
+	"Create a memory mapping, returning a bytevector..  @var{addr},\n"
+	"if non-zero, is the staring address; or, if zero, is assigned by\n"
+	"the system.  @var{prot}, if provided, assigns protection.\n"
+	"@var{fd}, if provided associates the memory region with a file\n"
+	"starting at @var{offset}, if prov

Re: Guile Developer Meetup at Guix days 2023

2022-12-28 Thread Matt Wette

On 12/27/22 4:42 PM, jgart wrote:

Hi Guilers,

I had mentioned on IRC a few weeks ago regarding meeting up to discuss ways 
that we can improve the Guile debugger, be it through better documentation 
tutorials, patches to the C or Scheme code, etc. People seemed to be interested 
in meeting up.


I'd suggest this paper if you don't know much about the dwarf format:

    https://dwarfstd.org/doc/Debugging%20using%20DWARF-2012.pdf

I'm in US/Pacific time zone and may attend remotely if 
timing/teleconnect works out.


From the digging I've done it seems a bit more dwarf generation needs 
to be added

to the compiler.

Matt





Re: patch to add support for mmap and friends

2022-12-21 Thread Matt Wette

On 12/20/22 5:21 PM, Matt Wette wrote:

Please consider the atttached patch for mmap and friends.
Includes mmap, mmap/shared, munmap, msync. \


I ran into a bug on this.  Not sure how it got there.  I was hoping to 
get into the 3.0.9

release.   Any idea when that might happen?

Matgt



patch to add support for mmap and friends

2022-12-20 Thread Matt Wette

Guile Maintainers:

Please consider the atttached patch for mmap and friends.
Includes mmap, mmap/shared, munmap, msync.

Matt
From 306570beb3d1895abd03700593cc342282e4ccd1 Mon Sep 17 00:00:00 2001
From: Matt Wette 
Date: Tue, 20 Dec 2022 17:15:27 -0800
Subject: [PATCH] Add support for mmap, munmap and msync

* libguile/filesys.c(mmap,munmap,msync): added implementation for mmap
  and friends
* doc/ref/posix.texi: add documentation for mmap and friends
---
 configure.ac   |  12 ++
 doc/ref/posix.texi |  45 ++
 libguile/filesys.c | 268 +
 libguile/filesys.h |   4 +
 test-suite/Makefile.am |   1 +
 test-suite/tests/mmap-api.test |  47 ++
 6 files changed, 377 insertions(+)
 create mode 100644 test-suite/tests/mmap-api.test

diff --git a/configure.ac b/configure.ac
index b3879df1f..da49d477a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -199,6 +199,10 @@ AC_ARG_ENABLE(regex,
   [  --disable-regex omit regular expression interfaces],,
   enable_regex=yes)
 
+AC_ARG_ENABLE(mmap_api,
+  AS_HELP_STRING([--disable-mmap_api],[omit mmap API]),,
+  enable_mmap_api=yes)
+
 AC_ARG_ENABLE(tmpnam,
   AS_HELP_STRING([--disable-tmpnam],[omit POSIX tmpnam]),,
   enable_tmpnam=yes)
@@ -950,6 +954,10 @@ if test "$enable_regex" = yes; then
AC_DEFINE([ENABLE_REGEX], 1, [Define when regex support is enabled.])
 fi
 
+if test "$enable_mmap_api" = yes; then
+   AC_DEFINE([ENABLE_MMAP_API], 1, [Define when mmap API support is enabled.])
+fi
+
 if test "$enable_tmpnam" = yes; then
AC_DEFINE([ENABLE_TMPNAM], 1, [Define when tmpnam support is enabled.])
 fi
@@ -1018,6 +1026,10 @@ AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,
 ])
 GUILE_STRUCT_UTIMBUF
 
+if test "$enable_mmap_api" = "yes"; then
+  AC_CHECK_FUNCS([msync])
+fi
+
 
 #
 #
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index bde0f150c..8114135fe 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -1216,6 +1216,51 @@ valid separators.  Thus, programs should not assume that
 separator---e.g., when extracting the components of a file name.
 @end defvr
 
+@deffn {Scheme Procedure} mmap addr len [prot [flags [fd [offset
+@deffnx {Scheme Procedure} mmap/search addr len [prot [flags [fd [offset
+Create a memory mapping, returning a bytevector.  @var{addr}, if
+non-zero, is the staring address; or, if zero, is assigned by the
+system.  @var{prot}, if provided, assigns protection.  @var{fd},
+if provided associates the memory region with a file, starting 
+at @var{offset}, if provided.
+The region returned by mmap will NOT be searched by the garbage
+ collector for pointers, while that returned by mmap/search will.
+Note that the finalizer for the returned bytevector will call munmap.
+Defaults for optional arguments are
+@table @asis
+@item prot
+(logior PROT_READ PROT_WRITE)
+@item flags
+(logior MAP_ANONYMOUS MAP_PRIVATE)
+@item fd
+-1
+@item offset
+0
+@end table
+@end deffn
+
+@deffn {Scheme Procedure} munmap bvec
+Given bytevector generated by mmap or mmap/search, unmap the
+the associated memory.  The argument will be modified to 
+reflect a zero length bv.  The return value is unspecified.
+Note that munmap is called by finalizer associated with
+bytevectors returned from mmap and mmap/search.
+@end deffn
+
+@deffn {Scheme Procedure} msync addr length flag
+Flush changes made to the in-core copy of a file mapped using
+mmap or mmap/search.  This should be executed on modified memory
+before calling munmap.  The @var{flags} argument must be exactly one
+of the following:
+@table @code
+@item MS_ASYNC
+Initiate update, return immediately.
+@item MS_SYNC
+Initiate update, block until complete.
+@item MS_INVALIDATE
+Invalidate other mappings of the same file.
+@end table
+@end deffn
 
 @node User Information
 @subsection User Information
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 1f0bba556..ad3dab471 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -67,11 +67,17 @@
 # include 
 #endif
 
+#if defined(ENABLE_MMAP_API) && defined(HAVE_SYS_MMAN_H)
+# include 
+#endif
+
 #include "async.h"
 #include "boolean.h"
 #include "dynwind.h"
 #include "fdes-finalizers.h"
 #include "feature.h"
+#include "finalizers.h"
+#include "foreign.h"
 #include "fports.h"
 #include "gsubr.h"
 #include "iselect.h"
@@ -2263,6 +2269,264 @@ scm_dir_free (SCM p)
 
 
 
+#ifdef ENABLE_MMAP_API
+#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MAP_ANONYMOUS)
+
+/* see https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html */
+
+static void
+mmap_finalizer (void *ptr, void *data)
+{
+  SCM bvec;
+  void *c_addr;
+  size_t c_len;
+  int rv;
+
+  bvec = SCM_PACK_POINTER (ptr);
+  if (!SCM_BYTEVECTOR_P (bvec))
+   

Re: mmap for guile

2022-06-26 Thread Matt Wette
Appologies: link is 
https://github.com/mwette/guile-contrib/blob/main/patch/3.0.8/mmap-api.patch


On 6/26/22 8:37 AM, Matt Wette wrote:

I have a candidate mmap implementation for guile (3.0.8) in

github.com/mwette/guile-contrib/patch/3.0.8/mmap-api.patch

It probably needs some review and update.  Maybe windows mmap-file 
would be nice.
I'm not sure I updated the configure correctly but --disable-mmap-api 
should remove.

It exposes features 'mmap-api and 'mmap-file.

scheme@(guile-user)> ,d mmap
- Scheme Procedure: mmap addr len [prot [flags [fd [offset
 See the man page.  Returns a bytevector.  Note that the region
 returned by mmap will NOT be searched by the garbage collector for
 pointers.  See also mmap/search.  Defaults are:

 prot
  (logior PROT_READ PROT_WRITE)

 flags
  (logior MAP_ANON MAP_PRIVATE)

 fd
  -1

 offset
  0

scheme@(guile-user)> ,d mmap/search
- Scheme Procedure: mmap/search addr len [prot [flags [fd [offset
 See the unix man page for mmap.  Returns a bytevector.  Note that
 the region allocated will be searched by the garbage collector for
 pointers.  Defaults:

 prot
  (logior PROT_READ PROT_WRITE)

 flags
  (logior MAP_ANON MAP_PRIVATE)

 fd
  -1

 offset
  0

scheme@(guile-user)> ,d mmap-file
- Scheme Procedure: mmap-file file [prot]
 This procedure accepts a file in the form of filename, file-port or
 fd.  It returns a bytevector.  It must not contain scheme allocated
 objects as it will not be searched for pointers.  Default PROT is
 `"r"'.







mmap for guile

2022-06-26 Thread Matt Wette

I have a candidate mmap implementation for guile (3.0.8) in

github.com/mwette/guile-contrib/patch/3.0.8/mmap-api.patch

It probably needs some review and update.  Maybe windows mmap-file would be 
nice.
I'm not sure I updated the configure correctly but --disable-mmap-api should 
remove.
It exposes features 'mmap-api and 'mmap-file.

scheme@(guile-user)> ,d mmap
- Scheme Procedure: mmap addr len [prot [flags [fd [offset
 See the man page.  Returns a bytevector.  Note that the region
 returned by mmap will NOT be searched by the garbage collector for
 pointers.  See also mmap/search.  Defaults are:

 prot
  (logior PROT_READ PROT_WRITE)

 flags
  (logior MAP_ANON MAP_PRIVATE)

 fd
  -1

 offset
  0

scheme@(guile-user)> ,d mmap/search
- Scheme Procedure: mmap/search addr len [prot [flags [fd [offset
 See the unix man page for mmap.  Returns a bytevector.  Note that
 the region allocated will be searched by the garbage collector for
 pointers.  Defaults:

 prot
  (logior PROT_READ PROT_WRITE)

 flags
  (logior MAP_ANON MAP_PRIVATE)

 fd
  -1

 offset
  0

scheme@(guile-user)> ,d mmap-file
- Scheme Procedure: mmap-file file [prot]
 This procedure accepts a file in the form of filename, file-port or
 fd.  It returns a bytevector.  It must not contain scheme allocated
 objects as it will not be searched for pointers.  Default PROT is
 `"r"'.




Re: new function

2021-09-19 Thread Matt Wette




On 9/19/21 7:41 AM, Matt Wette wrote:

On 9/19/21 12:54 AM, Damien Mattei wrote:

hello,
i'm developing an extension to Scheme
and i need a procedure or macro that define a variable only if it is 
not bind and if it is just set! it.


I can not do it in Guile or any Scheme,and i'm desperately searching 
a way to do that. I finally conclude that it can be done only by 
adding it in the language.


Can someone include a such function in Guile next release?
i know guile have a predicate defined? to test binfing of a vairable 
but writing a macro with it is not possible because define can be 
used in an expression context.


Thank in advance for any help
Damien


Check the manual.

scheme@(guile-user)> (define-once a 1)
scheme@(guile-user)> (define-once a 2)
scheme@(guile-user)> a
$1 = 1
scheme@(guile-user)>



Sorry.  I misread your post.   How about this:

mwette$ guile
scheme@(guile-user)> (define-once a 1)
scheme@(guile-user)> (define-once a 2)
scheme@(guile-user)> a
$1 = 1

scheme@(guile-user)> (define a 1)
scheme@(guile-user)> (define a 2)
scheme@(guile-user)> a
$2 = 2
scheme@(guile-user)>






Re: new function

2021-09-19 Thread Matt Wette

On 9/19/21 12:54 AM, Damien Mattei wrote:

hello,
i'm developing an extension to Scheme
and i need a procedure or macro that define a variable only if it is 
not bind and if it is just set! it.


I can not do it in Guile or any Scheme,and i'm desperately searching a 
way to do that. I finally conclude that it can be done only by adding 
it in the language.


Can someone include a such function in Guile next release?
i know guile have a predicate defined? to test binfing of a vairable 
but writing a macro with it is not possible because define can be used 
in an expression context.


Thank in advance for any help
Damien


Check the manual.

scheme@(guile-user)> (define-once a 1)
scheme@(guile-user)> (define-once a 2)
scheme@(guile-user)> a
$1 = 1
scheme@(guile-user)>





Re: more advanced bytevector => supervectors

2021-09-02 Thread Matt Wette

maybe guile could consider regexp's in scheme
see  https://ds26gte.github.io/pregexp/index.html

On 9/2/21 8:45 AM, Stefan Israelsson Tampe wrote:

Hi guilers!

My next project is to explore a more advanced bytevector structure 
than today's bytevectors.
I think that having this infrastructure in guile and core code taken 
advantage of it like having strings otop of it and allowing our string 
library to use those (the difficult case is probably to get regexps 
working properly)


Anyhow this is my initial comment in the code:

#|
The idea of this data structure is to note that when we employ full
large datastructure scans we can allow for a much more rich and 
featurefull

datastructure then a simple bytevector. The reason is that we can divide
the data in byte chunks and spend most of the time scanning copying maping
those areas with usual methis, even optimized C - code taken advantage 
of advanced cpu opcodes are possible here. ANd by dividing it in 
chunks we get a lot of new features with essentiually no cose with 
more than complexity which we manage mostly in scheme. We gain many 
things,


1. Many new features that can vary on the pages

2. less memory hogs as
   a. it can use copy ion write semantics
   b. it does not need to fins 1GB continuous blocks

3. potentially faster operations as we can fast foorward the zeroe on 
write

   pages compared to pure bytevectors

4. we can allow for swaping and refferential datastructures to speed 
up copying

   even further

5. can get better fiber features of C programs that spends seconds or 
minutes on
   performing an operation because it will just spend a microsecond or 
such

   in C-land and then swap back to Scheme. CTRL-C will also work nicely.

6. We could potentially build a string library untop of these 
datastructures and
   also we could add features to pages that lead to a much richer 
interface.


7. resizing is much faster end efficient

8. reversing is super quick

9. queues and stacks of byte data can have a very efficient 
implementations


Drawback:
1. More complex as we need to consider boudaries
2. Slower one off operations like bytevector-u8-get as guile compiles the
   core operatoins to quite effective JIT CPU encodings. But maybe we can
   disign some caching to make those operations much faster and even have
   suporting JIT operations.

|#

WDYT ?






Re: Implementing ES6 on top of Guile

2021-07-06 Thread Matt Wette

On 7/5/21 3:52 AM, Ayush Jha wrote:

The issue:

I found an implementation of ECMAScript on Guile in the docs, and I was
wondering if anyone is working on improving it/building an alternative.

I would love to get started on it. What is the status of the ECMAScript
implementation project as of now?


My Background:

I am very new to the Guile project. I have written scripts in Guile and
have dabbled in the source code, but over all - I am fairly new to the
project.



NYACC includes an example of partial javascript implementation:

https://git.savannah.nongnu.org/cgit/nyacc.git/tree/examples/nyacc/lang/javascript

I stopped at implementing objects, because I wanted to have a
uniform implementation.   The above does have functions and control 
structures.


Matt




Re: riscv files for lightening

2021-01-30 Thread Matt Wette




On 1/29/21 11:13 AM, Matt Wette wrote:

Andy,

I took a stab at porting RISC-V from lightning to lightening.
I have no riscv toolset or computer yet so these are untested.

I copied files from sv/lightning for riscv to wingo/lightening. Patch 
attached.

The changes are:
1) copy lightning/jit_riscv{.c,-cpu.c-fpu.c,-sz.c,.h} to lightening
2) s/include "jit_riscv/include "riscv/
3) s/git_int/int/ and s/git_uint/uint/
4) copied the JIT_RA0, etc defines from jit_private.h to riscv.c
5) updated lightening.am
6) updated lightening.h

Matt


I did find github.com/riscv/riscv/riscv-gnu-toolchain.
I'm going to see where that goes wrt testing.

Matt




generating SXML trees in guile

2021-01-09 Thread Matt Wette

This is a FYI, not saying this is a bug.

I'm digging into the sxml xpath procedures and came across a potential
issue with using sxml in Guile.

I believe I remember that Oleg's SXML code relies on the fact that no
nodes a sxml tree are eq?.   For example, in the SXML tree

    (define sx1  '(*TOP* (a "1") (a "1)))

node-parent in (sxml xpath) depends on the fact that

    (eq? (list-ref sx1 1) (list-ref sx1 2)
=>
#f

But the result, in Guile 3.0.4, is
#t

I'm guessing this is cse optimization at work.  I tried this also:

(let* ((sx2 '())
   (sx2 (cons '(a "1") sx2))
   (sx2 (cons '(a "1") sx2))
   (sx2 (cons '*TOP* sx2)))
  (eq? (list-ref sx2 1) (list-ref sx2 2)))
=>
#t

In my sandbox, I'm using copy-tree which seems to be changing
the #t to #f, so at least that works.

Matt




compile-file execution time driven by `reap-pipes'

2020-04-06 Thread Matt Wette

I'm wanted to trace down why some of my "compile-file" w/ no optimization
was tasking time.  I was able to turn compile-file under statprof for one
of the moderate sized .scm files, which has about 45,000 lines of code.
It was interesting that the major execution time consumer was reap-pipes.
I'm curious where that fits in.  Does anyone know how compile-file could
be banging on reap-pipes so much?  Below is the top output from statprof.
The results are for a run using guile 3.0.2 on Ubunu 18.04/x86_64.


% cumulative   self calls
time   secondsseconds   procedure
 12.67190.96154.99  ice-9/popen.scm:145:0:reap-pipes
 12.30363.41150.49  language/cps/intset.scm:270:2:adjoin
 11.23270.27137.34  anon #x55befcb4c430
 10.89186.95133.18  language/cps/slot-allocation.scm:843:19
 10.58129.40129.40  language/cps/intmap.scm:396:0:intmap-ref
  5.31   1279.35 64.90  language/cps/intmap.scm:247:2:adjoin
  3.81228.54 46.66  language/cps/intset.scm:269:0:intset-add
  3.48   4695.90 42.60  language/cps/intset.scm:470:5:visit-branch
  3.28 40.14 40.14  language/cps/intset.scm:349:0:intset-ref
  2.98567.14 36.46  language/cps/intmap.scm:246:0:intmap-add




Re: definitions in macros?

2020-03-22 Thread Matt Wette

On 3/22/20 12:07 PM, Han-Wen Nienhuys wrote:

Hi there,

in my quest to get lilypond working with GUILE 2+, I've hit another
stumbling block.

In order to make compilation with GUILE 2+ working, we have to move
away from runtime symbol definition (ie. module-define! calls).

In the code below, it looks like only one of the two definitions in
the body of my-macro-new takes effect. Is this expected, and if so,
why?

(defmacro-public my-macro-old (command-and-args . definition)
   (module-define! (current-module) 'x1 "I am X1\n")
   (module-define! (current-module) 'x2 "I am X2\n"))

(defmacro-public my-macro-new (command-and-args . definition)
 `(define p "i am P\n")
 `(define q "i am Q\n"))


(my-macro-old 1 2)
(my-macro-new 1 2)
(display x1)
(display x2)
(display q)
(display p)


thanks,



Try the following.  Not sure about defmacro but define-syntax must 
return a single form.


(defmacro-public my-macro-new (command-and-args . definition)
`(begin
  (define p "i am P\n")
  (define q "i am Q\n")))

 







dynamic-link issue: does not always load

2020-03-20 Thread Matt Wette

There is an old bug report #21076 on dynamic-link:

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21076

Say you have a file libyaml.0.so-2, dynamic-link can't load it

    (dynamic-link "libyaml.0.so-2") => exception

even if there is a file libyaml.so:

  $ cat /usr/lib64/libyaml.so
  INPUT(libyaml-0.so.2)

it fails with (dynamic-link "libyaml")

I have submitted the following patch, which at least
makes the first version work.  If you think this is a libtool
but you may be right, but the bug report on this has not
been touched for 8 years:

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=8976

This patch fixes issue with libtool and OSes which use
non-standard extensions for shared libraries.  The libltdl
function lt_dlopenext expects the argument to have a standard
extension or no extention.  Arguments reflecting shared object
files with non-standard extensions will fail to load.  For
example, my system has /usr/lib64/libyaml-0.so.2.  w/o this
patch (dynamic-link "libyaml-0.so.2") does not work; with it,
it does.  Go figure.

--- libguile/dynl.c-orig    2020-03-20 05:56:42.101214929 -0700
+++ libguile/dynl.c    2020-03-20 05:57:40.432893330 -0700
@@ -69,7 +69,10 @@
 handle = lt_dlopen (NULL);
   else
 {
-  handle = lt_dlopenext (fname);
+  handle = lt_dlopen (fname);
+
+  if (handle == NULL)
+ handle = lt_dlopenext (fname);

   if (handle == NULL
 #ifdef LT_DIRSEP_CHAR




guile's (begin) vs syntax-rules

2020-03-01 Thread Matt Wette

Scheme requires begin forms to have at least one expression.
Guile allows zero expressions, but ice-9/psyntax.scm reports a syntax error.
Do I add something like (if #f #f) to my syntax transformer or report a 
"bug"?





Re: Logo baseline

2020-01-19 Thread Matt Wette



On 1/19/20 6:11 AM, Arne Babenhauserheide wrote:

Ludovic Courtès  writes:

Other adjectives I proposed (fast, functional) don’t quite apply to
these, though.

Functional doesn’t apply to Guile much better than to CPython.



I think "functional" is used in the formal sense.
The term applies to Scheme, Haskell, SML: e.g., they iterate through 
recursion.
Python, Lua, Perl, Javascript are imperative: e.g., they iterate through 
i=i+1.






Re: Logo baseline

2020-01-18 Thread Matt Wette

On 1/18/20 6:08 AM, Ludovic Courtès wrote:

Hello Guilers!

The Guile logo has this “GNU extension language” baseline.  As Guile 3
came out, this baseline felt odd to me, not quite corresponding to the
way I see Guile.

Clearly, Guile is still an extension language, with many great
applications (Gnucash, Lepton-EDA, OpenCog, GDB, etc.), and I’m sure
libguile is here to stay.  Yet, to me, “extension language” does not
accurately capture what Guile today allows for and what people have been
doing with it; since 2.0, it’s more than an extension language, even
more so with the performance afforded by Guile 3.

Thus, I’d propose changing the baseline.  Something that would describe
what Guile is to me is:

   GNU, fast, fun, functional

What’s about you?  What’s Guile to you?  :-)

Ludo’.

To me "fast, fun, functional" does not distinguish guile very much.

I'll throw this out, though I don't think this is that good either:

Guile is GNU's functional, high-performance, systems programming 
implementation.


FWIW, I still look to guile for tool extension and integration.

Matt




Re: GNU Guile 2.9.8 Released [beta]

2020-01-02 Thread Matt Wette




On 1/2/20 5:36 AM, Andy Wingo wrote:

We are pleased to announce GNU Guile release 2.9.8.  This is the eighth
and possibly final pre-release of what will eventually become the 3.0
release series.



Compared to the previous prerelease (2.9.7), Guile 2.9.8 fixes a bug in
libguile that caused writes to unmapped memory in some circumstances.
This problem manifested itself as a failure of Guile to compile itself
on some systems, notably Ubuntu 18.04 on x86-64.  It also fixes a couple
warnings related to SRFI-35.



make and make check verified to work on Ubuntu 18.08 / x86_64





Re: GNU Guile 2.9.7 Released [beta]

2019-12-13 Thread Matt Wette



On 12/13/19 5:30 AM, Andy Wingo wrote:

We are pleased to announce GNU Guile release 2.9.7.  This is the seventh
and hopefully next-to-last pre-release of what will eventually become
the 3.0 release series.



mwette$ uname -a
Linux halibut 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 
2019 x86_64 x86_64 x86_64 GNU/Linux


mwette$ ./configure --prefix=/opt/local
...

mwette$ make
...
wrote `system/vm/frame.go'
  BOOTSTRAP GUILEC system/vm/linker.go
/bin/bash: line 6:  7565 Segmentation fault  (core dumped) 
GUILE_AUTO_COMPILE=0 ../meta/build-env guild compile 
--target="x86_64-pc-linux-gnu" -O1 -Oresolve-primitives -L 
"/home/mwette/proj/guile/guile-2.9.7/module" -L 
"/home/mwette/proj/guile/guile-2.9.7/guile-readline" -o 
"system/vm/linker.go" "../module/system/vm/linker.scm"

Makefile:1930: recipe for target 'system/vm/linker.go' failed

Same happened on 2.9.5.  Also, check this:

mwette$ cd bootstrap

mwette$ GUILE_AUTO_COMPILE=0 ../meta/build-env guild compile 
--target="x86_64-pc-linux-gnu" -O1 -Oresolve-primitives -L 
"/home/mwette/proj/guile/guile-2.9.7/module" -L 
"/home/mwette/proj/guile/guile-2.9.7/guile-readline" -o 
"system/vm/linker.go" "../module/system/vm/linker.scm"

Segmentation fault (core dumped)

mwette$ GUILE_AUTO_COMPILE=0 ../meta/build-env guild compile 
--target="x86_64-pc-linux-gnu" -O1 -L 
"/home/mwette/proj/guile/guile-2.9.7/module" -L 
"/home/mwette/proj/guile/guile-2.9.7/guile-readline" -o 
"system/vm/linker.go" "../module/system/vm/linker.scm"

wrote `system/vm/linker.go'

In the second case I removed "-Oresolve-primitives".  I could not trace 
down further.


Matt




Re: GNU Guile 2.9.6 Released [beta]

2019-12-07 Thread Matt Wette




On 12/6/19 5:14 AM, Andy Wingo wrote:

We are pleased to announce GNU Guile release 2.9.6.  This is the sixth
pre-release of what will eventually become the 3.0 release series.



Same error I get w/ 2.9.5, on Ubuntu 18.04:

  BOOTSTRAP GUILEC system/vm/linker.go
/bin/bash: line 6:  9159 Segmentation fault  (core dumped) 
GUILE_AUTO_COMPILE=0 ../meta/build-env guild compile 
--target="x86_64-pc-linux-gnu" -O1 -Oresolve-primitives -L 
"/home/mwette/proj/guile/guile-2.9.6/module" -L 
"/home/mwette/proj/guile/guile-2.9.6/guile-readline" -o 
"system/vm/linker.go" "../module/system/vm/linker.scm"

Makefile:1930: recipe for target 'system/vm/linker.go' failed
make[2]: *** [system/vm/linker.go] Error 139


I tried to get the guild-compile running under 
meta/gdb-uninstalled-guile but failed.


Matt




2.9.5 build segfault on Ubuntu 18.04 [WAS: Nyacc and guile-nearly-3.0 (progress report)]

2019-12-02 Thread Matt Wette



On 12/2/19 6:28 AM, Matt Wette wrote:

I'm building 2.9.5 now but running into errors (ubuntu 18.04):
/bin/bash: line 6: 14657 Segmentation fault  (core dumped) 
GUILE_AUTO_COMPILE=0 ../meta/build-env guild compile 
--target="x86_64-pc-linux-gnu" -O1 -Oresolve-primitives -L 
"/home/mwette/proj/guile/guile-2.9.5/module" -L 
"/home/mwette/proj/guile/guile-2.9.5/guile-readline" -o 
"system/vm/linker.go" "../module/system/vm/linker.scm"
So, as a random check, I first verified that I could reproduce the above 
error at the command line.  I did.


Then I removed "-Oresolve-primitives" and it compiled without error.   
Any help?


Matt




missing word in "Building CPS" v 2.9.4

2019-09-05 Thread Matt Wette
The reference manual for 2.9.4, Section 9.4.4.3 titled "Building CPS", 
paragraph 2, has sentence starting:


"Construction is handled by a set of mutually builder macros:"

I think there is a missing word between "mutually" and "builder". No 
clue what it is.


Matt



Re: GNU Guile 2.9.4 Released [beta]

2019-08-28 Thread Matt Wette



On 8/25/19 1:21 PM, Andy Wingo wrote:

We are pleased to announce GNU Guile release 2.9.4. This is the fourth
pre-release of what will eventually become the 3.0 release series.


macOS 10.14.6:
wrote `system/vm/frame.go'
  BOOTSTRAP GUILEC system/vm/linker.go
/bin/sh: line 1: 79336 Abort trap: 6 GUILE_AUTO_COMPILE=0 
../meta/build-env guild compile --target="x86_64-apple-darwin18.7.0" -O1 
-Oresolve-primitives -L "/Users/mwette/proj/guile/guile-2.9.4/module" -L 
"/Users/mwette/proj/guile/guile-2.9.4/guile-readline" -o 
"system/vm/linker.go" "../module/system/vm/linker.scm"

make[2]: *** [system/vm/linker.go] Error 134
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

I don't (yet) have time to hunt this down right now.  Building w/ 
up-to-date macports dep's.




2.9.2: typo in lang/cps/

2019-06-02 Thread Matt Wette

typo in 2.9.2, lang/cps/slot-allocation.scm, line 355:

    (($ $kargs _ _ ($ $continue k _($ $values args)))

note lack of space between _ and (





Re: Coexistence of different Guile versions

2019-03-10 Thread Matt Wette

On 3/10/19 8:23 AM, Tommi Höynälänmaa wrote:

Guile (at least the Debian version) is designed so that different
versions (e.g. 2.0 and 2.2) can coexist in the same system. However,
this is not so for packages guile-xxx-dev. Consequently, many software
libraries (such as guile-gnome-platform) have to be compiled for a
single Guile version and they can't be used for several Guile versions
in the same system.

Could this be changed? For example, we could rename libguile.h to
libguile-.h and do the same for Guile libraries.

 - Tommi Höynälänmaa


Shouldn't the solution be -I/usr/include/guile/2.2/libguile.h

mwette$ pkg-config --cflags --libs guile-2.2
-pthread -I/usr/include/guile/2.2 -lguile-2.2 -lgc




Re: FOSDEM 2019

2019-02-05 Thread Matt Wette




On 2/5/19 8:58 AM, Ludovic Courtès wrote:

Hi,

Amirouche Boubekki  skribis:


What does it mean in practice? What are the tasks that must dealt with?

Like I wrote, an immediate task is to write a Racket importer for Guix¹
and to actually package things.

Next, we could ensure the subset of these packages that use #r6rs can
also be used as Guile packages.  However Chris noted that there are few
of them; most use #lang racket.

Thus, the next idea is to have #lang racket in Guile, which is quite a
bit of work but probably doable.  And the converse: #lang guile in
Racket.

There are probably other things that could be done, or variants on this
theme.

Is that clearer?

Thanks,
Ludo’.

¹ https://gnu.org/software/guix/manual/en/html_node/Invoking-guix-import.html



I assume that means a  language/racket/spec.scm file.

A patch to 2.2.4 for maping #lang foo" in a file to 
langauge/foo/spec.scm is in


https://github.com/mwette/guile-contrib/blob/master/patch-2.2.4/load.patch





Re: FOSDEM 2019

2019-02-04 Thread Matt Wette
Thanks for filming.  It was great to follow and see you titans in 
action. -- Matt


On 2/3/19 1:34 PM, Mikael Djurfeldt wrote:
It was a great experience and joy for me to meet some of you at FOSDEM 
2019. Thank you all!







Re: failed to create path for auto-compiled file

2019-01-17 Thread Matt Wette

On 1/15/19 5:59 PM, Matt Wette wrote:

Hi All,

I maintain an add-on package to Guile.  I have a user reporting the 
following

WARNING:

;;; compiling /usr/share/guile/site/2.2/nyacc/lang/c99/ffi-help.scm
;;; WARNING: compilation of 
/usr/share/guile/site/2.2/nyacc/lang/c99/ffi-help.scm failed:
;;; failed to create path for auto-compiled file 
"/usr/share/guile/site/2.2/nyacc/lang/c99/ffi-help.scm"


So my part of my package, including the file above, depends on 
scheme-bytestructures.
If, on installation (presumably as root), bytestructures is not found, 
then only the
sources are installed.  Now it seems a user has bytestructures in his 
own path and
now he wants to use ffi-help, but it's not getting compiled.  I would 
expect
Guile to compile and install in the user's .cache directory if write 
to a root-owned

directory (e.g., /usr/lib/guile/2.2/site-ccache) fails.

Am I missing something?  Should this be reported as a bug?


I could not reproduce this warning, so I'm thinking it may be unique to this 
user.




failed to create path for auto-compiled file

2019-01-15 Thread Matt Wette

Hi All,

I maintain an add-on package to Guile.  I have a user reporting the following
WARNING:

;;; compiling /usr/share/guile/site/2.2/nyacc/lang/c99/ffi-help.scm
;;; WARNING: compilation of 
/usr/share/guile/site/2.2/nyacc/lang/c99/ffi-help.scm failed:
;;; failed to create path for auto-compiled file 
"/usr/share/guile/site/2.2/nyacc/lang/c99/ffi-help.scm"

So my part of my package, including the file above, depends on 
scheme-bytestructures.
If, on installation (presumably as root), bytestructures is not found, then 
only the
sources are installed.  Now it seems a user has bytestructures in his own path 
and
now he wants to use ffi-help, but it's not getting compiled.  I would expect
Guile to compile and install in the user's .cache directory if write to a 
root-owned
directory (e.g., /usr/lib/guile/2.2/site-ccache) fails.

Am I missing something?  Should this be reported as a bug?

Matt
 





working to update pointer->procedure

2018-11-30 Thread Matt Wette

Hi All,

I'm starting to look into libguile/foreign.c to add support for libffi's 
variadic
function calls.  My thinking is that that pointer->procedure would accept '... 
as
the last element of the arg list, and that on procedure calls one would pass a 
pair
to for each unspecified argument.  The car of the pair is the ffi type (e.g., 
int)
and the car is the value.

(use (system foreign))

(define scm-printf (pointer->procedure int (dynamic-func "printf") ('* '...)))

(scm-printf (string->pointer "ans=%d\n") (cons int 4))


Comments?

Matt




Re: GNU Guile 2.9.1 Released [beta]

2018-10-20 Thread Matt Wette




On 10/10/18 2:31 AM, Andy Wingo wrote:

We are pleased to announce GNU Guile release 2.9.1.  This is the first
pre-release of what will eventually become the 3.0 release series.


configure, make, check all worked for me on macOS 10.12.6 (w/ gcc 7.3)







Re: [PATCH] debugger: Support generics. WIP.

2018-09-12 Thread Matt Wette

On 09/12/2018 04:44 AM, Jan Nieuwenhuizen wrote:

Hi!

I'm looking at the debugger again and have found a number of things*)
that I would like to fix.  My first attempt is for GOOPS support: I want
,break-at-source FILE LINE to also support breaking if LINE happens to
be in a define-method.



I have been looking into debugging also.  My first attempt is to add option
(... #:debug #t ...) that will expand the frame so that slots are not reused.
Nothing is working yet, but to give you an idea ...

scripts/compile.scm:
@@ -95,6 +95,12 @@
 (cons (string->symbol arg) warnings)
 (alist-delete 'warnings result))
 
+	(option '(#\g "debug") #f #f

+   (lambda (opt name arg result)
+ (alist-cons 'optimizations
+ (cons* #:debug #t (optimizations-for-level 0))
+ result)))
+   
(option '(#\O "optimize") #t #f
(lambda (opt name arg result)
   (define (return val)


cps/compile-bytecode.scm:
@@ -84,6 +90,9 @@
 (define (compile-function cps asm opts)
   (let* ((allocation (allocate-slots cps #:precolor-calls?
  (kw-arg-ref opts #:precolor-calls? #t)))
+(allocation (if (kw-arg-ref opts #:debug #f)
+(expand-slots allocation)
+allocation))
  (forwarding-labels (compute-forwarding-labels cps allocation))
  (frame-size (lookup-nlocals allocation)))
 (define (forward-label k)
@@ -581,6 +590,7 @@
  (emit-end-arity asm)
  (emit-end-program asm



cps/slot-allocation.scm:
@@ -1059,3 +1059,19 @@
(frame-size (compute-frame-size cps slots calls shuffles)))
   (make-allocation slots representations constants calls
shuffles frame-size))
+
+(define (expand-slots allocation)
+  (display "expanding slots\n")
+  (match allocation
+(($ $allocation slots representations constant-values call-allocs
+   shuffles frame-size)
+ (call-with-values
+(lambda ()
+  (intmap-fold
+   (lambda (ix iv im n) (values (intmap-add im ix n) (1+ n)))
+   slots empty-intmap 0))
+   (lambda (xslots xframe-size)
+(make-allocation xslots representations constant-values call-allocs
+ shuffles xframe-size))
+(export expand-slots)
+




[ANN] nyacc version 0.86.0 released

2018-09-05 Thread Matt Wette

I have released nyacc version 0.86.0.  This release includes the following:
1) I reworked the parser to behave with interactive use in Guile better.
2) I hacked on the example language compilers to operate at the Guile
   command line.  (You can run "make install-nx-languages".)
3) I replaced use of (ice-9 regexp) for the bootstrapper team. (you know
   who you are)
4) I fixed a bug in in nyacc/lex.scm make-num-reader which broke on certain
   integer forms; and now allow .123 as a legal float.
5) I fixed compile-ffi.scm to correctly show help message w/o filename arg.

The nx-languages include javascript, octave and tcl.  "nx" stands for both
"nyacc extension" and "not exactly".  These are a bit rough right now.  But
the parser / compiler design becoming more uniform among them:
1) The nyacc-generated parsers (except for nx-tcl) generate SXMl trees.
2) The 'to Tree-IL" compilers use (Andy Wingo's) foldts*-values to pick
   off easy stuff and declarations on the way down and build up Tree-IL
   on the way up.

  scheme@(guile-user)> ,L nx-javascript
  Happy hacking with nx-javascript!  To switch back, type `,L scheme'.
  nx-javascript@(guile-user)> var a = 1;

  nx-javascript@(guile-user)> ,L nx-octave
  Happy hacking with nx-octave!  To switch back, type `,L nx-javascript'.
  nx-octave@(guile-user)> b = 2;

  nx-octave@(guile-user)> ,L nx-tcl
  Happy hacking with nx-tcl!  To switch back, type `,L nx-octave'.
  nx-tcl@(guile-user)> set c 3

  nx-tcl@(guile-user)> ,L scheme
  Happy hacking with Scheme!  To switch back, type `,L nx-tcl'.
  scheme@(guile-user)> (+ a b (string->number c))
  $1 = 6

I will be working on Tcl to do more agressive parsing (e..g, 123 as
integer instead of string) and lazy conversion to strings.

I am thinking about a simple object model that can be used with
multiple extension languages.

And I like my new elisp minor mode that helps make awesome docstrings:
(available athttps://github.com/mwette/guile-contrib)

  scheme@(guile-user)> ,use (nyacc parse)
  scheme@(guile-user)> ,d make-lalr-parser
  - Procedure: make-lalr-parser mach [options] => parser
   Generate a procedure for parsing a language, where MACH is a
   machine generated by 'make-lalr-machine'.  This generates a
   procedure that takes one argument, a lexical analyzer:
(parser lexical-analyzer #:debug #t)
   and is used as
(define xyz-parse (make-lalr-parser xyz-mach))
(with-input-from-file "sourcefile.xyz"
  (lambda () (xyz-parse (gen-lexer
   The generated parser is reentrant.  Options are:
   '#:skip-if-unexp'
This is a list of tokens to skip if not expected.  It is used
to allow comments to be skipped.  The default is ''()'.
   '#:interactive'
If '#t', this tells the parserthat this is being called
interactively, so that the token '$end' is not expected.  The
default value is '#f'.


NYACC, for Not Yet Another Compiler Compiler, is set of guile modules for
generating parsers and lexical analyzers.  It also provides sample parsers
and pretty-printers using SXML trees as an intermediate representation.

It provides a decent C parser and a `FFI Helper' tool to help create
Guile Scheme bindings for C-based libraries.

It provides (partially implemented) compilers based on above mentioned
parsers to allow execution with Guile as extension languages.

NYACC maturity is beta level.

NYACC is free software; the full source distribution is available through

* the tarball repository:
https://download.savannah.gnu.org/releases/nyacc/

* the git repository:
git://git.savannah.nongnu.org/nyacc.git

home page, project page and user's guide:
*http://www.nongnu.org/nyacc
*https://savannah.nongnu.org/projects/nyacc
*http://www.nongnu.org/nyacc/nyacc-ug.html

For support see:
https://savannah.nongnu.org/support/?group=nyacc




Re: GObject Introspection and GTK3 way forward

2018-09-05 Thread Matt Wette



On 09/05/2018 10:29 AM, Mike Gran wrote:

Hey all-

So, I've decided to make a go at finishing the GObject Introspection
and GTK3 story for Guile.  I would very much like to have something
running in time for Fosdem 2019.

I've looked at the other two previous attempts: g-golf, and the older
guile-gobject project.  The latter is moribund.

The former is beautiful code, the sort of code that you'd hope would
be able to solve the problem, but, I think the road to a beta release
doing things "properly" might take a long time.

But since I need something running in a couple of months, I'm going to
port PyGObject to Guile.  PyGObject is complex and full of special
cases, which leads me to believe that a proper Guile binding also
would need to be so.  Though PyGObject is complex, porting PyGObject
to Guile, however, looks comparatively straightforward.

I guess I just want to apologize in advance for not picking up the
ball on the older projects.  It is a bit rude to ignore them.  But
monkey patching C code is where my skills lie. ;-)

Feel free to contact me with questions, comments, and criticism.

The (currently empty) repo is
https://github.com/spk121/guile-gobject-introspection

Regards,
Mike


FYI, I have been able to run glib, gio, gobject, gdk2, gtk2+, pango through
the FFI helper go get scheme code that compiles.  And I've run some gtk2+
demos.  I believe I had issues with gtk3+.  The FH probably won't provide all
you what you want but it might help some (hence the name).

* the tarball repository:
https://download.savannah.gnu.org/releases/nyacc/

* the git repository:
git://git.savannah.nongnu.org/nyacc.git





patch for `(load "foo.js")'

2018-09-04 Thread Matt Wette

30094 @ debbugs got gnu dot org has a patch for adding support for extension 
languages

The patch is against guile-2.2.4


mwette$ cat jsinc
#lang ecmascript

function js_inc(a) {
  return a + 1;
}


mwette$ cat jsdec.js

function js_dec(a) {
  return a - 1;
}


mwette$ guile
GNU Guile 2.2.4
Copyright (C) 1995-2017 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.

scheme@(guile-user)> (load "jsinc")
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;   or pass the --no-auto-compile argument to disable.
;;; compiling /var/tmp/jsinc
;;; compiled /home/mwette/.cache/guile/ccache/2.2-LE-8-3.A/var/tmp/jsinc.go

scheme@(guile-user)> (load "jsdec.js")
;;; compiling /var/tmp/jsdec.js
;;; compiled /home/mwette/.cache/guile/ccache/2.2-LE-8-3.A/var/tmp/jsdec.js.go

scheme@(guile-user)> (js_inc 4)
$1 = 5

scheme@(guile-user)> (js_dec 9)
$2 = 8

scheme@(guile-user)>




Re: my emacs minor-mode for generating docstrings, v180902d

2018-09-03 Thread Matt Wette

On 09/02/2018 04:30 PM, Arne Babenhauserheide wrote:

Matt Wette  writes:


Now if I load my scheme-texidoc minor mode, place the point just before
`(define (' and hit [(control c) (control d)], I end up with a docstring
generated by running the comments through `texi2any --plaintext'.

;; @deffn {Procedure} prece a b po
;; Return precedence for arguments @var{a}, @var{b} given the partial
;; order @var{po}.  The result is of the form @code{'lt}, @code{'gt},
;; @code{'eq} or @code{#f}.@*
;; Note: @var{po} may not a true partial order as we can have a a=b.  For example,
;; @example
;; @code{(prece a a po)} => @code{'eq}.
;; @end example
;; @end deffn
(define (prece a b po)
   "- Procedure: prece a b po
  Return precedence for arguments A, B given the partial order PO.
  The result is of the form ''lt', ''gt', ''eq' or '#f'.
  Note: PO may not a true partial order as we can have a
  a=b.  For example,
   (prece a a po) => 'eq."
   (cond
((eqv? a b) 'eq)
((eqv? a '$error) 'lt)
((eqv? b '$error) 'gt)
(( ,d prece
- Procedure: prece a b po
  Return precedence for arguments A, B given the partial order PO.
  The result is of the form ''lt', ''gt', ''eq' or '#f'.
  Note: PO may not a true partial order as we can have a
  a=b.  For example,
   (prece a a po) => 'eq.

This looks pretty useful. I don’t write texinfo yet (though I should),
but if I did, getting rid of the repetition is great!


Thanks.  I was after formatted docstrings.  I still need to add:
1) robust way to find insert point for docstring
2) ability to remove old docstring if present

The elisp code has been added to my repo at 
https://github.com/mwette/guile-contrib.

Matt

or




my emacs minor-mode for generating docstrings, v180902d

2018-09-02 Thread Matt Wette

It's been many years since I hacked on elisp, but I have the beginnings
of an emacs minor mode (to scheme) for generating docstrings from texi-
motivated comments.

Here is an example of how I like to document my procedures:

;; @deffn {Procedure} prece a b po
;; Return precedence for arguments @var{a}, @var{b} given the partial
;; order @var{po}.  The result is of the form @code{'lt}, @code{'gt},
;; @code{'eq} or @code{#f}.@*
;; Note: @var{po} may not a true partial order as we can have a a=b.  For example,
;; @example
;; @code{(prece a a po)} => @code{'eq}.
;; @end example
;; @end deffn
(define (prece a b po)
  (cond
   ((eqv? a b) 'eq)
   ((eqv? a '$error) 'lt)
   ((eqv? b '$error) 'gt)
   (( a=b.  For example,
;; @example
;; @code{(prece a a po)} => @code{'eq}.
;; @end example
;; @end deffn
(define (prece a b po)
  "- Procedure: prece a b po
 Return precedence for arguments A, B given the partial order PO.
 The result is of the form ''lt', ''gt', ''eq' or '#f'.
 Note: PO may not a true partial order as we can have a
 a=b.  For example,
  (prece a a po) => 'eq."
  (cond
   ((eqv? a b) 'eq)
   ((eqv? a '$error) 'lt)
   ((eqv? b '$error) 'gt)
   (( ,d prece
- Procedure: prece a b po
 Return precedence for arguments A, B given the partial order PO.
 The result is of the form ''lt', ''gt', ''eq' or '#f'.
 Note: PO may not a true partial order as we can have a
 a=b.  For example,
  (prece a a po) => 'eq.



Here is scheme-texidoc.el:
;;; scheme-texidoc.el --- minor mode to make scheme doc-strings from texinfo

;; Copyright (C) 2018 Matthew R. Wette

;; Author: Matt Wette 
;; Keywords: scheme, texinfo

;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 3 of the License, or (at your option) any later version.
;;
;; This library is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public License
;; along with this library; if not, see <http://www.gnu.org/licenses/>.

;;; Notes:

;; M-x unload-feature RET scheme-texidoc RET

;; todo: remove old docstring, if present
;; todo: robustly find "(define ("
;; todo: handle (define foo (let (...) (lambda (...) "docstring"

;;; Code:

(require 'texinfmt)

(define-minor-mode scheme-texidoc
  "A minor-mode to create Scheme docstrings from texinfo comments.
Assume you have procedure that starts with
  (define (
and is preceeded by comments that provide documentation between
  ;; @deffn ...
and
  ;; @end deffn
Then set point to just before `(define (' and hit `C-cC->'.
A texi2any formatted docstring will be inserted."
  nil
  " Tx"
  '(([(control c) (control d)] . scheme-texidoc-transfer-deffn))
  )

(defvar scheme-texidoc-version "v180902e")

(defvar scheme-texidoc-texi-buffer-name "*scmtxi texi*")
(defvar scheme-texidoc-text-buffer-name "*scmtxi text*")

;; moves point
(defun find-deffn-above ()
  "find deffn to this point; give up if hit blank before"
  (interactive)
  (beginning-of-line)
  (while (and (not (looking-at ";; @deffn "))
  (not (looking-at "\\($\\| \\)")))
(forward-line -1))
  (if (looking-at ";; @deffn ") (point) nil))

;; moves point
(defun find-end-deffn-below ()
  "find end deffn blow non ;;"
  (interactive)
  (beginning-of-line)
  (while (and (not (looking-at ";; @end deffn"))
  (looking-at ";;\\($\\| \\)"))
(forward-line 1))
  (if (looking-at ";; @end deffn") (progn (forward-line) (point)) nil))

;; we want to find range for deffn and point for docstring
(defun find-deffn-posns ()
  "Find points of interest."
  (interactive)
  (save-excursion
(beginning-of-line)
(while (not (looking-at ";;")) (backward-line))
(let ((txi-st (find-deffn-above))
  (txi-nd (find-end-deffn-below))
  (doc-pt nil)
  )
  (while (not (looking-at "(")) (forward-line))
  (cond
   ((looking-at "(define *(")
(skip-chars-forward 9)
(forward-sexp)
(set! doc-pt (point)))
   ((looking-at "(define *[^ (]")
(re-search-forward "(lambda (" 100)
(error "not implemented"))
   (t
(error "couldn't find location for docstring")))
  (goto-char doc-pt)
  )))

;; run texi2any --plaintext on region
;; returns t or nil if success or failure to run command, respectively
;; error messages are not processed
(defun texi2any-on-regio

Re: speedup of modifying return values

2018-08-29 Thread Matt Wette




On 08/29/2018 03:58 AM, Stefan Israelsson Tampe wrote:
Hi all, I'm trying to make a python clone in guile. Currently the code 
is slow and one of  the reasons is the following,


in my pythoon

return 1,2

returns a (values 1 2) in order to get python and scheme to 
interoperate. but for python if you use


x = 1,2

then x is the tupple '(1 2) and in guile it is 1. So therefore we wrap 
the result for


x=f(10)

as
(set! x (call-with-values (lambda () (f x)) (case-lambda ((x) x) (x x

This can be compiled to efficient bytecode but is not done so in 
guile. In stead a closure is created at each assignment site and 
creating ineficient code.


Any ideas how to improve this (I don't want "return a,b" to mean (list 
a b) which is a quick solution
if we want to just stay in python and not interoperate with scheme at 
all on this level.


Regards
Stefan


So I'm working on extension languages in Guile.  I assume you are always 
returning tree-il
values from Python functions.  (Unless from functions returning tuples, but how 
do you
guarantee that?)  You could add a property to your functions and then compile 
to CPS and
do the optimization yourself.  Then convert to bytecode.  But that seems tough.

I assume the use case is being able to call Python code from Guile, so one 
would always call
from Scheme using call-with-values?

I am using call-with-values in nx-matlab when the function is declared with 
multiple values.

Also, I wonder if we should be "marking" functions with a property to indicate 
what the
source language is.  The property could be 'language.  (If no language assume 
'scheme.)


Matt




Re: FOSDEM 2019 - dev-room proposal

2018-08-27 Thread Matt Wette

On 08/27/2018 10:27 AM, Pjotr Prins wrote:

.
Manolis and I want to submit a plan for 'Minimalistic Languages - for
big ideas' dev-room.  Good examples that fit the room are

- mes and reproducible builds
- Guile and Guix
- Guile JIT
- Lua JIT
- Lua for scriptable projects (example?)

Anyone anything to add to this list? More ideas is better.


Cow?





handling alternative languages in Guile

2018-08-19 Thread Matt Wette

Hi All,

Guile bug report 30094 is a wishlist request for adding support for alterantive 
languages.
To that bug report I attached proposed code for allowing -from being generated 
from
(1) #lang  or (2) file extension.

The essential change is to compile-file in (system base compile):

(ensure-directory (dirname comp))
(call-with-output-file/atomic comp
! (lambda (port)
!   ((language-printer (ensure-language to))
!(read-and-compile in #:env env #:from from #:to to #:opts
!  (cons* #:to-file? #t opts))
!port))
! file)
!   comp)))
--- 16,31 
(ensure-directory (dirname comp))
(call-with-output-file/atomic comp
!   (lambda (port)
! (let* ((from (or from
!  (lang-from-port in)
!  (lang-from-file file)
!  (current-language)))
!(env (or env (default-environment from
!   (simple-format (current-error-port) "compiling from lang ~A\n" from)
!   ((language-printer (ensure-language to))
!(read-and-compile in #:env env #:from from #:to to #:opts
!  (cons* #:to-file? #t opts))
!port)))
! file)
!   comp)))

Matt




nyacc support for extension languages

2018-08-12 Thread Matt Wette

I am working on providing a module to add to the nyacc distribution for
the purpose of generating extension languages, and putting together a few
extensions for demo.  So far I'm playing with javascript and matlab.
These languages use a "nx-" prefix to designate them as "nyacc extension".
One can interpret "nx" to also mean "not exactly", so "nx-matlab" is not
exactly MATLAB.  It has taken some work to get my yacc like parser to
parse expressions instead of files, so some work has gone into updating
the nyacc parser.  nyacc/parse.scm now has parser generators that provide
an #:interactive option and more robust default-reductions for generating
parsers which work well in interactive mode.

nyacc/parse.scm fragment:
(define* (make-lalr-parser/num mach #:key (skip-if-unexp '()) interactive)
  (let* ((len-v (assq-ref mach 'len-v))
 (rto-v (assq-ref mach 'rto-v))
 (pat-v (assq-ref mach 'pat-v))
 (xct-v (make-xct (assq-ref mach 'act-v)))
 (start (assq-ref (assq-ref mach 'mtab) '$start)))
(lambda* (lexr #:key debug)
  (let iter ((state (list 0))   ; state stack
 (stack (list '$@)) ; sval stack
 (nval #f)  ; prev reduce to non-term val
 (lval #f)) ; lexical value (from lex'er)
(cond
 ((and interactive nval (eqv? (car nval) start)) ; done
  (cdr nval))
 ((not (or nval lval))
  (if (eqv? $default (caar (vector-ref pat-v (car state
  (iter state stack (cons $default #f) lval) ; default reduction
  (iter state stack nval (lexr   ; reload
 (else
  ...


Here is a demo for "nx-matlab":

$ cat simp0.m
function [c,d,e] = simp0(a, b)
x = a + 1;
y = b + 1;
c = x * y;
d = 1;
e = 2;
end

$ guild compile --from=nx-matlab simp0.m
wrote `/home/mwette/.cache/.../simp0.m.go'

$ guile
scheme@(guile-user)> (load "simp0.m")

scheme@(guile-user)> (call-with-values (lambda () (simp0 1 2))
... (lambda (c d e) (simple-format #t "~S\n~S\n~S\n" c d e)))
6
1
2

scheme@(guile-user)> ,L nx-matlab
Happy hacking with nx-matlab!  To switch back, type `,L scheme'.

nx-matlab@(guile-user)> [c,d,e] = simp0(1, 2);
nx-matlab@(guile-user)> c
$1 = 6
nx-matlab@(guile-user)> d
$2 = 1
nx-matlab@(guile-user)> e
$3 = 2


I am working in the nxdev branch of git://git.savannah.nongnu.org/nyacc.git.

Matt




Re: Why is Guile unable to find libtool?

2018-07-26 Thread Matt Wette

On 07/26/2018 04:57 PM, Brett Gilio wrote:


Bruce Korb writes:


 $ ./configure
.
checking for libltdl... no
configure: error: GNU libltdl (Libtool) not found, see README.
 $ type libtool
bash: type: libtool: not found
 $ sudo apt install libtool
Reading package lists... Done
Building dependency tree
Reading state information... Done
libtool is already the newest version (2.4.6-2).
0 upgraded, 0 newly installed, 0 to remove and 230 not upgraded.
 $ sudo apt install libtool-devel
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libtool-devel
 $ type libtool
bash: type: libtool: not found


Bruce,

Can you check to see if libtool has a PATH assigned to it?




I think you want `sudo apt install libltdl-dev'

I believe
1) libtool is a script generated in the guile-X.Y.Z top directory as a 
product of configure.

2) The command `apt install libtool-devel' provides the command libtoolize.



ldconfig complaint about libguile...-gdb.scm

2018-07-20 Thread Matt Wette

Hi All,

I run on Ubuntu and get the following.  I assume it may appear for other
OSes.  This message anytime I update software or otherwise run ldconfig.

 /sbin/ldconfig.real: /usr/local/lib/libguile-2.2.so.1.3.0-gdb.scm
 is not an ELF file - it has the wrong magic bytes at the start.

Has this been reported as a "bug"?  It is not a problem, but could lead to
numerous bug reports in the future.  I think ldconfig looks at all files
of the form lib* in searched lib dirs.

Matt




loading an ecmascript file

2018-07-15 Thread Matt Wette

Hi All,

I was hoping to kludge together a procedure to load a file containing
a non-Scheme extension language.  I am not surprised that it doesn't
work, given the complexity of the load/compile code in (ice-9 boot-9
(check load-in-vicinity) and (system base compile) (check compile-file).
Any ideas how to make progress?


(define file-ext-map
  '(("scm" . scheme)
("js" . ecmascript)))

(define* (load/x file-name)
  (let* ((ext (and=> (string-rindex file-name #\.)
(lambda (ix) (substring file-name (1+ ix)
 (ext-lang (assoc-ref file-ext-map ext)))
(simple-format #t "loading a ~S file\n" ext-lang)
(parameterize ((current-language ext-lang))
  (load file-name

Notice in my test below that I get dumped into ecmascript in the
debugger.  When I exit, I'm back in Scheme mode.  Also, if I try
to load with normal load I get the same error message.

scheme@(guile-user)> (load/x ",zz.js")
loading a ecmascript file
ERROR: In procedure %resolve-variable:
Unbound variable: var

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
ecmascript@(guile-user) [1]> ,bt
   2 (primitive-load-path "nyacc/lang/javascript/,zz.js")
In ice-9/eval.scm:
   223:20  1 (proc #)
In unknown file:
   0 (%resolve-variable (7 . var) #)
ecmascript@(guile-user) [1]>

scheme@(guile-user)> (load ",zz.js")
ERROR: In procedure %resolve-variable:
Unbound variable: var

Matt

P.S.  I am not working on ecmascript but my own javascript,
with goal to generate tools and procedures for adding more
extension languages with nyacc.




tree-il begin deprecated?

2018-07-15 Thread Matt Wette

Hi All,

I noticed that from 2.0 to 2.2 the reference manual section on compiling
to tree-il replaced `begin' with `seq'.  Is `begin' going to be deprecated?

Matt




Re: multi-lingual guile: language strictness

2018-07-14 Thread Matt Wette

On 07/14/2018 09:22 AM, Hans Åberg wrote:

On 14 Jul 2018, at 15:53, William ML Leslie  
wrote:

On 14 July 2018 at 12:57, Brett Gilio  wrote:

Is this possibility for making Guile multi-lingual a promised feature,
or more of a wishlist type thing? I'll have to think about some ways
that might be good to approach this, because the limiting
volunteer-community is definitely going to be an issue.


It's already a thing.

https://www.gnu.org/software/guile/manual/html_node/Other-Languages.html

Is it possible to call them at the same time, via the C interface?




I would think so.  In general all languages see the same name space.

scheme@(guile-user)> ,L ecmascript
Happy hacking with ECMAScript!  To switch back, type `,L scheme'.
ecmascript@(guile-user)> function foo(x) { return x + 1; };
ecmascript@(guile-user)> foo(1);
$1 = 2
ecmascript@(guile-user)> ,L scheme
Happy hacking with Scheme!  To switch back, type `,L ecmascript'.
scheme@(guile-user)> (foo 1)
$2 = 2



multi-lingual guile: language strictness

2018-07-13 Thread Matt Wette

Hi All,

I posed a question on #guile IRC last weekend asking for use cases for 
making Guile
multi-lingual.  The use case that came up was the desire to use Guile as 
an extension
that supports multiple languages for users.  To that end, I wonder how 
important it is
to make these extension languages meet published language conventions or 
standards.
I believe to do so is too difficult: the Guile community does not have 
the volunteer
workforce people to achieve this.  I think it would be more practical to 
look for
reasonable approximations.  If this is the direction to go, then should 
Guile name
these extension languages according to what they attempt to mimic (e.g., 
javascript),
or rather rename to something that has a similar sounding name (e.g., 
guavascript), or,

as another option, rename with an extension monicker (e.g., javascriptx)?

Matt



Re: flow-analysis and Offner's notes

2018-06-09 Thread Matt Wette

On 06/09/2018 06:34 AM, Matt Wette wrote:

On 06/08/2018 05:17 PM, Matt Wette wrote:
Andy Windo's blog on flow-analysis in Guile references Offner's 
"Notes on Graph
Algorithms Used in Optimizing Compilers"?  Anyone read this 
manuscript?  Lemma
2.2 says, in a flow-graph, if x>>z and y>>z, then either x>>y or 
y>>x.  The proof
uses the argument that the path from s, the start, to z has to 
include both x and y.
I'm not seeing that.  Consider a graph s->x, s->y, x->z and y->z. 
What am I missing?


I was missing the definition of "dominates."
Sorry for the interruption.
Now need to think about this.



Re: flow-analysis and Offner's notes

2018-06-09 Thread Matt Wette

On 06/08/2018 05:17 PM, Matt Wette wrote:
Andy Windo's blog on flow-analysis in Guile references Offner's "Notes 
on Graph
Algorithms Used in Optimizing Compilers"?  Anyone read this 
manuscript?  Lemma
2.2 says, in a flow-graph, if x>>z and y>>z, then either x>>y or 
y>>x.  The proof
uses the argument that the path from s, the start, to z has to include 
both x and y.
I'm not seeing that.  Consider a graph s->x, s->y, x->z and y->z. What 
am I missing?


(another example, in figure 2.1 C>>K and B>>K but C and B are not 
ordered.)


This example does not not qualify as C and B do not dominate K.
C dominates K iff every path from the start S to K goes through C.




flow-analysis and Offner's notes

2018-06-08 Thread Matt Wette

Hi All,

Andy Windo's blog on flow-analysis in Guile references Offner's "Notes on Graph
Algorithms Used in Optimizing Compilers"?  Anyone read this manuscript?  Lemma
2.2 says, in a flow-graph, if x>>z and y>>z, then either x>>y or y>>x.  The 
proof
uses the argument that the path from s, the start, to z has to include both x 
and y.
I'm not seeing that.  Consider a graph s->x, s->y, x->z and y->z. What am I 
missing?
(another example, in figure 2.1 C>>K and B>>K but C and B are not ordered.)

Ref: http://www.cs.umb.edu/~offner/files/flow_graph.pdf

Matt




Re: Simple picture language

2018-03-27 Thread Matt Wette



On 03/27/2018 05:40 AM, Thompson, David wrote:

On Mon, Mar 26, 2018 at 5:51 PM, Ricardo Wurmus  wrote:

Hi Guilers,

I wrote a simple SVG-based picture language.

Wow! I never would have thought to use sxml to generate svg files. I
always thought we would have to use cairo or some custom renderer in
order to have a picture language. This is a great hack!



Read Andy Wingo's paper on tree fold (mentioned in the Guile Manual).
I also use sxml for svg but never realized images could be rendered with 
Geiser.

Pretty sweet.

Matt





Re: Question: link to wrong library

2018-01-22 Thread Matt Wette

I think you need -Wl,-rpath=`pwd`/libguile/.libs


On 01/22/2018 03:36 AM, Chaos Eternal wrote:

 gcc  -pthread -I.  -Wl,-rpath -lguile-2.2  -lgc test.c

On Mon, Jan 22, 2018 at 7:30 PM 陶青云 > wrote:


some result

```
~/code/guile-2.2
$ LDFLAGS=-Wl,-rpath LD_LIBRARY_PATH=./libguile/.libs gcc 
-pthread -I.  -lguile-2.2  -lgc test.c
~/code/guile-2.2
$ ldd ./a.out
linux-vdso.so.1 (0x7ffc441a)
libguile-2.2.so.1 => /usr/lib/libguile-2.2.so.1 (0x7f3cfb519000)
libgc.so.1 => /usr/lib/libgc.so.1 (0x7f3cfb2af000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x7f3cfb091000)
libc.so.6 => /usr/lib/libc.so.6 (0x7f3cfacd9000)
libffi.so.6 => /usr/lib/libffi.so.6 (0x7f3cfaad)
libunistring.so.2 => /usr/lib/libunistring.so.2 (0x7f3cfa75f000)
libgmp.so.10 => /usr/lib/libgmp.so.10 (0x7f3cfa4cc000)
libltdl.so.7 => /usr/lib/libltdl.so.7 (0x7f3cfa2c2000)
libcrypt.so.1 => /usr/lib/libcrypt.so.1 (0x7f3cfa08a000)
libm.so.6 => /usr/lib/libm.so.6 (0x7f3cf9d3e000)
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2
(0x7f3cfba49000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x7f3cf9b3a000)
libatomic_ops.so.1 => /usr/lib/libatomic_ops.so.1 (0x7f3cf9937000)
```
-- Original --
*From: * "Chaos Eternal">;
*Date: * Mon, Jan 22, 2018 12:58 PM
*To: * "Nala Ginrut">;
*Cc: * "陶青云">;
"guile-devel">;
*Subject: * Re: Question: link to wrong library

or try this
LDFLAGS=-Wl,-rpath


On Mon, Jan 22, 2018, 09:08 Nala Ginrut > wrote:

I think you may need LD_LIBRARY_PATH

2018年1月21日 23:46,"陶青云" >写道:

Hi. I'm new to guile.  I compiled it from source without
`make install`.

I write a simple C file and use the flowing command to
compile it.
    `gcc -pthread -I. -L ./libguile/.libs -lguile-2.2 
-lgc test.c`
it successed. but the a.out is always link to my system
guile library.
   $ ldd ./a.out
linux-vdso.so.1 (0x7fffc259b000)
libguile-2.2.so.1 => /usr/lib/libguile-2.2.so.1
(0x7fa90f9fe000)
libgc.so.1 => /usr/lib/libgc.so.1 (0x7fa90f794000)


even I do the flowing:
$ cp libguile/.libs/libguile-2.2.so.1.3.0
libguile/.libs/libguile-2.5.so 

$ gcc -pthread -I. -L ./libguile/.libs -lguile-2.5  -lgc
test.c  # it successed

$ ldd ./a.out
linux-vdso.so.1 (0x7ffd283e)
libguile-2.2.so.1 => /usr/lib/libguile-2.2.so.1
(0x7f83c71cc000)
libgc.so.1 => /usr/lib/libgc.so.1 (0x7f83c6f62000)


Could someone give me some tips.  Thanks.





ffi-help: updated documentation

2018-01-19 Thread Matt Wette

Hi All,

I am working on a ffi-helper (FH): a program that will read in a C dot-h file
and generate a Guile dot-scm file which defines a module to provide hooks into
the associated C library.

This is a rework of the first part of the documentation.  It provides an example
and a section explaining part of the design.

(I have recently dumped my macbook w/ flaky keyboard for a ubuntu laptop.  I am
still adjusting.  I am missing macports a little.)

Matt

FFI Helper for Guile


Matt Wette
January 2018
With NYACC Version 0.83.0

1 Introduction
**

The acronym FFI stands for "Foreign Function Interface". It refers to
the Guile facility for binding functions and variables from C source
libraries into Guile programs.  This distribution provides utilities for
generating a loadable Guile module from a set of C declarations and
associated libraries.  The C declarations can, and conventionally do,
come from naming a set of C include files.  The nominal method for use
is to write a _ffi-module_ specification in a file which includes a
'define-ffi-module' declaration, and then use the command 'guild
compile-ffi' to produce an associated file of Guile Scheme code.
 $ guild compile-ffi ffi/cairo.ffi
 wrote `ffi/cairo.scm'
The FH does not generate C code.  The hooks to access functions in the
Cairo library are provided in 100% Guile Scheme via '(system foreign)'.

   The compiler for the FFI Helper (FH) is based on the C parser and
utilities which are included in the NYACC (https://www.nongnu.org/nyacc)
package.  Development for the FH is currently being performed in the
'c99dev' branch of the associated git repository.  Within the NYACC
distribution, the relevant modules can be found under the directory
'examples/'.

   Use of the FFI-helper module depends on the _scheme-bytestructure_
package available from
<https://github.com/TaylanUB/scheme-bytestructures>. Releases are
available at
<https://github.com/TaylanUB/scheme-bytestructures/releases>.

   At runtime, after the FFI Helper has been used to create Scheme code,
the modules '(system ffi-help-rt)' and '(bytestructures guile)' are
required.  No other code from the NYACC distribution is needed.
However, note that the process of creating the Scheme output depends on
reading system headers, so the generated code may well contain operating
system and machine dependencies.  If you copy code to a new machine, you
should re-run 'guild compile-ffi'.

   You are probably hoping to see an example, so let's try one.

   This is a small FH example to illustrate its use.  We will start with
the Cairo (cairographics.org) package because that is the first one I
started with in developing the FFI Helper.  Say you are an avid Guile
user and want to be able to use Cairo in Guile.  On most systems Cairo
comes with the associated _pkg-config_ support files; this demo depends
on that support.

   Warning: The FFI Helper package is under active development and there
is some chance the following example will cease to work in the future.

   If you want to follow along and are working in the distribution tree,
you should source the file 'env.sh' in the 'examples' directory.

   By practice, I like to put all FH generated modules under a directory
called 'ffi/', so we will do that.  We start by generating, in the 'ffi'
directory, a file named 'cairo.ffi' with the following contents:

 (define-ffi-module (ffi cairo)
   #:pkg-config "cairo"
   #:include '("cairo.h" "cairo-pdf.h" "cairo-svg.h"))

To generate a Guile module you execute 'guild' as follows:

 $ guild compile-ffi ffi/cairo.ffi
 wrote `ffi/cairo.scm'

Though the file 'cairo/cairo.ffi' is only three lines long, the file
'ffi/cairo.scm' will be over five thousand lines long. It looks like
the following:

 (define-module (ffi cairo)
   #:use-module (system ffi-help-rt)
   #:use-module ((system foreign) #:prefix ffi:)
   #:use-module (bytestructures guile))
 (define link-libs
   (list (dynamic-link "libcairo")))

 ;; int cairo_version(void);
 (define ~cairo_version
   (delay (fh-link-proc ffi:int "cairo_version" (list) link-libs)))
 (define (cairo_version)
   (let () ((force ~cairo_version
 (export cairo_version)

 ...

 ;; typedef struct _cairo_matrix {
 ;;   double xx;
 ;;   double yx;
 ;;   double xy;
 ;;   double yy;
 ;;   double x0;
 ;;   double y0;
 ;; } cairo_matrix_t;
 (define-public cairo_matrix_t-desc
   (bs:struct
 (list `(xx ,double) `(yx ,double) `(xy ,double)
   `(yy ,double) `(x0 ,double) `(y0 ,double
 (define-fh-compound-type cairo_matrix_t cairo_matrix_t-desc
  cairo_matrix_t? make-cairo_matrix_t)
 (export cairo_matrix_t cairo_matrix_t? make-cairo_matrix_t)

 ... many, many more declarations ...

 ;; access to enum symbol

Re: Website translations with Haunt

2017-12-12 Thread Matt Wette
The FFI Helper uses `gcc --print-search-dirs' to locate gcc directories.  It 
also adds /usr/include.
I don't understand why it is not finding them.  It also uses `gcc -dM -E' to 
determine #defines.
Even with that, on my macOS system, I need to make fixes.   Can you determine 
if some gcc 
command, via `gcc --print-search-dirs' will find the correct includes?  Maybe I 
should add a 
`--with-gcc' command line argument.

Thanks,
Matt




Re: Website translations with Haunt

2017-12-10 Thread Matt Wette

> On Dec 10, 2017, at 11:21 AM, pelzflorian (Florian Pelz) 
>  wrote:
>>(fh-object-set! eh-struct 'error error-p)

I was able to duplicate getting 0.  The problem was the argument `error-p'.
(The bytestructures i/f seems to be silent here about he incorrect argument.)
   
Please try instead the following:

  (fh-object-set! eh-struct 'error (ffi:pointer-address error-p))

Matt




Re: Website translations with Haunt

2017-12-10 Thread Matt Wette

> On Dec 10, 2017, at 11:21 AM, pelzflorian (Florian Pelz) 
> <pelzflor...@pelzflorian.de> wrote:
> 
> On Sun, Dec 10, 2017 at 07:22:55AM -0800, Matt Wette wrote:
>> 
> Thank you.  I’m sorry to say that it did not work.
> 
> Actually it is not the “struct po_error_handler” but the
> “struct po_xerror_handler” which I need.  I believe the “struct
> po_error_handler” is not used anymore in current Gettext but I am not
> sure.  varargs are not needed for “struct po_xerror_handler” (even
> though support for them is desirable in general).
> 
> Hmm I tried mostly the same as you propose before for the xerror
> handler and it did not work: fh-object-set! apparently did not have
> any effect, i.e. a subsequent fh-object-ref returned 0 and on error
> the callback handler function was called at address 0, causing a
> SIGSEGV.
> 
> Either way, I tried your code for “struct po_error_handler” and put it
> in my dot.ffi to see if it works.
> 

OK.  I will look at this.


> By the way, what I forgot to mention is that I needed to replace
> 
> #include 
> 
> in the gettext-po.h header file by
> 
> typedef long size_t;
> 
> otherwise “guild compile-ffi gettext-po.ffi” would fail with the error
> message
> 
> ffi-help: WARNING: the FFI helper is experimental
> (unknown):1: not found: "gnu/stubs-32.h"
> compile-ffi: parse failed
> 


The FH compiler executed gcc to find all the hidden include directories.  If 
you don't have gcc
in your path (you didn't seem to have guile in your path) then it won't find 
those directories.
You can add `-I path-to-gcc-inc-dirs' arg to your path or make make sure "gcc" 
is in your path.

Matt




Re: Website translations with Haunt

2017-12-10 Thread Matt Wette

> On Dec 9, 2017, at 10:06 AM, pelzflorian (Florian Pelz) 
>  wrote:
> (define xerror-handler-struct
>  (make-struct-po_xerror_handler)) ; TODO SET HANDLERS:
> ;; […]
> 

First of all, FFI helper + Guile can't deal with this pattern: using varargs 
function 
members in structs.  This would require things like `va_arg' in libffi and 
Guile.  I 
have posted a request on the libffi dev site.  Your example also brought up 
some gaps
in the ffi helper.  I think I may have a workaround for you, though.  Try to 
add code
like the following to your dot-ffi file.  In functions calls that want a error 
handler
specified use std-po-error-handler.


(define-ffi-module (gettext-po)
  #:include '("gettext-po.h")
  #:library '("libgettextpo"))

(define-public std-po-error-handler
  (let* ((error
  (lambda (status errnum format)
(simple-format #t "~A\n" (ffi:pointer->string format
 (error-p
  (ffi:procedure->pointer ffi:void error (list ffi:int ffi:int '*)))
 ;;
 (error_at_line
  (lambda (status errnum filename lineno format)
(simple-format #t "~A\n" (ffi:pointer->string format
 (error_at_line-p
  (ffi:procedure->pointer ffi:void error_at_line
  (list ffi:int ffi:int '* ffi:int '*)))
 ;;
 (multiline_warning
  (lambda (prefix message)
(simple-format #t "~A ~A\n"
   (ffi:pointer->string prefix)
   (ffi:pointer->string message
 (multiline_warning-p
  (ffi:procedure->pointer ffi:void multiline_warning (list '* '*)))
 ;;
 (multiline_error
  (lambda (prefix message)
(simple-format #t "~A ~A\n" prefix message)))
 (multiline_error-p
  (ffi:procedure->pointer ffi:void multiline_error (list '* '*)))
 ;;
 (eh-struct (make-struct-po_error_handler)))

(fh-object-set! eh-struct 'error error-p)
(fh-object-set! eh-struct 'error_at_line error_at_line-p)
(fh-object-set! eh-struct 'multiline_warning multiline_warning-p)
(fh-object-set! eh-struct 'multiline_error multiline_error-p)
;;
(make-po_error_handler_t
 (ffi:pointer-address
  ((fht-unwrap struct-po_error_handler*)
   (pointer-to eh-struct))




ffi-help: documentation

2017-12-06 Thread Matt Wette
Hi All,

I am working on a ffi-helper (FH): a program that will read in a C dot-h file 
and generate a Guile dot-scm file which defines a module to provide hooks into
the associated C library.  

Currently, I'm working on documentation.  I like manuals that start out with 
simple demos to show what's going on.  That is my approach here.   Enjoy ...

FFI Helper for Guile


Matt Wette
December 2017
With NYACC Version 0.00.0

1 Introduction
**

The acronym FFI stands for "Foreign Function Interface".  It refers to
the Guile facility for binding functions and variables from C source
libraries into Guile programs.  This distribution provides utilities for
generating a loadable Guile module from a set of C declarations and
associated libraries.  The C declarations can, and conventionally do,
come from naming a set of C include files.  The nominal method for use
is to write a _ffi-module_ specification in a file which includes a
'define-ffi-module' declaration and then use the command 'guild
compile-ffi' to convert this to Guile Scheme.
 $ guild compile-ffi ffi/cairo.ffi
 wrote `ffi/cairo.scm'
Note that no C code is generated.  The hooks to access C-coded functions
in the Cairo library are provided in 100% Guile Scheme.

   The compiler for the FFI Helper (FH) is based on the C parser and
utilities which are included in the NYACC (https://www.nongnu.org/nyacc)
package.  Development for the FH is currently being performed in the
'c99dev' branch of the associated git repository.  Within the NYACC
distribution, the relevant modules can be found under the directory
'examples/'.

   Use of the FFI-helper module depends on the _scheme-bytestructure_
package available from
<https://github.com/TaylanUB/scheme-bytestructures>.  Since this package
is currently not under version control we provide a partial copy in the
NYACC distribution.

   You are probably hoping to see an example, so let's do that.

2 Demonstration
***

This is a small FFI Helper example to illustrate its use.  We will start
with the Cairo (cairographics.org) package because that is the first one
I started with in developing this package.  Say you are an avid Guile
user and want to be able to use cairo in Guile.  On most systems this
comes with associated _pkg-config_ support files.

   WARNING: The FFI-helper package is under active development and there
is some chance the following example will cease to work in the future.

   If you want to follow along and are working in the distribution tree,
you should source the file 'env.sh' in the 'examples' directory.

   By practice, I like to put all FH generated modules under a directory
called 'ffi/', so we will do that.  We start by generating, in the 'ffi'
directory, a file named 'cairo.ffi' with the following contents:
 (define-ffi-module (ffi cairo)
   #:pkg-config "cairo"
   #:include '("cairo.h" "cairo-pdf.h" "cairo-svg.h"))

   Now to generate a Guile module you use 'guild' as follows:
 $ guild compile-ffi ffi/cairo.ffi
 wrote `ffi/cairo.scm'
Though the file 'cairo/cairo.ffi' is only three lines long, the file
'ffi/cairo.scm' will be over five thousand lines long.  It looks like
the following:
 (define-module (ffi cairo)
   #:use-module (system ffi-help-rt)
   #:use-module ((system foreign) #:prefix ffi:)
   #:use-module (bytestructures guile)
   )
 (define link-libs
   (list (dynamic-link "libcairo")))

 ;; int cairo_version(void);
 (define ~cairo_version
   (delay (fh-link-proc
ffi:int
"cairo_version"
(list)
link-libs)))
 (define (cairo_version)
   (let () ((force ~cairo_version
 (export cairo_version)

 ...

 ;; typedef struct _cairo_matrix {
 ;;   double xx;
 ;;   double yx;
 ;;   double xy;
 ;;   double yy;
 ;;   double x0;
 ;;   double y0;
 ;; } cairo_matrix_t;
 (define-public cairo_matrix_t-desc
   (bs:struct
 (list `(xx ,double)
   `(yx ,double)
   `(xy ,double)
   `(yy ,double)
   `(x0 ,double)
   `(y0 ,double
 (define-fh-compound-type cairo_matrix_t cairo_matrix_t-desc cairo_matrix_t?
  make-cairo_matrix_t)
 (export cairo_matrix_t cairo_matrix_t? make-cairo_matrix_t)

 ... many, many more declarations ...

 ;; access to enum symbols and #define'd constants:
 (define ffi-cairo-symbol-val
   (let ((sym-tab
   '((CAIRO_SVG_VERSION_1_1 . 0)
 (CAIRO_SVG_VERSION_1_2 . 1)
 (CAIRO_PDF_VERSION_1_4 . 0)
 (CAIRO_PDF_VERSION_1_5 . 1)
 (CAIRO_REGION_OVERLAP_IN . 0)
 (CAIRO_REGION_OVERLAP_OUT . 1)
 (CAIRO_REGION_OVERLAP_PART . 2)
 (CAIRO_FILTER_FAST . 0)

Re: GNU Guile 2.2.3 released.

2017-12-02 Thread Matt Wette

> On Dec 1, 2017, at 8:35 AM, Andy Wingo  wrote:
> 
> We are delighted to announce GNU Guile release 2.2.3, the third bug-fix
> release in the 2.2 stable release series.

One change from 2.2.2 to 2.2.3 I notice is that the ChangeLog has been zeroed 
out.  Accident or what?





Re: GNU Guile 2.2.3 released.

2017-12-02 Thread Matt Wette

> On Dec 2, 2017, at 11:50 AM, Matt Wette <matt.we...@gmail.com> wrote:
> 
> 
>> On Dec 1, 2017, at 8:35 AM, Andy Wingo <wi...@pobox.com> wrote:
>> 
>> We are delighted to announce GNU Guile release 2.2.3, the third bug-fix
>> release in the 2.2 stable release series.
> 
> Builds fine (`make' and `make check') on MacOS 10.12.6.
> 
> Builds fine (`configure --with-bdw-gc=bdw-gc-threaded', `gmake' and `gmake 
> check') on FreeBSD 11.1.
> 
> Note the instructions for FreeBSD in README are a little off.
> 1) always install package `pkgconf'   (README implies needed only for 
> threaded)
> 2) always install package `gmake'(README implies needed only for threaded)
> 3) for threads, install package `boehm-gc-threaded' and `./configure 
> --with-bdw-gc=bdw-gc-threaded'
>   else
> 4) for no threads,install package `boehm-gc' and  `./configure 
> --without-threads'
> 
> Matt

Oh, and one more thing:  On FreeBSD, there were warnings about sys/timeb.h 
being deprecated.




Re: GNU Guile 2.2.3 released.

2017-12-02 Thread Matt Wette

> On Dec 1, 2017, at 8:35 AM, Andy Wingo  wrote:
> 
> We are delighted to announce GNU Guile release 2.2.3, the third bug-fix
> release in the 2.2 stable release series.

Builds fine (`make' and `make check') on MacOS 10.12.6.

Builds fine (`configure --with-bdw-gc=bdw-gc-threaded', `gmake' and `gmake 
check') on FreeBSD 11.1.

Note the instructions for FreeBSD in README are a little off.
1) always install package `pkgconf'   (README implies needed only for threaded)
2) always install package `gmake'(README implies needed only for threaded)
3) for threads, install package `boehm-gc-threaded' and `./configure 
--with-bdw-gc=bdw-gc-threaded'
   else
4) for no threads,install package `boehm-gc' and  `./configure 
--without-threads'

Matt


Re: guile 3 desires: guile-3-0, and debugging

2017-11-24 Thread Matt Wette

> On Nov 24, 2017, at 3:42 PM, Christopher Allan Webber 
> <cweb...@dustycloud.org> wrote:
> 
> Matt Wette writes:
> 
>> Here are a couple desires:
>> 
>> 1) more cases for cond-expand, in case 3.2 has items 3.0 does not (e.g., 
>> srfi-199)
>> 
>> 2) better debugging.  
>>   Maybe I'm not doing it right, but I struggle in this area: I mostly resort 
>> to printing.
>>   For example, add scheme level hook, or command arg, to turn off 
>> optimization.
> 
> You aren't alone... read this thread:
> 
>  https://lists.gnu.org/archive/html/guile-user/2017-05/msg00068.html
> 
> And Andy's suggestion of what we need to do to make it better:
> 
>  https://lists.gnu.org/archive/html/guile-user/2017-05/msg00070.html

(set! (@@ (language tree-il optimize) tree-il-default-optimization-options) 
(lambda () '()))

and maybe this also?

(set! (@@ (language cps optimize) cps-default-optimization-options) (lambda () 
'()))







guile 3 desires: guile-3-0, and debugging

2017-11-22 Thread Matt Wette
Here are a couple desires:

1) more cases for cond-expand, in case 3.2 has items 3.0 does not (e.g., 
srfi-199)

2) better debugging.  
   Maybe I'm not doing it right, but I struggle in this area: I mostly resort 
to printing.
   For example, add scheme level hook, or command arg, to turn off optimization.




Re: [ANN] nyacc 0.82.1 released

2017-11-11 Thread Matt Wette

> On Nov 11, 2017, at 6:27 AM, Jan Nieuwenhuizen <jann...@gnu.org> wrote:
> 
> Matt Wette writes:
> 
> Hey Matt,
> 
>> Nyacc 0.82.1 has been released.
> 
> Congrats!
> 
> It's been a while but in 0.82.0 I found a regression of a bug that you
> fixed earlier, I think in 0.80.4
> 
>https://lists.gnu.org/archive/html/guile-user/2017-06/msg3.html
> 
> I've attached the problematic file again.  It's also still present in 0.82.1
> 
> $ guile
> GNU Guile 2.2.2
> Copyright (C) 1995-2017 Free Software Foundation, Inc.
> 
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
> 
> Enter `,help' for help.
> scheme@(guile-user)> (use-modules (nyacc lalr))
> scheme@(guile-user)> *nyacc-version*
> $1 = "0.82.1"
> scheme@(guile-user)> (use-modules (nyacc lang c99 parser))
> scheme@(guile-user)> (with-input-from-file "def-bwl.c" parse-c99)
> (unknown):1: parse failed at state 89, on input "DEF_BWL"
> (unknown):1: C99 parse error
> $2 = #f


Ugh.  I thought I had that one.  I will take a look

PASS: nyacc/c99-01, CPP: #, ##, __VA_ARGS__





Re: ffi-help: status to 19 Aug 2017

2017-11-10 Thread Matt Wette

> On Nov 10, 2017, at 3:04 PM, Stefan Israelsson Tampe 
>  wrote:
> 
> I'm trying out the ffi help stuff.
> 
> 1. It looks like 1.234f numeric constants is not lexed
> 2. characters constants can be included in #if preprocessor steps it looks,
> 3. character constants seam to follow L?'(\\.|[^\\'])+'

I believe these are fixed in commit fb03d613.  Thanks. I was not using the C 
readers in the CPP lexer.

Matt


Re: ffi-help: status to 19 Aug 2017

2017-11-09 Thread Matt Wette

> On Nov 9, 2017, at 11:10 AM, Roel Janssen  wrote:
> I wanted to try ffi-helper on htslib, but I am confused on how to get
> started.  Where does the "compile-ffi" subcommand for "guild" come from?
> 

And not sure I answered this question as intended.  The `guild' command looks 
for a scm file with 
basename of the first argument in a subdirectory scripts/ in LOAD_PATH.  So 
`guild compile-ffi foo.ffi'
will execute `scripts/compile-ffi.scm' with argument `foo.ffi'.

Matt





Re: ffi-help: status to 19 Aug 2017

2017-11-09 Thread Matt Wette

> On Nov 9, 2017, at 5:00 PM, Matt Wette <matt.we...@gmail.com> wrote:
> 
>> On Nov 9, 2017, at 11:10 AM, Roel Janssen <r...@gnu.org> wrote:
>>> ...
>> 
>> Thanks for creating this!  It seems to be very useful and powerful.
>> 
>> I wanted to try ffi-helper on htslib, but I am confused on how to get
>> started.  Where does the "compile-ffi" subcommand for "guild" come from?
>> 
>> Kind regards,
>> Roel Janssen
> 
> See the following, but I'm seeing a parse error so may be a bug in my C99 
> parser.  And not sure "hts.h" is the only include you need.

I got it to compile-ffi.  Still a few warnings I need to chase down.  
I made a couple fixes (and added examples/ffi/htslib.ffi) and pushed to my repo 
on savannah.

Also, htslib.scm is attached.  It is 1700 lines only.

Matt



htslib.scm
Description: Binary data


Re: ffi-help: status to date

2017-10-24 Thread Matt Wette

> On Oct 22, 2017, at 11:31 AM, Matt Wette <matt.we...@gmail.com> wrote:
> 
> Hi All,
> 
> I am working on a ffi-helper (FH): a program that will read in a C dot-h file 
> and generate a Guile dot-scm file 
> which defines a module to provide hooks into the associated C library.  
> 

> I was able to generate scm code for glib, gobject, gio, pango, and gtk2+.  
> The following demo code actually works.
> I get a GUI and click the button and it closes, though with an error message:
>gtkdemo.scm:16:0: Wrong number of arguments to # data)>
> 

> (define (hello widget data)
>  (display "Hello World!\n"))

>  (g_signal_connect button "clicked" hello NULL)

The reason I got error messages was that g_signal_connect uses signature `void 
(*f)(void)' for the 
callback but the semantics of GTK say use `void (*f)(void*, void*)', basically. 
 GTK handles this 
by providing casts for arguments.  I got the code working by hand generating 
casts:

  (define ~hello (ffi:procedure->pointer ffi:void hello (list '* '*)))

  (g_signal_connect button "clicked" ~hello NULL)

Doing this by hand is a bit of a mess, but ... there it is.  I am not confident 
that there is a way
to automate or make this easier.  I had to generate a couple other hand-casts 
but the result is that
the demo is now working w/o error messages.  

In case you are interested here are line counts for the text files and sizes 
for the object files.
(oops, didn't include pango; that is bigish)

mwette$ wc gobject.* glib.* gtk2+.* gdk2.*
  26  77 885 gobject.ffi
   12543   28465  426476 gobject.scm
  31  821006 glib.ffi
   31326   75035 1013504 glib.scm
  17  47 470 gtk2+.ffi
   92827  210107 3259549 gtk2+.scm
  18  52 534 gdk2.ffi
   18986   45046  639630 gdk2.scm

mwette$ ls -l gobject.* glib.* gtk2+.* gdk2.*
-rw-r--r--  1 mwette  staff   3619461 Oct 22 10:57 gdk2.scm.go
-rw-r--r--  1 mwette  staff   5546829 Oct 22 10:48 glib.scm.go
-rw-r--r--  1 mwette  staff   2554501 Oct 24 16:36 gobject.scm.go
-rw-r--r--  1 mwette  staff  18521997 Oct 22 11:06 gtk2+.scm.go




Re: libguile-2.2.2 uses tmpnam

2017-10-24 Thread Matt Wette

> On Oct 24, 2017, at 4:47 AM, Jeffrey Walton  wrote:
> 
> On Sat, Oct 21, 2017 at 5:05 AM, Jeffrey Walton  wrote:
>> My apologies for writing about this. I found one previous thread that
>> mentioned it, but it was working a clock_t problem. Cf.,
>> https://lists.gnu.org/archive/html/bug-guile/2011-05/msg00024.html
>> ...
>> I'm happy to configure libguile to remove tmpnam and break other
>> libraries. I don't believe its a configuration option at the moment.
>> `./configure --help | egrep 'tmpnam|insecure'` returns 0 hits.
> 
> --disable-deprecated does not remove it. I'm fairly certain Posix
> deprecated the function about a decade ago, so its not clear to me how
> its not being removed with the option.
> 
> Any hints on getting rid of this would be greatly appreciated.
> 
> Jeff

I am working on a patch to make default configure w/o tmpnam and provides 
--enable-tmpnam option.




ffi-help: status to date

2017-10-22 Thread Matt Wette
Hi All,

I am working on a ffi-helper (FH): a program that will read in a C dot-h file 
and generate a Guile dot-scm file 
which defines a module to provide hooks into the associated C library.  

Since last report I have removed the un-hygienic macros: all names are passed 
to macros now.  This makes
the generated Scheme code about double the size it was before, but so what.  
Also, the "wrap" and "unwrap"
functions are now mostly hidden: they should not be needed directly by the user.

I am fine-tuning the type handling.  Note:
1) In Scheme we need to have something that represents the pointer types.  When 
the FH sees a C type like
   typedef struct { ... } foo_t then the it generates SCM types for foo_t and 
foo_t*, a pointer-to-foo_t type.
   These types are connected to that (pointer-to ) for an object of type 
foo_t generates a foo_t* object.
2) The FH does not generate types for numerics: typedef int int_t; is just left 
alone, but wrappers are used
   to convert numerics.
3) The FH does not generate types for typedef enum { ... } enum_t;
4) I am using the bytestructures package from Taylan UB 
(github-dot-com/TaylanUB/scheme-bytestructures).
5) I have developed a function pseudo-descriptor for bytestructures so that 
(bs:pointer (fh:function ...))
   provides a way to deal with function pointers in structs.  Passing Scheme 
procedures as arguments to 
   pointer->procedure generated procedures works also.

Issues:
1) I am still working on a solution to functions w/ varargs.  I believe I have 
a solution for calling C vararg
   functions from Guile: the user provides casts for extra args, e.g., (printf 
"the value is %d\n" (fh-cast int 4)).
   The implementation will take a bit of work.
2) clean up some inefficiencies.  Not going into details here
3) Documentation:  This will have to be good because the FFI helper is not 
bullet proof.  Sometimes one needs
   to add extra pointer-types etc in the dot-ffi module, and there needs to be 
a document to help the user go
   through the process of finding the reason for error messages and how to add 
code to get things working.
4) Maybe a C to Guile C-SMOB generated is needed also.  The gtk2+ dot-go file 
is now ~ 20 MB.

I was able to generate scm code for glib, gobject, gio, pango, and gtk2+.  The 
following demo code actually works.
I get a GUI and click the button and it closes, though with an error message:
gtkdemo.scm:16:0: Wrong number of arguments to #

The code is being worked in the c99dev branch of nyacc, hosted on 
https://savannah.nongnu.org/projects/nyacc.

#!/opt/local/bin/guile
!#

;; https://developer.gnome.org/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD

(use-modules (ffi glib))
(use-modules (ffi gobject))
(use-modules (ffi gtk2+))
(use-modules (bytestructures guile))
(use-modules (system ffi-help-rt))
(use-modules ((system foreign) #:prefix ffi:))

(define NULL ffi:%null-pointer)

(define (hello widget data)
  ;;(g_print "Hello World!\n")
  (display "Hello World!\n")
  )

(define (delete-event widget event data)
  (display "delete event occurred\n")
  1)

(define (destroy widget data)
  (gtk_main_quit))

(define (main)
  (define window #f)
  (define button #f)
  (define argc (bytestructure int 0))

  (gtk_init (pointer-to argc) NULL)

  (set! window (gtk_window_new 'GTK_WINDOW_TOPLEVEL))
  (g_signal_connect window "delete-event" delete-event NULL)
  (g_signal_connect window "destroy" destroy NULL)
  (gtk_container_set_border_width window 10)

  (set! button (gtk_button_new_with_label "Hello World"))
  (g_signal_connect button "clicked" hello NULL)
  (g_signal_connect_swapped button "clicked" gtk_widget_destroy window)
  (gtk_container_add window button)

  (gtk_widget_show button)
  (gtk_widget_show window)

  (gtk_main))

;; --- last line ---

And here, for example, is the FFI module for gtk2+ and gobject:
;; gtk2+.ffi-*- Scheme -*-

(define-ffi-module (ffi gtk2+)
  #:pkg-config "gtk+-2.0"
  #:include '("gtk/gtk.h")
  #:inc-filter (lambda (f p) (string-contains p "gtk/" 0))
  #:use-ffi-module (ffi gdk2)
  #:use-ffi-module (ffi pango)
  #:use-ffi-module (ffi gobject)
  #:use-ffi-module (ffi glib)
  )

(define-fh-pointer-type GtkEnumValue* int*-desc
  GtkEnumValue*? make-GtkEnumValue*)
(export GtkEnumValue* GtkEnumValue*? make-GtkEnumValue*)
  
;; --- last line ---

;; gobject.ffi  -*- Scheme -*-

(define-ffi-module (ffi gobject)
  #:use-ffi-module (ffi glib)
  #:pkg-config "gobject-2.0"
  #:include '("glib-object.h")
  #:inc-filter (lambda (file-spec path-spec)
 (string-contains path-spec "gobject/" 0))
  #:use-module ((system foreign) #:prefix ffi: #:select(%null-pointer))
  )

(define NULL ffi:%null-pointer)

(define-public (g_signal_connect instance detailed_signal c_handler data)
  (g_signal_connect_data instance detailed_signal c_handler data NULL 0))

(define-public (g_signal_connect_after instance detailed_signal c_handler data)
  (g_signal_connect_data 

Re: Reduce/Reduce conflict errors

2017-10-21 Thread Matt Wette

> On Oct 21, 2017, at 12:43 AM, Jeffrey Walton  wrote:
> 
> Hi Everyone,
> 
> I'm building GnuTLS 3.5.15 from sources, including its dependencies.
> One of them is libguile, and I am using version 2.2.2 from
> ftp.gnu.org. I'm working on Ubuntu 17, x86_64.
> 
> The GnuTLS self tests are failing. As a first step I looked through
> the build logs and found the issues below.
> 
> According to the Bison manual, "A reduce/reduce conflict occurs if
> there are two or more rules that apply to the same sequence of input.
> This usually indicates a serious error in the grammar."
> (https://www.gnu.org/software/bison/manual/html_node/Reduce_002fReduce.html).
> 
> My question is, is this something that I should be concerned about?
> Here, I'm only concerned about running GnuTLS self tests; not about Go
> because I don't use Go.
> 
> My second question is, if this needs to be addressed, which version of
> libguile does not experience the issue?
> 
> Thanks in advance,
> 
> Jeff
> 
> 
> 
>  GUILEC language/cps/with-cps.go
> wrote `language/cps/verify.go'
>  GUILEC language/ecmascript/tokenize.go
> wrote `language/cps/slot-allocation.go'
>  GUILEC language/ecmascript/parse.go
> wrote `language/cps/with-cps.go'
>  GUILEC language/ecmascript/impl.go
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '--' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '++' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '-' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '+' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'semicolon' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'dot' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'lbracket' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'lparen' in state 422
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '--' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '++' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '-' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '+' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on 'semicolon' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on 'dot' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on 'lbracket' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on 'lparen' in state 397
> %% Shift/Reduce conflict (shift 367, reduce 49) on 'else' in state 319
> %% Shift/Reduce conflict (shift 144, reduce 177) on 'in' in state 242
> %% Shift/Reduce conflict (shift 144, reduce 178) on 'in' in state 241
> %% Shift/Reduce conflict (shift 144, reduce 179) on 'in' in state 240
> %% Shift/Reduce conflict (shift 144, reduce 180) on 'in' in state 239
> %% Shift/Reduce conflict (shift 80, reduce 119) on 'colon' in state 125
> %% Shift/Reduce conflict (shift 170, reduce 139) on '++' in state 85
> %% Shift/Reduce conflict (shift 169, reduce 139) on '--' in state 85
> %% Shift/Reduce conflict (shift 153, reduce 159) on '+' in state 49
> %% Shift/Reduce conflict (shift 152, reduce 159) on '-' in state 49
> %% Shift/Reduce conflict (shift 144, reduce 176) on 'in' in state 47
> wrote `language/ecmascript/tokenize.go'
>  GUILEC language/ecmascript/base.go
> language/ecmascript/base.scm:229:22: warning: possibly unbound
> variable `Boolean'
> language/ecmascript/base.scm:230:21: warning: possibly unbound variable 
> `String'
> language/ecmascript/base.scm:231:21: warning: possibly unbound variable 
> `Number'
> wrote `language/ecmascript/impl.go'
>  GUILEC language/ecmascript/function.go
> language/ecmascript/function.scm:40:9: warning: possibly unbound
> variable `'
> language/ecmascript/function.scm:44:43: warning: possibly unbound
> variable `js-array-vector'
> wrote `language/ecmascript/function.go'
>  GUILEC language/ecmascript/array.go
> wrote `language/ecmascript/base.go'
>  GUILEC language/ecmascript/compile-tree-il.go
> wrote `language/ecmascript/array.go'
>  GUILEC language/ecmascript/spec.go
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '--' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '++' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '-' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on '+' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'semicolon' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'dot' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'lbracket' in state 422
> %% Reduce/Reduce conflict (reduce 11, reduce 7) on 'lparen' in state 422
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '--' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '++' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '-' in state 397
> %% Reduce/Reduce conflict (reduce 9, reduce 6) on '+' in state 397
> %% Reduce/Reduce conflict 

Re: Wisp as shipped language in Guile?

2017-09-17 Thread Matt Wette

> On Sep 17, 2017, at 4:22 PM, Arne Babenhauserheide <arne_...@web.de> wrote:
> 
> 
> Matt Wette <matt.we...@gmail.com> writes:
>> Looks promising, especailly if the footprint is small.  
>> Can someone post the sample guix specification?
>> I could not access from the gnunet log.
> 
> Do you mean the wisp package for Guix?

No, I meant the guix package spec for package foo written in wisp.

define-public foo
   package 
  name "guile-wisp"
  source : origin 
 ...


Thanks,
Matt






Re: Wisp as shipped language in Guile?

2017-09-17 Thread Matt Wette

Looks promising, especailly if the footprint is small.  
Can someone post the sample guix specification?
I could not access from the gnunet log.





[ANN] nyacc 0.82.1 released

2017-09-16 Thread Matt Wette
Nyacc 0.82.1 has been released.

This is a fix to 0.82.0, which has issues with running the FFI helper.
I can now run the cairo ffi helper demo on Centos.  To run the ffi helper 
cairo demo, check the file HACKING in the distribution.

NYACC, for Not Yet Another Compiler Compiler!, is set of guile modules for
generating parsers and lexical analyzers.  It also provides sample parsers
and pretty-printers using SXML trees as an intermediate representation.

NYACC maturity is beta level.

NYACC is free software; the full source distribution is available through

tarball repository:
https://download.savannah.gnu.org/releases/nyacc/

git repository:
git://git.savannah.nongnu.org/nyacc.git

home page, project page, user's guide:
http://www.nongnu.org/nyacc
https://savannah.nongnu.org/projects/nyacc
http://www.nongnu.org/nyacc/nyacc-ug.html

For support see:
https://savannah.nongnu.org/support/?group=nyacc



Re: macro helpers

2017-09-12 Thread Matt Wette

> On Sep 12, 2017, at 11:09 AM, Stefan Israelsson Tampe 
>  wrote:
> 
> Writing efficient macros is a bit difficult. Let me explain by using an 
> example. The background
> is that I maintaining a python compiler and python like object system and 
> would like to program
> a scheme macro that would be the scheme counterpart to various python 
> construct. For fun
> consider pythons for loop. it's looping depending on iterators and have break 
> and continue.
> 
> Here is a hypothetical for loop:
> 
> (for lp ((x : I)) ((c 1))
>  (lp #:continue (+ x c))
> 
>  #:final
>  c)
> 
> The python iterators signals the end of the loop with raising en exception 
> which is not too costly and we will return the #:final as a value at that 
> point. This is a mix of scheme and python. Now what we
> can do further is to introduce break,continue and break and final as
> 
> (lp #:continue c)   e.g. continue with c
> (lp #:break  c)   e.g. break with c
> (lp #:final) e.g. execute final with current c
> 
> This has a great potential of a easy generalization of python for loops an 
> implementation could be like, its very slow though, here is a take on the 
> implementation which describes the macro 
> (more work is needed, not a propper pattern here)
> 
> (define-syntax for
>   (lambda (x)
> (syntax-case x ()
>   ((for lp ((x ... : E) ... (c n) ...) code ... #:final fin ...)
>(with-syntax (((It ...)   (generate-temporaries #'(O ...)))
>  ((cc ...)   (generate-temporaries #'(c ...)))
>  (((x1 ...) ...) (generate-temporaries #'((x ...) ...)))
>  (((x2 ...) ...) (generate-temporaries #'((x ...) ...
>  #'(let ((It E) ... (c n) ... (x 'None) ... ...)
>  (let/ec lp-break
>(catch IteratorException
>  (lambda ()
>(letrec ((enclosing
>  (lambda (cc ...)
>(set! c cc) ...
>(call-with-values
>(lambda () (next It))
>  (lambda (x2 ...)
>(set! x1 x2) ...))
>...
>(set! x x1)
>... ...
>(call-with-values
>(lambda ()
>  (let/ec lp-continue
>(define (lp tag . args)
>  (cond
>   ((eq? tag #:continue)
>(apply lp-continue args))
>   ((eq? tag #:break)
>(apply lp-break args))
>((eq? tag #:final)
>  (lp-continuation #:final
>   code ...
>  (lambda args
>(if (eq? (car args) #:final)
>(throw IteratorException)
>(apply enclosing (cdr args
>  (enclosing c ...)))
>  (lambda q fin ...)
>
> The value of tail position is transfered to the next iteration of the loop. 
> It's not functional. But this is for the full featured version in which lp 
> may be transferred to another function and there inside a loop called e.g.all 
> crazy things, the easy steps would be to have full control in multiple loops.
> Note how this enables great refactoring of functions with many loops inside 
> loops. Anyway for normal loops this is really really slow, and one would 
> really like to have streamlined code when (lp #:continue ...) is used at tail 
> positions and for cases where we can prove that lp is never used in any 
> advanced configuration, we would like to know if lp, (lp #:continue ..) (in 
> tail position) and finally if (lp #:break ...) is used or not. But how to do 
> this at the macro level? I don't think that we
> have any good history of optimizing this case!
> 
> WDYT

I don't quite understand why this is a macro issue.  Is there efficient code, 
in this patterh, you could 
write by hand that is not done by macro?  My guess is you are looking for a 
clean pattern for efficient
execution of python for-loops.  Why not start with a list of possible 
implementations, try them out, and 
then work to develop your syntax-pattern?  You could try prompts or 
continuations maybe.  I make :( when
I see set! in your pattern, BTW.

Matt

CC to guile-user as this may be of interest there.





Re: [ANN] nyacc 0.82.0 released

2017-09-11 Thread Matt Wette

> On Sep 10, 2017, at 8:37 AM, Matt Wette <matt.we...@gmail.com> wrote:
> 
> Nyacc 0.82.0 has been released

Appologies if you have tried this and running into problems.  I found a few 
bugs.
I have been working on macos but now trying on Centos system.  I will release
a minor update by end of the coming weekend.  The patch below should help you 
get by for now. -- Matt

diff --git a/examples/nyacc/lang/c99/ffi-help.scm 
b/examples/nyacc/lang/c99/ffi-help.scm
index a9ec063..f4a2221 100644
--- a/examples/nyacc/lang/c99/ffi-help.scm
+++ b/examples/nyacc/lang/c99/ffi-help.scm
@@ -19,6 +19,8 @@
 ;; bytestructure->descriptor->ffi-descriptor
 ;; bs:pointer->proc
 
+;; For enum typedefs we are not creating types but just using wrappers.
+
 (define-module (nyacc lang c99 ffi-help)
   #:export (*ffi-help-version*
define-ffi-module
@@ -73,7 +75,7 @@
"__attribute__(X)="
"__inline=" "__inline__="
"__asm(X)=" "__asm__(X)="
-   "__has_include=(X)__has_include__(X)"
+   "__has_include(X)=__has_include__(X)"
"__extension__="
)
   ;;("sys/cdefs.h" "__DARWIN_ALIAS(X)=")
@@ -82,9 +84,10 @@
 '(("__builtin"
"__builtin_va_list=void*" "__attribute__(X)="
"__inline=" "__inline__="
-   "__asm(X)=" "__asm__(X)=")
-   "__has_include=(X)__has_include__(X)"
+   "__asm(X)=" "__asm__(X)="
+   "__has_include(X)=__has_include__(X)"
"__extension__="
+   )
   
 (define fh-cpp-defs
   (cond
@@ -753,7 +756,9 @@
 (define (gen-exec-params params)
   (fold-right
(lambda (param-decl seed)
- (let* ((param-decl (expand-typerefs param-decl (*udict*) (*defined*)))
+ ;; Changed to (*wrapped*) to include enum types.  If we need (*defined*)
+ ;; then we will need to create enum types in cnvt-udecl typedefs.
+ (let* ((param-decl (expand-typerefs param-decl (*udict*) (*wrapped*)))
(param-decl (udecl-rem-type-qual param-decl)) ;; ???
(mspec (udecl->mspec param-decl)))
(acons (car mspec) (mspec->fh-unwrapper mspec) seed)))
@@ -798,27 +803,6 @@
 ;; specl is decl-spec-list tree
 ;; params is list of param-decl trees (i.e., cdr of param-list tree)
 ;; @end deffn
-(define (OLD-cnvt-fctn name rdecl params)
-  #;(when (string=? name "gdbm_store") (sfout "cnvt-fctn\n") (ppout params))
-  (let* ((decl-return (gen-decl-return rdecl))
-(decl-params (gen-decl-params params))
-(exec-return (gen-exec-return-wrapper rdecl))
-(exec-params (gen-exec-params params)))
-(when #f
-  (sfout "cnvt-fctn\n") (ppout params)
-  (ppout decl-params) (ppout exec-params))
-(ppscm
- `(define ,(string->symbol name)
-   (let ((~f #f))
- (lambda ,(gen-exec-arg-names exec-params)
-   (unless ~f
- (set! ~f (fh-link-proc
-   ,name ,decl-return (list ,@decl-params
-   (let ,(gen-exec-unwrappers exec-params)
- ,(if exec-return
-  `(,exec-return (~f ,@(gen-exec-call-args exec-params)))
-  `(~f ,@(gen-exec-call-args exec-params
-(sfscm "(export ~A)\n" name)))
 (define (cnvt-fctn name rdecl params)
   (let* ((decl-return (gen-decl-return rdecl))
 (decl-params (gen-decl-params params))
diff --git a/examples/system/ffi-help-rt.scm b/examples/system/ffi-help-rt.scm
index 80f0382..9550ac7 100644
--- a/examples/system/ffi-help-rt.scm
+++ b/examples/system/ffi-help-rt.scm
@@ -194,7 +194,7 @@
   (make-fht (quote type) unwrap #f #f
 (make-bs*-printer (quote type
 (define (wrap val) ;; pointer returned from code
-  (make (bytestructure type val)))
+  (make (bytestructure desc (ffi:pointer-address val
 (export make type? unwrap type wrap)
 )))
 
@@ -353,7 +353,7 @@
 (define (unwrap~pointer obj)
   (cond
((ffi:pointer? obj) obj)
-   ((string? obj) (string->pointer obj))
+   ((string? obj) (ffi:string->pointer obj))
((bytestructure? obj) (ffi:make-pointer (bytestructure-ref obj)))
((fh-object? obj) (unwrap~pointer (struct-ref obj 0)))
(else (error "expecting pointer type"




Re: [ANN] nyacc 0.82.0 released

2017-09-10 Thread Matt Wette

> On Sep 10, 2017, at 8:37 AM, Matt Wette <matt.we...@gmail.com> wrote:
> 
> Nyacc 0.82.0 has been released
> 
> In this version I have cleaned up more of the FFI Helper.  Note:
> 1) In the distribution, you will see example .ffi files in examples/ffi/.
> 2) use of the FFI Helper required the bytestructures package, available from:
>   https://github.com/TaylanUB/scheme-bytestructures
> 3) ffi/cairo.ffi is converted to ffi/cairo.scm by the command
>   $ guild compile-ffi ffi/cairo.ffi
> 4) It works on my mac.  I don't know what else: the code needs to have access
>   to files in odd places (e.g., lib/gcc//include
> 5) If you do `make install', and have bytestructures in the SITE_SCM_DIR, 
> then 
>   this should work:
>   $ make install-ffi-help
>   ...
>   +++ warning: the FFI Helper is experimental
>   ffi-help: can't do varargs (yet)
>   wrote `/var/tmp/zz/scm/ffi/sqlite3.scm'
>   wrote `/var/tmp/zz/go/ffi/sqlite3.go'
>   +++ warning: the FFI Helper is experimental
>   ffi-help: can't do varargs (yet)
>   wrote `/var/tmp/zz/scm/ffi/libgit2.scm'
>   wrote `/var/tmp/zz/go/ffi/libgit2.go'
>   +++ warning: the FFI Helper is experimental
>   ffi-help: can't do varargs (yet)
>   ffi-help: no FFI float-type for "long double"
>   wrote `/var/tmp/zz/scm/ffi/glib.scm'
>   wrote `/var/tmp/zz/go/ffi/glib.go'

Some additional notes: 
6) compile-ffi and compile may take significant time.  I have seen compile-ffi 
take time on 
   include files that have a large number of re-includes.  Nyacc does not try 
to skip re-reading
   include files (like gcc does).  And compile takes a long time because the 
.scm files can be
   huge.  On my machine, ffi/gio.scm turns out to be about 24 K lines and the 
gio.go file is 8 MB.
7) In examples I show that passing strings to function is done via (foo 
(string->pointer "abc")).
   Using string->pointer is not required: unwrap~pointer will now deal with 
this.
8) the FFI Helper files .scm files are distributed in SCM_DIR -- not under 
nyacc/ :
   + scripts/compile-ffi.scm is the compiler driver invoked by `guild'
   + system/ffi-help-rt.scm is the FFI Helper runtime (macros for defining 
types, etc)
   + ffi/ is the conventional place to host .ffi files, so ffi/glib.scm is code 
for (ffi glib)
9) I will need to look into how to add some needed types in guile FFI: 
intptr_t, long long, long
   double.

Matt




[ANN] nyacc 0.82.0 released

2017-09-10 Thread Matt Wette
Nyacc 0.82.0 has been released

In this version I have cleaned up more of the FFI Helper.  Note:
1) In the distribution, you will see example .ffi files in examples/ffi/.
2) use of the FFI Helper required the bytestructures package, available from:
https://github.com/TaylanUB/scheme-bytestructures
3) ffi/cairo.ffi is converted to ffi/cairo.scm by the command
$ guild compile-ffi ffi/cairo.ffi
4) It works on my mac.  I don't know what else: the code needs to have access
   to files in odd places (e.g., lib/gcc//include
5) If you do `make install', and have bytestructures in the SITE_SCM_DIR, then 
   this should work:
$ make install-ffi-help
...
+++ warning: the FFI Helper is experimental
ffi-help: can't do varargs (yet)
wrote `/var/tmp/zz/scm/ffi/sqlite3.scm'
wrote `/var/tmp/zz/go/ffi/sqlite3.go'
+++ warning: the FFI Helper is experimental
ffi-help: can't do varargs (yet)
wrote `/var/tmp/zz/scm/ffi/libgit2.scm'
wrote `/var/tmp/zz/go/ffi/libgit2.go'
+++ warning: the FFI Helper is experimental
ffi-help: can't do varargs (yet)
ffi-help: no FFI float-type for "long double"
wrote `/var/tmp/zz/scm/ffi/glib.scm'
wrote `/var/tmp/zz/go/ffi/glib.go'
...

NYACC, for Not Yet Another Compiler Compiler!, is set of guile modules for
generating parsers and lexical analyzers.  It also provides sample parsers
and pretty-printers using SXML trees as an intermediate representation.

NYACC maturity is beta level.

NYACC is free software; the full source distribution is available through

tarball repository:
https://download.savannah.gnu.org/releases/nyacc/

git repository:
git://git.savannah.nongnu.org/nyacc.git

home page, project page, user's guide:
http://www.nongnu.org/nyacc
https://savannah.nongnu.org/projects/nyacc
http://www.nongnu.org/nyacc/nyacc-ug.html

For support see:
https://savannah.nongnu.org/support/?group=nyacc




Re: ffi-help: #:use-ffi-module

2017-09-07 Thread Matt Wette

> On Sep 7, 2017, at 8:32 PM, Matt Wette <matt.we...@gmail.com> wrote:
> 
> 
> Hi All,
> 
> I am working on a ffi-helper: a program that will read in a C dot-h file and 
> generate a Guile dot-scm file 
> which defines a module to provide hooks into the associated C library.  Goal 
> is to release something 
> around Apr 2018.
> 

I should mention that the compound type system uses the slick bytestructures 
Scheme package 
developed by TaylanUB: https://github.com/TaylanUB/scheme-bytestructures





ffi-help: #:use-ffi-module

2017-09-07 Thread Matt Wette

Hi All,

I am working on a ffi-helper: a program that will read in a C dot-h file and 
generate a Guile dot-scm file 
which defines a module to provide hooks into the associated C library.  Goal is 
to release something 
around Apr 2018.

With the helper interfaces are with ffi-modules.  A module is a set of C 
includes and C libraries.  The Scheme
interface code encapsulated in a Guile module.  If a C type is defined in the 
set of C includes, you will see it
in the associated Guile module.  If a C type is defined outside the set of 
includes, and is not included in a 
use-ffi-module declaration, then the type is expanded.  So, the ffi-module 
declaration has expressions to 
indicate which files should be include in the set defining the module.

Here is a ffi-module declaration for the gobject:

  mwette$ cat gobject.ffi 
  ;; gobject.ffi-*- Scheme -*-

  (define-ffi-module (gobject)
#:use-ffi-module (glib)
#:pkg-config "gobject-2.0"
#:include '("glib-object.h")
#:inc-filter (lambda (file-spec path-spec)
 (string-contains path-spec "gobject/" 0))
)

  ;; --- last line ---

To convert a dot-ffi module to dot-scm you use guild:
  mwette$ guild compile-ffi gobject.ffi

Currently not handled: varargs, long double, some function types, ...
I have some ideas for handling varargs.

But otherwise I'm getting things to compile:

  mwette$ wc {cairo,gdbm,gio,glib,gobject,libgit2,sqlite3}.ffi
  25  65 657 cairo.ffi
  14  45 371 gdbm.ffi
  10  27 218 gio.ffi
  19  47 509 glib.ffi
  11  27 265 gobject.ffi
  14  35 403 libgit2.ffi
  12  34 339 sqlite3.ffi

  mwette$ wc {cairo,gdbm,gio,glib,gobject,libgit2,sqlite3}.scm
6629   16556  221347 cairo.scm
 7472067   23093 gdbm.scm
   42884  109771 1554684 gio.scm
   28275   74979  887380 glib.scm
   10417   26654  349534 gobject.scm
   15702   45142  524011 libgit2.scm
4980   14389  168532 sqlite3.scm

  mwette$ ls -l {cairo,gdbm,gio,glib,gobject,libgit2,sqlite3}.scm.go
  -rw-r--r--  1 mwette  staff   657197 Sep  7 20:15 cairo.scm.go
  -rw-r--r--  1 mwette  staff   105509 Sep  7 20:15 gdbm.scm.go
  -rw-r--r--  1 mwette  staff  7313669 Sep  7 20:07 gio.scm.go
  -rw-r--r--  1 mwette  staff  3168869 Sep  7 19:03 glib.scm.go
  -rw-r--r--  1 mwette  staff  1672685 Sep  7 18:43 gobject.scm.go
  -rw-r--r--  1 mwette  staff  2018653 Sep  7 20:17 libgit2.scm.go
  -rw-r--r--  1 mwette  staff   766205 Sep  7 20:17 sqlite3.scm.go

Matt






Re: Auto compile from many different languages that interoperates with guile

2017-09-02 Thread Matt Wette

> On Sep 2, 2017, at 6:00 AM, Matt Wette <matt.we...@gmail.com> wrote:
> 
> 
>> On Sep 1, 2017, at 1:45 PM, Stefan Israelsson Tampe 
>> <stefan.ita...@gmail.com> wrote:
>> 
>> Hi,
>> 
>> I am maintaining a prolog->scheme compiler and a python->scheme compiler. 
>> The nice thing with those implementation is that they work well with the 
>> guile module system and are proper scheme functions and variables etc. So 
>> python objects can be treated as goops objects and prolog predicates can be 
>> used in kanren etc.
>> 
>> There is a headake though. When loading a module from one language to 
>> another language the autocompilation fails. It would be nice to load a 
>> python module and work with it from scheme land and vice versa.
>> 
>> One problem is the following funciton in system base compile
>> 
>> (define* (compile-file file #:key
>>   (output-file #f)
>>   (from (current-language))
>>   (to 'bytecode)
>>   (env (default-environment from))
>>   (opts '())
>>   (canonicalization 'relative))
>> ...)
>> 
>> form is either specified or current-language and what I propose is to add a 
>> knob that enables another version of the default for from e.g. something 
>> like the following.
>> 
>> (define %extension-map '((("py" "python") python) ((("pl" "prolog") prolog) 
>> (("scm") scheme)))
>> (define %use-extension-map #f)
>> (define (default-from-file file)
>>  (define default (current-language))
>>  (if %use-extension-map   
>>   (let* ((ext   (get-extension file))
>>   (lang  (find-language ext %extension-map)))
>>   (if lang lang default
>> 
>> (define* (compile-file file #:key
>>   (output-file #f)
>>   (from (default-from file))
>>   (to 'bytecode)
>>   (env (default-environment from))
>>   (opts '())
>>   (canonicalization 'relative))
>> 
>> ...)
>> 
>> I think that we already have variables that discovers the source files that 
>> guile can compile and I don't think that we should get name clashes as long 
>> as we use the prefix (languge prolog module) as a prefix for modules in 
>> other languages than scheme.
>> 
>> WDYT
> 
> Will this handle all possible option processing?   
> 
> Another option is to change compile.scm to hand-off unknown extensions to 
> another script using some convension.  
> For example, for py files, compile.scm would call out compile-py.scm, and for 
> prolog, compile-pl.scm.
> 

Oops -- never mind.   You are talking about the compile procedure; my mind was 
off in a differnent context: guild.

But there is an issue here, because I would like "guile -s foo.py" to interpret 
the file foo.py as Python and not Scheme.





Re: Auto compile from many different languages that interoperates with guile

2017-09-02 Thread Matt Wette

> On Sep 1, 2017, at 1:45 PM, Stefan Israelsson Tampe  
> wrote:
> 
> Hi,
> 
> I am maintaining a prolog->scheme compiler and a python->scheme compiler. The 
> nice thing with those implementation is that they work well with the guile 
> module system and are proper scheme functions and variables etc. So python 
> objects can be treated as goops objects and prolog predicates can be used in 
> kanren etc.
> 
> There is a headake though. When loading a module from one language to another 
> language the autocompilation fails. It would be nice to load a python module 
> and work with it from scheme land and vice versa.
> 
> One problem is the following funciton in system base compile
> 
> (define* (compile-file file #:key
>(output-file #f)
>(from (current-language))
>(to 'bytecode)
>(env (default-environment from))
>(opts '())
>(canonicalization 'relative))
> ...)
> 
> form is either specified or current-language and what I propose is to add a 
> knob that enables another version of the default for from e.g. something like 
> the following.
> 
> (define %extension-map '((("py" "python") python) ((("pl" "prolog") prolog) 
> (("scm") scheme)))
> (define %use-extension-map #f)
> (define (default-from-file file)
>   (define default (current-language))
>   (if %use-extension-map   
>(let* ((ext   (get-extension file))
>(lang  (find-language ext %extension-map)))
>(if lang lang default
> 
> (define* (compile-file file #:key
>(output-file #f)
>(from (default-from file))
>(to 'bytecode)
>(env (default-environment from))
>(opts '())
>(canonicalization 'relative))
> 
> ...)
> 
> I think that we already have variables that discovers the source files that 
> guile can compile and I don't think that we should get name clashes as long 
> as we use the prefix (languge prolog module) as a prefix for modules in other 
> languages than scheme.
> 
> WDYT

Will this handle all possible option processing?   

Another option is to change compile.scm to hand-off unknown extensions to 
another script using some convension.  
For example, for py files, compile.scm would call out compile-py.scm, and for 
prolog, compile-pl.scm.





Re: feature request: simple hashbang for executable scripts

2017-08-24 Thread Matt Wette
> For example, it is quite common to put a shell script between #! and !#
> that ends by running Guile on the same file.  It is also quite common to
> put "-*- scheme -*-" on the second line to that Emacs will recognize the
> type of the file.


I hadn't thought of this.  Pretty cool.  


mwette$ cat zzz
#!/bin/sh

echo "hello from shell"

export FOO="custom"

exec guile -s $0
!#

(display "hello from guile\n")
(display "FOO: ")
(display (getenv "FOO"))
(newline)

mwette$ ./zzz
hello from shell
;;; note: source file /private/tmp/./zzz
;;;   newer than compiled 
/Users/mwette/.cache/guile/ccache/2.2-LE-8-3.9/private/tmp/zzz.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;   or pass the --no-auto-compile argument to disable.
;;; compiling /private/tmp/./zzz
;;; compiled /Users/mwette/.cache/guile/ccache/2.2-LE-8-3.9/private/tmp/zzz.go
hello from guile
FOO: custom
mwette$ 


  1   2   >