Guile documentation overhaul (was Re: What's to be considered on-topic for Guile mailing lists?)

2023-10-18 Thread Matt
 On Thu, 06 Jul 2023 13:37:09 +0300 Blake  wrote --- 

> I'm sorry, I'm the one supposed to be working on a rehaul of the 
> documentation, but the review process has slowed this down. I started 
> integrating
> everyones suggestions for the revamped map section after it was proposed in 
> January and its almost done but not complete, and but I've been so
> busy the past few months its really my last priority and given the extent of 
> the changes demanded its a lot of work.

Hi!  I just got the paperwork worked out between the FSF and my employer.  I 
have a strong interest in helping to improve the Guile documentation.  I tried 
searching the archives for information about a "rehaul" and found nothing.  Can 
someone tell me more?  Are there any threads discussing it?





Re: 2.2.0 release plan

2017-03-14 Thread Matt Wette

> On Mar 14, 2017, at 8:50 AM, Andy Wingo  wrote:
> 
> On Tue 14 Mar 2017 16:25, Greg Troxel  writes:
> 
>> Andy Wingo  writes:
>> 
>>> However!  Even though the code says 2.2.0 and the tag says 2.2.0, the
>>> release is not until Thursday.  I will not upload the tag yet.
>> 
>> I have just barely caught up with 2.0.x in pkgsrc, and haven't gotten to
>> testing 2.1.x yet.  I wonder how many platforms 2.1.x has been tested
>> on, and really I mean "has it been tested on other than GNU/Linux".
> 
> Things are in the early days, you are right.  GNU/Linux and macOS have
> been tested.  Cygwin builds and works though it has some test errors; we
> are working on it.  I don't know about mingw yet.  I think there might
> be some errors on the other BSDs but I don't know yet.

Just got my desktop to extra-boot FreeBSD.  I’m taking a shot at that target 
(amd64).





Re: 2.2.0 release plan

2017-03-14 Thread Matt Wette

> On Mar 14, 2017, at 5:35 PM, Matt Wette  wrote:
> 
>> 
>> On Mar 14, 2017, at 8:50 AM, Andy Wingo  wrote:
>> 
>> On Tue 14 Mar 2017 16:25, Greg Troxel  writes:
>> 
>>> Andy Wingo  writes:
>>> 
>>>> However!  Even though the code says 2.2.0 and the tag says 2.2.0, the
>>>> release is not until Thursday.  I will not upload the tag yet.
>>> 
>>> I have just barely caught up with 2.0.x in pkgsrc, and haven't gotten to
>>> testing 2.1.x yet.  I wonder how many platforms 2.1.x has been tested
>>> on, and really I mean "has it been tested on other than GNU/Linux".
>> 
>> Things are in the early days, you are right.  GNU/Linux and macOS have
>> been tested.  Cygwin builds and works though it has some test errors; we
>> are working on it.  I don't know about mingw yet.  I think there might
>> be some errors on the other BSDs but I don't know yet.
> 
> Just got my desktop to extra-boot FreeBSD.  I’m taking a shot at that target 
> (amd64).

Status: The (g)make is grinding away, now building ice-9/psyntax-pp.go, going 
slow ...

Notes:

To configure, besides the mentioned items (e.g., libffi), must "pkg install"
* pkgconf
* gmake
* boehm-gc-threaded

Must use “gmake”, “make” breaks on meta/Makefile

The first gmake produced "not found" link errors for
  GC_unregister_my_thread
  GC_get_suspend_signal
  GC_allow_register_threads
  GC_register_my_thread

So I reconfigured using
  BDW_GC_LIBS=-L/usr/local/lib -lgc-threaded ./configure --prefix=/usr/local


Now the HACK:
ran into issue w/ weak-set.c (?), so I
edited config.h and changed
  /* #undef HAVE_GC_MOVE_DISAPPEARING_LINK */
to
  #define HAVE_GC_MOVE_DISAPPEARING_LINK 1

I will report more later, as time permits.
Matt



Re: 2.2.0 release plan

2017-03-15 Thread Matt Wette

> On Mar 14, 2017, at 7:59 PM, Matt Wette  wrote:
> 
> 
>> On Mar 14, 2017, at 5:35 PM, Matt Wette > <mailto:matt.we...@gmail.com>> wrote:
>> 
>>> 
>>> On Mar 14, 2017, at 8:50 AM, Andy Wingo >> <mailto:wi...@pobox.com>> wrote:
>>> 
>>> On Tue 14 Mar 2017 16:25, Greg Troxel >> <mailto:g...@lexort.com>> writes:
>>> 
>>>> Andy Wingo mailto:wi...@pobox.com>> writes:
>>>> 
>>>>> However!  Even though the code says 2.2.0 and the tag says 2.2.0, the
>>>>> release is not until Thursday.  I will not upload the tag yet.
>>>> 
>>>> I have just barely caught up with 2.0.x in pkgsrc, and haven't gotten to
>>>> testing 2.1.x yet.  I wonder how many platforms 2.1.x has been tested
>>>> on, and really I mean "has it been tested on other than GNU/Linux".
>>> 
>>> Things are in the early days, you are right.  GNU/Linux and macOS have
>>> been tested.  Cygwin builds and works though it has some test errors; we
>>> are working on it.  I don't know about mingw yet.  I think there might
>>> be some errors on the other BSDs but I don't know yet.
>> 
>> Just got my desktop to extra-boot FreeBSD.  I’m taking a shot at that target 
>> (amd64).
> 
> Status: The (g)make is grinding away, now building ice-9/psyntax-pp.go, going 
> slow ...
> 
> Notes:
> 
> To configure, besides the mentioned items (e.g., libffi), must "pkg install"
> * pkgconf
> * gmake
> * boehm-gc-threaded
> 
> Must use “gmake”, “make” breaks on meta/Makefile
> 
> The first gmake produced "not found" link errors for
>   GC_unregister_my_thread
>   GC_get_suspend_signal
>   GC_allow_register_threads
>   GC_register_my_thread
> 
> So I reconfigured using
>   BDW_GC_LIBS=-L/usr/local/lib -lgc-threaded ./configure --prefix=/usr/local
> 
> 
> Now the HACK:
> ran into issue w/ weak-set.c (?), so I
> edited config.h and changed
>   /* #undef HAVE_GC_MOVE_DISAPPEARING_LINK */
> to
>   #define HAVE_GC_MOVE_DISAPPEARING_LINK 1
> 
> I will report more later, as time permits.
> Matt
> 

“gmake” and “gmake check” completed on FreeBSD 11.0

There were some warnings in the make check regarding forking w/ multiple 
threads running.  I assume this is an OS issue.

The remaining task is to get configure to work correctly with the FreeBSD 
boehm-gc-threaded package.  Not sure how long that will take.




Re: 2.2.0 release plan

2017-03-15 Thread Matt Wette

> On Mar 15, 2017, at 6:07 AM, Matt Wette  wrote:
> 
> 
>> On Mar 14, 2017, at 7:59 PM, Matt Wette > <mailto:matt.we...@gmail.com>> wrote:
>> 
>> 
>>> On Mar 14, 2017, at 5:35 PM, Matt Wette >> <mailto:matt.we...@gmail.com>> wrote:
>>> 
>>>> 
>>>> On Mar 14, 2017, at 8:50 AM, Andy Wingo >>> <mailto:wi...@pobox.com>> wrote:
>>>> 
>>>> On Tue 14 Mar 2017 16:25, Greg Troxel >>> <mailto:g...@lexort.com>> writes:
>>>> 
>>>>> Andy Wingo mailto:wi...@pobox.com>> writes:
>>>>> 
>>>>>> However!  Even though the code says 2.2.0 and the tag says 2.2.0, the
>>>>>> release is not until Thursday.  I will not upload the tag yet.
>>>>> 
>>>>> I have just barely caught up with 2.0.x in pkgsrc, and haven't gotten to
>>>>> testing 2.1.x yet.  I wonder how many platforms 2.1.x has been tested
>>>>> on, and really I mean "has it been tested on other than GNU/Linux".
>>>> 
>>>> Things are in the early days, you are right.  GNU/Linux and macOS have
>>>> been tested.  Cygwin builds and works though it has some test errors; we
>>>> are working on it.  I don't know about mingw yet.  I think there might
>>>> be some errors on the other BSDs but I don't know yet.
>>> 
>>> Just got my desktop to extra-boot FreeBSD.  I’m taking a shot at that 
>>> target (amd64).
>> 
>> Status: The (g)make is grinding away, now building ice-9/psyntax-pp.go, 
>> going slow ...
>> 
>> Notes:
>> 
>> To configure, besides the mentioned items (e.g., libffi), must "pkg install"
>> * pkgconf
>> * gmake
>> * boehm-gc-threaded
>> 
>> Must use “gmake”, “make” breaks on meta/Makefile
>> 
>> The first gmake produced "not found" link errors for
>>   GC_unregister_my_thread
>>   GC_get_suspend_signal
>>   GC_allow_register_threads
>>   GC_register_my_thread
>> 
>> So I reconfigured using
>>   BDW_GC_LIBS=-L/usr/local/lib -lgc-threaded ./configure --prefix=/usr/local
>> 
>> 
>> Now the HACK:
>> ran into issue w/ weak-set.c (?), so I
>> edited config.h and changed
>>   /* #undef HAVE_GC_MOVE_DISAPPEARING_LINK */
>> to
>>   #define HAVE_GC_MOVE_DISAPPEARING_LINK 1
>> 
>> I will report more later, as time permits.
>> Matt
>> 
> 
> “gmake” and “gmake check” completed on FreeBSD 11.0
> 
> There were some warnings in the make check regarding forking w/ multiple 
> threads running.  I assume this is an OS issue.
> 
> The remaining task is to get configure to work correctly with the FreeBSD 
> boehm-gc-threaded package.  Not sure how long that will take.

So I think this is a clue for FreeBSD config w/ boehm-gc-threaded, but final 
fix.  My total fix below does not work.  Maybe someone knows autoconf better.

Near line 1323 in configure.ac is the line
PKG_CHECK_MODULES([BDW_GC], [bdw-gc >= 7.2])

I changed it on my FreeBSD system to
PKG_CHECK_MODULES([BDW_GC], [bdw-gc-threaded >= 7.2])
which WORKS!

But if I try this general solution:
PKG_CHECK_MODULES([BDW_GC], [bdw-gc-threaded >= 7.2],[],
  [PKG_CHECK_MODULES([BDW_GC],, [bdw-gc >= 7.2])])
NOT WORKING

Andy, can you get it working?  (If bdw-gc-threaded not available try bdw-gc.). 
I assume something like this should work for the other platforms also.

Matt



Re: GNU Guile 2.2.0 released

2017-03-17 Thread Matt Wette
FYI, 2.2.0 has already been placed into MacPorts distribution (though still 
some minor hiccups wrt macport checksums.)

root# port upgrade outdated
...
--->  Computing dependencies for guile
--->  Fetching distfiles for guile
--->  Attempting to fetch guile-2.2.0.tar.gz from 
https://distfiles.macports.org/guile





Re: GNU Guile 2.2.0 released

2017-03-17 Thread Matt Wette

> On Mar 17, 2017, at 7:19 AM, Matt Wette  wrote:
> 
> FYI, 2.2.0 has already been placed into MacPorts distribution (though still 
> some minor hiccups wrt macport checksums.)
> 
> root# port upgrade outdated
> ...
> --->  Computing dependencies for guile
> --->  Fetching distfiles for guile
> --->  Attempting to fetch guile-2.2.0.tar.gz from 
> https://distfiles.macports.org/guile
> 

My mistake.  Not updated.  It was a customization that I had forgotten about. — 
Matt




Re: GNU Guile 2.2.2 released

2017-05-13 Thread Matt Wette

> On Apr 21, 2017, at 7:41 AM, Andy Wingo  wrote:
> 
> We sheepishly announce GNU Guile release 2.2.2, a quick bug-fix to the
> recent 2.2.1 release.

The FreeBSD section in README is not quite correct IMO.   Here are suggested 
changes:
 
 FreeBSD 11.0:
-  For a build supporting threads, please `pkg install' the following
+  Please `pkg install' the following:
 - pkgconf : provides pkg-config
+- texinfo : provides makeinfo
 - gmake : /usr/bin/make does not work
-- boehm-gc-threaded : needed for threaded support
 
-  Configure as:
+  If you want a Guile with threads, then install boehm-gc-threaded and
+  configure as:
 
 ./configure --with-bdw-gc=bdw-gc-threaded
 




Re: ffi helper

2017-05-13 Thread Matt Wette

> On Apr 17, 2017, at 7:26 PM, Matt Wette  wrote:
> 
> 
>> On Mar 21, 2017, at 3:40 PM, Matt Wette  wrote:
>>> On Mar 19, 2017, at 10:23 AM, Matt Wette  wrote:
>>>> On Mar 13, 2017, at 5:53 PM, Matt Wette  wrote:
>>>>> On Mar 8, 2017, at 6:06 PM, Matt Wette  wrote:
>>>>> I’m now working on a FFI helper based on the nyacc C99 parser.   

Still grinding away.  I can generate wrappers for function pointers passed to C 
routines: see cairo_destroy_func_t below.  I don’t know if the converter should 
be called “wrap” or something else as, wrt the pointer wrappers, we are adding 
a “C” wrapper instead of a “scheme” wrapper.

I am deciding how to handle enums.  I will likely have wrapper to map symbols 
to integers and vice versa, but I will have to handle anonymous enums as well 
(e.g." enum { ABC = 1 };”). 

Matt

(use-modules (ffi-help))

(define-ffi-helper (cairo cairo)
  #:pkg-config "cairo"
  #:include "cairo-svg.h"
  #:library "libcairo"
  #:filter (lambda (path) (string=? "cairo" (substring path 0 5)))
  )

==[GENERATES]==>[filter samples]==>

;;
;; auto-generated by ffi-help.scm
;;

(define-module (cairo cairo)
  #:use-module (ffi-help)
  #:use-module ((system foreign) #:prefix ffi:)
  #:use-module ((bytestructures guile) #:prefix bs:)
  )
(define bs:struct bs:bs:struct)

(define lib-link (dynamic-link "libcairo"))
(define (lib-func name) (dynamic-func name lib-link))

;; typedef struct _cairo_surface cairo_surface_t;
(define-std-pointer-wrapper cairo_surface_t*)

;; cairo_matrix_t
(define cairo_matrix_t
  (bs:struct
(list `(xx ,bs:double)
  `(yx ,bs:double)
  `(xy ,bs:double)
  `(yy ,bs:double)
  `(x0 ,bs:double)
  `(y0 ,bs:double
(export cairo_matrix_t)


;; typedef void  (*cairo_destroy_func_t)(void  *data);
(define (wrap-cairo_destroy_func_t proc) ;; => pointer
 (ffi:procedure->pointer ffi:void proc (list '*))
 )
(export wrap-cairo_destroy_func_t)

;; cairo_t *cairo_create(cairo_surface_t *target);
(define cairo_create
  (let ((f (ffi:pointer->procedure
 '*
 (lib-func "cairo_create")
 (list '*
(lambda (target)
  (let ((~target ((unwrap-cairo_surface_t* target
(identity (f ~target))
(export cairo_create)

;; typedef struct _cairo_region cairo_region_t;
(define-std-pointer-wrapper cairo_region_t*)

;; cairo_bool_t cairo_region_contains_point(const cairo_region_t *region, int 
;; x, int y);
(define cairo_region_contains_point
  (let ((f (ffi:pointer->procedure
 ffi:int
 (lib-func "cairo_region_contains_point")
 (list '* ffi:int ffi:int
(lambda (region x y)
  (let ((~region ((unwrap-cairo_region_t* region
(f ~region x y)
(export cairo_region_contains_point)

;; --- last line ---




make install-examples ???

2017-05-17 Thread Matt Wette
Is there a plan to support copying examples (e.g., “make install-examples”) 
from the build directory tree into the destination directory tree?  

I am working on a project that has a number of examples that are referenced 
from the info files.

If so, it would be nice for %guile-build-info to include the target directory.

Matt




Tree-IL on let

2017-05-30 Thread Matt Wette
In Tree-IL there is let, letrec and letrec* but not let*.   Any reason why?  I 
guess I should use (let () (let () …, right? — Matt




ffi helper: enums

2017-06-17 Thread Matt Wette
The following seems to be a Guile architecture wrt how FFI-based interfaces 
should be implemented.

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.  I am looking for concurrence on the following:

Enums and #defines:
Here is how I plan to handle enums and #defines
1) visibility to values is provided through an access function
   e.g., (get-foo-val ‘ABC)
   not ABC via (define ABC 1)
2) only #defined symbols that evaluate to constants (e.g., 123, “ABC”, etc) 
will be visible
3) all enum-defined symbols will be visible
4) for enum typedefs and enum def's I will provide (but not export) wrappers so 
that functions that 
   take an enum type as argument will require the symbolic form   
   e.g., if signature is 
   typedef enum { ABC = 1 } foo_enum_t;
   typedef enum { OK = 0, ERROR = 1 } foo_status_t;
   foo_status_t bar(foo_enum_t flag)
   then the guile un-wrapper/wrapper will convert symbols<=>ints to allow users 
code to look like
   (bar ‘ABC) => ‘OK
   Optionally, the un-wrappers could be coded tolerate integers.

OK?

Matt

P.S. auto-generated and hand-clean-up (i.e., not fully working yet)

;; access to #define constants:
(define cairo-svg-def-val
  (let ((deftab
  '((CAIRO_VERSION_MAJOR . 1)
(CAIRO_VERSION_MINOR . 14)
...
(CAIRO_SVG_VERSION_1_1 . 1)
(CAIRO_SVG_VERSION_1_2 . 2
(lambda (k) (assq-ref deftab k
(export cairo-svg-def-val)

;; typedef struct _cairo_font_options cairo_font_options_t;
(define-std-pointer-wrapper cairo_font_options_t*)

;; typedef enum _cairo_status cairo_status_t;
(define wrap-cairo_status_t
  (let ((vnl '((0 . CAIRO_STATUS_SUCCESS)
   (1 . CAIRO_STATUS_NO_MEMORY)
   ...
   (38 . CAIRO_STATUS_JBIG2_GLOBAL_MISSING)
   (39 . CAIRO_STATUS_LAST_STATUS
(lambda (code) (assq-ref vnl code
(define unwrap-cairo_status_t
  (let ((nvl '((CAIRO_STATUS_SUCCESS . 0)
   (CAIRO_STATUS_NO_MEMORY . 1)
   ...
   (CAIRO_STATUS_JBIG2_GLOBAL_MISSING . 38)
   (CAIRO_STATUS_LAST_STATUS . 39
(lambda (name) (assq-ref nvl name
(define wrap-enum-_cairo_status
  (let ((vnl '((0 . CAIRO_STATUS_SUCCESS)
   (1 . CAIRO_STATUS_NO_MEMORY)
   (2 . CAIRO_STATUS_INVALID_RESTORE)
   ...
   (38 . CAIRO_STATUS_JBIG2_GLOBAL_MISSING)
   (39 . CAIRO_STATUS_LAST_STATUS
(lambda (code) (assq-ref vnl code
(define unwrap-enum-_cairo_status
  (let ((nvl '((CAIRO_STATUS_SUCCESS . 0)
   (CAIRO_STATUS_NO_MEMORY . 1)
   ...
   (CAIRO_STATUS_JBIG2_GLOBAL_MISSING . 38)
   (CAIRO_STATUS_LAST_STATUS . 39
(lambda (name) (assq-ref nvl name

;; cairo_status_t cairo_font_options_status(cairo_font_options_t *options);
(define cairo_font_options_status
  (let ((f (ffi:pointer->procedure
 ffi:int
 (lib-func "cairo_font_options_status")
 (list '*
(lambda (options)
  (let ((~options (unwrap-cairo_font_options_t* options)))
(wrap-cairo_status_t (f ~options))
(export cairo_font_options_status)





ffi-helper: modules and guild

2017-06-17 Thread Matt Wette
More on my ffi-helper project.  This time about modules and guild 

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.  I am looking for concurrence on the following:

The paradigm for using the helper is (1) write ffi-module; (2) compile to 
Scheme using guild.

1) I can support module-like syntax like the following:

 mwette$ cat cairo/cairo-svg.ffi
 ;; cairo-svg.ffi   -*- Scheme -*-

 (define-ffi-module (cairo cairo-svg)
   #:include "cairo.h"
   #:include "cairo-svg.h"
   #:inc-filter (lambda (path) (string=? "cairo" (substring path 0 5)))
   #:pkg-config "cairo"
   #:library "libcairo" ;; not needed when pkg-config fully working
   ;; the following are bent pipe to scm-module
   #:use-module ((srfi srfi-1) #:select (remove))
   #:export (my-cairo-ftn)
   )

 (define my-cairo-hack ()
   (first '(("hello"
 
 ;; end of file

2) I can run “guild compile-fyi cairo/cairo-svg.ffi” and get the following

 ;; auto-generated by ffi-help.scm

 (define-module (cairo cairo-svg)
   #:use-module ((srfi srfi-1) #:select (remove))
   #:export (my-cairo-ftn)
   #:use-module (ffi-help)
   #:use-module ((system foreign) #:prefix ffi:)
   #:use-module ((bytestructures guile) #:prefix bs:)
   )
 (define bs:struct bs:bs:struct)
 (define bs:union bs:bs:union)

 (define lib-link (dynamic-link #f))
 (define (lib-func name) (dynamic-func name lib-link))

 ;; here will be ~1000 lines of autogenerated code

 (define my-cairo-hack () (first '(("hello"

 ;; --- last line —

Matt





Re: #if __GNUC__ > 2 ..

2017-06-18 Thread Matt Wette
With patch below, this looks to be working.  I will update and release later 
today. — Matt

diff --git a/module/nyacc/lang/c99/cpp.scm b/module/nyacc/lang/c99/cpp.scm
index 7ea57f7..511553a 100644
--- a/module/nyacc/lang/c99/cpp.scm
+++ b/module/nyacc/lang/c99/cpp.scm
@@ -230,7 +230,7 @@
((or) (if (and (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
((and) (if (or (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
((cond-expr) (if (zero? (ev1 tree)) (ev3 tree) (ev2 tree)))
-   ((ident) (cpp-err "undefined identifier: ~S" (cadr tree)))
+   ((ident) 0)
(else (error "incomplete implementation"))
 (eval-expr tree)))
 
@@ -464,6 +464,7 @@
 
 ;; @deffn {Procedure} eval-cpp-cond-text text defs => string
 ;; Evaluate CPP condition expression (text).
+;; Undefined identifiers are replaced with @code{0}.
 ;; @end deffn
 (define (eval-cpp-cond-text text defs)
   (with-throw-handler




[ANN] nyacc 0.80.3 released

2017-06-18 Thread Matt Wette
NYACC V0.80.3 is released.

This release has work on the ffi-helper and numerous bug fixes:
1) use 0 for undefined identifiers in CPP conditional expressions
2) fixed lex routine make-ident-like-p to check for zero-length strings
3) fixed bug in c99/util2.smc that added comments in struct cleanup
4) changed c99/util2.scm:c99-trans-unit->udict to use fold-right


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




ffi-help: handling types

2017-06-27 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.  A little status on type handling:

For nominal C types I am trying to stick to the (system foreign) type system.  
For aggregate types I am using scheme-bytestructures 
(https://github.com/TaylanUB/scheme-bytestructures).  However, I am currently 
putting a guile struct wrapper on top of bytestructure descriptors in order to 
provide a more user-friendly interface (IMO).  

In the demo I have created a (cairo cairo-svg) ffi-module which gets converted 
to a guile module via
$ guild compile-ffi cairo/cairo-svg.ffi

Then I start guile and do this:

scheme@(guile-user)> (use-modules (cairo cairo-svg))
scheme@(guile-user)> (use-modules (ffi-help))
scheme@(guile-user)> (use-modules (system foreign))

scheme@(guile-user)> (define srf (cairo_svg_surface_create (string->pointer 
"abc.svg") 200.0 200.0))
scheme@(guile-user)> srf
$2 = 

@(guile-user)> (define cr (cairo_create srf))
scheme@(guile-user)> cr
$1 = 

scheme@(guile-user)> (define mx (make-cairo_matrix_t))
scheme@(guile-user)> mx
$3 = #

scheme@(guile-user)> (pointer-to mx)   
$4 = 

scheme@(guile-user)> (cairo_get_font_matrix cr (pointer-to mx))
scheme@(guile-user)> 

Matt




ffi-help: documentation

2017-07-03 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.

I wanted to let you know that I have posted my start on documentation 
accessible from the following URL:

https://www.nongnu.org/nyacc/


Matt




download link from guile project page is busted

2017-07-07 Thread Matt Wette
Hey folks,

The link for “2.2 stable series” from the www.gnu.org/software/guile/download/ 
<http://www.gnu.org/software/guile/download/> , namely 
http://hydra.nixos.org/job/gnu/guile-2-2/tarball/latest 
<http://hydra.nixos.org/job/gnu/guile-2-2/tarball/latest> ,
Is BUSTED, yielding: “404 not found"

I was thinking this is the best place to report.

Matt



ffi-helper: status

2017-07-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.  My goal is to 
have something to release ~Oct 2017.

I have now been able to compile-ffi the following on my Mac. There is some 
non-standard C syntax in sys/cdefs.h
that is driving me crazy, but I have a hack around it (see inc-help below).  
I’m sure there are numerous bugs.

(define-ffi-module (cairo cairo)
  #:pkg-config "cairo"
  #:include '("cairo.h"
  "cairo-pdf.h"
  "cairo-svg.h"
  )
  #:inc-help (cond
  ((string-contains %host-type "darwin")
   '(("__builtin" "__builtin_va_list=void*")
 ("sys/cdefs.h" "__DARWIN_ALIAS(X)=")))
  (else '()))

  ;; the following are bent pipe to scm-module
  #:export (make-cairo-unit-matrix)
  )

(define (make-cairo-unit-matrix)
  (make-cairo_matrix_t #(1.0 0.0 0.0 1.0 0.0 0.0)))


Some of the other Cairo headers (e.g., cairo-ft.h) give me problems with the 
rat’s nest under /usr/include.

However, the above generates 397 FFI declarations into a cairo.scm file which 
is about 6000 lines long.  I’m not 
sure if I want to start testing this code or start converting suggestions and 
have guile-users do some testing.  

Matt

P.S.  Here is some sample code from the auto-generated file cairo/cairo.scm.  
Notice that the helper includes the original C declarations as comments.

;; typedef struct _cairo_device cairo_device_t;
(define-fh-pointer-type cairo_device_t*)

;; union _cairo_path_data_t {
;;   struct {
;; cairo_path_data_type_t type;
;; int length;
;;   } header;
;;   struct {
;; double x, y;
;;   } point;
;; };
(define cairo_path_data_t-desc
  (bs:union
(list `(header
 ,(bs:struct
(list `(type ,cairo_path_data_type_t-desc)
  `(length ,int
  `(point ,(bs:struct (list `(y ,double) `(x ,double)))
(export cairo_path_data_t-desc)
(define-fh-bytestructure-type/p cairo_path_data_t cairo_path_data_t-desc)
(define union-_cairo_path_data_t cairo_path_data_t)

;; typedef enum _cairo_path_data_type {
;;   CAIRO_PATH_MOVE_TO,
;;   CAIRO_PATH_LINE_TO,
;;   CAIRO_PATH_CURVE_TO,
;;   CAIRO_PATH_CLOSE_PATH,
;; } cairo_path_data_type_t;
(define-fh-enum-type cairo_path_data_type_t
  '((CAIRO_PATH_MOVE_TO . 0)
(CAIRO_PATH_LINE_TO . 1)
(CAIRO_PATH_CURVE_TO . 2)
(CAIRO_PATH_CLOSE_PATH . 3))
  )

;; typedef void (*cairo_destroy_func_t)(void *data);
(define (wrap-cairo_destroy_func_t proc) ;; => pointer
 (ffi:procedure->pointer ffi:void proc (list '*))
 )
(export wrap-cairo_destroy_func_t)

;; cairo_status_t cairo_device_set_user_data(cairo_device_t *device, const 
;; cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t 
;; destroy);
(define cairo_device_set_user_data
  (let ((~f (ffi:pointer->procedure
  ffi:int
  (lib-func "cairo_device_set_user_data")
  (list '* '* '* '*
(lambda (device key user_data destroy)
  (let ((~device (unwrap-cairo_device_t* device))
(~key (unwrap-cairo_user_data_key_t* key))
(~user_data (unwrap~pointer user_data))
(~destroy (unwrap-cairo_destroy_func_t destroy)))
(wrap-cairo_status_t
  (~f ~device ~key ~user_data ~destroy))
(export cairo_device_set_user_data)





Re: ffi-helper: status

2017-07-07 Thread Matt Wette

> On Jul 7, 2017, at 5:18 PM, Matt Wette  wrote:
> However, the above generates 397 FFI declarations into a cairo.scm file which 
> is about 6000 lines long.  I’m not 
> sure if I want to start testing this code or start converting suggestions and 
> have guile-users do some testing.  

That is, for this example, I no longer run into declarations which my code says 
“failed,” indicating that it didn’t know what to do with the declaration.

I already notice that the function types converters should be called “unwrap” 
and that they should be called by the procedure interface.  I am going to start 
playing with cairo_set_user_data to see if passed procedures work. 


Re: ffi-helper: status

2017-07-10 Thread Matt Wette

> On Jul 7, 2017, at 5:31 PM, Matt Wette  wrote:
> 
> 
>> On Jul 7, 2017, at 5:18 PM, Matt Wette  wrote:
>> However, the above generates 397 FFI declarations into a cairo.scm file 
>> which is about 6000 lines long.  I’m not 
>> sure if I want to start testing this code or start converting suggestions 
>> and have guile-users do some testing.  
> 
> That is, for this example, I no longer run into declarations which my code 
> says “failed,” indicating that it didn’t know what to do with the declaration.
> 
> I already notice that the function types converters should be called “unwrap” 
> and that they should be called by the procedure interface.  I am going to 
> start playing with cairo_set_user_data to see if passed procedures work. 

Another working demo:

mwette$ guile exam.d/cairo02.scm
d1 called with ((abc . 123) (def . 456))

mwette$ cat exam.d/cairo02.scm
;; exam.d/cairo02.scm

(use-modules (cairo cairo)) ; auto-generated from cairo.h etc
(use-modules (ffi-help-rt)) ; pointer-to
(use-modules (system foreign))  ; string->pointer, pointer<->scm

(define srf (cairo_svg_surface_create (string->pointer "abc.svg") 200.0 200.0))
(define cr (cairo_create srf))

;; typedef struct _cairo_user_data_key {
;;   int unused;
;; } cairo_user_data_key_t;
;;
;; typedef void (*cairo_destroy_func_t)(void *data);
;;
;; cairo_status_t cairo_set_user_data(cairo_t *cr, const cairo_user_data_key_t
;;  *key, void *user_data, cairo_destroy_func_t destroy);

(define k1 (make-cairo_user_data_key_t)) ; make a key
(define v1 '((abc . 123) (def . 456)))   ; make some data
(define (d1 data); callback
  (simple-format #t "d1 called with ~S\n" (pointer->scm data)))
 
(cairo_set_user_data cr (pointer-to k1) (scm->pointer v1) d1)

(cairo_destroy cr)
(cairo_surface_destroy srf)

;; --- last line ---



Re: New object system?

2017-08-01 Thread Matt Wette

> On Jul 28, 2017, at 11:34 AM, Stefan Israelsson Tampe 
>  wrote:
> 
> Hi all. We have goops, but I wondered how a functional object system can look 
> like and after some thought I modeled together functional and python together 
> with scheme. you can find the result at
> 
> http://www.c-lambda.se/functional-python.html 
> <http://www.c-lambda.se/functional-python.html>
> 
> If you want to discuss, continue with the email or on the site. I would like 
> to have a functional object system for guile per default.
> 
> I have a parser for python3 and will try to compile python to the guile VM. 
> This study is an approach to add features to python that are not in. In the 
> end I will add mutating objects as well so that one can mix them.
> 
> I also plan to make a system where the property of mutability can flow in the 
> execution path and so that dynamically if specifically requested nothing will 
> mutate and only new data structure will be created someting like
> 
> (define newobj (do-not-mutate thunk))
> 
> But that's for the future.
> 
> Have fun!

So no generics?  Looks cool.

Matt



ffi varargs support

2017-08-13 Thread Matt Wette
libffi will have support for varargs in the future.  How could the syntax in 
Guile be handled?

How about ellipsis symbol in pointer->procedure and a pair for each va-arg: 
type in car and value in car?

> (define p (dynamic-func “printf” (dynamic-link)))
> (define f (pointer->procedure int p (list ‘* ‘…)))
> (f (string->pointer “n = %d\n”) `(int . 30))
n = 10




ffi-help: status to 19 Aug 2017

2017-08-19 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 in
Oct 2017 but that date is likely to slip.

Current shortcomings:
1) Guile does not currently handle some types (e..g, long long, uintptr_t).
2) Guile does not have support for varargs (e.g., printf(char *, ...) ).
   I may take a look at this.  One idea I have is to use '... in the call 
interface spec
   and use (type . value) pairs in the calls.
3) The bytestructures module does not support function declarations.
4) ... (probably more)

Someone asked to have libgit2 converted and this, and some others, turned out 
to give visibility
to several limitations and bugs in my C parser.  For one, how #include 
 is interpreted 
is not specified by the language: it is implementation defined, and I had to 
track down how libgit2 
was including files.  I also had to add some GNUC extensions (e.g., asm, 
statement-block expressions,
include_next) to the parser and preprocessor.  As one can see from the file 
listing below, libgit2 
has a large number of files, and declarations.

mwette$ ls include/git2
annotated_commit.h  indexer.h   repository.h
attr.h  inttypes.h  reset.h
blame.h merge.h revert.h
blob.h  message.h   revparse.h
branch.hnet.h   revwalk.h
buffer.hnotes.h signature.h
checkout.h  object.hstash.h
cherrypick.hodb.h   status.h
clone.h odb_backend.h   stdint.h
commit.hoid.h   strarray.h
common.hoidarray.h  submodule.h
config.hpack.h  sys/
cred_helpers.h  patch.h tag.h
describe.h  pathspec.h  trace.h
diff.h  proxy.h transaction.h
errors.hrebase.htransport.h
filter.hrefdb.h tree.h
global.hreflog.htypes.h
graph.h refs.h  version.h
ignore.hrefspec.h   worktree.h
index.h remote.h

mwette$ cat libgit2.ffi
(define-ffi-module (libgit2)
  #:include '("git2.h")
  #:inc-filter (lambda (file-spec path-spec)
 (string-contains path-spec "git2/" 0))
  #:library '("libgit2"))

The following command takes 10.5 seconds on my new macbook pro 
and produces a libgit2.scm file that is 14,546 lines long.

mwette$ guild compile-ffi libgit2.ffi

The following command takes 66 seconds on my mac (Guile 2.0.13).

mwette$ guile -c '(use-modules (libgit2))' 

(However, I'm still getting some unresolved references: that's work to go.)
(The compile takes significantly longer using Guile 2.2.)


Here are some excerpts from (100% autogenerated) libgit2.scm:

;; typedef struct git_repository git_repository;
(define-fh-pointer-type git_repository*)

;; typedef struct git_remote git_remote;
(define-fh-pointer-type git_remote*)

;; extern git_repository *git_remote_owner(const git_remote *remote);
(define git_remote_owner
  (let ((~f (ffi:pointer->procedure
  '*
  (dynamic-func "git_remote_owner" (dynamic-link))
  (list '*
(lambda (remote)
  (let ((~remote (unwrap-git_remote* remote)))
(wrap-git_repository* (~f ~remote))
(export git_remote_owner)

;; typedef enum {
;;   GIT_REF_INVALID = 0,
;;   GIT_REF_OID = 1,
;;   GIT_REF_SYMBOLIC = 2,
;;   GIT_REF_LISTALL = GIT_REF_OID | GIT_REF_SYMBOLIC,
;; } git_ref_t;
(define-fh-enum git_ref_t
  '((GIT_REF_INVALID . 0)
(GIT_REF_OID . 1)
(GIT_REF_SYMBOLIC . 2)
(GIT_REF_LISTALL . 3))
  )

;; typedef struct git_remote_callbacks git_remote_callbacks;
;; struct git_remote_callbacks {
;;   unsigned int version;
;;   /**
;;   * Textual progress from the remote. Text send over the
;;   * progress side-band will be passed to this function (this is
;;   * the 'counting objects' output).
;;   */
;;   git_transport_message_cb sideband_progress;
;;   /**
;;   * Completion is called when different parts of the download
;;   * process are done (currently unused).
;;   */
;;   int (*completion)(git_remote_completion_type type, void *data);
;;   /**
;;   * This will be called if the remote host requires
;;   * authentication in order to connect to it.
;;   *
;;   * Returning GIT_PASSTHROUGH will make libgit2 behave as
;;   * though this field isn't set.
;;   */
;;   git_cred_acquire_cb credentials;
;;   /**
;;   * If cert verification fails, this will be called to let the
;;   * user make the final decision of whether to allow the
;;   * connection to proc

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$ 


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: 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  wrote:
> 
> 
>> 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.
> 

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.





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: ffi-help: #:use-ffi-module

2017-09-07 Thread Matt Wette

> On Sep 7, 2017, at 8:32 PM, Matt Wette  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





[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: [ANN] nyacc 0.82.0 released

2017-09-10 Thread Matt Wette

> On Sep 10, 2017, at 8:37 AM, Matt Wette  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




Re: [ANN] nyacc 0.82.0 released

2017-09-11 Thread Matt Wette

> On Sep 10, 2017, at 8:37 AM, Matt Wette  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: 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.





[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: 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.





Re: Wisp as shipped language in Guile?

2017-09-17 Thread Matt Wette

> On Sep 17, 2017, at 4:22 PM, Arne Babenhauserheide  wrote:
> 
> 
> Matt Wette  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: 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 (reduce 9, reduce 6) on '

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 insta

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.




Re: ffi-help: status to date

2017-10-24 Thread Matt Wette

> On Oct 22, 2017, at 11:31 AM, Matt Wette  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: ffi-help: status to 19 Aug 2017

2017-11-09 Thread Matt Wette

> On Nov 9, 2017, at 11:10 AM, Roel Janssen  wrote:
> 
> 
> Matt Wette writes:
> 
>> 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 in
>> Oct 2017 but that date is likely to slip.
>> 
>> Current shortcomings:
>> 1) Guile does not currently handle some types (e..g, long long, uintptr_t).
>> 2) Guile does not have support for varargs (e.g., printf(char *, ...) ).
>>   I may take a look at this.  One idea I have is to use '... in the call 
>> interface spec
>>   and use (type . value) pairs in the calls.
>> 3) The bytestructures module does not support function declarations.
>> 4) ... (probably more)
>> 
>> Someone asked to have libgit2 converted and this, and some others, turned 
>> out to give visibility
>> to several limitations and bugs in my C parser.  For one, how #include 
>>  is interpreted 
>> is not specified by the language: it is implementation defined, and I had to 
>> track down how libgit2 
>> was including files.  I also had to add some GNUC extensions (e.g., asm, 
>> statement-block expressions,
>> include_next) to the parser and preprocessor.  As one can see from the file 
>> listing below, libgit2 
>> has a large number of files, and declarations.
>> 
>> ...
> 
> 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.


mwette$ git clone -b c99dev git://git.savannah.nongnu.org/nyacc.git nyacc
Cloning into 'nyacc'...
remote: Counting objects: 5927, done.
mwette$ cd nyacc
mwette$ cd examples
mwette$ source env.sh
mwette$ cd ffi
mwette$ cp TMPL.ffi htslib.ffi
mwette$ vi htslib.ffi
mwette$ cat htslib.ffi
;; htslib.ffi   -*- Scheme -*-

(define-ffi-module (ffi htslib)
  #:pkg-config "htslib"
  #:include '("htslib/hts.h")
  #:inc-filter (lambda (file-spec path-spec)
 (string-contains path-spec "htslib/" 0))
  )

;; --- last line ---
mwette$ guild compile ffi/htslib.fif
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;   or pass the --no-auto-compile argument to disable.
;;; compiling /var/tmp/yy/nyacc/examples/scripts/compile-ffi.scm
...
;;; compiled .../c99/ffi-help.scm.go
TODO: fix gen-lookup-proc: it's including imported symbols
;;; scripts/compile-ffi.scm:119:8: warning: possibly unbound variable `compile'
;;; compiled 
/Users/mwette/.cache/guile/ccache/2.2-LE-8-3.A/private/var/tmp/yy/nyacc/examples/scripts/compile-ffi.scm.go
ffi-help: WARNING: the FFI helper is experimental
/opt/local/include/htslib/hts.h:774: parse failed at state 313, on input "U"
(unknown):1: C99 parse error
*** compile-ffi: parse failed

The offending line is the following, which seems to indicate my lexer is not 
reading "LLU" constants. I will check.

v = ((v & 0xLLU) << 32) | (v >> 32);

Had the above worked, then you should be able to `(use-modules (ffi htslib))':

mwette$ 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 (ffi htslib))
ERROR: no code for module (ffi htslib)




Re: ffi-help: status to 19 Aug 2017

2017-11-09 Thread Matt Wette

> On Nov 9, 2017, at 5:00 PM, Matt Wette  wrote:
> 
>> On Nov 9, 2017, at 11:10 AM, Roel Janssen  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 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-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: [ANN] nyacc 0.82.1 released

2017-11-11 Thread Matt Wette

> On Nov 11, 2017, at 6:27 AM, Jan Nieuwenhuizen  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__





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: 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 
>  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 () 
'()))







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: GNU Guile 2.2.3 released.

2017-12-02 Thread Matt Wette

> On Dec 2, 2017, at 11:50 AM, Matt Wette  wrote:
> 
> 
>> 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

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.

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





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_REGIO

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))




Re: Website translations with Haunt

2017-12-10 Thread Matt Wette

> On Dec 10, 2017, at 11:21 AM, pelzflorian (Florian Pelz) 
>  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 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-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




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
 

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"mailto:eternalch...@shlug.org>>;
*Date: * Mon, Jan 22, 2018 12:58 PM
*To: * "Nala Ginrut"mailto:nalagin...@gmail.com>>;
*Cc: * "陶青云"mailto:qingyun@tophant.com>>;
"guile-devel"mailto:guile-devel@gnu.org>>;
*Subject: * Re: Question: link to wrong library

or try this
LDFLAGS=-Wl,-rpath


On Mon, Jan 22, 2018, 09:08 Nala Ginrut mailto:nalagin...@gmail.com>> wrote:

I think you may need LD_LIBRARY_PATH

2018年1月21日 23:46,"陶青云" mailto:qingyun@tophant.com>>写道:

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.





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





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: 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.




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.



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: 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



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




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.




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




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.



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




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




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?





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




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

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




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: 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





[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: [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)
+




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)







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




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
 





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.




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: 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: 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




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: 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.




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



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




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




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.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: 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: 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.






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"?





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




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")))

 







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




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




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




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




  1   2   >