Skip to content

Commit

Permalink
Update syntactic_closure to have elements directly as class members
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Aug 4, 2024
1 parent f89b3cb commit c704ea0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 46 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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.213_amd64.deb
sudo apt install build/meevax_0.5.214_amd64.deb
```

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

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.213.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.214.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.213_amd64.deb`
| `package` | Generate debian package `meevax_0.5.214_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.213
0.5.214
89 changes: 48 additions & 41 deletions include/meevax/kernel/syntactic_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,36 @@ inline namespace kernel
template <typename Environment>
struct syntactic_environment : public virtual pair // (<bound-variables> . <free-variables>)
{
struct syntactic_closure : public virtual pair // (<syntactic-environment> <free-names> . <expression>)
, public identifier
struct syntactic_closure : public identifier
{
template <typename... Ts>
auto compile(let const& user, Ts&&... xs)
let macro_environment, free_names, expression;

explicit syntactic_closure(let const& macro_environment,
let const& free_names,
let const& expression)
: macro_environment { macro_environment }
, free_names { free_names }
, expression { expression }
{
assert(user.is<syntactic_environment>());

let const& maker = car(*this);

let const& free_variables = cadr(*this);

let const& expression = cddr(*this);
assert(macro_environment.is<syntactic_environment>());
}

return maker.as<syntactic_environment>().compile(expression,
unify(car(maker), car(user)),
map([&](let const& free_variable)
{
return cons(free_variable, user);
},
free_variables,
cdr(user)
),
std::forward<decltype(xs)>(xs)...);
template <typename... Ts>
auto compile(let const& use_environment, Ts&&... xs)
{
assert(use_environment.is<syntactic_environment>());

return macro_environment.as<syntactic_environment>()
.compile(expression,
unify(car(macro_environment),
car(use_environment)),
map([&](let const& free_name)
{
return cons(free_name, use_environment);
},
free_names,
cdr(use_environment)),
std::forward<decltype(xs)>(xs)...);
}

friend auto operator ==(syntactic_closure const& x, syntactic_closure const& y) -> bool
Expand All @@ -67,24 +73,21 @@ inline namespace kernel
as else in a cond clause. A macro definition for syntax-rules would
use free-identifier=? to look for literals in the input.
*/
assert(car(x).template is<syntactic_environment>());
assert(car(y).template is<syntactic_environment>());

return cddr(x).template is_also<identifier>() and
cddr(y).template is_also<identifier>() and
eqv(car(x).template as<syntactic_environment>()
.identify(cddr(x),
caar(x),
nullptr),
car(y).template as<syntactic_environment>()
.identify(cddr(y),
caar(y),
nullptr));
return x.expression.is_also<identifier>() and
y.expression.is_also<identifier>() and
eqv(x.macro_environment.as<syntactic_environment>()
.identify(x.expression,
car(x.macro_environment),
nullptr),
y.macro_environment.as<syntactic_environment>()
.identify(y.expression,
car(y.macro_environment),
nullptr));
}

friend auto operator <<(std::ostream & os, syntactic_closure const& datum) -> std::ostream &
{
return os << underline(cddr(datum));
return os << underline(datum.expression);
}
};

Expand Down Expand Up @@ -478,7 +481,8 @@ inline namespace kernel

static GENERATOR(quote)
{
return CONS(make(instruction::load_constant), car(expression).is<syntactic_closure>() ? cddar(expression) : car(expression),
return CONS(make(instruction::load_constant), car(expression).is<syntactic_closure>() ? car(expression).as<syntactic_closure>().expression
: car(expression),
continuation);
}

Expand Down Expand Up @@ -981,10 +985,13 @@ inline namespace kernel

if (variable.is<syntactic_closure>())
{
return car(variable).as<syntactic_environment>()
.identify(cddr(variable),
unify(caar(variable), bound_variables),
nullptr);
return variable.as<syntactic_closure>()
.macro_environment
.template as<syntactic_environment>()
.identify(variable.as<syntactic_closure>().expression,
unify(car(variable.as<syntactic_closure>().macro_environment),
bound_variables),
nullptr);
}
else
{
Expand Down Expand Up @@ -1037,7 +1044,7 @@ inline namespace kernel

static auto rename(std::string const& variable)
{
return make<syntactic_closure>(core(), cons(nullptr, make_symbol(variable)));
return make<syntactic_closure>(core(), unit, make_symbol(variable));
}

inline auto sweep(object const& form,
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ inline namespace kernel

library.define<procedure>("make-syntactic-closure", [](let const& xs)
{
return make<syntactic_closure>(car(xs), cons(cadr(xs), caddr(xs)));
return make<syntactic_closure>(car(xs), cadr(xs), caddr(xs));
});
});

Expand Down

0 comments on commit c704ea0

Please sign in to comment.