diff --git a/docs/TODO.md b/docs/TODO.md index ab0637fd..38266e8d 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -2,23 +2,25 @@ More of a wish-list than a hard and fast plan. -* Types +* Types. * Consider type classes as a general solution to `EQ ` etc. * Records should create accessor functions for each tag. -* Parser + * if there is only one type variant. +* Parser. * re-elist the now-available `macro` keyword for proper syntactic extensibility: * if/then/else => `(fn { (true) {then} (false) {else} }(if))` (we already do this but hard-coded in the parser). * `do` notation for monads. -* Memory Management - * Replace mark and sweep GC with a generational stop and copy -* Target LLVM -* `syntax` construct that allows large-scale syntactic structures to be defined by the user. -* Generate +* Memory Management. + * Replace mark and sweep GC with a generational stop and copy. +* Pipeline. + * Port/Implement prototype closure conversion from fn/rewrite. + * Target LLVM. +* Generate. * Move all signatures into `signature_helper.py`, not just the shared ones. -* More numbers: +* More numbers. + * Vectors. * Matrices. * Quaternions. - * Vectors. * Improve arithmetic. * ceil, floor and round operations. * move to [libgmp](https://gmplib.org/)? @@ -26,15 +28,17 @@ More of a wish-list than a hard and fast plan. * allow numeric (not symbolic) arithmetic expressions in patterns. * allow unpacking of numerator and denominator variables in patterns. * special case: `a / b` because there is a canonical form (via gcd). - * but does `a / 6` match `2 / 3` and bind `a` to `4`? + * does `a / 6` match `2 / 3` and bind `a` to `4`. * match would fail if the actual argument is not integer or rational. * `b` would be bound to `1` if the argument was an integer. - * can't allow arbitrary ops and combinations because i.e. `a * b` - can't uniquely determine `a` and `b`, and `a ** 2` would require `a` - to be bound to the square root of the actual argument. + * can't allow arbitrary ops and combinations because i.e. `a * b` can't uniquely determine `a` and `b`, and `a ** 2` would require `a` to be bound to the square root of the actual argument. * allow unpacking of the real and imaginary parts of a complex number in patterns. - * another special case: `a + b`, `b` would be bound to `0i` if the actual argument is not complex. + * another special case: `a + b`, `b` would be bound to `0i` if the actual argument is not complex. * Curried binary operators `(2+)` etc. * (internal) have a NEWZ variant of NEW that bzero's its result. -* Builtins +* Builtins. * `now()` builtin returns current time in milliseconds. +* I/O. + * Make i/o pleasant to use. + * Any ideas welcome, currently it's a mess. + * Specifically think about ways to support parsing. diff --git a/fn/rewrite/closure-convert.fn b/fn/rewrite/closure-convert.fn index 9f30e018..32ea4313 100644 --- a/fn/rewrite/closure-convert.fn +++ b/fn/rewrite/closure-convert.fn @@ -7,6 +7,8 @@ link "freevars.fn" as FV; link "gensym.fn" as GS; link "subst.fn" as SUBST; +// https://matt.might.net/articles/closure-conversion/ + fn closure_convert { (exp=M.lambda(params, body)) { let diff --git a/fn/rewrite/minexpr.fn b/fn/rewrite/minexpr.fn index 7999c958..c4d879c4 100644 --- a/fn/rewrite/minexpr.fn +++ b/fn/rewrite/minexpr.fn @@ -77,11 +77,11 @@ namespace x; } (x=make_closure(func, env)) { - puts("(CLO "); + puts("[CLO "); print_expr(func); puts(" "); print_expr(env); - puts(")"); + puts("]"); x; } (x=make_env(bindings)) { diff --git a/fn/rewrite/test_harness.fn b/fn/rewrite/test_harness.fn index 7f13b287..ef0189f4 100644 --- a/fn/rewrite/test_harness.fn +++ b/fn/rewrite/test_harness.fn @@ -46,12 +46,11 @@ in // M.print_expr(f); // puts("\n==> operator folding"); // puts(nltab); - puts("\n "); - M.print_expr(g); + // M.print_expr(g); // puts("\n==> shared closure convert"); // puts(nltab); - // M.print_expr(h); - // puts("\n\n\n") + puts("\n "); + M.print_expr(h); puts("\n\n") } }, Samples.data()); \ No newline at end of file diff --git a/src/lambda.yaml b/src/lambda.yaml index 522c5082..5af3d100 100644 --- a/src/lambda.yaml +++ b/src/lambda.yaml @@ -26,7 +26,7 @@ config: - bigint.h - tc.h - tc_debug.h - - lambda_functions.h + - minlam_functions.h structs: LamLam: diff --git a/src/lambda_functions.h b/src/lambda_functions.h deleted file mode 100644 index 20b98a9b..00000000 --- a/src/lambda_functions.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef cekf_lambda_functions_h -#define cekf_lambda_functions_h -/* - * CEKF - VM supporting amb - * Copyright (C) 2022-2025 Bill Hails - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -struct MinExp; -struct AnfKontEnv; -struct CpsKontEnv; - -typedef struct MinExp *(*AnfKontProcWrapper)(struct MinExp *, - struct AnfKontEnv *); -typedef struct MinExp *(*CpsKontProcWrapper)(struct MinExp *, - struct CpsKontEnv *); - -#endif diff --git a/src/main.c b/src/main.c index e9c52f7e..7cfc5486 100644 --- a/src/main.c +++ b/src/main.c @@ -37,13 +37,13 @@ #include "hash.h" #include "init.h" #include "inline.h" -#include "lambda_alphaconvert.h" #include "lambda_conversion.h" #include "lambda_debug.h" #include "lambda_desugar.h" #include "lambda_pp.h" #include "lambda_simplification.h" #include "memory.h" +#include "minlam_alphaconvert.h" #include "minlam_beta.h" #include "minlam_eta.h" #include "minlam_fold.h" @@ -64,7 +64,7 @@ // #define TEST_CPS #ifdef TEST_CPS -#include "lambda_cps.h" +#include "minlam_cps.h" #endif // temporary test diff --git a/src/lambda_alphaconvert.c b/src/minlam_alphaconvert.c similarity index 99% rename from src/lambda_alphaconvert.c rename to src/minlam_alphaconvert.c index 292f0679..881fe77a 100644 --- a/src/lambda_alphaconvert.c +++ b/src/minlam_alphaconvert.c @@ -26,7 +26,7 @@ #include "symbol.h" #include "utils.h" -#include "lambda_alphaconvert.h" +#include "minlam_alphaconvert.h" // Forward declarations static MinLam *visitMinLam(MinLam *node, MinAlphaEnv *context); diff --git a/src/lambda_alphaconvert.h b/src/minlam_alphaconvert.h similarity index 100% rename from src/lambda_alphaconvert.h rename to src/minlam_alphaconvert.h diff --git a/src/lambda_cps.h b/src/minlam_cps.h similarity index 100% rename from src/lambda_cps.h rename to src/minlam_cps.h diff --git a/src/lambda_cpsTc.c b/src/minlam_cpsTc.c similarity index 99% rename from src/lambda_cpsTc.c rename to src/minlam_cpsTc.c index fd6a33e4..34e4c513 100644 --- a/src/lambda_cpsTc.c +++ b/src/minlam_cpsTc.c @@ -26,8 +26,8 @@ #include "cps_kont.h" #include "cps_kont_impl.h" -#include "lambda_cps.h" -#include "lambda_functions.h" +#include "minlam_cps.h" +#include "minlam_functions.h" #ifdef DEBUG_LAMBDA_CPSTC #include "debugging_on.h" diff --git a/src/lambda_cpsTk.c b/src/minlam_cpsTk.c similarity index 99% rename from src/lambda_cpsTk.c rename to src/minlam_cpsTk.c index d444f2b2..9f970ab0 100644 --- a/src/lambda_cpsTk.c +++ b/src/minlam_cpsTk.c @@ -26,8 +26,8 @@ #include "cps_kont.h" #include "cps_kont_impl.h" -#include "lambda_cps.h" -#include "lambda_functions.h" +#include "minlam_cps.h" +#include "minlam_functions.h" #ifdef DEBUG_LAMBDA_CPSTK #include "debugging_on.h" diff --git a/src/minlam_functions.h b/src/minlam_functions.h index 39829901..0e6b052d 100644 --- a/src/minlam_functions.h +++ b/src/minlam_functions.h @@ -19,7 +19,12 @@ */ struct MinExp; +struct AnfKontEnv; +struct CpsKontEnv; -#include "lambda_functions.h" +typedef struct MinExp *(*AnfKontProcWrapper)(struct MinExp *, + struct AnfKontEnv *); +typedef struct MinExp *(*CpsKontProcWrapper)(struct MinExp *, + struct CpsKontEnv *); #endif