From c091ffacbd3a0e33cda96f404179cb7ad6e028ec Mon Sep 17 00:00:00 2001 From: Kyler Date: Tue, 9 Dec 2025 23:06:51 -0700 Subject: [PATCH] Saving stuff from presentation --- SLS_C/fib.min.sls | 1 + SLS_C/fib.sls | 17 ++++++++++ SLS_C/tests/lexer_tests.c | 70 +++++++++++++++++++-------------------- SLS_Rust/sls/state.json | 1 + 4 files changed, 54 insertions(+), 35 deletions(-) create mode 100644 SLS_C/fib.min.sls create mode 100644 SLS_C/fib.sls create mode 100644 SLS_Rust/sls/state.json diff --git a/SLS_C/fib.min.sls b/SLS_C/fib.min.sls new file mode 100644 index 0000000..058ffe0 --- /dev/null +++ b/SLS_C/fib.min.sls @@ -0,0 +1 @@ +{ 2 - dup 0 <= { drop 1 } { 1 1 rot 0 swap { drop swap 1 pick + } for swap drop } if } lambda ::fib const diff --git a/SLS_C/fib.sls b/SLS_C/fib.sls new file mode 100644 index 0000000..2b5dfba --- /dev/null +++ b/SLS_C/fib.sls @@ -0,0 +1,17 @@ +{ + // Start with which Fibonacci number we want (Nth Fibonacci number) + 2 - // We push the first two already + dup 0 <= { drop 1 } { + 1 1 // Starting Fibonacci numbers + rot 0 swap // Setting up loop from zero to N + { + drop // Discard the loop counter + swap 1 pick // Swap n-1 and n-2 and copy n-1 + + // Add n-2 and the copy of n-1 + // n and n-1 left on stack + } for + swap drop // Drop n-1 from the stack + } if +} lambda ::fib const + +8 fib diff --git a/SLS_C/tests/lexer_tests.c b/SLS_C/tests/lexer_tests.c index e817e21..5d41918 100644 --- a/SLS_C/tests/lexer_tests.c +++ b/SLS_C/tests/lexer_tests.c @@ -1803,8 +1803,8 @@ static TestResult test_Float_f32_Negative_Zero() { return pass_test(&test, result); } -static TestResult test_Char_Simple_Letter_A() { - LexerTest test = start_up_test(SLS_STR("Char Simple Letter A"), SLS_STR("'A'")); +static TestResult test_Char_Simple_Letter_Uppercase_A() { + LexerTest test = start_up_test(SLS_STR("Char Simple Letter Uppercase A"), SLS_STR("'A'")); LexerResult result = lexical_analysis(&test.lexer_info); if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); size_t i = 0; @@ -1813,8 +1813,8 @@ static TestResult test_Char_Simple_Letter_A() { return pass_test(&test, result); } -static TestResult test_Char_Simple_Letter_a() { - LexerTest test = start_up_test(SLS_STR("Char Simple Letter a"), SLS_STR("'a'")); +static TestResult test_Char_Simple_Letter_Lowercase_a() { + LexerTest test = start_up_test(SLS_STR("Char Simple Letter Lowercase a"), SLS_STR("'a'")); LexerResult result = lexical_analysis(&test.lexer_info); if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); size_t i = 0; @@ -1823,8 +1823,8 @@ static TestResult test_Char_Simple_Letter_a() { return pass_test(&test, result); } -static TestResult test_Char_Simple_Letter_Z() { - LexerTest test = start_up_test(SLS_STR("Char Simple Letter Z"), SLS_STR("'Z'")); +static TestResult test_Char_Simple_Letter_Uppercase_Z() { + LexerTest test = start_up_test(SLS_STR("Char Simple Letter Uppercase Z"), SLS_STR("'Z'")); LexerResult result = lexical_analysis(&test.lexer_info); if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); size_t i = 0; @@ -1833,8 +1833,8 @@ static TestResult test_Char_Simple_Letter_Z() { return pass_test(&test, result); } -static TestResult test_Char_Simple_Letter_z() { - LexerTest test = start_up_test(SLS_STR("Char Simple Letter z"), SLS_STR("'z'")); +static TestResult test_Char_Simple_Letter_Lowercase_z() { + LexerTest test = start_up_test(SLS_STR("Char Simple Letter Lowercase z"), SLS_STR("'z'")); LexerResult result = lexical_analysis(&test.lexer_info); if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); size_t i = 0; @@ -2073,22 +2073,22 @@ static TestResult test_Char_Right_Brace() { return pass_test(&test, result); } -static TestResult test_Char_Escape_Tab() { - LexerTest test = start_up_test(SLS_STR("Char Escape Tab"), SLS_STR("'\\t'")); +static TestResult test_Char_Escape_Single_quote() { + LexerTest test = start_up_test(SLS_STR("Char Escape Single quote"), SLS_STR("'\\''")); LexerResult result = lexical_analysis(&test.lexer_info); if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); size_t i = 0; - if (test_character_value(&test, result, i++, &(uint8_t){9})) return test.result; + if (test_character_value(&test, result, i++, &(uint8_t){39})) return test.result; if (test_eof_value(&test, result, i++, 0)) return test.result; return pass_test(&test, result); } -static TestResult test_Char_Escape_Backslash() { - LexerTest test = start_up_test(SLS_STR("Char Escape Backslash"), SLS_STR("'\\\\'")); +static TestResult test_Char_Escape_Newline() { + LexerTest test = start_up_test(SLS_STR("Char Escape Newline"), SLS_STR("'\\n'")); LexerResult result = lexical_analysis(&test.lexer_info); if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); size_t i = 0; - if (test_character_value(&test, result, i++, &(uint8_t){92})) return test.result; + if (test_character_value(&test, result, i++, &(uint8_t){10})) return test.result; if (test_eof_value(&test, result, i++, 0)) return test.result; return pass_test(&test, result); } @@ -2103,12 +2103,22 @@ static TestResult test_Char_Escape_Null_character() { return pass_test(&test, result); } -static TestResult test_Char_Escape_Single_quote() { - LexerTest test = start_up_test(SLS_STR("Char Escape Single quote"), SLS_STR("'\\''")); +static TestResult test_Char_Escape_Backslash() { + LexerTest test = start_up_test(SLS_STR("Char Escape Backslash"), SLS_STR("'\\\\'")); LexerResult result = lexical_analysis(&test.lexer_info); if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); size_t i = 0; - if (test_character_value(&test, result, i++, &(uint8_t){39})) return test.result; + if (test_character_value(&test, result, i++, &(uint8_t){92})) return test.result; + if (test_eof_value(&test, result, i++, 0)) return test.result; + return pass_test(&test, result); +} + +static TestResult test_Char_Escape_Tab() { + LexerTest test = start_up_test(SLS_STR("Char Escape Tab"), SLS_STR("'\\t'")); + LexerResult result = lexical_analysis(&test.lexer_info); + if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); + size_t i = 0; + if (test_character_value(&test, result, i++, &(uint8_t){9})) return test.result; if (test_eof_value(&test, result, i++, 0)) return test.result; return pass_test(&test, result); } @@ -2123,16 +2133,6 @@ static TestResult test_Char_Escape_Carriage_return() { return pass_test(&test, result); } -static TestResult test_Char_Escape_Newline() { - LexerTest test = start_up_test(SLS_STR("Char Escape Newline"), SLS_STR("'\\n'")); - LexerResult result = lexical_analysis(&test.lexer_info); - if (result.type == SLS_ERROR) return error_fail_test(&test, result, result.error); - size_t i = 0; - if (test_character_value(&test, result, i++, &(uint8_t){10})) return test.result; - if (test_eof_value(&test, result, i++, 0)) return test.result; - return pass_test(&test, result); -} - static TestResult test_Char_With_Leading_Whitespace() { LexerTest test = start_up_test(SLS_STR("Char With Leading Whitespace"), SLS_STR(" 'A'")); LexerResult result = lexical_analysis(&test.lexer_info); @@ -3845,10 +3845,10 @@ TestsReport run_lexer_tests() { test_report.tests[i++] = test_Float_Default_Negative_Zero(); test_report.tests[i++] = test_Float_f32_Positive_Zero(); test_report.tests[i++] = test_Float_f32_Negative_Zero(); - test_report.tests[i++] = test_Char_Simple_Letter_A(); - test_report.tests[i++] = test_Char_Simple_Letter_a(); - test_report.tests[i++] = test_Char_Simple_Letter_Z(); - test_report.tests[i++] = test_Char_Simple_Letter_z(); + test_report.tests[i++] = test_Char_Simple_Letter_Uppercase_A(); + test_report.tests[i++] = test_Char_Simple_Letter_Lowercase_a(); + test_report.tests[i++] = test_Char_Simple_Letter_Uppercase_Z(); + test_report.tests[i++] = test_Char_Simple_Letter_Lowercase_z(); test_report.tests[i++] = test_Char_Digit_0(); test_report.tests[i++] = test_Char_Digit_5(); test_report.tests[i++] = test_Char_Digit_9(); @@ -3872,12 +3872,12 @@ TestsReport run_lexer_tests() { test_report.tests[i++] = test_Char_Right_Bracket(); test_report.tests[i++] = test_Char_Left_Brace(); test_report.tests[i++] = test_Char_Right_Brace(); - test_report.tests[i++] = test_Char_Escape_Tab(); - test_report.tests[i++] = test_Char_Escape_Backslash(); - test_report.tests[i++] = test_Char_Escape_Null_character(); test_report.tests[i++] = test_Char_Escape_Single_quote(); - test_report.tests[i++] = test_Char_Escape_Carriage_return(); test_report.tests[i++] = test_Char_Escape_Newline(); + test_report.tests[i++] = test_Char_Escape_Null_character(); + test_report.tests[i++] = test_Char_Escape_Backslash(); + test_report.tests[i++] = test_Char_Escape_Tab(); + test_report.tests[i++] = test_Char_Escape_Carriage_return(); test_report.tests[i++] = test_Char_With_Leading_Whitespace(); test_report.tests[i++] = test_Char_With_Trailing_Whitespace(); test_report.tests[i++] = test_Char_With_Both_Whitespace(); diff --git a/SLS_Rust/sls/state.json b/SLS_Rust/sls/state.json new file mode 100644 index 0000000..63ec579 --- /dev/null +++ b/SLS_Rust/sls/state.json @@ -0,0 +1 @@ +{"stack":[{"I64":10}],"functions":{"asin":{"Builtin":"asin"},"if":{"Builtin":"if"},"*":{"Builtin":"*"},"tan":{"Builtin":"tan"},"floor":{"Builtin":"floor"},"bitor":{"Builtin":"bitor"},"shl":{"Builtin":"shl"},"rot":{"TokenString":{"tokens":[{"I64":3},{"I64":1},{"Identifier":{"name":"roll","is_literal":false}}]}},"not":{"Builtin":"not"},"while":{"Builtin":"while"},"<=":{"Builtin":"<="},"pick":{"Builtin":"pick"},"ln":{"Builtin":"ln"},"shr":{"Builtin":"shr"},"round":{"Builtin":"round"},"atan":{"Builtin":"atan"},"log":{"Builtin":"log"},"swap":{"Builtin":"swap"},"dup":{"Builtin":"dup"},"or":{"Builtin":"or"},"eval":{"Builtin":"eval"},"type_of":{"Builtin":"type_of"},"rand":{"Builtin":"rand"},"/":{"Builtin":"/"},"depth":{"Builtin":"depth"},"seed":{"Builtin":"seed"},"logb":{"TokenString":{"tokens":[{"Identifier":{"name":"ln","is_literal":false}},{"Identifier":{"name":"swap","is_literal":false}},{"Identifier":{"name":"ln","is_literal":false}},{"Identifier":{"name":"swap","is_literal":false}},{"Identifier":{"name":"/","is_literal":false}}]}},"+":{"Builtin":"+"},"cos":{"Builtin":"cos"},"max":{"TokenString":{"tokens":[{"I64":1},{"Identifier":{"name":"pick","is_literal":false}},{"I64":1},{"Identifier":{"name":"pick","is_literal":false}},{"Identifier":{"name":"<","is_literal":false}},{"TokenString":{"tokens":[{"Identifier":{"name":"swap","is_literal":false}},{"Identifier":{"name":"drop","is_literal":false}}]}},{"TokenString":{"tokens":[{"Identifier":{"name":"drop","is_literal":false}}]}},{"Identifier":{"name":"if","is_literal":false}}]}},"ceil":{"Builtin":"ceil"},"-":{"Builtin":"-"},"for":{"Builtin":"for"},"and":{"Builtin":"and"},"min":{"TokenString":{"tokens":[{"I64":1},{"Identifier":{"name":"pick","is_literal":false}},{"I64":1},{"Identifier":{"name":"pick","is_literal":false}},{"Identifier":{"name":"<","is_literal":false}},{"TokenString":{"tokens":[{"Identifier":{"name":"drop","is_literal":false}}]}},{"TokenString":{"tokens":[{"Identifier":{"name":"swap","is_literal":false}},{"Identifier":{"name":"drop","is_literal":false}}]}},{"Identifier":{"name":"if","is_literal":false}}]}},"atan2":{"Builtin":"atan2"},"const":{"Builtin":"const"},"sqrt":{"Builtin":"sqrt"},">":{"Builtin":">"},"bitand":{"Builtin":"bitand"},"!=":{"Builtin":"!="},"<":{"Builtin":"<"},"acos":{"Builtin":"acos"},"%":{"Builtin":"%"},">=":{"Builtin":">="},"==":{"Builtin":"=="},"abs":{"Builtin":"abs"},"sin":{"Builtin":"sin"},"^":{"Builtin":"^"},"bitnot":{"Builtin":"bitnot"},"lambda":{"Builtin":"lambda"},"bitxor":{"Builtin":"bitxor"},"ten":{"TokenString":{"tokens":[{"I64":10}]}},"roll":{"Builtin":"roll"},"drop":{"Builtin":"drop"}}} \ No newline at end of file