Skip to content

Commit

Permalink
Merge pull request #457 from yamacir-kit/syntactic-closure
Browse files Browse the repository at this point in the history
Syntactic closure
  • Loading branch information
yamacir-kit authored Jul 19, 2023
2 parents d0f129b + f2f5d83 commit 04e0b2f
Show file tree
Hide file tree
Showing 21 changed files with 576 additions and 646 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|--------------------|---
| `all` (default) | Build shared-library `libmeevax.0.4.733.so` and executable `meevax`
| `all` (default) | Build shared-library `libmeevax.0.4.752.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.4.733_amd64.deb`
| `package` | Generate debian package `meevax_0.4.752_amd64.deb`
| `install` | Copy files into `/usr/local`
| `install.deb` | `all` + `package` + `sudo apt install <meevax>.deb`

## Usage

```
Meevax Lisp 0.4.733
Meevax Lisp 0.4.752
Usage:
meevax [option...] [file...]
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.733
0.4.752
16 changes: 9 additions & 7 deletions basis/r4rs.ss
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,24 @@
(else (inexact (denominator (exact x))))))

(define (rationalize x e) ; from Chibi-Scheme lib/scheme/extras.scm (https://ml.cddddr.org/scheme/msg01498.html)
(define (sr x y return)
(define (simplest-rational x y return)
(let ((fx (floor x))
(fy (floor y)))
(cond ((>= fx x) (return fx 1))
((= fx fy) (sr (/ (- y fy))
(/ (- x fx))
(lambda (n d)
(return (+ d (* fx n)) n))))
(cond ((>= fx x)
(return fx 1))
((= fx fy)
(simplest-rational (/ (- y fy))
(/ (- x fx))
(lambda (n d)
(return (+ d (* fx n)) n))))
(else (return (+ fx 1) 1)))))
(let ((return (if (negative? x)
(lambda (num den)
(/ (- num) den))
/))
(x (abs x))
(e (abs e)))
(sr (- x e) (+ x e) return)))
(simplest-rational (- x e) (+ x e) return)))

(define (make-rectangular x y)
(+ x (* y (sqrt -1))))
Expand Down
8 changes: 4 additions & 4 deletions include/meevax/kernel/dynamic_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ inline namespace kernel
* ----------------------------------------------------------------- */
assert(cadr(c).template is<absolute>());

if (let const& value = cadr(c).template as<absolute>().load(); value == undefined)
if (let const& x = cdadr(c); x == undefined)
{
throw error(make<string>("undefined variable"), cadr(c).template as<absolute>().symbol());
throw error(make<string>("undefined variable"), caadr(c));
}
else
{
s = cons(cadr(c).template as<absolute>().load(), s);
s = cons(x, s);
c = cddr(c);
goto fetch;
}
Expand Down Expand Up @@ -456,7 +456,7 @@ inline namespace kernel
*
* ----------------------------------------------------------------- */
assert(cadr(c).template is<absolute>());
cadr(c).template as<absolute>().store(car(s));
cdadr(c) = car(s);
c = cddr(c);
goto fetch;

Expand Down
12 changes: 2 additions & 10 deletions include/meevax/kernel/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,11 @@ inline namespace kernel
{
using syntactic_environment::syntactic_environment;

template <typename T, typename... Ts>
auto declare(Ts&&... xs) -> decltype(auto)
{
return std::invoke(std::decay_t<T>(std::forward<decltype(xs)>(xs)...), *this);
}

auto evaluate(object const&) -> object;

auto load(std::string const&) -> void;

auto operator [](object const&) -> object const&;
auto import(object const&) -> void;

auto operator [](std::string const&) -> object const&;
auto load(std::string const&) -> void;
};

auto operator <<(std::ostream &, environment const&) -> std::ostream &;
Expand Down
39 changes: 0 additions & 39 deletions include/meevax/kernel/export_spec.hpp

This file was deleted.

24 changes: 6 additions & 18 deletions include/meevax/kernel/identity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,16 @@ inline namespace kernel
using index = std::uint32_t;
};

struct absolute : public identity
, public virtual pair // (<symbol> . <object>)
struct absolute : public virtual pair // (<identifier> . <object>)
, public identity
{
using pair::pair;

auto load() const -> object const&;

template <typename T>
auto load() const -> decltype(auto)
{
return load().as<T>();
}

auto store(object const&) -> void;

auto symbol() const -> object const&;
};

auto operator <<(std::ostream &, absolute const&) -> std::ostream &;

struct relative : public identity
, public virtual pair // de Bruijn index
struct relative : public virtual pair // de Bruijn index
, public identity
{
using pair::pair;
};
Expand All @@ -59,8 +47,8 @@ inline namespace kernel
return false; // for free-identifier=?
}

struct variadic : public identity
, public virtual pair // de Bruijn index
struct variadic : public virtual pair // de Bruijn index
, public identity
{
using pair::pair;
};
Expand Down
41 changes: 0 additions & 41 deletions include/meevax/kernel/import_set.hpp

This file was deleted.

5 changes: 5 additions & 0 deletions include/meevax/kernel/input_string_port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ inline namespace kernel
};

auto operator <<(std::ostream &, input_string_port const&) -> std::ostream &;

namespace literals
{
auto operator ""_read(char const*, std::size_t) -> object;
} // namespace literals
} // namespace kernel
} // namespace meevax

Expand Down
20 changes: 3 additions & 17 deletions include/meevax/kernel/library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define INCLUDED_MEEVAX_KERNEL_LIBRARY_HPP

#include <meevax/kernel/environment.hpp>
#include <meevax/kernel/export_spec.hpp>
#include <meevax/kernel/interaction_environment.hpp>

namespace meevax
Expand All @@ -29,7 +28,7 @@ inline namespace kernel
{
let declarations = unit;

let subset = unit;
let export_specs = unit;

template <typename F, REQUIRES(std::is_invocable<F, library &>)>
explicit library(F declare)
Expand All @@ -41,29 +40,16 @@ inline namespace kernel

friend auto boot() -> void;

template <typename T, typename... Ts>
auto declare(Ts&&... xs) -> decltype(auto)
{
if constexpr (std::is_invocable_v<T, library &>)
{
return std::invoke(std::decay_t<T>(std::forward<decltype(xs)>(xs)...), *this);
}
else
{
return environment::declare<T>(std::forward<decltype(xs)>(xs)...);
}
}

template <typename T, typename... Ts>
auto define(std::string const& name, Ts&&... xs) -> void
{
environment::define<T>(name, std::forward<decltype(xs)>(xs)...);
declare<export_spec>(input_string_port(name).read());
export_specs = cons(input_string_port(name).read(), export_specs);
}

auto evaluate(object const&) -> void;

auto resolve() -> object const&;
auto resolve() -> object;
};

auto operator <<(std::ostream &, library const&) -> std::ostream &;
Expand Down
2 changes: 2 additions & 0 deletions include/meevax/kernel/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ inline namespace kernel
return unit;
}
}

auto longest_common_tail(let const&, let const&) -> object const&;
} // namespace kernel
} // namespace meevax

Expand Down
Loading

0 comments on commit 04e0b2f

Please sign in to comment.