diff --git a/CMakeLists.txt b/CMakeLists.txt index dcd7e9160..1679c8721 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,7 @@ cmake_minimum_required(VERSION 3.16.3) # Ubuntu 20.04 LTS default execute_process( - COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/VERSION - COMMAND tr -d "\n" + COMMAND head -c -1 ${CMAKE_CURRENT_SOURCE_DIR}/VERSION OUTPUT_VARIABLE CURRENT_VERSION) project(meevax @@ -13,8 +12,7 @@ project(meevax include(GNUInstallDirs) -string(JOIN " " AGGRESSIVE_OPTIMIZATION_OPTIONS - # "-flto" # This optimization causes a SEGV when compiling with Clang 10. +string(JOIN " " ${PROJECT_NAME}_RELEASE_PLUS # "-fmerge-all-constants" # This optimization is very effective in reducing binary size, but non-standard to the C++ standard. # "-march=native" # This optimization causes "Illegal instruction" error (is Valgrind's bug) on CI. # "-mtune=native" @@ -23,8 +21,8 @@ string(JOIN " " AGGRESSIVE_OPTIMIZATION_OPTIONS set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_FLAGS_DEBUG "-Og -gdwarf-4") # NOTE: The `-gdwarf-4` option is set due to the following issues with Clang 14 and Valgrind versions below 3.20: https://bugzilla.mozilla.org/show_bug.cgi?id=1758782 set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") -set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${AGGRESSIVE_OPTIMIZATION_OPTIONS}") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gdwarf-4 -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -DNDEBUG ${${PROJECT_NAME}_RELEASE_PLUS}") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-4") set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -pipe") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/README.md b/README.md index 6a483660c..96d355cd0 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,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.119_amd64.deb +sudo apt install build/meevax_0.5.159_amd64.deb ``` or @@ -123,9 +123,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |-------------|------------- -| `all` | Build shared-library `libmeevax.0.5.119.so` and executable `meevax` +| `all` | Build shared-library `libmeevax.0.5.159.so` and executable `meevax` | `test` | Test executable `meevax` -| `package` | Generate debian package `meevax_0.5.119_amd64.deb` +| `package` | Generate debian package `meevax_0.5.159_amd64.deb` | `install` | Copy files into `/usr/local` directly ## Usage diff --git a/VERSION b/VERSION index e8b2b30cf..7948d08ba 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.119 +0.5.159 diff --git a/basis/include/meevax/basis.hpp b/basis/include/meevax/basis.hpp index 9fe642b3a..c983fca78 100644 --- a/basis/include/meevax/basis.hpp +++ b/basis/include/meevax/basis.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/basis/meevax.ss b/basis/meevax.ss index 098b20678..914877bf1 100644 --- a/basis/meevax.ss +++ b/basis/meevax.ss @@ -98,3 +98,45 @@ ((cdr before/after))) (current-dynamic-extents)) (emergency-exit . xs))))) + +(define-library (meevax apply) + (import (only (meevax core) define if lambda) + (only (meevax list) append null? reverse) + (only (meevax pair) car cdr cons)) + + (export apply) + + (begin (define (apply f x . xs) + (if (null? xs) + (f . x) + ((lambda (xs) + ((lambda (x) + (f . x)) + (append (reverse (cdr xs)) + (car xs)))) + (reverse (cons x xs))))))) + +(define-library (meevax map) + (import (only (meevax apply) apply) + (only (meevax core) define if quote) + (only (meevax list) memq null? reverse) + (only (meevax pair) car cdr cons)) + + (export map) + + (begin (define (map f . xs) + (define (map f x a) + (if (null? x) + (reverse a) + (map f + (cdr x) + (cons (f (car x)) a)))) + (define (map* f xs a) + (if (memq '() xs) + (reverse a) + (map* f + (map cdr xs '()) + (cons (apply f (map car xs '())) a)))) + (if (null? (cdr xs)) + (map f (car xs) '()) + (map* f xs '()))))) diff --git a/basis/r4rs.ss b/basis/r4rs.ss index 71a31bfff..20714a17b 100644 --- a/basis/r4rs.ss +++ b/basis/r4rs.ss @@ -35,7 +35,8 @@ |# (define-library (scheme r4rs) - (import (only (meevax boolean) boolean? not) + (import (only (meevax apply) apply) + (only (meevax boolean) boolean? not) (only (meevax character) char? char=? char? char<=? char>=? char-ci=? char-ci? char-ci<=? char-ci>=? char-alphabetic? char-numeric? char-whitespace? char-upper-case? char-lower-case? char->integer integer->char char-upcase char-downcase) (only (meevax comparator) eq? eqv? equal?) (only (meevax complex) make-rectangular make-polar real-part imag-part magnitude angle) @@ -44,6 +45,7 @@ (only (meevax inexact) exp log sqrt sin cos tan asin acos atan) (only (meevax list) null? list? list length append reverse list-tail list-ref memq memv assq assv) (only (meevax macro-transformer) er-macro-transformer identifier?) + (only (meevax map) map) (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) (only (meevax pair) pair? cons car cdr set-car! set-cdr! caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr) (only (meevax port) input-port? output-port? standard-input-port standard-output-port open-input-file open-output-file close eof-object?) @@ -51,9 +53,10 @@ (only (meevax string) string? make-string string string-length string-ref string-set! string=? string? string<=? string>=? string-ci=? string-ci? string-ci<=? string-ci>=? string-append string->list list->string string-copy string-fill!) (only (meevax symbol) symbol? symbol->string string->symbol) (only (meevax vector) vector? make-vector vector vector-length vector-ref vector-set! vector->list list->vector vector-fill!) - (prefix (only (meevax environment) load) %) (prefix (meevax read) %) (prefix (meevax write) %) + (prefix (only (meevax environment) load) %) + (only (srfi 39) make-parameter parameterize) (only (srfi 45) delay force)) (export quote lambda if set! cond case and or let let* letrec begin do delay @@ -183,39 +186,6 @@ (else x))) (expand (cadr form) 0)))) - (define (every f xs) - (if (pair? xs) - (and (f (car xs)) - (every f (cdr xs))) - #t)) - - (define (map f x . xs) ; Chibi-Scheme - (define (map f x a) - (if (pair? x) - (map f - (cdr x) - (cons (f (car x)) a)) - (reverse a))) - (define (map* f xs a) - (if (every pair? xs) - (map* f - (map cdr xs '()) - (cons (apply f (map car xs '())) a)) - (reverse a))) - (if (null? xs) - (map f x '()) - (map* f (cons x xs) '()))) - - (define (apply f x . xs) ; Chibi-Scheme - (letrec ((apply (lambda (f xs) - (f . xs)))) - (if (null? xs) - (apply f x) - ((lambda (xs) - (apply f (append (reverse (cdr xs)) - (car xs)))) - (reverse (cons x xs)))))) - (define-syntax let ; Chibi-Scheme (er-macro-transformer (lambda (form rename compare) @@ -310,8 +280,7 @@ (else (+ 1 fx))))) (cond ((< y x) (simplest-rational y x)) - ((not (< x y)) - (if (rational? x) x (error x))) + ((not (< x y)) x) ((positive? x) (simplest-rational-internal x y)) ((negative? x) @@ -348,25 +317,23 @@ result)) (call-with-output-port (open-output-file path) f)) - (define %current-input-port (standard-input-port)) - - (define (current-input-port) %current-input-port) - - (define %current-output-port (standard-output-port)) + (define current-input-port + (make-parameter (standard-input-port))) - (define (current-output-port) %current-output-port) + (define current-output-port + (make-parameter (standard-output-port))) (define (with-input-from-file path thunk) - (let ((previous-input-port (current-input-port))) - (set! %current-input-port (open-input-file path)) - (thunk) - (set! %current-input-port previous-input-port))) + (parameterize ((current-input-port (open-input-file path))) + (let ((result (thunk))) + (close-input-port (current-input-port)) + result))) (define (with-output-to-file path thunk) - (let ((previous-output-port (current-output-port))) - (set! %current-output-port (open-output-file path)) - (thunk) - (set! %current-output-port previous-output-port))) + (parameterize ((current-output-port (open-output-file path))) + (let ((result (thunk))) + (close-output-port (current-output-port)) + result))) (define close-input-port close) diff --git a/basis/r7rs.ss b/basis/r7rs.ss index 22353c49b..7b5d562d4 100644 --- a/basis/r7rs.ss +++ b/basis/r7rs.ss @@ -1,15 +1,15 @@ (define-library (scheme base) (import (only (meevax core) include include-case-insensitive) (only (meevax error) error-object? read-error? file-error?) - (only (meevax macro-transformer) er-macro-transformer) (only (meevax list) make-list list-copy) + (only (meevax macro-transformer) er-macro-transformer) (only (meevax number) exact-integer? exact-integer-square-root) (only (meevax port) binary-port? eof-object flush get-output-u8vector open-input-u8vector open-output-u8vector open? port? standard-error-port standard-input-port standard-output-port textual-port?) - (prefix (meevax read) %) (only (meevax string) string-copy!) (only (meevax vector homogeneous) u8vector? make-u8vector u8vector u8vector-length u8vector-ref u8vector-set! u8vector-copy u8vector-copy! u8vector-append u8vector->string string->u8vector) (only (meevax vector) vector-append vector-copy vector-copy! vector->string string->vector) (only (meevax version) features) + (prefix (meevax read) %) (prefix (meevax write) %) (scheme r5rs) (srfi 0) @@ -250,32 +250,8 @@ (define output-port-open? open?) - (define current-input-port - (make-parameter (standard-input-port) - (lambda (x) - (cond ((not (input-port? x)) - (error "not an input-port" x)) - ((not (input-port-open? x)) - (error "not an opened input-port" x)) - (else x))))) - - (define current-output-port - (make-parameter (standard-output-port) - (lambda (x) - (cond ((not (output-port? x)) - (error "not an output-port" x)) - ((not (output-port-open? x)) - (error "not an opened output-port" x)) - (else x))))) - (define current-error-port - (make-parameter (standard-error-port) - (lambda (x) - (cond ((not (output-port? x)) - (error "not an output-port" x)) - ((not (output-port-open? x)) - (error "not an opened output-port" x)) - (else x))))) + (make-parameter (standard-error-port))) (define (close-port x) (cond ((input-port? x) (close-input-port x)) @@ -440,21 +416,10 @@ (import (only (meevax file) delete-file file-exists?) (only (meevax port) open-binary-input-file open-binary-output-file) (only (scheme base) close-input-port close-output-port current-input-port current-output-port define parameterize) - (only (scheme r5rs) call-with-input-file call-with-output-file open-input-file open-output-file)) - + (only (scheme r5rs) call-with-input-file call-with-output-file open-input-file open-output-file with-input-from-file with-output-to-file)) (export call-with-input-file call-with-output-file delete-file file-exists? open-binary-input-file open-binary-output-file open-input-file - open-output-file with-input-from-file with-output-to-file) - - (begin (define (with-input-from-file path thunk) - (parameterize ((current-input-port (open-input-file path))) - (thunk) - (close-input-port (current-input-port)))) - - (define (with-output-to-file path thunk) - (parameterize ((current-output-port (open-output-file path))) - (thunk) - (close-output-port (current-output-port)))))) + open-output-file with-input-from-file with-output-to-file)) (define-library (scheme inexact) (import (only (meevax inexact) finite? infinite? nan?) diff --git a/basis/srfi-39.ss b/basis/srfi-39.ss index 85abb1c21..ec61a2800 100644 --- a/basis/srfi-39.ss +++ b/basis/srfi-39.ss @@ -26,9 +26,8 @@ (only (meevax core) define define-syntax if lambda letrec quote) (only (meevax list) null? list append assq) (only (meevax macro-transformer) er-macro-transformer) - (only (meevax pair) cons car cdr cadr cddr set-car! set-cdr!) - (only (scheme r5rs) map) - ) + (only (meevax map) map) + (only (meevax pair) cons car cdr cadr cddr set-car! set-cdr!)) (export make-parameter parameterize) diff --git a/configure/basis.cpp b/configure/basis.cpp index cc6bc4a33..2dc0cd7b1 100644 --- a/configure/basis.cpp +++ b/configure/basis.cpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/configure/version.cpp b/configure/version.cpp index 45847c87e..732ec34ab 100644 --- a/configure/version.cpp +++ b/configure/version.cpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/bit/bit_cast.hpp b/include/meevax/bit/bit_cast.hpp index 352214aa3..43108b9c2 100644 --- a/include/meevax/bit/bit_cast.hpp +++ b/include/meevax/bit/bit_cast.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/bit/log2.hpp b/include/meevax/bit/log2.hpp index a5acc705b..c6de7be60 100644 --- a/include/meevax/bit/log2.hpp +++ b/include/meevax/bit/log2.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/bitset/simple_bitset.hpp b/include/meevax/bitset/simple_bitset.hpp index b5f55e6aa..9ea4f7aab 100644 --- a/include/meevax/bitset/simple_bitset.hpp +++ b/include/meevax/bitset/simple_bitset.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/chrono/duration.hpp b/include/meevax/chrono/duration.hpp index 28e657457..4b3999961 100644 --- a/include/meevax/chrono/duration.hpp +++ b/include/meevax/chrono/duration.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/functional/combinator.hpp b/include/meevax/functional/combinator.hpp index 9eecbee1c..9aeec4f31 100644 --- a/include/meevax/functional/combinator.hpp +++ b/include/meevax/functional/combinator.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/functional/compose.hpp b/include/meevax/functional/compose.hpp index 347b792d5..ada1c2c94 100644 --- a/include/meevax/functional/compose.hpp +++ b/include/meevax/functional/compose.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/functional/curry.hpp b/include/meevax/functional/curry.hpp index 51387b612..b659549ca 100644 --- a/include/meevax/functional/curry.hpp +++ b/include/meevax/functional/curry.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/iostream/escape_sequence.hpp b/include/meevax/iostream/escape_sequence.hpp index e758263cd..0c09990a3 100644 --- a/include/meevax/iostream/escape_sequence.hpp +++ b/include/meevax/iostream/escape_sequence.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/iostream/is_console.hpp b/include/meevax/iostream/is_console.hpp index 55c148b66..31e1a4d18 100644 --- a/include/meevax/iostream/is_console.hpp +++ b/include/meevax/iostream/is_console.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/iostream/lexical_cast.hpp b/include/meevax/iostream/lexical_cast.hpp index 9539e631c..d59ada057 100644 --- a/include/meevax/iostream/lexical_cast.hpp +++ b/include/meevax/iostream/lexical_cast.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/iterator/index_iterator.hpp b/include/meevax/iterator/index_iterator.hpp index 06a90015a..ff367ad65 100644 --- a/include/meevax/iterator/index_iterator.hpp +++ b/include/meevax/iterator/index_iterator.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/binary_input_file_port.hpp b/include/meevax/kernel/binary_input_file_port.hpp index d745d6ccd..c24896966 100644 --- a/include/meevax/kernel/binary_input_file_port.hpp +++ b/include/meevax/kernel/binary_input_file_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/binary_input_port.hpp b/include/meevax/kernel/binary_input_port.hpp index 29838d3bc..07c1a27ef 100644 --- a/include/meevax/kernel/binary_input_port.hpp +++ b/include/meevax/kernel/binary_input_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/binary_output_file_port.hpp b/include/meevax/kernel/binary_output_file_port.hpp index c341a67fa..89359b3f5 100644 --- a/include/meevax/kernel/binary_output_file_port.hpp +++ b/include/meevax/kernel/binary_output_file_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/binary_output_port.hpp b/include/meevax/kernel/binary_output_port.hpp index 6ccd14f85..475bc4303 100644 --- a/include/meevax/kernel/binary_output_port.hpp +++ b/include/meevax/kernel/binary_output_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/binary_port.hpp b/include/meevax/kernel/binary_port.hpp index f0f23fe15..9665a205a 100644 --- a/include/meevax/kernel/binary_port.hpp +++ b/include/meevax/kernel/binary_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/boolean.hpp b/include/meevax/kernel/boolean.hpp index 8a0065fc6..74db373a7 100644 --- a/include/meevax/kernel/boolean.hpp +++ b/include/meevax/kernel/boolean.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/boot.hpp b/include/meevax/kernel/boot.hpp index 52930e1ad..d7eaa7781 100644 --- a/include/meevax/kernel/boot.hpp +++ b/include/meevax/kernel/boot.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/box.hpp b/include/meevax/kernel/box.hpp index 14800a058..92bcdc4fc 100644 --- a/include/meevax/kernel/box.hpp +++ b/include/meevax/kernel/box.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ namespace meevax { inline namespace kernel { - struct box : public virtual pair // (value . unit) + struct box : public virtual pair // (value . null) { using pair::pair; }; diff --git a/include/meevax/kernel/character.hpp b/include/meevax/kernel/character.hpp index b6a115ff5..59533cc1a 100644 --- a/include/meevax/kernel/character.hpp +++ b/include/meevax/kernel/character.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/closure.hpp b/include/meevax/kernel/closure.hpp index 7e0c2ffa7..1fc2bec9d 100644 --- a/include/meevax/kernel/closure.hpp +++ b/include/meevax/kernel/closure.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/comparator.hpp b/include/meevax/kernel/comparator.hpp index 495fd1d64..314696b73 100644 --- a/include/meevax/kernel/comparator.hpp +++ b/include/meevax/kernel/comparator.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/complex.hpp b/include/meevax/kernel/complex.hpp index df05495bb..e3417550f 100644 --- a/include/meevax/kernel/complex.hpp +++ b/include/meevax/kernel/complex.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 07b1a477a..4255e5d1d 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/continuation.hpp b/include/meevax/kernel/continuation.hpp index bfedb7fb5..2a5762c10 100644 --- a/include/meevax/kernel/continuation.hpp +++ b/include/meevax/kernel/continuation.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/dynamic_environment.hpp b/include/meevax/kernel/dynamic_environment.hpp index 78c15301c..6752f26e4 100644 --- a/include/meevax/kernel/dynamic_environment.hpp +++ b/include/meevax/kernel/dynamic_environment.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ namespace meevax { inline namespace kernel { - template struct dynamic_environment { /* @@ -69,16 +68,16 @@ inline namespace kernel `kernel-exception-handler-set!`, it is basically assumed to be set to R7RS Scheme's standard procedure `raise`. */ - let static inline raise = unit; + let static inline raise = nullptr; template - auto apply(object const& f, Ts&&... xs) -> object + auto apply(object const& f, Ts&&... xs) -> decltype(auto) { s = list(f, list(std::forward(xs)...)); - e = unit; + e = nullptr; c = list(make(instruction::call), make(instruction::stop)); - d = unit; + d = nullptr; return run(); } @@ -95,7 +94,7 @@ inline namespace kernel return run(); } - auto reraise(object const& x) -> object + auto reraise(object const& x) -> decltype(auto) { return raise.is() ? throw x : apply(raise, x); } @@ -110,14 +109,6 @@ inline namespace kernel fetch: assert(c); - if constexpr (false) - { - std::cerr << faint("; s = ") << s << "\n" - << faint("; e = ") << e << "\n" - << faint("; c = ") << c << "\n" - << faint("; d = ") << d << "\n" << std::endl; - } - switch (car(c).template as()) { case instruction::load_absolute: /* ------------------------------------ @@ -214,7 +205,7 @@ inline namespace kernel * where = (c' . e) * * ----------------------------------------------------------------- */ - s = cons(make(cadr(c), e), s); + s = cons(make>(cadr(c), e), s); c = cddr(c); goto fetch; @@ -225,7 +216,7 @@ inline namespace kernel * where = (s e c' . d) * * ----------------------------------------------------------------- */ - s = cons(list(make(s, e, cadr(c), d)), s); + s = cons(list(make>(s, cons(e, cons(cadr(c), d)))), s); c = cddr(c); goto fetch; @@ -247,15 +238,18 @@ inline namespace kernel * * ----------------------------------------------------------------- */ d = cons(cdddr(c), d); - [[fallthrough]]; + c = car(s) != f ? cadr(c) : caddr(c); + s = cdr(s); + goto fetch; case instruction::tail_select: /* -------------------------------------- * - * ( . s) e (%select c1 c2 . c) d => s e c' d + * ( . s) e (%tail-select c1 c2) d => s e c' d * * where c' = (if c1 c2) * * ----------------------------------------------------------------- */ + assert(cdddr(c).template is()); c = car(s) != f ? cadr(c) : caddr(c); s = cdr(s); goto fetch; @@ -283,7 +277,7 @@ inline namespace kernel d = cons(cddr(s), e, cdr(c), d); c = car(callee); e = cons(cadr(s), cdr(callee)); - s = unit; + s = nullptr; goto fetch; } else if (callee.is_also()) /* ------------------- @@ -333,7 +327,7 @@ inline namespace kernel assert(tail(c, 1).template is()); c = car(callee); e = cons(cadr(s), cdr(callee)); - s = unit; + s = nullptr; goto fetch; } else if (callee.is_also()) /* ------------------- @@ -378,35 +372,36 @@ inline namespace kernel * s e (%dummy . c) d => s ( . e) c d * * ----------------------------------------------------------------- */ - e = cons(unit, e); + e = cons(nullptr, e); c = cdr(c); goto fetch; - case instruction::tail_letrec: /* -------------------------------------- + case instruction::letrec: /* ------------------------------------------- * - * ( xs . s) ( . e) (%letrec . c) d => () (set-car! e' xs) c' d + * ( xs . s) ( . e) (%letrec . c) d => () (set-car! e' xs) c' (s e c . d) * * where = (c' . e') * * ----------------------------------------------------------------- */ cadar(s) = cadr(s); + d = cons(cddr(s), cdr(e), cdr(c), d); c = caar(s); e = cdar(s); - s = unit; + s = nullptr; goto fetch; - case instruction::letrec: /* ------------------------------------------- + case instruction::tail_letrec: /* -------------------------------------- * - * ( xs . s) ( . e) (%letrec . c) d => () (set-car! e' xs) c' (s e c . d) + * ( xs . s) ( . e) (%tail-letrec) d => () (set-car! e' xs) c' d * * where = (c' . e') * * ----------------------------------------------------------------- */ + assert(cdr(c).template is()); cadar(s) = cadr(s); - d = cons(cddr(s), cdr(e), cdr(c), d); c = caar(s); e = cdar(s); - s = unit; + s = nullptr; goto fetch; case instruction::return_: /* ------------------------------------------ @@ -428,7 +423,8 @@ inline namespace kernel * (x y . s) e (%cons . c) d => ((x . y) . s) e c d * * ----------------------------------------------------------------- */ - s = cons(cons(car(s), cadr(s)), cddr(s)); + car(s) = cons(car(s), cadr(s)); + cdr(s) = cddr(s); c = cdr(c); goto fetch; @@ -509,7 +505,7 @@ inline namespace kernel case instruction::install: /* ------------------------------------------ * - * (x . s) e (%intall i . c) d => (x . s) e c d + * (x . s) e (%install i . c) d => (x . s) e c d * * ----------------------------------------------------------------- */ assert(cadr(c).template is()); diff --git a/include/meevax/kernel/environment.hpp b/include/meevax/kernel/environment.hpp index 07c62cb80..ce348e912 100644 --- a/include/meevax/kernel/environment.hpp +++ b/include/meevax/kernel/environment.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ #include #include -#include #include namespace meevax @@ -27,8 +26,7 @@ namespace meevax inline namespace kernel { struct environment : public configurator - , public dynamic_environment - , public optimizer + , public dynamic_environment , public syntactic_environment { using syntactic_environment::syntactic_environment; @@ -44,8 +42,6 @@ inline namespace kernel extern template struct configurator; - extern template struct dynamic_environment; - extern template struct syntactic_environment; } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/eof.hpp b/include/meevax/kernel/eof.hpp index 1be6f5fc1..76e17f29f 100644 --- a/include/meevax/kernel/eof.hpp +++ b/include/meevax/kernel/eof.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/error.hpp b/include/meevax/kernel/error.hpp index 8f6326ea1..f441bc983 100644 --- a/include/meevax/kernel/error.hpp +++ b/include/meevax/kernel/error.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/exact_integer.hpp b/include/meevax/kernel/exact_integer.hpp index 2a70f15f1..3d2dff835 100644 --- a/include/meevax/kernel/exact_integer.hpp +++ b/include/meevax/kernel/exact_integer.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/ghost.hpp b/include/meevax/kernel/ghost.hpp index 79a467a9f..ead7c2b4f 100644 --- a/include/meevax/kernel/ghost.hpp +++ b/include/meevax/kernel/ghost.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/homogeneous_vector.hpp b/include/meevax/kernel/homogeneous_vector.hpp index bca80268f..5b0822600 100644 --- a/include/meevax/kernel/homogeneous_vector.hpp +++ b/include/meevax/kernel/homogeneous_vector.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/identifier.hpp b/include/meevax/kernel/identifier.hpp index 11bdf4ffc..de36684f2 100644 --- a/include/meevax/kernel/identifier.hpp +++ b/include/meevax/kernel/identifier.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/identity.hpp b/include/meevax/kernel/identity.hpp index 4b128e6ff..fcb32d145 100644 --- a/include/meevax/kernel/identity.hpp +++ b/include/meevax/kernel/identity.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ inline namespace kernel { struct identity { - using index = std::uint32_t; + using index = std::int32_t; }; struct absolute : public virtual pair // ( . ) diff --git a/include/meevax/kernel/implementation_dependent.hpp b/include/meevax/kernel/implementation_dependent.hpp index 81c8a5762..1d65f4ee0 100644 --- a/include/meevax/kernel/implementation_dependent.hpp +++ b/include/meevax/kernel/implementation_dependent.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/include.hpp b/include/meevax/kernel/include.hpp index 5f7393851..e0383d66c 100644 --- a/include/meevax/kernel/include.hpp +++ b/include/meevax/kernel/include.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ namespace meevax { inline namespace kernel { - auto include(object const&, bool = true, object const& = unit) -> object; + auto include(object const&, bool = true, object const& = nullptr) -> object; } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/input_file_port.hpp b/include/meevax/kernel/input_file_port.hpp index 50c88e8f4..d2685b042 100644 --- a/include/meevax/kernel/input_file_port.hpp +++ b/include/meevax/kernel/input_file_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/input_homogeneous_vector_port.hpp b/include/meevax/kernel/input_homogeneous_vector_port.hpp index e448a3eb9..d278932f9 100644 --- a/include/meevax/kernel/input_homogeneous_vector_port.hpp +++ b/include/meevax/kernel/input_homogeneous_vector_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -79,7 +79,14 @@ inline namespace kernel auto peek() -> object override { - return deque.empty() ? eof_object : make(deque.front()); + if (deque.empty()) + { + return eof_object; + } + else + { + return make(deque.front()); + } } }; diff --git a/include/meevax/kernel/input_port.hpp b/include/meevax/kernel/input_port.hpp index b7640eb55..e6ffd6ea7 100644 --- a/include/meevax/kernel/input_port.hpp +++ b/include/meevax/kernel/input_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/input_string_port.hpp b/include/meevax/kernel/input_string_port.hpp index b3decfa02..2f1efb565 100644 --- a/include/meevax/kernel/input_string_port.hpp +++ b/include/meevax/kernel/input_string_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/instruction.hpp b/include/meevax/kernel/instruction.hpp index 9cc90487c..6847c5df4 100644 --- a/include/meevax/kernel/instruction.hpp +++ b/include/meevax/kernel/instruction.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,14 +17,13 @@ #ifndef INCLUDED_MEEVAX_KERNEL_INSTRUCTION_HPP #define INCLUDED_MEEVAX_KERNEL_INSTRUCTION_HPP -#include #include namespace meevax { inline namespace kernel { - enum class instruction : std::uint8_t + enum class instruction { call, // a.k.a APP cons, // @@ -52,44 +51,6 @@ inline namespace kernel }; auto operator <<(std::ostream &, instruction const&) -> std::ostream &; - - constexpr auto size(instruction const& datum) - { - switch (datum) - { - case instruction::call: - case instruction::cons: - case instruction::drop: - case instruction::dummy: - case instruction::join: - case instruction::letrec: - case instruction::return_: - case instruction::stop: - case instruction::tail_call: - case instruction::tail_letrec: - return 1; - - case instruction::current: - case instruction::install: - case instruction::load_absolute: - case instruction::load_closure: - case instruction::load_constant: - case instruction::load_continuation: - case instruction::load_relative: - case instruction::load_variadic: - case instruction::store_absolute: - case instruction::store_relative: - case instruction::store_variadic: - return 2; - - case instruction::select: - case instruction::tail_select: - return 3; - - default: - return 0; - } - } } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/interaction_environment.hpp b/include/meevax/kernel/interaction_environment.hpp index 3fc3bcdb8..4fc778b59 100644 --- a/include/meevax/kernel/interaction_environment.hpp +++ b/include/meevax/kernel/interaction_environment.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/library.hpp b/include/meevax/kernel/library.hpp index ce1a56f8e..7d4c0c1fc 100644 --- a/include/meevax/kernel/library.hpp +++ b/include/meevax/kernel/library.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,9 +26,9 @@ inline namespace kernel { struct library : public environment { - let declarations = unit; + let declarations = nullptr; - let export_specs = unit; + let export_specs = nullptr; template )> explicit library(F declare) diff --git a/include/meevax/kernel/list.hpp b/include/meevax/kernel/list.hpp index fed4695b4..8b3138b05 100644 --- a/include/meevax/kernel/list.hpp +++ b/include/meevax/kernel/list.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,10 +26,10 @@ inline namespace kernel { inline auto list = [](auto&&... xs) constexpr { - return (std::forward(xs) | ... | unit); + return (std::forward(xs) | ... | nullptr); }; - auto make_list(std::size_t, object const& = unit) -> object; + auto make_list(std::size_t, object const& = nullptr) -> object; auto iota(std::size_t, object const& = e0, object const& = e1) -> object; @@ -93,7 +93,7 @@ inline namespace kernel auto drop_right(object &, std::size_t) -> object; - auto length(object const&) -> std::size_t; + auto length(object const&) -> std::ptrdiff_t; auto append(object const&, object const&) -> object; @@ -110,7 +110,14 @@ inline namespace kernel template auto map(F f, object const& xs) -> object { - return xs.is() ? cons(f(car(xs)), map(f, cdr(xs))) : unit; + if (xs.is()) + { + return cons(f(car(xs)), map(f, cdr(xs))); + } + else + { + return nullptr; + } } auto memq(object const&, object const&) -> object const&; @@ -141,7 +148,7 @@ inline namespace kernel } else { - return unit; + return nullptr; } } diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 5fce56d68..1dd0ba0d7 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/optimizer.hpp b/include/meevax/kernel/optimizer.hpp index ec3877482..56a8066d4 100644 --- a/include/meevax/kernel/optimizer.hpp +++ b/include/meevax/kernel/optimizer.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,106 +17,13 @@ #ifndef INCLUDED_MEEVAX_KERNEL_OPTIMIZER_HPP #define INCLUDED_MEEVAX_KERNEL_OPTIMIZER_HPP -#include +#include namespace meevax { inline namespace kernel { - struct optimizer - { - static inline auto fmerge_constants = true; - - static auto merge_constants(object const& c) -> object - { - if (not c.is() or not car(c).is()) - { - return c; - } - else switch (auto n = size(car(c).as()); car(c).as()) - { - case instruction::load_constant: /* -------------------------------------- - * - * (load-constant x - * load-constant y - * cons - * ...) - * - * => (load-constant (y . x) - * ...) - * - * --------------------------------------------------------------------- */ - if (tail(c, 2).is() and head(c, 2).is() and head(c, 2).as() == instruction::load_constant and - tail(c, 4).is() and head(c, 4).is() and head(c, 4).as() == instruction::cons) - { - return merge_constants(cons(head(c, 0), - cons(head(c, 3), - head(c, 1)), - merge_constants(tail(c, 5)))); - } - else if (let const& c2 = merge_constants(tail(c, 2)); c2 == tail(c, 2)) - { - return c; - } - else - { - return cons(head(c, 0), head(c, 1), c2); - } - - default: - if (let const& cn = merge_constants(tail(c, n)); cn == tail(c, n)) - { - return c; - } - else - { - return append(take(c, n), cn); - } - - case instruction::load_closure: - case instruction::load_continuation: - if (let const& c1 = merge_constants(head(c, 1)), - c2 = merge_constants(tail(c, 2)); - c1 == head(c, 1) and - c2 == tail(c, 2)) - { - return c; - } - else - { - return cons(head(c, 0), c1, c2); - } - - case instruction::select: - case instruction::tail_select: - if (let const& c1 = merge_constants(head(c, 1)), - c2 = merge_constants(head(c, 2)), - c3 = merge_constants(tail(c, 3)); - c1 == head(c, 1) and - c2 == head(c, 2) and - c3 == tail(c, 3)) - { - return c; - } - else - { - return cons(head(c, 0), c1, c2, c3); - } - } - } - - static auto optimize(object const& c) - { - let code = c; - - if (fmerge_constants) - { - code = merge_constants(code); - } - - return code; - } - }; + auto optimize(object) -> object; } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/output_file_port.hpp b/include/meevax/kernel/output_file_port.hpp index 21fe11adf..95000450e 100644 --- a/include/meevax/kernel/output_file_port.hpp +++ b/include/meevax/kernel/output_file_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/output_homogeneous_vector_port.hpp b/include/meevax/kernel/output_homogeneous_vector_port.hpp index 08883a4a2..5479c6d74 100644 --- a/include/meevax/kernel/output_homogeneous_vector_port.hpp +++ b/include/meevax/kernel/output_homogeneous_vector_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/output_port.hpp b/include/meevax/kernel/output_port.hpp index 60d6df414..81f94ac88 100644 --- a/include/meevax/kernel/output_port.hpp +++ b/include/meevax/kernel/output_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/output_string_port.hpp b/include/meevax/kernel/output_string_port.hpp index 0e7f7e607..3dc93dea8 100644 --- a/include/meevax/kernel/output_string_port.hpp +++ b/include/meevax/kernel/output_string_port.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/include/meevax/kernel/pair.hpp b/include/meevax/kernel/pair.hpp index a5b02366f..048f4ccce 100644 --- a/include/meevax/kernel/pair.hpp +++ b/include/meevax/kernel/pair.hpp @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Tatsuya Yamasaki. + Copyright 2018-2024 Tatsuya Yamasaki. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,44 +17,53 @@ #ifndef INCLUDED_MEEVAX_KERNEL_PAIR_HPP #define INCLUDED_MEEVAX_KERNEL_PAIR_HPP +#include #include #include -#include +#include +#include namespace meevax { inline namespace kernel { + using null = std::nullptr_t; + struct pair; - using object = gc_pointer; + using default_collector = collector; + + using object = default_collector::mutator; using let = object; let extern unit; - template , - typename... Ts> - auto make(Ts&&... xs) -> object + template + auto make(Ts&&... xs) -> decltype(auto) + { + return default_collector::make(std::forward(xs)...); + } + + template + auto make(Ts&&... xs) -> decltype(auto) { - return object::allocate(std::forward(xs)...); + if constexpr (std::is_same_v) { + return default_collector::make>(std::forward(xs)...); + } else { + return default_collector::make>(std::forward(xs)...); + } } template > - auto make(T&& x) -> object + typename Allocator = std::allocator> + auto make(T&& x) -> decltype(auto) { - return object::allocate, Allocator>(std::forward(x)); + return default_collector::make, Allocator>(std::forward(x)); } template