Skip to content

Commit fc2876f

Browse files
authored
Merge pull request #464 from yamacir-kit/release-candidate
Release candidate
2 parents 0a079aa + 7be15e5 commit fc2876f

30 files changed

+1660
-1403
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ target_link_libraries(format PRIVATE kernel)
9797

9898
add_custom_target(basis
9999
DEPENDS format
100-
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/basis/configure.cmake)
100+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/configure/basis.cmake)
101101

102102
# ---- Target shell ------------------------------------------------------------
103103

README.md

+44-52
Large diffs are not rendered by default.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.0
1+
0.5.32

basis/r4rs-essential.ss

-516
This file was deleted.

basis/r4rs.ss

+317-104
Large diffs are not rendered by default.

basis/r7rs.ss

+5-2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@
394394
(car xs)
395395
(current-output-port))))))
396396

397+
(define-library (scheme box)
398+
(import (srfi 111))
399+
(export box box? unbox set-box!))
400+
397401
(define-library (scheme case-lambda)
398402
(import (srfi 16))
399403
(export case-lambda))
@@ -421,8 +425,7 @@
421425
(string-map char-foldcase x))))
422426

423427
(define-library (scheme complex)
424-
(import (only (meevax complex) make-rectangular real-part imag-part)
425-
(only (scheme r5rs) make-polar magnitude angle))
428+
(import (only (scheme r5rs) make-rectangular make-polar real-part imag-part magnitude angle))
426429
(export make-rectangular make-polar real-part imag-part magnitude angle))
427430

