Skip to content

Commit 16445a9

Browse files
authored
Merge pull request #334 from yamacir-kit/module
Module
2 parents 55a2f4e + 3a3c2df commit 16445a9

28 files changed

+1223
-974
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ subset of **R7RS Scheme** implementation.
4747

4848
There is no stable version.
4949

50-
Development HEAD: 0.3.409.
50+
Development HEAD: 0.3.474.
5151

5252
### Characteristic Features
5353

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.409
1+
0.3.474

basis/overture.ss

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
; display do dynamic-wind else equal? even?
1313
; exact->inexact exact? for-each force gcd imag-part
1414
; inexact->exact inexact? input-port? integer?
15-
; interaction-environment lcm length let let* let-syntax letrec
15+
; interaction-environment lcm length let let* let-syntax
1616
; letrec-syntax list list-ref list-tail list? log
1717
; magnitude make-polar make-rectangular map max member
1818
; memq memv min modulo negative? newline not null-environment null?
@@ -261,13 +261,11 @@
261261
#f)
262262
(any-2+ f (cons x xs))))
263263

264-
(define-syntax (letrec bindings . body)
264+
(define-syntax (letrec* bindings . body)
265265
((lambda (definitions)
266266
`((,lambda () ,@definitions ,@body)) )
267267
(map (lambda (x) (cons define x)) bindings)))
268268

269-
(define-syntax letrec* letrec) ; TODO MOVE INTO (scheme base)
270-
271269
(define-syntax (let bindings . body)
272270
(if (identifier? bindings)
273271
`(,letrec ((,bindings (,lambda ,(map car (car body)) ,@(cdr body))))
@@ -702,9 +700,9 @@
702700
; ---- 6.10. Control features --------------------------------------------------
703701

704702
(define (procedure? x)
705-
(or (native-procedure? x)
706-
(closure? x)
707-
(continuation? x)))
703+
(or (closure? x)
704+
(continuation? x)
705+
(foreign-function? x)))
708706

709707
(define %current-dynamic-extents '()) ; https://www.cs.hmc.edu/~fleck/envision/scheme48/meeting/node7.html
710708

basis/srfi-39.ss

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
(if (null? conv) (lambda (x) x) (car conv))))
2525
(let ((global-cell
2626
(cons #f (converter init))))
27-
(define parameter
28-
(lambda new-val
29-
(let ((cell (dynamic-lookup parameter global-cell)))
30-
(cond ((null? new-val)
31-
(cdr cell))
32-
((null? (cdr new-val))
33-
(set-cdr! cell (converter (car new-val))))
34-
(else ; this case is needed for parameterize
35-
(converter (car new-val)))))))
36-
(set-car! global-cell parameter)
37-
parameter))))
27+
(letrec ((parameter
28+
(lambda new-val
29+
(let ((cell (dynamic-lookup parameter global-cell)))
30+
(cond ((null? new-val)
31+
(cdr cell))
32+
((null? (cdr new-val))
33+
(set-cdr! cell (converter (car new-val))))
34+
(else ; this case is needed for parameterize
35+
(converter (car new-val))))))))
36+
(set-car! global-cell parameter)
37+
parameter)))))
3838

