Skip to content

🔨 Refactor code-generation#77

Open
serkor1 wants to merge 8 commits into
develfrom
refactor-codegen
Open

🔨 Refactor code-generation#77
serkor1 wants to merge 8 commits into
develfrom
refactor-codegen

Conversation

@serkor1

@serkor1 serkor1 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

📚 What?

The library is currently standing at +300k line additions and 230k line removals. TA-Lib indicators are at 12k lines alone, and the code-generators alone are in a ballpark that is beyond what is maintainable in the long run. Furthermore, the transition from manually coding everything to migrating to BASH for auto-generating the code has introduced a wide variety of bugs (See, example, Issue #39).

To mitigate this I have opened Issue #75, but the {boilerplate.rs} did not really solve the complexity of the code-generation as the config.toml-file itself varied between 700-1200 lines of code (And this is even with the help AI). This PR introduces the following changes:

  • Use ta_func_list.txt to identify all exported functions, and (somewhat) simple Rust program to mine all indicators with all input-arguments from ta_func.h. This has two benefits. First, Rust is easier to maintain and handle and secondly the deterministic mining forces ALL signatures to be "correct" on the C-side which means that Issues like 🔨 Change MA-wrapper #39 should not happen.1
  • Use X-Macros for creating R-wrappers via the C API which has the following benefit: way faster compilation time, and an extra layer of protection against Issues like 🔨 Change MA-wrapper #39 in the long run. The downside: Its one giant black box that I have only started to understand.1

📋 TODO

  • Rewrite the C-wrappers so it uses X-Macros
  • Rewrite the Makefile so obsolete targets are removed
  • Delete obsolete C-related BASH scripts

Important

We need to implement Candlestick indicators so it candlestick specific logic can be implemented
in the core logic.

Footnotes

  1. The bugs, errors and slow compilation time is obviously my own fault. And the rewrite is mainly driven by me wanting to learn new stuff and having a maintainable repository. 2

* The code-generator currently only works for the TA-Lib (C-side) indicators and uses the TA-Lib functions list to identify all indicators with their respective signatures wrapped in X-Macros. The goal is to be independent from BASH and use an algorithmic approach so input arguments that has default values are not silently dropped. Furthermore it is expected that ALL TA-Lib indicators will be generated using X-Macros.
@serkor1 serkor1 added enhancement New feature or request dependencies Pull requests that update a dependency file labels Jul 9, 2026
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.23353% with 223 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.02%. Comparing base (1f8d568) to head (0010b89).

Files with missing lines Patch % Lines
src/TA-Lib.h 0.00% 195 Missing ⚠️
src/TA-Lib.c 26.92% 19 Missing ⚠️
src/init.c 25.00% 3 Missing ⚠️
src/names.c 83.33% 3 Missing ⚠️
src/shift.c 88.88% 2 Missing ⚠️
src/attributes.c 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel      #77      +/-   ##
==========================================
- Coverage   96.47%   95.02%   -1.46%     
==========================================
  Files         281      153     -128     
  Lines       23849    16890    -6959     
==========================================
- Hits        23009    16049    -6960     
- Misses        840      841       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

serkor1 added 7 commits July 10, 2026 07:22
* The X-Macros will be using TA_* prefixes
  for readable preprocessing. So DBL --> TA_DOUBLE
  for doubles.
* The codegen/ now also parses the TA_<indicator>_Lookback
  signatures which is the optional inputs for all the functions.

* The original C_MACRO has been renamed to BATCH to distinguish
  between streaming (Upcoming) and batch API for later TA-Lib versions.
* The identifiers follows a simple if-else statement for identifying
  candlesticks based on the indicator name 'CDL'.
  With this implementation it is now possible to implement candlestick-specific
  logic on the C preprocessing side without having to rewrite the logic downstream.
* All lookback related functions have been removed to accomodate
  the new codegen that uses the exact signature of the TA_<indicato>_lookback
  funtions.
## 📚 What?

This PR is a rewrite of the source code that binds TA-Lib to R. The
overall goal is to reduce the amount of code, and simplify the
C-wrappers. It has been implemented incrementally, so much of the
original functionality as been deleted but is to be reintroduced in a
similar fashion.

There has been no consideration for backwards compatibility which in
this case means that a part of the R logic has to be re-written (This
does not affect the signatures at all). All *_lookback functions, for
example, now only accepts the relevant arguments in `.Call()` which
breaks with the current R side logic. (This should be possible by only
rewriting the templates, so the PR is mainly focused on the C-side)
* fmt target now also runs cargo fmt on the crate
* gen-code target now includes cargo run
* Deleted old script runners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant