Skip to content

Commit

Permalink
Rename struct function to procedure
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 7, 2023
1 parent 256e118 commit b12d9a1
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 167 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.26_amd64.deb
sudo apt install build/meevax_0.5.27_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.26.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.27.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.26_amd64.deb`
| `package` | Generate debian package `meevax_0.5.27_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.26
0.5.27
2 changes: 1 addition & 1 deletion example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C"

auto dummy_procedure(object const& xs)
{
std::cout << "\n; calling C++ function via foreign-function-interface." << std::endl;
std::cout << "\n; calling C++ function." << std::endl;

std::size_t count = 0;

Expand Down
22 changes: 11 additions & 11 deletions example/example.ss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(import (only (meevax procedure) foreign-function? foreign-function)
(import (only (meevax procedure) procedure)
(scheme base)
(scheme process-context)
(scheme write)
Expand All @@ -7,37 +7,37 @@
; ------------------------------------------------------------------------------

(define dummy-procedure
(foreign-function "build/libexample.so" "dummy_procedure"))
(procedure "build/libexample.so" "dummy_procedure"))

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

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

; ------------------------------------------------------------------------------

(define length-of-arguments
(foreign-function "build/libexample.so" "length_of_arguments"))
(procedure "build/libexample.so" "length_of_arguments"))

(check (foreign-function? length-of-arguments) => #t)
(check (procedure? length-of-arguments) => #t)

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

; ------------------------------------------------------------------------------

(define make-hoge
(foreign-function "build/libexample.so" "make_hoge"))
(procedure "build/libexample.so" "make_hoge"))

(define hoge?
(foreign-function "build/libexample.so" "is_hoge"))
(procedure "build/libexample.so" "is_hoge"))

(define hoge-value
(foreign-function "build/libexample.so" "hoge_value"))
(procedure "build/libexample.so" "hoge_value"))

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

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

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

(define h (make-hoge 100))

Expand Down
12 changes: 6 additions & 6 deletions include/meevax/kernel/dynamic_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@ inline namespace kernel
s = unit;
goto fetch;
}
else if (callee.is_also<procedure>()) /* -----------------------------
else if (callee.is_also<callable>()) /* ------------------------------
*
* (<procedure> xs . s) e (%call . c) d => (x . s) e c d
* (<callable> xs . s) e (%call . c) d => (x . s) e c d
*
* where x = procedure(xs)
*
* ----------------------------------------------------------------- */
{
assert(tail(c, 1).template is<pair>());
s = cons(callee.as<procedure>()(cadr(s)), cddr(s));
s = cons(callee.as<callable>()(cadr(s)), cddr(s));
c = cdr(c);
goto fetch;
}
Expand Down Expand Up @@ -336,17 +336,17 @@ inline namespace kernel
s = unit;
goto fetch;
}
else if (callee.is_also<procedure>()) /* -----------------------------
else if (callee.is_also<callable>()) /* ------------------------------
*
* (<procedure> xs) e (%tail-call) (s' e' c' . d) => (x . s') e' c' d
* (<callable> xs) e (%tail-call) (s' e' c' . d) => (x . s') e' c' d
*
* where x = procedure(xs)
*
* ----------------------------------------------------------------- */
{
assert(tail(s, 2).template is<null>());
assert(tail(c, 1).template is<null>());
s = cons(callee.as<procedure>()(cadr(s)), car(d));
s = cons(callee.as<callable>()(cadr(s)), car(d));
e = cadr(d);
c = caddr(d);
d = cdddr(d);
Expand Down
42 changes: 21 additions & 21 deletions include/meevax/kernel/procedure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,44 @@ namespace meevax
{
inline namespace kernel
{
struct procedure
struct callable
{
std::string const name;

explicit procedure(std::string const& name)
explicit callable(std::string const& name)
: name { name }
{}

virtual auto operator ()(object & = unit) const -> object = 0;
};

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

#define FUNCTION(...) auto __VA_ARGS__(meevax::object const& xs) -> meevax::object

struct function : public procedure
struct procedure : public callable
{
auto (*call)(object const&) -> object;

explicit function(std::string const& name, auto (*call)(object const&) -> object)
: procedure { name }
explicit procedure(std::string const& name, auto (*call)(object const&) -> object)
: callable { name }
, call { call }
{}

explicit function(std::string const&, std::string const&);
explicit procedure(std::string const&, std::string const&);

auto operator ()(object & xs) const -> object override
{
return call(xs);
}
};

struct functor : public procedure
struct functor : public callable
{
#define FUNCTION(...) auto __VA_ARGS__(meevax::object const& xs) -> meevax::object

std::function<FUNCTION()> const call;

explicit functor(std::string const& name, std::function<FUNCTION()> const& call)
: procedure { name }
: callable { name }
, call { call }
{}

Expand All @@ -72,12 +72,12 @@ inline namespace kernel
}
};

struct accessor : public procedure
struct accessor : public callable
{
auto (*call)(object const&) -> object const&;

explicit accessor(std::string const& name, auto (*call)(object const&) -> object const&)
: procedure { name }
: callable { name }
, call { call }
{}

Expand All @@ -87,12 +87,12 @@ inline namespace kernel
}
};

struct predicate : public procedure
struct predicate : public callable
{
auto (*call)(object const&) -> bool;

explicit predicate(std::string const& name, auto (*call)(object const&) -> bool)
: procedure { name }
: callable { name }
, call { call }
{}

Expand All @@ -102,12 +102,12 @@ inline namespace kernel
}
};

struct mutation : public procedure
struct mutation : public callable
{
auto (*call)(object &) -> void;

explicit mutation(std::string const& name, auto (*call)(object &) -> void)
: procedure { name }
: callable { name }
, call { call }
{}

Expand All @@ -118,12 +118,12 @@ inline namespace kernel
}
};

struct command : public procedure
struct command : public callable
{
auto (*call)(object const&) -> void;

explicit command(std::string const& name, auto (*call)(object const&) -> void)
: procedure { name }
: callable { name }
, call { call }
{}

Expand All @@ -134,12 +134,12 @@ inline namespace kernel
}
};

struct thunk : public procedure
struct thunk : public callable
{
auto (*call)() -> object;

explicit thunk(std::string const& name, auto (*call)() -> object)
: procedure { name }
: callable { name }
, call { call }
{}

Expand Down
Loading

0 comments on commit b12d9a1

Please sign in to comment.