feat: add std.d

This commit is contained in:
Shunsuke Shibayama 2023-02-17 21:09:23 +09:00
parent 51cae591a3
commit 677ced0fcd
7 changed files with 131 additions and 14 deletions

View file

@ -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);

View file

@ -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);
}