3939
(define dynamic-bind
4040
(lambda (parameters values body)
@@ -59,12 +59,10 @@
5959

6060
(define dynamic-env-local '())
6161

62-
(define dynamic-env-local-get
63-
(lambda () dynamic-env-local))
62+
(define (dynamic-env-local-get) dynamic-env-local)
6463

65-
(define dynamic-env-local-set!
66-
(lambda (new-env)
67-
(set! dynamic-env-local new-env)))
64+
(define (dynamic-env-local-set! new-env)
65+
(set! dynamic-env-local new-env))
6866

6967
; (define-syntax parameterize
7068
; (er-macro-transformer

example/foreign-function.ss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
(define dummy-procedure (foreign-function "build/libexample-1.so" "dummy_procedure"))
2-
(define length-of-arguments (foreign-function "build/libexample-1.so" "length_of_arguments"))
1+
(let ((dummy-procedure (foreign-function "build/libexample-1.so" "dummy_procedure")))
2+
(check (foreign-function? dummy-procedure) => #t)
3+
)
34

4-
(check (length-of-arguments 'hoge 42 #(1 2 3) 3.14) => 4)
5+
(let ((length-of-arguments (foreign-function "build/libexample-1.so" "length_of_arguments")))
6+
(check (foreign-function? length-of-arguments) => #t)
7+
(check (length-of-arguments 'hoge 42 #(1 2 3) 3.14) => 4)
8+
)
59

610
(exit (check-passed? check:correct))

include/meevax/functional/curry.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ namespace meevax
2323
{
2424
inline namespace functional
2525
{
26-
template <typename F>
27-
constexpr auto curry(F&& f) -> decltype(auto)
26+
template <typename Function>
27+
constexpr auto curry(Function&& function) -> decltype(auto)
2828
{
2929
return [&](auto&&... xs)
3030
{
3131
return [&](auto&&... ys) -> decltype(auto)
3232
{
33-
return
34-
f(std::forward<decltype(xs)>(xs)...,
35-
std::forward<decltype(ys)>(ys)...);
33+
return function(std::forward<decltype(xs)>(xs)...,
34+
std::forward<decltype(ys)>(ys)...);
3635
};
3736
};
3837
}

include/meevax/kernel/configurator.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ inline namespace kernel
4848
let trace = f;
4949
let verbose = f;
5050

51-
let prompt = make<symbol>("> ");
51+
let prompt = make<string>(u8"λ> ");
5252

5353
template <typename Key>
5454
using dispatcher = std::unordered_map<Key, std::function<PROCEDURE()>>;
@@ -261,9 +261,9 @@ inline namespace kernel
261261
}();
262262
}
263263

264-
auto current_prompt() const -> auto const&
264+
auto current_prompt() const
265265
{
266-
return prompt;
266+
return static_cast<std::string>(prompt.as<string>());
267267
}
268268

269269
void display_version() const
@@ -300,8 +300,8 @@ inline namespace kernel
300300
write_line(" -e, --evaluate=STRING read and evaluate given STRING at configuration step.");
301301
write_line(" -h, --help display this help text and exit.");
302302
write_line(" -i, --interactive take over control of root syntactic-continuation.");
303-
write_line(" -l, --load=FILE same as -e '(load FILE)'");
304-
write_line(" --prompt=SYMBOL same as -e '(set-prompt! SYMBOL)'");
303+
write_line(" -l, --load=FILENAME same as -e '(load FILENAME)'");
304+
write_line(" --prompt=STRING same as -e '(set-prompt! STRING)'");
305305
write_line(" -t, --trace display stacks of virtual machine for each steps.");
306306
write_line(" -v, --version display version information and exit.");
307307
write_line(" --verbose display detailed informations.");
@@ -317,14 +317,14 @@ inline namespace kernel
317317
write_line(" meevax -i");
318318
write_line(" => start interactive session.");
319319
write_line();
320-
write_line(" meevax -i --prompt '#,(string->symbol \"my-prompt> \")'");
321-
write_line(" => start interactive session with given prompt.");
320+
write_line(" meevax -i --prompt '\"my-prompt> \"'");
321+
write_line(" => Start interactive session with given prompt.");
322322
write_line();
323323
write_line(" meevax -e '(+ 1 2 3)'");
324-
write_line(" => display 6.");
324+
write_line(" => Display 6.");
325325
write_line();
326326
write_line(" meevax -e \"(define home \\\"$HOME\\\")\" -i");
327-
write_line(" => define value of environment variable $HOME to interaction-environment,");
327+
write_line(" => Define value of environment variable $HOME to interaction-environment,");
328328
write_line(" and then start interactive session.");
329329
}
330330

include/meevax/kernel/de_brujin_index.hpp renamed to include/meevax/kernel/de_bruijn_index.hpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
limitations under the License.
1515
*/
1616

17-
#ifndef INCLUDED_MEEVAX_KERNEL_DE_BRUJIN_INDEX_HPP
18-
#define INCLUDED_MEEVAX_KERNEL_DE_BRUJIN_INDEX_HPP
17+
#ifndef INCLUDED_MEEVAX_KERNEL_DE_BRUIJN_INDEX_HPP
18+
#define INCLUDED_MEEVAX_KERNEL_DE_BRUIJN_INDEX_HPP
1919

2020
#include <meevax/kernel/list.hpp>
2121

@@ -24,37 +24,37 @@ namespace meevax
2424
inline namespace kernel
2525
{
2626
template <typename Comparator = default_equivalence_comparator>
27-
class de_bruijn_index
28-
: public let
27+
struct de_bruijn_index
2928
{
30-
bool variadic;
31-
32-
public:
3329
Comparator compare {};
3430

31+
bool is_variadic;
32+
33+
let const index;
34+
3535
template <typename... Ts>
3636
explicit de_bruijn_index(Ts&&... xs)
37-
: let { lookup(std::forward<decltype(xs)>(xs)...) }
37+
: index { notate(std::forward<decltype(xs)>(xs)...) }
3838
{}
3939

40-
let lookup(let const& value, let const& frames)
40+
auto notate(pair::const_reference value, pair::const_reference frames) -> pair::value_type // XXX UGLY CODE!!!
4141
{
4242
std::size_t layer = 0;
4343

44-
for (const auto& frame : frames)
44+
for (auto const& frame : frames)
4545
{
4646
std::size_t index = 0;
4747

48-
for (auto iter = std::begin(frame); iter != std::end(frame); ++iter)
48+
for (let node = frame; node; node = cdr(node))
4949
{
50-
if (static_cast<let const&>(iter).is<pair>() and compare(*iter, value))
50+
if (node.is<pair>() and compare(car(node), value))
5151
{
52-
variadic = false;
52+
is_variadic = false;
5353
return cons(make<exact_integer>(layer), make<exact_integer>(index));
5454
}
55-
else if (static_cast<let const&>(iter).is<symbol>() and compare(iter, value))
55+
else if (node.is<symbol>() and compare(node, value))
5656
{
57-
variadic = true;
57+
is_variadic = true;
5858
return cons(make<exact_integer>(layer), make<exact_integer>(index));
5959
}
6060

@@ -67,12 +67,17 @@ inline namespace kernel
6767
return unit;
6868
}
6969

70-
bool is_variadic() const noexcept
70+
auto is_bound() const -> bool
71+
{
72+
return not is_free();
73+
}
74+
75+
auto is_free() const -> bool
7176
{
72-
return variadic;
77+
return index.is<null>();
7378
}
7479
};
7580
} // namespace kernel
7681
} // namespace meevax
7782

78-
#endif // INCLUDED_MEEVAX_KERNEL_DE_BRUJIN_INDEX_HPP
83+
#endif // INCLUDED_MEEVAX_KERNEL_DE_BRUIJN_INDEX_HPP

include/meevax/kernel/error.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ inline namespace kernel
142142
return underlying_cast(exit_status::failure);
143143
}
144144
}
145+
146+
auto invalid_application(let const&) -> error;
145147
} // namespace kernel
146148
} // namespace meevax
147149

include/meevax/kernel/heterogeneous.hpp

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ inline namespace kernel
4141

4242
~binder() override = default;
4343

44-
auto type() const noexcept -> std::type_info const& override
45-
{
46-
return typeid(Bound);
47-
}
48-
49-
bool eqv(heterogeneous const& x) const override
44+
auto eqv(heterogeneous const& x) const -> bool override
5045
{
5146
if constexpr (is_equality_comparable<Bound>::value)
5247
{
@@ -65,6 +60,11 @@ inline namespace kernel
6560
}
6661
}
6762

63+
auto type() const noexcept -> std::type_info const& override
64+
{
65+
return typeid(Bound);
66+
}
67+
6868
auto write_to(std::ostream & port) const -> std::ostream & override
6969
{
7070
return delay<write>().yield<decltype(port)>(port, static_cast<Bound const&>(*this));
@@ -92,8 +92,7 @@ inline namespace kernel
9292
#undef BOILERPLATE
9393
};
9494

95-
public: /* ---- CONSTRUCTORS ---------------------------------------------- */
96-
95+
public:
9796
using Pointer<Top>::Pointer;
9897

9998
template <typename Bound, typename... Ts, REQUIRES(std::is_compound<Bound>)>
@@ -109,60 +108,53 @@ inline namespace kernel
109108
}
110109
}
111110

112-
public: /* ---- TYPE PREDICATES ------------------------------------------- */
113-
114-
auto type() const -> decltype(auto)
115-
{
116-
return *this ? Pointer<Top>::load().type() : typeid(null);
117-
}
118-
119111
template <typename U>
120-
auto is() const
112+
inline auto as() const -> U &
121113
{
122-
return type() == typeid(typename std::decay<U>::type);
123-
}
124-
125-
template <typename U,
126-
typename std::enable_if<
127-
std::is_null_pointer<typename std::decay<U>::type>::value
128-
>::type = 0>
129-
auto is() const
130-
{
131-
return not static_cast<bool>(*this);
114+
if (pointer<U> data = dynamic_cast<pointer<U>>(Pointer<Top>::get()); data)
115+
{
116+
return *data;
117+
}
118+
else
119+
{
120+
throw make_error("no viable conversion from ", demangle(Pointer<Top>::load().type()), " to ", demangle(typeid(U)));
121+
}
132122
}
133123

134-
template <typename U>
135-
auto is_polymorphically() const
124+
inline auto eqv(heterogeneous const& rhs) const -> bool
136125
{
137-
return dynamic_cast<pointer<const U>>(Pointer<Top>::get()) != nullptr;
126+
return type() == rhs.type() and Pointer<Top>::load().eqv(rhs);
138127
}
139128

140-
public: /* ---- ACCESSORS ------------------------------------------------- */
141-
142129
template <typename U>
143-
auto as() const -> typename std::add_lvalue_reference<U>::type
130+
inline auto is() const
144131
{
145-
if (pointer<U> address = dynamic_cast<pointer<U>>(Pointer<Top>::get()); address)
132+
if constexpr (std::is_null_pointer<typename std::decay<U>::type>::value)
146133
{
147-
return *address;
134+
return not static_cast<bool>(*this);
148135
}
149136
else
150137
{
151-
throw make_error(
152-
"no viable conversion from ", demangle(Pointer<Top>::load().type()), " to ", demangle(typeid(U)));
138+
return type() == typeid(typename std::decay<U>::type);
153139
}
154140
}
155141

156-
bool eqv(heterogeneous const& rhs) const
142+
template <typename U>
143+
inline auto is_also() const
157144
{
158-
return type() == rhs.type() and Pointer<Top>::load().eqv(rhs);
145+
return dynamic_cast<pointer<U>>(Pointer<Top>::get()) != nullptr;
146+
}
147+
148+
inline auto type() const -> std::type_info const&
149+
{
150+
return *this ? Pointer<Top>::load().type() : typeid(null);
159151
}
160152
};
161153

162154
template <template <typename...> typename Pointer, typename Top>
163-
auto operator <<(std::ostream & port, heterogeneous<Pointer, Top> const& datum) -> std::ostream &
155+
auto operator <<(std::ostream & os, heterogeneous<Pointer, Top> const& datum) -> std::ostream &
164156
{
165-
return (datum.template is<null>() ? port << magenta << "()" : datum.load().write_to(port)) << reset;
157+
return (datum.template is<null>() ? os << magenta << "()" : datum.load().write_to(os)) << reset;
166158
}
167159

168160
#define BOILERPLATE(SYMBOL) \

0 commit comments

Comments
 (0)