Skip to content

Commit

Permalink
Merge branch 'master' of github.com:shirok/Gauche
Browse files Browse the repository at this point in the history
  • Loading branch information
shirok committed Oct 26, 2024
2 parents 565ff46 + 851ed10 commit 81aa3c6
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, macos-12]
os: [macos-latest, macos-13]
runs-on: ${{ matrix.os }}
timeout-minutes: 90
env:
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
literal closures given to getter-with-setter
https://github.com/shirok/Gauche/issues/1076

2024-10-19 Shiro Kawai <[email protected]>

* lib/srfi/234.scm (connected-components): Fix a bug in the
reference impl.

2024-10-10 Shiro Kawai <[email protected]>

* lib/gauche/version-alist.scm (gauche): Allow excluding certain
Expand Down
2 changes: 1 addition & 1 deletion doc/HOWTO-gc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ keep `gc/configure.ac` compatible with older autotools.

You can update `gc/configure.ac` with `autoreconf`, but there's a caveat.
It doesn't handle nested `AC_TRY_COMPLE`/`AC_TRY_LINK`, and produces
soem artifacts. You need to manually edit it and repeat `autoreconf` until
some artifacts. You need to manually edit it and repeat `autoreconf` until
all the nested old macros are processed.
11 changes: 6 additions & 5 deletions doc/coresyn.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1515,16 +1515,17 @@ Takes two procedure @var{get} and @var{set}. Returns a new
procedure which does the same thing as @var{get}, and its setter is
locked to @var{set}.

The intention of this procedure is, according to the SRFI-17 document,
to allow implementations to inline setters efficiently. Gauche
hasn't implement such optimization yet.
When an inlinable procedure has a locked setter, generalized @code{set!}
may be inlined by the compiler. @xref{Definitions}, for inlinable
procedure definition.
@c JP
2つの手続き、@var{get}と@var{set}を取り、新しい手続きを返します。
新しい手続きは@var{get}と同じ動作をし、そのsetter手続きは@var{set}にロックされて
います。

この手続きは、SRFI-17によれば、setter手続きのインライン展開を可能にするための
ものですが、Gaucheではまだそのような最適化は実装されていません。
インライン化可能な手続きにsetterがロックされている場合、一般化された@code{set!}は
コンパイラによってインライン展開される場合があります。
インライン化可能な手続きの定義については@ref{Definitions}を参照してください。
@c COMMON
@end defun

Expand Down
33 changes: 33 additions & 0 deletions doc/modsrfi.texi
Original file line number Diff line number Diff line change
Expand Up @@ -16314,21 +16314,54 @@ of at least one cycle.
@defun edgelist->graph edgelist :optional retriever
[SRFI-234]
@c MOD srfi.234
Converts a list of edges @var{edgelist} to a graph acceptable by
@code{topolocial-sort}. Each edge is a list of two nodes, representing
a directed edge @code{(@var{from-node} @var{to-node})}.
The returned graph is a list of
@code{(@var{from-node} @var{downstream-node} @var{downstream-node2} @dots{})}.

The optional argument @var{retriever} is called
as @code{(@var{retriever} @var{from-node} @var{graph})} to get a
graph entry starting with @var{from-node}. When omitted, @code{assoc}
is used. If you need to compare nodes in a special way different from
@code{equal?}, you can give a customized procedure.

