一键导入
macro-code-gen
How libraries (html_cbi, preact_cbi, react_cbi, solid_cbi, universal_cbi) generate code
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
How libraries (html_cbi, preact_cbi, react_cbi, solid_cbi, universal_cbi) generate code
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Comprehensive guide to the Chemical compiler test infrastructure — how tests are organized, written, and executed. Covers the test framework, @test annotation dispatch, test_env and test libraries, and how compiler plugins get tested via lang/tests/build.lab.
Comprehensive deep-dive into the Chemical build pipeline — how chemical.mod is converted to build.lab, how build scripts are JIT-compiled via TinyCC, how jobs are created and executed, and how ASTProcessor orchestrates the parallel compilation passes.
All documentation related to building and running Project or Tests
Comprehensive guide to the Chemical Compiler Binding Interface (CBI) — how compiler plugins are built, registered, and integrated into the compilation pipeline.
Documentation of Syntax and APIs for Chemical Programming Language, A must read before implementing something in chemical programming language.s
Comprehensive guide to Chemical's compiler intrinsic functions and reflection APIs — how GlobalFunctions.cpp provides interpreter-friendly implementations, compile-time reflection, and metadata access.
| name | Macro Code gen |
| description | How libraries (html_cbi, preact_cbi, react_cbi, solid_cbi, universal_cbi) generate code |
When you write in chemical
func my_html(page : &mut HtmlPage) {
#html {
<span>Hello World</span>
}
}
Whats actually happening is, behind the scenes this code gets generated
func my_html(page : &mut HtmlPage) {
page.append_html_view("<span>Hello World</span>");
}
Its not the exact code, but its pretty close, The difference happens when you use a chemical value, for example This code
func my_html(page : &mut HtmlPage, name : &std::string_view) {
#html {
<span>Hello {name}</span>
}
}
generates
func my_html(page : &mut HtmlPage, name : &std::string_view) {
page.append_html_view("<span>Hello ");
// this method basically calls append_html
// it exists in lang/libs/page/src/PageWriter.ch
name.writeToPageBody(page)
page.append_html_view("</span>");
}
This is how we handle chemical values, But you may notice that we support top level macros
#preact, #react, #solid, #universal All these component framework libraries are top level macros. The reason being
that these handle components and that's why.
for example
#preact Greeting(props) {
return <div>Hello {props.name}</div>
}
It doesn't have a encapsulating function, so it generates one, it generates code like
func Greeting(page : &mut HtmlPage) {
if(!page.requires_component(123)) {
return;
}
page.set_has_component(123)
page.append_head_js_view("function Greeting_component(props) { ... }")
}
The function names maybe a little different, but they accomplish similar logic, however universal is different
universal lib generate a function that takes two more parameters, an SsrAttributeList, content for the children
universal lib also generates in both bundles, HTML that is server side rendered (from the component) and then a js function
that would hydrate the emitted html.
universal components are fast and they render everywhere, they work in react, preact and solid components. They work in #html too.
For more information on universal components, load the universal skill. For developing new compiler plugins or understanding the plugin API, load the cbi_plugin_api skill. For understanding the compiler intrinsics and reflection APIs that macros can use at compile time, load the intrinsics_compiler_reflection skill.