mirror of
https://github.com/erg-lang/erg.git
synced 2025-07-07 21:25:31 +00:00
.. | ||
context | ||
error | ||
lib | ||
module | ||
tests | ||
ty | ||
.gitignore | ||
artifact.rs | ||
build.rs | ||
build_hir.rs | ||
build_package.rs | ||
Cargo.toml | ||
codegen.rs | ||
compile.rs | ||
declare.rs | ||
desugar_hir.rs | ||
effectcheck.rs | ||
hir.rs | ||
lib.rs | ||
link_ast.rs | ||
link_hir.rs | ||
lint.rs | ||
lower.rs | ||
main.rs | ||
optimize.rs | ||
ownercheck.rs | ||
README.md | ||
transpile.rs | ||
varinfo.rs |
The Erg compiler (codename: Centimetre)
The overall structure is described in detail in architecture.md(English).For other language translations of architecture.md, please check them out by yourself.
Use erg_compiler
as a Python library
erg_compiler
can be built as a Python library by using pyo3/maturin.
Example
import erg_compiler
module = erg_compiler.exec_module(".i = 1")
# foo.er:
# .bar = 1
foo = erg_compiler.__import__("foo")
assert module.i == 1
assert foo.bar == 1
import erg_compiler
erg_parser = erg_compiler.erg_parser
erg_ast = erg_compiler.erg_parser.ast
module = erg_parser.parse(".i = 1")
d = module.pop()
d.sig = erg_ast.VarSignature.new(erg_ast.Identifier.public("j"), None)
module.push(d)
ast = erg_ast.AST.new("test", module)
code = erg_compiler.compile_ast(ast)
exec(code)
assert j == 1
Debug install (using venv)
python -m venv .venv
source .venv/bin/activate
maturin develop --features pylib_compiler
Release install
maturin build -i python --release --features pylib_compiler
pip install <output wheel>