Skip to content

Commit

Permalink
Update procedure string-fill! to built-in
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Oct 3, 2023
1 parent a8504cf commit 0904663
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 56 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.17_amd64.deb
sudo apt install build/meevax_0.5.18_amd64.deb
```

or
Expand Down Expand Up @@ -131,9 +131,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.17.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.18.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.17_amd64.deb`
| `package` | Generate debian package `meevax_0.5.18_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.17
0.5.18
35 changes: 1 addition & 34 deletions basis/r4rs.ss
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,7 @@
(only (meevax inexact) exp log sqrt sin cos tan asin acos atan)
(meevax list)
(only (meevax macro-transformer) er-macro-transformer identifier?)
(only (meevax number)
number? complex? real? rational? integer?
exact? inexact?
= < > <= >=
zero? positive? negative? odd? even?
max min
+ * - /
abs
quotient remainder modulo
gcd lcm
numerator denominator
floor ceiling truncate round
expt
exact inexact
string->number

; to be removed
exact-integer? ; r7rs
)
(only (meevax number) number? complex? real? rational? integer? exact? inexact? = < > <= >= zero? positive? negative? odd? even? max min + * - / abs quotient remainder modulo gcd lcm numerator denominator floor ceiling truncate round expt exact inexact number->string string->number)
(meevax pair)
(meevax port)
(prefix (meevax read) %)
Expand Down Expand Up @@ -430,21 +412,6 @@

(define substring string-copy)

(define (string-fill! s c . o) ; Chibi-Scheme
(let ((start (if (and (pair? o)
(exact-integer? (car o)))
(car o)
0))
(end (if (and (pair? o)
(pair? (cdr o))
(exact-integer? (cadr o)))
(cadr o)
(string-length s))))
(let rec ((k (- end 1)))
(if (<= start k)
(begin (string-set! s k c)
(rec (- k 1)))))))

(define (for-each f x . xs) ; Chibi-Scheme
(if (null? xs)
(letrec ((for-each (lambda (f x)
Expand Down
94 changes: 76 additions & 18 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,34 @@ inline namespace kernel
return inexact(xs[0]);
});

library.define<function>("number->string", [](let const& xs)
{
switch (length(xs))
{
case 1:
return number_to_string(xs[0], 10);

case 2:
return number_to_string(xs[0], xs[1].as<exact_integer>());

default:
throw error(make<string>("procedure number->string takes one or two arugments, but got"), xs);
}
});

library.define<function>("string->number", [](let const& xs)
{
return make_number(xs[0].as<string>(), 1 < length(xs) ? xs[1].as<exact_integer>() : 10);
switch (length(xs))
{
case 1:
return make_number(xs[0].as<string>(), 10);

case 2:
return make_number(xs[0].as<string>(), xs[1].as<exact_integer>());

default:
throw error(make<string>("procedure string->number takes one or two arugments, but got"), xs);
}
});
});

Expand Down Expand Up @@ -1139,6 +1164,33 @@ inline namespace kernel
std::next(std::begin(s1), xs[1].as<exact_integer>()));
});

library.define<mutation>("string-fill!", [](let & xs)
{
switch (length(xs))
{
case 2:
std::fill(xs[0].as<string>().vector.begin(),
xs[0].as<string>().vector.end(),
xs[1].as<character>());
break;

case 3:
std::fill(std::next(xs[0].as<string>().vector.begin(),
xs[2].as<exact_integer>()),
xs[0].as<string>().vector.end(),
xs[1].as<character>());
break;

case 4:
std::fill(std::next(xs[0].as<string>().vector.begin(),
xs[2].as<exact_integer>()),
std::next(xs[0].as<string>().vector.begin(),
xs[3].as<exact_integer>()),
xs[1].as<character>());
break;
}
});

#define STRING_COMPARE(COMPARE) \
[](let const& xs) \
{ \
Expand Down Expand Up @@ -1168,11 +1220,6 @@ inline namespace kernel
return make_symbol(xs[0].as<string>());
});

library.define<function>("number->string", [](let const& xs)
{
return number_to_string(xs[0], 1 < length(xs) ? xs[1].as<exact_integer>() : 10);
});

library.define<function>("string->list", [](let const& xs)
{
/*
Expand Down Expand Up @@ -1449,18 +1496,29 @@ inline namespace kernel

library.define<mutation>("vector-fill!", [](let & xs)
{
/*
(vector-fill! vector fill) procedure
(vector-fill! vector fill start) procedure
(vector-fill! vector fill start end) procedure
The vector-fill! procedure stores fill in the elements of vector
between start and end.
*/

std::fill(std::next(std::begin(xs[0].as<vector>().vector), 2 < length(xs) ? xs[2].as<exact_integer>() : 0),
std::next(std::begin(xs[0].as<vector>().vector), 3 < length(xs) ? xs[3].as<exact_integer>() : xs[0].as<vector>().vector.size()),
1 < length(xs) ? xs[1] : unspecified);
switch (length(xs))
{
case 2:
std::fill(xs[0].as<vector>().vector.begin(),
xs[0].as<vector>().vector.end(),
xs[1]);
break;

case 3:
std::fill(std::next(xs[0].as<vector>().vector.begin(),
xs[2].as<exact_integer>()),
xs[0].as<vector>().vector.end(),
xs[1]);
break;

case 4:
std::fill(std::next(xs[0].as<vector>().vector.begin(),
xs[2].as<exact_integer>()),
std::next(xs[0].as<vector>().vector.begin(),
xs[3].as<exact_integer>()),
xs[1]);
break;
}
});

library.define<function>("vector->list", [](let const& xs)
Expand Down

0 comments on commit 0904663

Please sign in to comment.