428431
(define-library (scheme cxr)

basis/srfi-45.ss

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
(define-library (srfi 45) ; Based on r7rs reference implementation.
2-
(import (only (meevax core) define-syntax)
2+
(import (only (meevax boolean) not)
3+
(only (meevax comparator) eq?)
4+
(only (meevax core) define define-syntax if lambda quote)
5+
(only (meevax list) list)
36
(only (meevax macro-transformer) er-macro-transformer)
4-
(scheme r4rs essential))
7+
(only (meevax pair) pair? cons car cdr cadr cddr set-car! set-cdr!))
58

69
(export delay eager force lazy promise?)
710

@@ -11,8 +14,9 @@
1114
(cons <promise> (cons done? value)))
1215

1316
(define (promise? x)
14-
(and (pair? x)
15-
(eq? <promise> (car x))))
17+
(if (pair? x)
18+
(eq? <promise> (car x))
19+
#f))
1620

1721
(define promise-done? cadr)
1822

configure/README.md

+41-49
Large diffs are not rendered by default.
File renamed without changes.

configure/basis.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ inline namespace kernel
3333
{
3434
return make_array(
3535
R"##(${CONFIGURED_meevax.ss})##",
36-
R"##(${CONFIGURED_r4rs-essential.ss})##",
3736
R"##(${CONFIGURED_r4rs.ss})##",
3837
R"##(${CONFIGURED_r5rs.ss})##",
3938
R"##(${CONFIGURED_r7rs.ss})##",

example/example.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
#include <meevax/basis/scheme.hpp>
21
#include <meevax/kernel/environment.hpp>
32

43
using namespace meevax; // NOTE: DIRTY HACK
54

65
extern "C"
76
{
8-
let length_of_arguments(let const& xs)
7+
auto arity(object & xs)
98
{
109
return make<exact_integer>(length(xs));
1110
}
1211

13-
let dummy_procedure(let const& xs)
12+
auto dummy_procedure(object & xs)
1413
{
15-
std::cout << "\n; calling C++ function via foreign-function-interface." << std::endl;
14+
std::cout << "\n; calling C++ function." << std::endl;
1615

1716
std::size_t count = 0;
1817

@@ -46,17 +45,17 @@ extern "C"
4645
}
4746
};
4847

49-
let make_hoge(let const& xs)
48+
auto make_hoge(object & xs)
5049
{
5150
return make<hoge>(xs[0].as<exact_integer>());
5251
}
5352

54-
let is_hoge(let const& xs)
53+
auto is_hoge(object & xs)
5554
{
5655
return xs[0].is<hoge>() ? t : f;
5756
}
5857

59-
let hoge_value(let const& xs)
58+
auto hoge_value(object & xs)
6059
{
6160
return make<exact_integer>(xs[0].as<hoge>().value);
6261
}

example/example.ss

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(import (meevax function)
1+
(import (only (meevax procedure) procedure)
22
(scheme base)
33
(scheme process-context)
44
(scheme write)
@@ -7,37 +7,37 @@
77
; ------------------------------------------------------------------------------
88

99
(define dummy-procedure
10-
(foreign-function "build/libexample.so" "dummy_procedure"))
10+
(procedure "build/libexample.so" 'dummy_procedure))
1111

12-
(check (foreign-function? dummy-procedure) => #t)
12+
(check (procedure? dummy-procedure) => #t)
1313

1414
(check (dummy-procedure 'hoge 42 #(1 2 3) 3.14) => 43)
1515

1616
; ------------------------------------------------------------------------------
1717

18-
(define length-of-arguments
19-
(foreign-function "build/libexample.so" "length_of_arguments"))
18+
(define arity
19+
(procedure "build/libexample.so" 'arity))
2020

21-
(check (foreign-function? length-of-arguments) => #t)
21+
(check (procedure? arity) => #t)
2222

23-
(check (length-of-arguments 'hoge 42 #(1 2 3) 3.14) => 4)
23+
(check (arity 'hoge 42 #(1 2 3) 3.14) => 4)
2424

2525
; ------------------------------------------------------------------------------
2626

2727
(define make-hoge
28-
(foreign-function "build/libexample.so" "make_hoge"))
28+
(procedure "build/libexample.so" 'make_hoge))
2929

3030
(define hoge?
31-
(foreign-function "build/libexample.so" "is_hoge"))
31+
(procedure "build/libexample.so" 'is_hoge))
3232

3333
(define hoge-value
34-
(foreign-function "build/libexample.so" "hoge_value"))
34+
(procedure "build/libexample.so" 'hoge_value))
3535

36-
(check (foreign-function? make-hoge) => #t)
36+
(check (procedure? make-hoge) => #t)
3737

38-
(check (foreign-function? hoge?) => #t)
38+
(check (procedure? hoge?) => #t)
3939

40-
(check (foreign-function? hoge-value) => #t)
40+
(check (procedure? hoge-value) => #t)
4141

4242
(define h (make-hoge 100))
4343

include/meevax/kernel/complex.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ inline namespace kernel
4141
};
4242

4343
auto operator <<(std::ostream &, complex const&) -> std::ostream &;
44+
45+
auto real_part(object const&) -> object const&;
46+
47+
auto imag_part(object const&) -> object const&;
48+
49+
auto magnitude(object const&) -> object;
50+
51+
auto angle(object const&) -> object;
4452
} // namespace kernel
4553
} // namespace meevax
4654

include/meevax/kernel/configurator.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ inline namespace kernel
6666
{
6767
option("(i|interactive)", [this](auto)
6868
{
69-
let const f = make<functor>("", [this](let const&)
69+
let const f = make<procedure>("", [this](let const&)
7070
{
7171
interactive = true;
7272
return unspecified;
@@ -82,7 +82,7 @@ inline namespace kernel
8282

8383
option("(h|help)", [](auto)
8484
{
85-
let static const f = make<command>("", [](let const&)
85+
let static const f = make<procedure>("", [](let const&)
8686
{
8787
std::cout << help() << std::endl;
8888
throw EXIT_SUCCESS;
@@ -93,7 +93,7 @@ inline namespace kernel
9393

9494
option("(l|load)", [this](auto read)
9595
{
96-
let const f = make<functor>("", [this](let const& xs)
96+
let const f = make<procedure>("", [this](let const& xs)
9797
{
9898
static_cast<Environment &>(*this).load(xs[0].as<string>());
9999
return unspecified;
@@ -104,7 +104,7 @@ inline namespace kernel
104104

105105
option("(v|version)", [](auto)
106106
{
107-
let static const f = make<command>("", [](let const&)
107+
let static const f = make<procedure>("", [](let const&)
108108
{
109109
std::cout << version() << std::endl;
110110
throw EXIT_SUCCESS;
@@ -115,7 +115,7 @@ inline namespace kernel
115115

116116
option("(w|write)", [](auto read)
117117
{
118-
let static const f = make<command>("", [](let const& xs)
118+
let static const f = make<procedure>("", [](let const& xs)
119119
{
120120
std::cout << xs[0] << std::endl;
121121
});
@@ -184,7 +184,7 @@ inline namespace kernel
184184
}
185185
else
186186
{
187-
let const f = make<functor>("", [iter](let const&)
187+
let const f = make<procedure>("", [iter](let const&)
188188
{
189189
Environment().load(*iter);
190190
return unspecified;

include/meevax/kernel/dynamic_environment.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,16 @@ inline namespace kernel
286286
s = unit;
287287
goto fetch;
288288
}
289-
else if (callee.is_also<procedure>()) /* -----------------------------
289+
else if (callee.is_also<callable>()) /* ------------------------------
290290
*
291-
* (<procedure> xs . s) e (%call . c) d => (x . s) e c d
291+
* (<callable> xs . s) e (%call . c) d => (x . s) e c d
292292
*
293293
* where x = procedure(xs)
294294
*
295295
* ----------------------------------------------------------------- */
296296
{
297297
assert(tail(c, 1).template is<pair>());
298-
s = cons(callee.as<procedure>()(cadr(s)), cddr(s));
298+
s = cons(callee.as<callable>()(cadr(s)), cddr(s));
299299
c = cdr(c);
300300
goto fetch;
301301
}
@@ -336,17 +336,17 @@ inline namespace kernel
336336
s = unit;
337337
goto fetch;
338338
}
339-
else if (callee.is_also<procedure>()) /* -----------------------------
339+
else if (callee.is_also<callable>()) /* ------------------------------
340340
*
341-
* (<procedure> xs) e (%tail-call) (s' e' c' . d) => (x . s') e' c' d
341+
* (<callable> xs) e (%tail-call) (s' e' c' . d) => (x . s') e' c' d
342342
*
343343
* where x = procedure(xs)
344344
*
345345
* ----------------------------------------------------------------- */
346346
{
347347
assert(tail(s, 2).template is<null>());
348348
assert(tail(c, 1).template is<null>());
349-
s = cons(callee.as<procedure>()(cadr(s)), car(d));
349+
s = cons(callee.as<callable>()(cadr(s)), car(d));
350350
e = cadr(d);
351351
c = caddr(d);
352352
d = cdddr(d);

include/meevax/kernel/library.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ inline namespace kernel
4747
export_specs = cons(input_string_port(name).read(), export_specs);
4848
}
4949

50+
template <template <typename...> typename Template, typename... Ts>
51+
auto define(Ts&&... xs) -> decltype(auto)
52+
{
53+
return define<Template<Ts...>>(std::forward<decltype(xs)>(xs)...);
54+
}
55+
5056
auto evaluate(object const&) -> object;
5157

5258
auto resolve() -> object;

include/meevax/kernel/list.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ inline namespace kernel
105105

106106
auto make_list(std::size_t, object const& = unit) -> object;
107107

108+
auto is_list(object const&) -> bool;
109+
108110
template <typename T>
109111
auto tail(T&& x, std::size_t size) -> decltype(x)
110112
{

include/meevax/kernel/number.hpp

+32
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,50 @@ inline namespace number
363363

364364
auto is_integer(object const&) -> bool;
365365

366+
auto is_exact(object const&) -> bool;
367+
368+
auto is_inexact(object const&) -> bool;
369+
366370
auto is_finite(object const&) -> bool;
367371

368372
auto is_infinite(object const&) -> bool;
369373

370374
auto is_nan(object const&) -> bool;
371375

376+
auto is_zero(object const&) -> bool;
377+
378+
auto is_positive(object const&) -> bool;
379+
380+
auto is_negative(object const&) -> bool;
381+
382+
auto is_odd(object const&) -> bool;
383+
384+
auto is_even(object const&) -> bool;
385+
386+
auto max(object const&) -> object;
387+
388+
auto min(object const&) -> object;
389+
372390
auto abs(object const&) -> object;
373391

392+
auto quotient(object const&, object const&) -> object;
393+
394+
auto remainder(object const&, object const&) -> object;
395+
396+
auto modulo(object const&, object const&) -> object;
397+
398+
auto gcd(object const&, object const&) -> object;
399+
400+
auto lcm(object const&, object const&) -> object;
401+
374402
auto sqrt(object const&) -> object;
375403

376404
auto pow(object const&, object const&) -> object;
377405

406+
auto numerator(object const&) -> object;
407+
408+
auto denominator(object const&) -> object;
409+
378410
auto floor(object const&) -> object;
379411

380412
auto ceil(object const&) -> object;

include/meevax/kernel/pair.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ inline namespace kernel
4444
return object::allocate<std::decay_t<T>>(std::forward<decltype(x)>(x));
4545
}
4646

47+
template <template <typename...> typename Template, typename... Ts, REQUIRES(std::is_constructible<Template<Ts...>, Ts...>)>
48+
auto make(Ts&&... xs) -> decltype(auto)
49+
{
50+
return make<Template<Ts...>>(std::forward<decltype(xs)>(xs)...);
51+
}
52+
4753
struct pair : public std::pair<object, object>
4854
{
4955
template <auto ReadOnly>

0 commit comments

Comments
 (0)