Skip to content

Commit 73a7739

Browse files
committed
Support SRFI 111
Signed-off-by: yamacir-kit <[email protected]>
1 parent d849993 commit 73a7739

File tree

10 files changed

+112
-36
lines changed

10 files changed

+112
-36
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Subset of R7RS-small.
5555
| [ 78](https://srfi.schemers.org/srfi-78/srfi-78.html) | Lightweight testing | [`(srfi 78)`](./basis/srfi-78.ss) | Except `check-ec` |
5656
| [ 87](https://srfi.schemers.org/srfi-87/srfi-87.html) | => in case clauses | | R7RS 4.2.1 |
5757
| [ 98](https://srfi.schemers.org/srfi-98/srfi-98.html) | An interface to access environment variables | [`(srfi 98)`](./basis/srfi-98.ss) | R7RS 6.14 |
58+
| [111](https://srfi.schemers.org/srfi-111/srfi-111.html) | Boxes | [`(srfi 111)`](./basis/srfi-111.ss) | |
5859
| [149](https://srfi.schemers.org/srfi-149/srfi-149.html) | Basic syntax-rules template extensions | [`(srfi 149)`](./basis/srfi-149.ss) | R7RS 4.3.2 |
5960

6061
## Installation
@@ -73,7 +74,7 @@ Subset of R7RS-small.
7374
cmake -B build -DCMAKE_BUILD_TYPE=Release
7475
cd build
7576
make package
76-
sudo apt install build/meevax_0.4.778_amd64.deb
77+
sudo apt install build/meevax_0.4.779_amd64.deb
7778
```
7879

7980
or
@@ -105,15 +106,15 @@ sudo rm -rf /usr/local/share/meevax
105106

106107
| Target Name | Description
107108
|-----------------|-------------
108-
| `all` (default) | Build shared-library `libmeevax.0.4.778.so` and executable `meevax`
109+
| `all` (default) | Build shared-library `libmeevax.0.4.779.so` and executable `meevax`
109110
| `test` | Test executable `meevax`
110-
| `package` | Generate debian package `meevax_0.4.778_amd64.deb`
111+
| `package` | Generate debian package `meevax_0.4.779_amd64.deb`
111112
| `install` | Copy files into `/usr/local` directly
112113

113114
## Usage
114115

115116
```
116-
Meevax Lisp 0.4.778
117+
Meevax Lisp 0.4.779
117118
118119
Usage:
119120
meevax [option...] [file...]

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.778
1+
0.4.779

basis/srfi-111.ss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(define-library (srfi 111)
2+
(import (meevax box))
3+
(export box box? (rename box-ref unbox) (rename box-set! set-box!)))

configure/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Subset of R7RS-small.
5555
| [ 78](https://srfi.schemers.org/srfi-78/srfi-78.html) | Lightweight testing | [`(srfi 78)`](./basis/srfi-78.ss) | Except `check-ec` |
5656
| [ 87](https://srfi.schemers.org/srfi-87/srfi-87.html) | => in case clauses | | R7RS 4.2.1 |
5757
| [ 98](https://srfi.schemers.org/srfi-98/srfi-98.html) | An interface to access environment variables | [`(srfi 98)`](./basis/srfi-98.ss) | R7RS 6.14 |
58+
| [111](https://srfi.schemers.org/srfi-111/srfi-111.html) | Boxes | [`(srfi 111)`](./basis/srfi-111.ss) | |
5859
| [149](https://srfi.schemers.org/srfi-149/srfi-149.html) | Basic syntax-rules template extensions | [`(srfi 149)`](./basis/srfi-149.ss) | R7RS 4.3.2 |
5960

6061
## Installation

configure/basis.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ inline namespace kernel
4444
R"##(${${PROJECT_NAME}_BASIS_srfi-45.ss})##",
4545
R"##(${${PROJECT_NAME}_BASIS_srfi-78.ss})##",
4646
R"##(${${PROJECT_NAME}_BASIS_srfi-98.ss})##",
47+
R"##(${${PROJECT_NAME}_BASIS_srfi-111.ss})##",
4748
R"##(${${PROJECT_NAME}_BASIS_srfi-149.ss})##",
4849
};
4950
}

include/meevax/kernel/box.hpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2018-2023 Tatsuya Yamasaki.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef INCLUDED_MEEVAX_KERNEL_BOX_HPP
18+
#define INCLUDED_MEEVAX_KERNEL_BOX_HPP
19+
20+
#include <meevax/kernel/pair.hpp>
21+
22+
namespace meevax
23+
{
24+
inline namespace kernel
25+
{
26+
struct box : public virtual pair // (value . unit)
27+
{
28+
using pair::pair;
29+
};
30+
31+
auto operator <<(std::ostream &, box const&) -> std::ostream &;
32+
} // namespace kernel
33+
} // namespace meevax
34+
35+
#endif // INCLUDED_MEEVAX_KERNEL_BOX_HPP

src/kernel/box.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright 2018-2023 Tatsuya Yamasaki.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include <meevax/kernel/box.hpp>
18+
19+
namespace meevax
20+
{
21+
inline namespace kernel
22+
{
23+
auto operator <<(std::ostream & os, box const& datum) -> std::ostream &
24+
{
25+
return os << magenta("#,(") << green("box ") << datum.first << magenta(")");
26+
}
27+
} // namespace kernel
28+
} // namespace meevax

src/kernel/comparator.cpp

+12-29
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,25 @@
1414
limitations under the License.
1515
*/
1616

17+
#include <meevax/kernel/box.hpp>
1718
#include <meevax/kernel/list.hpp>
1819

1920
namespace meevax
2021
{
2122
inline namespace kernel
2223
{
23-
struct box : public virtual pair // (value . unit)
24-
{
25-
auto unbox() -> object &
26-
{
27-
return first;
28-
}
29-
30-
auto unbox() const -> object const&
31-
{
32-
return first;
33-
}
34-
35-
auto set(object const& x) -> object const&
36-
{
37-
return first = x;
38-
}
39-
};
40-
4124
auto find(let const& b) -> object const&
4225
{
43-
if (let x = b.as<box>().unbox(); x.is<box>())
26+
if (let & x = car(b); x.is<box>())
4427
{
45-
return b.as<box>().set(find(x));
28+
return x = find(x);
4629
}
4730
else
4831
{
4932
return b;
5033
}
5134
}
5235

53-
/*
54-
Efficient Nondestructive Equality Checking for Trees and Graphs
55-
*/
5636
auto union_find(object const& x, object const& y, std::unordered_map<object, object> & forest)
5737
{
5838
using rank = std::uint32_t;
@@ -68,16 +48,16 @@ inline namespace kernel
6848
}
6949
else
7050
{
71-
if (auto rank_x = root_x.as<box>().unbox().as<rank>(),
72-
rank_y = root_y.as<box>().unbox().as<rank>(); rank_x > rank_y)
51+
if (auto rank_x = car(root_x).as<rank>(),
52+
rank_y = car(root_y).as<rank>(); rank_x > rank_y)
7353
{
74-
root_x.as<box>().set(make<rank>(rank_x + rank_y));
75-
root_y.as<box>().set(root_x);
54+
car(root_x) = make<rank>(rank_x + rank_y);
55+
car(root_y) = root_x;
7656
}
7757
else
7858
{
79-
root_x.as<box>().set(root_y);
80-
root_y.as<box>().set(make<rank>(rank_x + rank_y));
59+
car(root_x) = root_y;
60+
car(root_y) = make<rank>(rank_x + rank_y);
8161
}
8262
}
8363
}
@@ -103,6 +83,9 @@ inline namespace kernel
10383
return false;
10484
}
10585

86+
/*
87+
Efficient Nondestructive Equality Checking for Trees and Graphs
88+
*/
10689
auto equal(object const& x, object const& y, std::unordered_map<object, object> & forest) -> bool
10790
{
10891
return eqv(x, y) or (x.is<pair>() and

src/kernel/library.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <meevax/kernel/basis.hpp>
2222
#include <meevax/kernel/binary_input_file_port.hpp>
2323
#include <meevax/kernel/binary_output_file_port.hpp>
24+
#include <meevax/kernel/box.hpp>
2425
#include <meevax/kernel/disassemble.hpp>
2526
#include <meevax/kernel/input_file_port.hpp>
2627
#include <meevax/kernel/input_homogeneous_vector_port.hpp>
@@ -126,6 +127,29 @@ inline namespace kernel
126127

127128
auto boot() -> void
128129
{
130+
define<library>("(meevax box)", [](library & library)
131+
{
132+
library.define<procedure>("box", [](let const& xs)
133+
{
134+
return make<box>(car(xs));
135+
});
136+
137+
library.define<procedure>("box?", [](let const& xs)
138+
{
139+
return car(xs).is<box>();
140+
});
141+
142+
library.define<procedure>("box-ref", [](let const& xs)
143+
{
144+
return caar(xs);
145+
});
146+
147+
library.define<procedure>("box-set!", [](let const& xs)
148+
{
149+
return caar(xs) = cadr(xs);
150+
});
151+
});
152+
129153
define<library>("(meevax character)", [](library & library)
130154
{
131155
library.define<procedure>("char?", [](let const& xs)

test/r7rs.ss

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
; ---- 2.2. --------------------------------------------------------------------
5151

5252
#|
53-
The FACT procedure computes the factorial
54-
of a non-negative integer.
53+
The FACT procedure computes the factorial
54+
of a non-negative integer.
5555
|#
5656
(define fact
5757
(lambda (n)

0 commit comments

Comments
 (0)