mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
feat: add std.d
This commit is contained in:
parent
51cae591a3
commit
677ced0fcd
7 changed files with 131 additions and 14 deletions
|
@ -77,19 +77,17 @@ impl Context {
|
|||
Public,
|
||||
Some(FUNC_CONJUGATE),
|
||||
);
|
||||
float.register_builtin_py_impl(
|
||||
FUNC_IS_INTEGER,
|
||||
fn0_met(Float, Bool),
|
||||
Const,
|
||||
Public,
|
||||
Some(FUNC_IS_INTEGER),
|
||||
);
|
||||
float.register_builtin_py_impl(
|
||||
float.register_py_builtin(
|
||||
FUNC_HEX,
|
||||
fn0_met(Float, Str),
|
||||
Const,
|
||||
Public,
|
||||
Some(FUNC_HEX),
|
||||
24,
|
||||
);
|
||||
float.register_py_builtin(
|
||||
FUNC_IS_INTEGER,
|
||||
fn0_met(Float, Bool),
|
||||
Some(FUNC_IS_INTEGER),
|
||||
32,
|
||||
);
|
||||
float.register_builtin_py_impl(
|
||||
FUNC_FROMHEX,
|
||||
|
@ -562,6 +560,7 @@ impl Context {
|
|||
Public,
|
||||
Some(FUNC_COUNT),
|
||||
);
|
||||
str_.register_py_builtin(FUNC_CAPITALIZE, fn0_met(Str, Str), Some(FUNC_CAPITALIZE), 13);
|
||||
str_.register_builtin_erg_impl(FUNC_CONTAINS, fn1_met(Str, Str, Bool), Immutable, Public);
|
||||
let str_getitem_t = fn1_kw_met(Str, kw(KW_IDX, Nat), Str);
|
||||
str_.register_builtin_erg_impl(FUNDAMENTAL_GETITEM, str_getitem_t, Immutable, Public);
|
||||
|
|
|
@ -134,6 +134,7 @@ const FUNC_UPPER: &str = "upper";
|
|||
const FUNC_TO_INT: &str = "to_int";
|
||||
const FUNC_STARTSWITH: &str = "startswith";
|
||||
const FUNC_ENDSWITH: &str = "endswith";
|
||||
const FUNC_CAPITALIZE: &str = "capitalize";
|
||||
const FUNC_CONTAINS: &str = "contains";
|
||||
const FUNC_SPLIT: &str = "split";
|
||||
const FUNC_SPLITLINES: &str = "splitlines";
|
||||
|
@ -438,6 +439,15 @@ pub fn builtins_path() -> PathBuf {
|
|||
PathBuf::from("lib/pystd/builtins.d.er")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
pub fn std_decl_path() -> PathBuf {
|
||||
erg_common::env::erg_std_decl_path()
|
||||
}
|
||||
#[cfg(feature = "no_std")]
|
||||
pub fn builtins_path() -> PathBuf {
|
||||
PathBuf::from("lib/std.d")
|
||||
}
|
||||
|
||||
impl Context {
|
||||
fn register_builtin_decl(
|
||||
&mut self,
|
||||
|
@ -578,14 +588,19 @@ impl Context {
|
|||
} else {
|
||||
VarName::from_static(name)
|
||||
};
|
||||
let vis = if cfg!(feature = "py_compatible") {
|
||||
let vis = if cfg!(feature = "py_compatible") || &self.name[..] != "<builtins>" {
|
||||
Public
|
||||
} else {
|
||||
Private
|
||||
};
|
||||
let muty = Immutable;
|
||||
let loc = Location::range(lineno, 0, lineno, name.inspect().len() as u32);
|
||||
let abs_loc = AbsLocation::new(Some(builtins_path()), loc);
|
||||
let module = if &self.name[..] == "<builtins>" {
|
||||
builtins_path()
|
||||
} else {
|
||||
std_decl_path().join(format!("{}.d.er", self.name))
|
||||
};
|
||||
let abs_loc = AbsLocation::new(Some(module), loc);
|
||||
self.register_builtin_impl(name, t, muty, vis, py_name, abs_loc);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue