~octaspire/dern

0fe6688ceae623b6f6c646d814240187233975de — octaspire 1 year, 8 months ago 813dd38 v0.489.0
Do a small fix, add unit tests and documentation
M dev/doc/book/examples/dern/applyEvalAndGenerate.dern => dev/doc/book/examples/dern/applyEvalAndGenerate.dern +9 -1
@@ 16,7 16,15 @@
; ({D+0} {D+1} {D+2} {D+3} {D+4} {D+5} {D+6} {D+7} {D+8} {D+9})
(generate 'vector of {D+10} (fn (container index) index))

; Generate first 11 Fibonacci numbers into a vector
; ({D+0} {D+1} {D+1} {D+2} {D+3} {D+5} {D+8} {D+13} {D+21} {D+34} {D+55})
(generate 'vector of {D+11}
  (fn (container index)
    (select (== index {D+0}) {D+0}
            (== index {D+1}) {D+1}
            default      (+ (cp@ container (- index {D+1}))
                            (cp@ container (- index {D+2}))))))

; "map" or "mapcar" of other Lisps can be done like this:
(generate 'vector mapping to-integer on '(|a| |b| |c|))        ; ({D+97} {D+98} {D+99})
(generate 'vector mapping * on '({D+1} {D+2}) '({D+3} {D+4}))  ; ({D+3} {D+8})


M dev/include/octaspire/dern/octaspire_dern_config.h => dev/include/octaspire/dern/octaspire_dern_config.h +2 -2
@@ 18,8 18,8 @@ limitations under the License.
#define OCTASPIRE_DERN_CONFIG_H

#define OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "0"
#define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "488"
#define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "1"
#define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "489"
#define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "0"

#define OCTASPIRE_DERN_CONFIG_VERSION_STR "Octaspire Dern version " \
    OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "." \

M dev/src/octaspire_dern_value.c => dev/src/octaspire_dern_value.c +2 -1
@@ 3615,7 3615,7 @@ bool octaspire_dern_value_as_collection_push_back_element(
    }
    else if (octaspire_dern_value_is_vector(self))
    {
        return octaspire_dern_value_as_vector_push_back_element(self, element);
        return octaspire_dern_value_as_vector_push_back_element(self, &element);
    }

    return false;


@@ 5171,3 5171,4 @@ struct octaspire_dern_vm_t const * octaspire_dern_value_get_vm_const(
    octaspire_helpers_verify_not_null(self);
    return self->vm;
}


M dev/test/test_dern_vm.c => dev/test/test_dern_vm.c +101 -0
@@ 12922,6 12922,45 @@ TEST octaspire_dern_vm_special_eval_used_as_apply_1_test(void)
    PASS();
}

TEST octaspire_dern_vm_special_generate_vector_of_3_ones_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(
        octaspireDernVmTestAllocator,
        octaspireDernVmTestStdio);

    octaspire_dern_value_t *evaluatedValue =
        octaspire_dern_vm_read_from_c_string_and_eval_in_global_environment(
            vm,
            "(generate 'vector of {D+3} {D+1})");

    size_t const expectedLen = 3;
    int    const expectedNum = 1;

    ASSERT(evaluatedValue);
    ASSERT(octaspire_dern_value_is_vector(evaluatedValue));
    ASSERT_EQ(expectedLen, octaspire_dern_value_as_vector_get_length(evaluatedValue));

    for (size_t i = 0; i < expectedLen; ++i)
    {
        octaspire_dern_value_t const * const elemVal =
            octaspire_dern_value_as_vector_get_element_of_type_at_const(
                evaluatedValue,
                OCTASPIRE_DERN_VALUE_TAG_INTEGER,
                i);

        ASSERT(elemVal);

        ASSERT_EQ(
            expectedNum,
            octaspire_dern_value_as_integer_get_value(elemVal));
    }

    octaspire_dern_vm_release(vm);
    vm = 0;

    PASS();
}

TEST octaspire_dern_vm_special_generate_string_of_10_a_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(


@@ 12971,6 13010,66 @@ TEST octaspire_dern_vm_special_generate_string_of_10_fn_97plusindex_test(void)
    PASS();
}

TEST octaspire_dern_vm_special_generate_vector_of_11_first_fibonacci_numbers_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(
        octaspireDernVmTestAllocator,
        octaspireDernVmTestStdio);

    octaspire_dern_value_t *evaluatedValue =
        octaspire_dern_vm_read_from_c_string_and_eval_in_global_environment(
            vm,
            "(generate 'vector of {D+11}\n"
            "  (fn (container index)\n"
            "    (select (== index {D+0}) {D+0}\n"
            "            (== index {D+1}) {D+1}\n"
            "            default      (+ (cp@ container (- index {D+1}))\n"
            "                            (cp@ container (- index {D+2}))))))");
    size_t const expectedLen = 11;

    ASSERT(evaluatedValue);
    ASSERT_EQ(OCTASPIRE_DERN_VALUE_TAG_VECTOR, evaluatedValue->typeTag);
    ASSERT_EQ(expectedLen, octaspire_dern_value_as_vector_get_length(evaluatedValue));

    int expected[11] =
    {
        0,
        1,
        1,
        2,
        3,
        5,
        8,
        13,
        21,
        34,
        55
    };

    ASSERT_EQ(expectedLen, sizeof(expected) / sizeof(expected[0]));

    for (size_t i = 0; i < expectedLen; ++i)
    {
        octaspire_dern_value_t const * const elemVal =
            octaspire_dern_value_as_vector_get_element_of_type_at_const(
                evaluatedValue,
                OCTASPIRE_DERN_VALUE_TAG_INTEGER,
                i);

        ASSERT(elemVal);

        ASSERT_EQ(
            expected[i],
            octaspire_dern_value_as_integer_get_value(elemVal));
    }


    octaspire_dern_vm_release(vm);
    vm = 0;

    PASS();
}

TEST octaspire_dern_vm_special_eval_plus_1_2_in_given_global_env_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(octaspireDernVmTestAllocator, octaspireDernVmTestStdio);


@@ 18142,8 18241,10 @@ GREATEST_SUITE(octaspire_dern_vm_suite)
    RUN_TEST(octaspire_dern_vm_error_during_special_call_during_user_function_call_test);
    RUN_TEST(octaspire_dern_vm_special_eval_plus_1_2_test);
    RUN_TEST(octaspire_dern_vm_special_eval_used_as_apply_1_test);
    RUN_TEST(octaspire_dern_vm_special_generate_vector_of_3_ones_test);
    RUN_TEST(octaspire_dern_vm_special_generate_string_of_10_a_test);
    RUN_TEST(octaspire_dern_vm_special_generate_string_of_10_fn_97plusindex_test);
    RUN_TEST(octaspire_dern_vm_special_generate_vector_of_11_first_fibonacci_numbers_test);
    RUN_TEST(octaspire_dern_vm_special_eval_plus_1_2_in_given_global_env_test);
    RUN_TEST(octaspire_dern_vm_special_eval_value_from_given_local_env_test);
    RUN_TEST(octaspire_dern_vm_special_eval_eval_eval_f_1_2_test);

M release/documentation/dern-manual.html => release/documentation/dern-manual.html +9 -1
@@ 1664,10 1664,18 @@ http://www.gnu.org/software/src-highlite -->
<span class="comment">; ({D+0} {D+1} {D+2} {D+3} {D+4} {D+5} {D+6} {D+7} {D+8} {D+9})</span>
<span class="cbracket">(</span><span class="normal">generate '</span><span class="keyword">vector</span><span class="normal"> of </span><span class="number">{D+10}</span><span class="normal"> </span><span class="cbracket">(</span><span class="keyword">fn</span><span class="normal"> </span><span class="cbracket">(</span><span class="normal">container index</span><span class="cbracket">)</span><span class="normal"> index</span><span class="cbracket">))</span>

<span class="comment">; Generate first 11 Fibonacci numbers into a vector</span>
<span class="comment">; ({D+0} {D+1} {D+1} {D+2} {D+3} {D+5} {D+8} {D+13} {D+21} {D+34} {D+55})</span>
<span class="cbracket">(</span><span class="normal">generate '</span><span class="keyword">vector</span><span class="normal"> of </span><span class="number">{D+11}</span>
<span class="normal">  </span><span class="cbracket">(</span><span class="keyword">fn</span><span class="normal"> </span><span class="cbracket">(</span><span class="normal">container index</span><span class="cbracket">)</span>
<span class="normal">    </span><span class="cbracket">(</span><span class="keyword">select</span><span class="normal"> </span><span class="cbracket">(</span><span class="keyword">==</span><span class="normal"> index </span><span class="number">{D+0}</span><span class="cbracket">)</span><span class="normal"> </span><span class="number">{D+0}</span>
<span class="normal">            </span><span class="cbracket">(</span><span class="keyword">==</span><span class="normal"> index </span><span class="number">{D+1}</span><span class="cbracket">)</span><span class="normal"> </span><span class="number">{D+1}</span>
<span class="normal">            default      </span><span class="cbracket">(</span><span class="keyword">+</span><span class="normal"> </span><span class="cbracket">(</span><span class="keyword">cp@</span><span class="normal"> container </span><span class="cbracket">(</span><span class="keyword">-</span><span class="normal"> index </span><span class="number">{D+1}</span><span class="cbracket">))</span>
<span class="normal">                            </span><span class="cbracket">(</span><span class="keyword">cp@</span><span class="normal"> container </span><span class="cbracket">(</span><span class="keyword">-</span><span class="normal"> index </span><span class="number">{D+2}</span><span class="cbracket">))))))</span>

<span class="comment">; "map" or "mapcar" of other Lisps can be done like this:</span>
<span class="cbracket">(</span><span class="normal">generate '</span><span class="keyword">vector</span><span class="normal"> mapping </span><span class="keyword">to-integer</span><span class="normal"> on '</span><span class="cbracket">(</span><span class="normal">|a| |b| |c|</span><span class="cbracket">))</span><span class="normal">        </span><span class="comment">; ({D+97} {D+98} {D+99})</span>
<span class="cbracket">(</span><span class="normal">generate '</span><span class="keyword">vector</span><span class="normal"> mapping </span><span class="keyword">*</span><span class="normal"> on '</span><span class="cbracket">(</span><span class="number">{D+1}</span><span class="normal"> </span><span class="number">{D+2}</span><span class="cbracket">)</span><span class="normal"> '</span><span class="cbracket">(</span><span class="number">{D+3}</span><span class="normal"> </span><span class="number">{D+4}</span><span class="cbracket">))</span><span class="normal">  </span><span class="comment">; ({D+3} {D+8})</span>

</pre>

  <h2><a id="23"></a>23. Input and output ports</h2>

M release/octaspire-dern-amalgamated.c => release/octaspire-dern-amalgamated.c +105 -3
@@ 26447,8 26447,8 @@ limitations under the License.
#define OCTASPIRE_DERN_CONFIG_H

#define OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "0"
#define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "488"
#define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "1"
#define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "489"
#define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "0"

#define OCTASPIRE_DERN_CONFIG_VERSION_STR "Octaspire Dern version " \
    OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "." \


@@ 50730,7 50730,7 @@ bool octaspire_dern_value_as_collection_push_back_element(
    }
    else if (octaspire_dern_value_is_vector(self))
    {
        return octaspire_dern_value_as_vector_push_back_element(self, element);
        return octaspire_dern_value_as_vector_push_back_element(self, &element);
    }

    return false;


@@ 52286,6 52286,7 @@ struct octaspire_dern_vm_t const * octaspire_dern_value_get_vm_const(
    octaspire_helpers_verify_not_null(self);
    return self->vm;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// END OF          dev/src/octaspire_dern_value.c
//////////////////////////////////////////////////////////////////////////////////////////////////


@@ 75678,6 75679,45 @@ TEST octaspire_dern_vm_special_eval_used_as_apply_1_test(void)
    PASS();
}

TEST octaspire_dern_vm_special_generate_vector_of_3_ones_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(
        octaspireDernVmTestAllocator,
        octaspireDernVmTestStdio);

    octaspire_dern_value_t *evaluatedValue =
        octaspire_dern_vm_read_from_c_string_and_eval_in_global_environment(
            vm,
            "(generate 'vector of {D+3} {D+1})");

    size_t const expectedLen = 3;
    int    const expectedNum = 1;

    ASSERT(evaluatedValue);
    ASSERT(octaspire_dern_value_is_vector(evaluatedValue));
    ASSERT_EQ(expectedLen, octaspire_dern_value_as_vector_get_length(evaluatedValue));

    for (size_t i = 0; i < expectedLen; ++i)
    {
        octaspire_dern_value_t const * const elemVal =
            octaspire_dern_value_as_vector_get_element_of_type_at_const(
                evaluatedValue,
                OCTASPIRE_DERN_VALUE_TAG_INTEGER,
                i);

        ASSERT(elemVal);

        ASSERT_EQ(
            expectedNum,
            octaspire_dern_value_as_integer_get_value(elemVal));
    }

    octaspire_dern_vm_release(vm);
    vm = 0;

    PASS();
}

TEST octaspire_dern_vm_special_generate_string_of_10_a_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(


@@ 75727,6 75767,66 @@ TEST octaspire_dern_vm_special_generate_string_of_10_fn_97plusindex_test(void)
    PASS();
}

TEST octaspire_dern_vm_special_generate_vector_of_11_first_fibonacci_numbers_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(
        octaspireDernVmTestAllocator,
        octaspireDernVmTestStdio);

    octaspire_dern_value_t *evaluatedValue =
        octaspire_dern_vm_read_from_c_string_and_eval_in_global_environment(
            vm,
            "(generate 'vector of {D+11}\n"
            "  (fn (container index)\n"
            "    (select (== index {D+0}) {D+0}\n"
            "            (== index {D+1}) {D+1}\n"
            "            default      (+ (cp@ container (- index {D+1}))\n"
            "                            (cp@ container (- index {D+2}))))))");
    size_t const expectedLen = 11;

    ASSERT(evaluatedValue);
    ASSERT_EQ(OCTASPIRE_DERN_VALUE_TAG_VECTOR, evaluatedValue->typeTag);
    ASSERT_EQ(expectedLen, octaspire_dern_value_as_vector_get_length(evaluatedValue));

    int expected[11] =
    {
        0,
        1,
        1,
        2,
        3,
        5,
        8,
        13,
        21,
        34,
        55
    };

    ASSERT_EQ(expectedLen, sizeof(expected) / sizeof(expected[0]));

    for (size_t i = 0; i < expectedLen; ++i)
    {
        octaspire_dern_value_t const * const elemVal =
            octaspire_dern_value_as_vector_get_element_of_type_at_const(
                evaluatedValue,
                OCTASPIRE_DERN_VALUE_TAG_INTEGER,
                i);

        ASSERT(elemVal);

        ASSERT_EQ(
            expected[i],
            octaspire_dern_value_as_integer_get_value(elemVal));
    }


    octaspire_dern_vm_release(vm);
    vm = 0;

    PASS();
}

TEST octaspire_dern_vm_special_eval_plus_1_2_in_given_global_env_test(void)
{
    octaspire_dern_vm_t *vm = octaspire_dern_vm_new(octaspireDernVmTestAllocator, octaspireDernVmTestStdio);


@@ 80898,8 80998,10 @@ GREATEST_SUITE(octaspire_dern_vm_suite)
    RUN_TEST(octaspire_dern_vm_error_during_special_call_during_user_function_call_test);
    RUN_TEST(octaspire_dern_vm_special_eval_plus_1_2_test);
    RUN_TEST(octaspire_dern_vm_special_eval_used_as_apply_1_test);
    RUN_TEST(octaspire_dern_vm_special_generate_vector_of_3_ones_test);
    RUN_TEST(octaspire_dern_vm_special_generate_string_of_10_a_test);
    RUN_TEST(octaspire_dern_vm_special_generate_string_of_10_fn_97plusindex_test);
    RUN_TEST(octaspire_dern_vm_special_generate_vector_of_11_first_fibonacci_numbers_test);
    RUN_TEST(octaspire_dern_vm_special_eval_plus_1_2_in_given_global_env_test);
    RUN_TEST(octaspire_dern_vm_special_eval_value_from_given_local_env_test);
    RUN_TEST(octaspire_dern_vm_special_eval_eval_eval_f_1_2_test);