{"id":50657356,"url":"https://github.com/pineforge-4pass/pineforge-codegen-oss","last_synced_at":"2026-06-08T00:11:23.551Z","repository":{"id":362348742,"uuid":"1258481542","full_name":"pineforge-4pass/pineforge-codegen-oss","owner":"pineforge-4pass","description":"PineScript v6 → C++ transpiler (source-available, PolyForm Noncommercial). Targets the pineforge-engine runtime.","archived":false,"fork":false,"pushed_at":"2026-06-03T19:33:04.000Z","size":291,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-03T21:12:58.700Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pineforge-4pass.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-03T16:09:14.000Z","updated_at":"2026-06-03T19:33:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pineforge-4pass/pineforge-codegen-oss","commit_stats":null,"previous_names":["pineforge-4pass/pineforge-codegen-oss"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pineforge-4pass/pineforge-codegen-oss","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-oss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-oss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-oss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-oss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pineforge-4pass","download_url":"https://codeload.github.com/pineforge-4pass/pineforge-codegen-oss/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-oss/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34042761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-07T02:00:07.652Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-08T00:11:20.910Z","updated_at":"2026-06-08T00:11:23.545Z","avatar_url":"https://github.com/pineforge-4pass.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pineforge-codegen\n\n\u003e PineScript v6 → C++ transpiler that emits against the [pineforge-engine](https://github.com/pineforge-4pass/pineforge-engine) runtime.\n\n[![PyPI](https://img.shields.io/pypi/v/pineforge-codegen.svg)](https://pypi.org/project/pineforge-codegen/)\n[![Python](https://img.shields.io/pypi/pyversions/pineforge-codegen.svg)](https://pypi.org/project/pineforge-codegen/)\n[![License](https://img.shields.io/badge/license-PolyForm%20Noncommercial%201.0.0-orange.svg)](LICENSE)\n[![Personal use](https://img.shields.io/badge/personal%20trading-free-22c55e.svg)](#license)\n\nA pure-Python library that turns a PineScript v6 strategy into a complete C++\nsource file you can compile against the [`pineforge-engine`](https://github.com/pineforge-4pass/pineforge-engine)\nruntime — a deterministic native backtester validated **trade-for-trade against\nTradingView** (231/232 corpus parity).\n\nIt is **source-available and free for personal trading** — research, backtest,\nand trade your own account with your own capital at no cost. See\n[License](#license) for the line between personal and commercial use.\n\n- **Pure Python, zero runtime dependencies** — one function, `transpile()`.\n- **Fails loud, never silent** — a support checker rejects Pine the engine can't\n  faithfully run *before* codegen, with a `file:line:col` error. You never get\n  silently-wrong C++.\n- First complete PineScript v6 → C++ transpiler with a real support checker (to\n  our knowledge).\n\n---\n\n## Install\n\n```bash\npip install pineforge-codegen\n```\n\nRequires Python ≥ 3.11. No runtime dependencies.\n\nFrom source (development / contributing):\n\n```bash\ngit clone https://github.com/pineforge-4pass/pineforge-codegen-oss.git\ncd pineforge-codegen-oss\npip install -e \".[dev]\"\n```\n\n## Quick start\n\n```python\nfrom pineforge_codegen import transpile\n\npine = \"\"\"\n//@version=6\nstrategy(\"SMA cross\", overlay=true)\nfast = ta.sma(close, 10)\nslow = ta.sma(close, 30)\nif ta.crossover(fast, slow)\n    strategy.entry(\"long\", strategy.long)\nif ta.crossunder(fast, slow)\n    strategy.close(\"long\")\n\"\"\"\n\ncpp = transpile(pine)\nprint(cpp)          # complete C++ source string\n```\n\nThe output `#include`s `\u003cpineforge/engine.hpp\u003e`, `\u003cpineforge/ta.hpp\u003e`, … and\ncompiles into a `.so` exposing the engine's documented C-ABI.\n\n## Usage\n\n### The `transpile()` function\n\n```python\ntranspile(\n    pine_source: str,\n    *,\n    check_support: bool = True,   # run the support checker before codegen\n    filename: str = \"\u003cinput\u003e\",    # name used in error locations\n) -\u003e str\n```\n\nReturns the generated C++ source as a string. Raises\n`pineforge_codegen.errors.CompileError` on any unsupported construct or syntax\nerror.\n\n### Transpile a file to a `.cpp`\n\n```python\nfrom pathlib import Path\nfrom pineforge_codegen import transpile\n\npine = Path(\"strategy.pine\")\ncpp = transpile(pine.read_text(), filename=pine.name)   # filename → better errors\nPath(\"strategy.generated.cpp\").write_text(cpp)\n```\n\n### Handle unsupported features\n\nThe support checker raises a `CompileError` with the exact source location\ninstead of emitting broken C++:\n\n```python\nfrom pineforge_codegen import transpile\nfrom pineforge_codegen.errors import CompileError\n\ntry:\n    transpile('//@version=6\\nindicator(\"x\")\\n')\nexcept CompileError as e:\n    print(e)\n    # \u003cinput\u003e:2:1: indicator() declarations are not supported; PineForge runs strategies only.\n\ntry:\n    transpile('//@version=6\\nstrategy(\"x\")\\n'\n              'x = request.financial(\"AAPL\", \"REV\", \"FQ\")\\n')\nexcept CompileError as e:\n    print(e)\n    # \u003cinput\u003e:3:22: request.financial(...) is not supported.\n```\n\nPass `filename=` so the location points back at the user's file:\n\n```python\ntranspile(src, filename=\"my_strategy.pine\")\n# raises e.g.  my_strategy.pine:12:5: ...\n```\n\n### Skip the support checker\n\n`check_support=False` bypasses the gate (intended only for tests of legacy\nfixtures — it can produce C++ the engine won't accept):\n\n```python\ncpp = transpile(src, check_support=False)\n```\n\n### Trace intermediate expressions (`@pf-trace`)\n\nA `// @pf-trace name=expr` comment makes the engine emit `name`'s per-bar value\nin the backtest report — useful for debugging parity against TradingView:\n\n```python\npine = \"\"\"\n//@version=6\nstrategy(\"traced\")\n// @pf-trace rsi=ta.rsi(close, 14)\ne = ta.ema(close, 20)\nif close \u003e e\n    strategy.entry(\"L\", strategy.long)\n\"\"\"\ncpp = transpile(pine)   # emitted on_bar tail records `rsi` each bar\n```\n\n### Advanced: run the pipeline stages directly\n\n`transpile()` is a thin wrapper over five passes. Drive them yourself to inspect\ntokens, the AST, or the analyzer context:\n\n```python\nfrom pineforge_codegen import (\n    Lexer, Parser, Analyzer, CodeGen,\n    extract_pf_trace_pragmas, check_support_or_raise,\n)\n\nsrc = open(\"strategy.pine\").read()\npragmas = extract_pf_trace_pragmas(src)\ntokens  = Lexer(src, filename=\"strategy.pine\").tokenize()\nast     = Parser(tokens, source=src, filename=\"strategy.pine\").parse()\ncheck_support_or_raise(ast, filename=\"strategy.pine\")\nctx     = Analyzer(ast, filename=\"strategy.pine\").analyze()\nctx.pf_trace_pragmas = pragmas\ncpp     = CodeGen(ctx).generate()\n```\n\n## How it works\n\n`transpile()` runs five passes, in order:\n\n```\npine source\n  │\n  ├─ 1. extract_pf_trace_pragmas   // @pf-trace comments pulled out first\n  ├─ 2. Lexer → Parser             token stream → Pine v6 AST\n  ├─ 3. support_checker            reject anything the engine can't run faithfully\n  ├─ 4. Analyzer                   type inference, scope resolution, TA bookkeeping\n  └─ 5. CodeGen                    → C++ source string\n```\n\n## Compile \u0026 run against the engine\n\nThe emitted C++ targets the C-ABI in `\u003cpineforge/pineforge.h\u003e`. To build and run\na strategy:\n\n```bash\n# Get the runtime (Apache-2.0) next to this repo\ngit clone https://github.com/pineforge-4pass/pineforge-engine.git\n```\n\nFollow the engine's [`tutorial/`](https://github.com/pineforge-4pass/pineforge-engine/tree/main/tutorial)\nto build `libpineforge.a`, compile your transpiled `.cpp` into a strategy `.so`,\nfeed it OHLCV, and read back the closed-trade list. The codegen version must\ntarget a matching engine ABI (see [`VERSION`](VERSION)).\n\nPrefer no local build? A hosted transpile API + MCP server is available so AI\nagents can transpile and backtest for you — see \u003chttps://www.pineforge.dev\u003e.\n\n## Running tests\n\n```bash\npip install -e \".[dev]\"\npytest\n```\n\nThe pure-transpiler suite is fast (\u003c 1 s) and has no native dependencies — it\nchecks token streams, parse trees, analyzer output, and canonical C++ strings\nwithout invoking a C++ compiler.\n\nOpt-in compile checks (`tests/test_compile_smoke.py`, `tests/test_compile_corpus.py`)\nrun `g++ -fsyntax-only` on transpiled C++ against the engine headers. They\nauto-detect a sibling `../pineforge-engine` checkout, or set the path explicitly:\n\n```bash\nexport PINEFORGE_ENGINE_INCLUDE=/path/to/pineforge-engine/include\npytest\n```\n\nWithout an engine checkout these tests skip cleanly, so CI stays green.\n\n## License\n\nSource-available under the [PolyForm Noncommercial License 1.0.0](LICENSE), with\ntwo supplemental terms (the `LICENSE` file is the controlling text):\n\n- **Personal Trading exception** — free to research, backtest, and trade for your\n  own account with your own capital.\n- **Commercial use** — companies, funds, managing third-party capital, embedding\n  in a product, or operating a hosted / public-facing service requires a\n  commercial license.\n\nCompeting hosted services are not permitted under the noncommercial terms. This\nis source-available, not OSI open source.\n\n### Buying a commercial license\n\nCommercial licenses are available — flexible terms for funds, products, and\nhosted/embedded use. Email **luis@4pass.com.tw** with your use case for a quote.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpineforge-4pass%2Fpineforge-codegen-oss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpineforge-4pass%2Fpineforge-codegen-oss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpineforge-4pass%2Fpineforge-codegen-oss/lists"}