Refactor: Introduce system library

- Add `rtl/system.myc` as the system library, containing core utilities
  like `while` and `cache`.
- Remove the duplicate `prelude.myc` from `src/ast/rtl/`.
- Modify `Environment::collect_dependencies` to implicitly add `#use
  system` when necessary.
- Update `Environment::with_cwd` to also add the `rtl` subdirectory to
  search paths.
- Add `target/` to `.geminiignore` to exclude build artifacts.
- Adjust example `sma.myc` to use the new `cache` macro and reduce
  sample data size.
- Update `rtl/sma.myc` to correctly initialize the `history` series with
  its `length`.
- Add `preload_dependencies` calls to `dump_ast` and `run_script` for
  proper module loading.
This commit is contained in:
Michael Schimmel
2026-03-08 12:09:32 +01:00
parent 595bcf09e5
commit 4dfdc75545
7 changed files with 56 additions and 63 deletions
-31
View File
@@ -1,31 +0,0 @@
;; Myc Prelude
;; This file is evaluated during Environment bootstrapping.
;; It contains standard macros and functions.
(macro while [cond body]
`((fn [] (if ~cond
(do ~body (again))
)))
)
;; Creates a stateful cache (Series) from a stateless stream.
;;
;; Pipes are highly optimized, stateless stream-routers that do not allocate memory
;; for historical data. If multiple indicators need to read historical data from
;; a stream, or if you need to access previous items via index (e.g. `(my_data 5)`),
;; you must explicitly cache the stream.
;;
;; Parameters:
;; lookback: The maximum number of items to keep in memory (e.g. 100).
;; type: The data type or schema of the series (e.g. :float or {:price :float}).
;; src: The source stream to observe and cache.
;;
;; Returns:
;; A stateful Series object that automatically updates when the source stream fires.
(macro cache [lookback type src]
`(do
(def data (series ~lookback ~type))
(pipe [~src] (fn [s] (do (push data s))))
data
)
)