Struct erg_compiler::Compiler
source · pub struct Compiler {
pub cfg: ErgConfig,
/* private fields */
}
Expand description
Generates a CodeObj
from an String or other File inputs.
Fields§
§cfg: ErgConfig
Implementations§
source§impl Compiler
impl Compiler
sourcepub fn compile_and_dump_as_pyc<P: AsRef<Path>>(
&mut self,
pyc_path: P,
src: String,
mode: &str
) -> Result<CompileWarnings, ErrorArtifact>
pub fn compile_and_dump_as_pyc<P: AsRef<Path>>(
&mut self,
pyc_path: P,
src: String,
mode: &str
) -> Result<CompileWarnings, ErrorArtifact>
pub fn eval_compile_and_dump_as_pyc<P: AsRef<Path>>(
&mut self,
pyc_path: P,
src: String,
mode: &str
) -> Result<CompleteArtifact<Option<Expr>>, ErrorArtifact>
sourcepub fn compile(
&mut self,
src: String,
mode: &str
) -> Result<CompleteArtifact<CodeObj>, ErrorArtifact>
pub fn compile(
&mut self,
src: String,
mode: &str
) -> Result<CompleteArtifact<CodeObj>, ErrorArtifact>
Examples found in repository?
compile.rs (line 162)
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
fn eval(&mut self, src: String) -> Result<String, CompileErrors> {
let arti = self.compile(src, "eval").map_err(|eart| {
eart.warns.fmt_all_stderr();
eart.errors
})?;
arti.warns.fmt_all_stderr();
Ok(arti.object.code_info(Some(self.code_generator.py_version)))
}
}
use crate::context::Context;
use crate::varinfo::VarInfo;
use erg_parser::ast::VarName;
impl ContextProvider for Compiler {
fn dir(&self) -> Vec<(&VarName, &VarInfo)> {
self.builder.dir()
}
fn get_receiver_ctx(&self, receiver_name: &str) -> Option<&Context> {
self.builder.get_receiver_ctx(receiver_name)
}
fn get_var_info(&self, name: &str) -> Option<(&VarName, &VarInfo)> {
self.builder.get_var_info(name)
}
}
impl Compiler {
pub fn compile_and_dump_as_pyc<P: AsRef<Path>>(
&mut self,
pyc_path: P,
src: String,
mode: &str,
) -> Result<CompileWarnings, ErrorArtifact> {
let arti = self.compile(src, mode)?;
arti.object
.dump_as_pyc(pyc_path, self.cfg.py_magic_num)
.expect("failed to dump a .pyc file (maybe permission denied)");
Ok(arti.warns)
}
sourcepub fn eval_compile(
&mut self,
src: String,
mode: &str
) -> Result<CompleteArtifact<(CodeObj, Option<Expr>)>, ErrorArtifact>
pub fn eval_compile(
&mut self,
src: String,
mode: &str
) -> Result<CompleteArtifact<(CodeObj, Option<Expr>)>, ErrorArtifact>
Examples found in repository?
compile.rs (line 209)
203 204 205 206 207 208 209 210 211 212 213 214
pub fn eval_compile_and_dump_as_pyc<P: AsRef<Path>>(
&mut self,
pyc_path: P,
src: String,
mode: &str,
) -> Result<CompleteArtifact<Option<Expr>>, ErrorArtifact> {
let arti = self.eval_compile(src, mode)?;
let (code, last) = arti.object;
code.dump_as_pyc(pyc_path, self.cfg.py_magic_num)
.expect("failed to dump a .pyc file (maybe permission denied)");
Ok(CompleteArtifact::new(last, arti.warns))
}
Trait Implementations§
source§impl ContextProvider for Compiler
impl ContextProvider for Compiler
source§impl Runnable for Compiler
impl Runnable for Compiler
type Err = CompileError
type Errs = CompileErrors
const NAME: &'static str = "Erg compiler"
fn new(cfg: ErgConfig) -> Self
fn cfg(&self) -> &ErgConfig
fn cfg_mut(&mut self) -> &mut ErgConfig
fn finish(&mut self)
source§fn initialize(&mut self)
fn initialize(&mut self)
Erase all but immutable information.