mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
refactor: std -> core
This commit is contained in:
parent
767d51d48b
commit
6de8355a25
40 changed files with 52 additions and 37 deletions
|
@ -32,14 +32,24 @@ fn _erg_std_path() -> PathBuf {
|
||||||
fallback_erg_path().join("lib/std")
|
fallback_erg_path().join("lib/std")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn _erg_std_decl_path() -> PathBuf {
|
fn _erg_core_path() -> PathBuf {
|
||||||
_erg_path()
|
_erg_path()
|
||||||
.join("lib")
|
.join("lib")
|
||||||
.join("std.d")
|
.join("core")
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
eprintln!("{RED}[ERR] ERG_PATH/lib/std.d not found {RESET}");
|
eprintln!("{RED}[ERR] ERG_PATH/lib/core not found{RESET}");
|
||||||
fallback_erg_path().join("lib/std.d")
|
fallback_erg_path().join("lib/core")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn _erg_core_decl_path() -> PathBuf {
|
||||||
|
_erg_path()
|
||||||
|
.join("lib")
|
||||||
|
.join("core.d")
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap_or_else(|_| {
|
||||||
|
eprintln!("{RED}[ERR] ERG_PATH/lib/core.d not found {RESET}");
|
||||||
|
fallback_erg_path().join("lib/core.d")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn _erg_pystd_path() -> PathBuf {
|
fn _erg_pystd_path() -> PathBuf {
|
||||||
|
@ -76,8 +86,9 @@ fn _python_site_packages() -> impl Iterator<Item = PathBuf> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static ERG_PATH: OnceLock<PathBuf> = OnceLock::new();
|
pub static ERG_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||||
|
pub static ERG_CORE_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||||
|
pub static ERG_CORE_DECL_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||||
pub static ERG_STD_PATH: OnceLock<PathBuf> = OnceLock::new();
|
pub static ERG_STD_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||||
pub static ERG_STD_DECL_PATH: OnceLock<PathBuf> = OnceLock::new();
|
|
||||||
pub static ERG_PYSTD_PATH: OnceLock<PathBuf> = OnceLock::new();
|
pub static ERG_PYSTD_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||||
pub static ERG_EXTERNAL_LIB_PATH: OnceLock<PathBuf> = OnceLock::new();
|
pub static ERG_EXTERNAL_LIB_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||||
pub static PYTHON_SITE_PACKAGES: OnceLock<Vec<PathBuf>> = OnceLock::new();
|
pub static PYTHON_SITE_PACKAGES: OnceLock<Vec<PathBuf>> = OnceLock::new();
|
||||||
|
@ -87,16 +98,21 @@ pub fn erg_path() -> &'static PathBuf {
|
||||||
ERG_PATH.get_or_init(|| normalize_path(_erg_path())) // .with(|s| s.clone())
|
ERG_PATH.get_or_init(|| normalize_path(_erg_path())) // .with(|s| s.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// == `Path::new("~/.erg/lib/core")` if ERG_PATH is not set
|
||||||
|
pub fn erg_core_path() -> &'static PathBuf {
|
||||||
|
ERG_CORE_PATH.get_or_init(|| normalize_path(_erg_core_path()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// == `Path::new("~/.erg/lib/core.d")` if ERG_PATH is not set
|
||||||
|
pub fn erg_core_decl_path() -> &'static PathBuf {
|
||||||
|
ERG_CORE_DECL_PATH.get_or_init(|| normalize_path(_erg_core_decl_path()))
|
||||||
|
}
|
||||||
|
|
||||||
/// == `Path::new("~/.erg/lib/std")` if ERG_PATH is not set
|
/// == `Path::new("~/.erg/lib/std")` if ERG_PATH is not set
|
||||||
pub fn erg_std_path() -> &'static PathBuf {
|
pub fn erg_std_path() -> &'static PathBuf {
|
||||||
ERG_STD_PATH.get_or_init(|| normalize_path(_erg_std_path()))
|
ERG_STD_PATH.get_or_init(|| normalize_path(_erg_std_path()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// == `Path::new("~/.erg/lib/std.d")` if ERG_PATH is not set
|
|
||||||
pub fn erg_std_decl_path() -> &'static PathBuf {
|
|
||||||
ERG_STD_DECL_PATH.get_or_init(|| normalize_path(_erg_std_decl_path()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// == `Path::new("~/.erg/lib/pystd")` if ERG_PATH is not set
|
/// == `Path::new("~/.erg/lib/pystd")` if ERG_PATH is not set
|
||||||
pub fn erg_pystd_path() -> &'static PathBuf {
|
pub fn erg_pystd_path() -> &'static PathBuf {
|
||||||
ERG_PYSTD_PATH.get_or_init(|| normalize_path(_erg_pystd_path()))
|
ERG_PYSTD_PATH.get_or_init(|| normalize_path(_erg_pystd_path()))
|
||||||
|
@ -113,7 +129,6 @@ pub fn python_site_packages() -> &'static Vec<PathBuf> {
|
||||||
|
|
||||||
pub fn is_std_decl_path(path: &Path) -> bool {
|
pub fn is_std_decl_path(path: &Path) -> bool {
|
||||||
path.starts_with(erg_pystd_path().as_path())
|
path.starts_with(erg_pystd_path().as_path())
|
||||||
|| path.starts_with(erg_std_decl_path().as_path())
|
|
||||||
|| path.starts_with(erg_py_external_lib_path().as_path())
|
|| path.starts_with(erg_py_external_lib_path().as_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::process;
|
||||||
|
|
||||||
use erg_common::cache::CacheSet;
|
use erg_common::cache::CacheSet;
|
||||||
use erg_common::config::ErgConfig;
|
use erg_common::config::ErgConfig;
|
||||||
use erg_common::env::erg_std_path;
|
use erg_common::env::erg_core_path;
|
||||||
use erg_common::error::{ErrorDisplay, Location};
|
use erg_common::error::{ErrorDisplay, Location};
|
||||||
use erg_common::fresh::SharedFreshNameGenerator;
|
use erg_common::fresh::SharedFreshNameGenerator;
|
||||||
use erg_common::io::Input;
|
use erg_common::io::Input;
|
||||||
|
@ -3809,7 +3809,7 @@ impl PyCodeGenerator {
|
||||||
);
|
);
|
||||||
self.emit_load_name_instr(Identifier::private("#path"));
|
self.emit_load_name_instr(Identifier::private("#path"));
|
||||||
self.emit_load_method_instr(Identifier::public("append"));
|
self.emit_load_method_instr(Identifier::public("append"));
|
||||||
self.emit_load_const(erg_std_path().to_str().unwrap());
|
self.emit_load_const(erg_core_path().to_str().unwrap());
|
||||||
self.emit_call_instr(1, BoundAttr);
|
self.emit_call_instr(1, BoundAttr);
|
||||||
self.stack_dec();
|
self.stack_dec();
|
||||||
self.emit_pop_top();
|
self.emit_pop_top();
|
||||||
|
|
|
@ -15,7 +15,7 @@ use std::path::PathBuf;
|
||||||
use erg_common::config::ErgConfig;
|
use erg_common::config::ErgConfig;
|
||||||
use erg_common::consts::{DEBUG_MODE, ERG_MODE, PYTHON_MODE};
|
use erg_common::consts::{DEBUG_MODE, ERG_MODE, PYTHON_MODE};
|
||||||
use erg_common::dict;
|
use erg_common::dict;
|
||||||
use erg_common::env::{erg_pystd_path, erg_std_decl_path};
|
use erg_common::env::{erg_core_decl_path, erg_pystd_path};
|
||||||
use erg_common::error::Location;
|
use erg_common::error::Location;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use erg_common::log;
|
use erg_common::log;
|
||||||
|
@ -729,7 +729,7 @@ impl Context {
|
||||||
let module = if &self.name[..] == "<builtins>" {
|
let module = if &self.name[..] == "<builtins>" {
|
||||||
builtins_path()
|
builtins_path()
|
||||||
} else {
|
} else {
|
||||||
erg_std_decl_path().join(format!("{}.d.er", self.name))
|
erg_core_decl_path().join(format!("{}.d.er", self.name))
|
||||||
};
|
};
|
||||||
let abs_loc = AbsLocation::new(Some(module.into()), loc);
|
let abs_loc = AbsLocation::new(Some(module.into()), loc);
|
||||||
self.register_builtin_impl(name, t, muty, vis, py_name, abs_loc);
|
self.register_builtin_impl(name, t, muty, vis, py_name, abs_loc);
|
||||||
|
|
|
@ -14,7 +14,7 @@ use DefaultInfo::*;
|
||||||
use Mutability::*;
|
use Mutability::*;
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// see std/prelude.er
|
/// see core/prelude.er
|
||||||
/// All type boundaries are defined in each subroutine
|
/// All type boundaries are defined in each subroutine
|
||||||
/// `push_subtype_bound`, etc. are used for type boundary determination in user-defined APIs
|
/// `push_subtype_bound`, etc. are used for type boundary determination in user-defined APIs
|
||||||
// 型境界はすべて各サブルーチンで定義する
|
// 型境界はすべて各サブルーチンで定義する
|
||||||
|
|
|
@ -433,29 +433,29 @@ impl PyScriptGenerator {
|
||||||
// TODO: name escaping
|
// TODO: name escaping
|
||||||
fn load_range_ops_if_not(&mut self) {
|
fn load_range_ops_if_not(&mut self) {
|
||||||
if !self.range_ops_loaded {
|
if !self.range_ops_loaded {
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_result.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_result.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_int.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_int.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_nat.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_nat.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_str.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_str.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_range.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_range.py"));
|
||||||
self.range_ops_loaded = true;
|
self.range_ops_loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_contains_op_if_not(&mut self) {
|
fn load_contains_op_if_not(&mut self) {
|
||||||
if !self.contains_op_loaded {
|
if !self.contains_op_loaded {
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_result.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_result.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_range.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_range.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_type.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_type.py"));
|
||||||
self.prelude +=
|
self.prelude +=
|
||||||
&Self::replace_import(include_str!("lib/std/_erg_contains_operator.py"));
|
&Self::replace_import(include_str!("lib/core/_erg_contains_operator.py"));
|
||||||
self.contains_op_loaded = true;
|
self.contains_op_loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_mutate_op_if_not(&mut self) {
|
fn load_mutate_op_if_not(&mut self) {
|
||||||
if !self.mutate_op_loaded {
|
if !self.mutate_op_loaded {
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_mutate_operator.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_mutate_operator.py"));
|
||||||
self.mutate_op_loaded = true;
|
self.mutate_op_loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,15 +465,15 @@ impl PyScriptGenerator {
|
||||||
self.load_builtin_controls_if_not();
|
self.load_builtin_controls_if_not();
|
||||||
self.load_contains_op_if_not();
|
self.load_contains_op_if_not();
|
||||||
if self.range_ops_loaded {
|
if self.range_ops_loaded {
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_float.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_float.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_array.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_array.py"));
|
||||||
} else {
|
} else {
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_int.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_int.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_nat.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_nat.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_bool.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_bool.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_str.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_str.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_float.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_float.py"));
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_array.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_array.py"));
|
||||||
}
|
}
|
||||||
self.builtin_types_loaded = true;
|
self.builtin_types_loaded = true;
|
||||||
}
|
}
|
||||||
|
@ -481,14 +481,14 @@ impl PyScriptGenerator {
|
||||||
|
|
||||||
fn load_builtin_controls_if_not(&mut self) {
|
fn load_builtin_controls_if_not(&mut self) {
|
||||||
if !self.builtin_control_loaded {
|
if !self.builtin_control_loaded {
|
||||||
self.prelude += include_str!("lib/std/_erg_control.py");
|
self.prelude += include_str!("lib/core/_erg_control.py");
|
||||||
self.builtin_control_loaded = true;
|
self.builtin_control_loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_convertors_if_not(&mut self) {
|
fn load_convertors_if_not(&mut self) {
|
||||||
if !self.convertors_loaded {
|
if !self.convertors_loaded {
|
||||||
self.prelude += &Self::replace_import(include_str!("lib/std/_erg_convertors.py"));
|
self.prelude += &Self::replace_import(include_str!("lib/core/_erg_convertors.py"));
|
||||||
self.convertors_loaded = true;
|
self.convertors_loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue