Skip to content

Commit

Permalink
Update digit-value to account for characters in the non-ASCII range
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Sep 16, 2023
1 parent 3238345 commit 9a261ac
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
include/meevax/kernel/digit_value.hpp
src/kernel/basis.cpp
src/kernel/version.cpp
32 changes: 8 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,25 @@ else()
set(${PROJECT_NAME}_BYTE_ORDER "little-endian")
endif()

set(${PROJECT_NAME}_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/configure/UnicodeData.txt)
set(${PROJECT_NAME}_OBJECTS "")
foreach(EACH IN LISTS ${PROJECT_NAME}_RESOURCES)
get_filename_component(FILENAME ${EACH} NAME)
get_filename_component(FILEPATH ${EACH} PATH)
message(STATUS "Copying resource ${EACH} as ")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}.o
WORKING_DIRECTORY ${FILEPATH}
COMMAND ${CMAKE_OBJCOPY}
ARGS -I binary
-O elf64-x86-64
-B i386
${FILENAME}
${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}.o)
list(APPEND ${PROJECT_NAME}_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}.o)
endforeach()
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/script/unicode.sh --digit-value
OUTPUT_VARIABLE ${PROJECT_NAME}_DIGIT_VALUE)

file(GLOB ${PROJECT_NAME}_BASIS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/basis/*.ss)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/configure/help.txt ${PROJECT_NAME}_HELP_UNCONFIGURED)
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/kernel/digit_value.hpp ${${PROJECT_NAME}_DIGIT_VALUE})

string(CONFIGURE ${${PROJECT_NAME}_HELP_UNCONFIGURED} ${PROJECT_NAME}_HELP)

string(TOLOWER ${CMAKE_SYSTEM_NAME} ${PROJECT_NAME}_SYSTEM_NAME)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/version.cpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/README.md ${CMAKE_CURRENT_SOURCE_DIR}/README.md)

file(GLOB ${PROJECT_NAME}_BASIS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/basis/*.ss)

foreach(EACH IN LISTS ${PROJECT_NAME}_BASIS_SOURCES)
get_filename_component(FILENAME ${EACH} NAME)
file(READ ${EACH} ${PROJECT_NAME}_BASIS_${FILENAME})
endforeach()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/basis.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/basis.cpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/README.md ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/basis.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/basis.cpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/version.cpp)

# ---- Target kernel -----------------------------------------------------------

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Subset of R7RS-small.
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.4.796_amd64.deb
sudo apt install build/meevax_0.4.797_amd64.deb
```

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

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

## Usage

```
Meevax Lisp 0.4.796
Meevax Lisp 0.4.797
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.796
0.4.797
6 changes: 4 additions & 2 deletions include/meevax/kernel/character.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ inline namespace kernel
return std::char_traits<char_type>::eq_int_type(c1, c2);
}

inline constexpr auto eq(int_type const& c) const
constexpr auto eq(int_type const& c) const
{
return std::char_traits<char_type>::eq_int_type(codepoint, c);
}

auto digit_value() const -> object const&;

static constexpr auto is_ascii(int_type c)
{
return 0x00 <= c and c <= 0x7F;
Expand All @@ -62,7 +64,7 @@ inline namespace kernel
return eq(eof(), c);
}

inline constexpr operator int_type() const
constexpr operator int_type() const
{
return codepoint;
}
Expand Down
30 changes: 0 additions & 30 deletions include/meevax/kernel/unicode.hpp

This file was deleted.

38 changes: 38 additions & 0 deletions script/unicode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh -e

# https://www.unicode.org/L2/L1999/UnicodeData.html
#
# \1 = Code value
# \2 = Character name
# \3 = General category
# \4 = Canonical combining classes
# \5 = Bidirectional category
# \6 = Character decomposition mapping
# \7 = Decimal digit value
# \8 = Digit value
# \9 = Numeric value
# \10 = Mirrored
# \11 = Unicode 1.0 Name
# \12 = 10646 comment field
# \13 = Uppercase mapping
# \14 = Lowercase mapping
# \15 = Titlecase mapping

unicode_data='^([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);(.*)$'

substitute()
{
sed -E "s/$unicode_data/$1/g" "$(git rev-parse --show-toplevel)/configure/UnicodeData.txt"
}

digit_value()
{
substitute '{ 0x\1, make_number("\9") },' | grep -e '{ .\+, make_number(".\+") },'
}

for each in "$@"
do
case "$each" in
--digit-value ) digit_value ;;
esac
done
9 changes: 1 addition & 8 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,7 @@ inline namespace kernel

library.define<function>("digit-value", [](let const& xs)
{
if (auto c = xs[0].as<character>(); std::isdigit(c.codepoint))
{
return make<exact_integer>(c.codepoint - '0');
}
else
{
return f;
}
return xs[0].as<character>().digit_value();
});

library.define<function>("integer->char", [](let const& xs)
Expand Down
18 changes: 18 additions & 0 deletions src/kernel/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,31 @@
limitations under the License.
*/

#include <meevax/kernel/boolean.hpp>
#include <meevax/kernel/eof.hpp>
#include <meevax/kernel/error.hpp>
#include <meevax/kernel/number.hpp>

namespace meevax
{
inline namespace kernel
{
auto character::digit_value() const -> object const&
{
static const std::unordered_map<character::int_type, object> table {
#include <meevax/kernel/digit_value.hpp>
};

if (auto iterator = table.find(codepoint); iterator != table.end())
{
return iterator->second;
}
else
{
return f;
}
}

character::operator std::string() const
{
auto chars = std::array<char, 5>();
Expand Down
31 changes: 0 additions & 31 deletions src/kernel/unicode.cpp

This file was deleted.

8 changes: 4 additions & 4 deletions test/r7rs.ss
Original file line number Diff line number Diff line change
Expand Up @@ -1299,11 +1299,11 @@

(check (digit-value #\3) => 3)

; (check (digit-value #\x0664) => 4)
(check (digit-value #\x0664) => 4)

; (check (digit-value #\x0AE6) => 0)
(check (digit-value #\x0AE6) => 0)

; (check (digit-value #\x0EA6) => #f) ; BUG: MEMORY-LEAK
(check (digit-value #\x0EA6) => #f)

; ---- 6.7. --------------------------------------------------------------------

Expand Down Expand Up @@ -1619,4 +1619,4 @@

(check-report)

(exit (check-passed? 429))
(exit (check-passed? 432))

0 comments on commit 9a261ac

Please sign in to comment.