@example
(edgelist->graph '((a b) (a c) (b e) (c b)))
@result{} ((a b c) (b e) (c b))
@end example
@end defun

@defun edgelist/inverted->graph edgelist :optional retriever
[SRFI-234]
@c MOD srfi.234
Like @code{edgelist->graph}, but take each edge entry
as @code{(@var{to-node} @var{from-node})}.

@example
(edgelist/inverted->graph '((a b) (a c) (b e) (a e)))
@result{} ((b a) (c a) (e b a))
@end example
@end defun

@defun graph->edgelist graph
[SRFI-234]
@c MOD srfi.234
Given @var{graph}, which is a list of
@code{(@var{from-node} @var{downstream-node} @var{downstream-node1} @dots{})},
returns a list of edges, each of which being
@code{(@var{from-node} @var{to-node})}.
This is an inverse operation of @code{edgelist->graph}.
@end defun

@defun graph->edgelist/inverted graph
[SRFI-234]
@c MOD srfi.234
Given @var{graph}, which is a list of
@code{(@var{from-node} @var{downstream-node} @var{downstream-node1} @dots{})},
returns a list of edges, each of which being
@code{(@var{to-node} @var{from-node})}.
This is an inverse operation of @code{edgelist/inverted->graph}.
@end defun

@defun connected-components graph
Expand Down
83 changes: 56 additions & 27 deletions doc/program.texi
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ Gaucheがシステムにインストールされていた場合、指定バー
これは、Gaucheのバージョンを特定して実行したい場合に便利です。
なお、この機能で指定できる@var{version}は0.9.6かそれ以降のみです。
@c COMMON

@c EN
If the specified version isn't installed on the system, @code{gosh} exits
with a message. If you add @code{:} before @var{version}, however,
@code{gosh} falls back to itself when it can't find the given version.
@c JP
指定のバージョンのGaucheがシステムにインストールされていない場合、@code{gosh}は
メッセージを出して終了します。これを避けたい場合、@var{version}の前に@code{:}を
加えると、Gaucheは指定バージョンが見つからない場合は自分自身の実行を続けます。
@c COMMON

@example
# Suppose you don't have version 0.9.13 on your machine.
$ gosh -v 0.9.13
No installed Gauche with version 0.9.13 under /usr/lib/.
$ gosh -v :0.9.13
WARNING: No installed Gauche with version 0.9.13 under /usr/lib/. Using the current version.
gosh$ (gauche-version)
"0.9.15"
@end example
@end deftp


Expand Down Expand Up @@ -261,11 +281,10 @@ This option controls compiler and runtime behavior. For now we have
following options available:
@table @asis
@item case-fold
Ignore case for symbols.
Ignore case for symbols. @xref{Case-sensitivity}.
@item include-verbose
Reports whenever a file is included.
Useful to check precisely which files are included in what order.

@item load-verbose
Reports whenever a file is loaded.
Useful to check precisely which files are loaded in what order.
Expand All @@ -289,12 +308,13 @@ Prohibits the compiler from running post-inline optimization pass.
Don't keep source information for debugging. Consumes less memory.
@item safe-string-cursors
String cursors used on wrong strings will raise an error. This may
cause performance problems because all cursors will be allocated on
heap. @xref{String cursors}.
catch bugs but decreases performance
because all cursors will be allocated on heap. @xref{String cursors}.
@item test
Adds "@code{../src}" and "@code{../lib}" to the load path before loading
initialization file. This is useful when you want to test the
compiled @code{gosh} REPL without installing it.
This option allows you to run @code{gosh} when you build it, without
installing it. If given, this adds @code{../lib}, @code{../libsrc},
and @code{../src}, relative to the place @code{gosh} is, to
the load path before loading initialization file.
@item warn-legacy-syntax
Warns if the reader sees legacy hex-escape syntax in string literals.
@xref{Reader lexical mode}.
Expand All @@ -304,37 +324,46 @@ Warns if the reader sees legacy hex-escape syntax in string literals.
このオプションはコンパイラとランタイムの動作に影響を与えます。
今のところ、次のオプションのみが@var{compiler-option}として有効です。
@table @asis
@item case-fold
シンボルの大文字小文字を区別しません。
@ref{Case-sensitivity} を参照して下さい。
@item include-verbose
ファイルがincludeされる時にそれを報告します。
正確にどのファイルがどういう順序でincludeされているかを調べるのに便利です。
@item load-verbose
ファイルがロードされる時にそれを報告します。
正確にどのファイルがどういう順序でロードされているかを調べるのに便利です。
@item no-inline
一切のインライン展開を行いません。このオプションは以下の no-inline-globals
no-inline-locals および no-inline-constants を同時に指定したのと等価です。
一切のインライン展開を行いません。このオプションは以下の no-inline-globals、
no-inline-locals、no-inline-constants、no-inline-setters
を同時に指定したのと等価です。
@item no-inline-constants
定数のインライン展開を行ないません。
@item no-inline-globals
大域(global)関数のインライン展開を展開を行ないません。
@item no-inline-locals
局所(local)関数のインライン展開を展開を行ないません。
@item no-inline-constants
定数のインライン展開を行ないません。
@item no-post-inline-pass
インライン展開後に再び最適化パスを走らせるのを抑止します。
@item no-inline-setters
セッター関数のインライン展開を行いません。
@item no-lambda-lifting-pass
lambda lifting最適化パスを抑止します。
@item no-post-inline-pass
インライン展開後に再び最適化パスを走らせるのを抑止します。
@item no-source-info
デバッグのためのソースファイル情報を保持しません。メモリの使用量は小さくなります。
@item load-verbose
ファイルがロードされる時にそれを報告します。
正確にどのファイルがどういう順序でロードされているかを調べるのに便利です。
@item include-verbose
ファイルがincludeされる時にそれを報告します。
正確にどのファイルがどういう順序でincludeされているかを調べるのに便利です。
@item safe-string-cursors
文字列カーソルをそのカーソルが作られた文字列以外の文字列に使おうとした時に
エラーを投げます。バグを検出できますが、文字列カーソルが常にヒープアロケートされる
ので性能は低下します。@ref{String cursors}参照。
@item test
Gaucheをソースツリーからコンパイルしたまま、
インストールせずに実行するためのオプションです。
このオプションが指定されると、@code{gosh}は初期化ファイルを読む前に、
@code{gosh}のあるディレクトリからの相対パスで
@code{../lib}、@code{../libsrc}、@code{../src} をロードパスに加えます。
@item warn-legacy-syntax
文字列リテラル中に古い形式の16進数エスケープ形式があったら警告します。
@ref{Reader lexical mode} を参照して下さい。
@item case-fold
シンボルの大文字小文字を区別しません。
@ref{Case-sensitivity} を参照して下さい。
@item test
"@code{../src}" と "@code{../lib}" を、初期化ファイルを読む前に
ロードパスに加えます。これは、作成された@code{gosh}をインストールせずに
実行してみるのに便利です。
@end table
@c COMMON
@end deftp
Expand Down Expand Up @@ -523,7 +552,7 @@ we plan to make this default.
@code{#<undef>}に依存してたコードは壊れる可能性があります。
詳しくは@ref{Undefined values}を参照してください。

この機能はなるべくONtにしておくようにお勧めします
この機能はなるべくONにしておくようにお勧めします
将来はデフォルトで警告を出すようにする予定です。
@c COMMON
@end deftp
Expand Down
6 changes: 3 additions & 3 deletions lib/srfi/234.scm
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@
;; Calculate the connected components from a graph of in-neighbors
;; implements Kosaraju's algorithm: https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm
(define (connected-components graph)
(define nodes-with-inbound-links (map car graph))
;; graph of out-neighbors
(define graph/inverted (edgelist->graph (graph->edgelist/inverted graph)))
(define nodes-with-outbound-links (map car graph/inverted))
;; for simplicity this uses a list of nodes to query for membership. This is expensive.
(define visited '())
(define vertex-list '())
Expand Down Expand Up @@ -140,7 +138,9 @@
(unless (member u in-component)
(set! components (cons '() components))
(assign! u u)))
(for-each visit! nodes-with-outbound-links)
;; We visit all vertices. The next expression may call visit! on
;; the same node more than once, but second time and after is no-op.
(for-each (lambda (g) (for-each visit! g)) graph)
(for-each assign-as-component! vertex-list)
components)

Expand Down
48 changes: 37 additions & 11 deletions test/include/srfi-234-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,43 @@
(6 5)
(7 4) (7 6) (7 7))))

(test-equal
'((2 0 1) (6 5) (3 4) (7))
(connected-components
(edgelist->graph '((0 1)
(1 2)
(2 0)
(3 1) (3 2) (3 4)
(4 3) (4 5)
(5 2) (5 6)
(6 5)
(7 4) (7 6) (7 7)))))
(test-assert
(lset= (lambda (a b) (lset= eqv? a b))
'((1) (2))
(connected-components '((1 2)))))

(test-assert
(lset= (lambda (a b) (lset= eqv? a b))
'((1 2))
(connected-components '((1 2) (2 1)))))

(test-assert
(lset= (lambda (a b) (lset= eqv? a b))
'((1 2) (3 4))
(connected-components '((1 2 3 4)
(2 1 3)
(3 4)
(4 3)))))

(test-assert
(lset= (lambda (a b) (lset= eqv? a b))
'((1) (2) (3) (4))
(connected-components '((1 2 3 4)
(2 3)
(3 4)))))

(test-assert
(lset= (lambda (a b) (lset= eqv? a b))
'((2 0 1) (6 5) (3 4) (7))
(connected-components
(edgelist->graph '((0 1)
(1 2)
(2 0)
(3 1) (3 2) (3 4)
(4 3) (4 5)
(5 2) (5 6)
(6 5)
(7 4) (7 6) (7 7))))))

(define (permutations edgelist)
(if (null? edgelist) '(())
Expand Down

0 comments on commit 81aa3c6

Please sign in to comment.