mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 20:34:44 +00:00
Add datetime
This commit is contained in:
parent
e31d109b32
commit
f99c788b85
4 changed files with 49 additions and 9 deletions
|
@ -6,7 +6,8 @@ use std::process::Command;
|
||||||
use crate::serialize::get_magic_num_from_bytes;
|
use crate::serialize::get_magic_num_from_bytes;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub const BUILTIN_PYTHON_MODS: [&str; 18] = [
|
pub const BUILTIN_PYTHON_MODS: [&str; 19] = [
|
||||||
|
"datetime",
|
||||||
"glob",
|
"glob",
|
||||||
"http",
|
"http",
|
||||||
"importlib",
|
"importlib",
|
||||||
|
@ -27,7 +28,8 @@ pub const BUILTIN_PYTHON_MODS: [&str; 18] = [
|
||||||
"zipfile",
|
"zipfile",
|
||||||
];
|
];
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
pub const BUILTIN_PYTHON_MODS: [&str; 17] = [
|
pub const BUILTIN_PYTHON_MODS: [&str; 18] = [
|
||||||
|
"datetime",
|
||||||
"glob",
|
"glob",
|
||||||
"http",
|
"http",
|
||||||
"importlib",
|
"importlib",
|
||||||
|
|
|
@ -130,8 +130,13 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_builtin_immutable_private_var(&mut self, name: &'static str, t: Type) {
|
fn register_builtin_immutable_private_var(
|
||||||
self.register_builtin_impl(name, t, Immutable, Private);
|
&mut self,
|
||||||
|
name: &'static str,
|
||||||
|
t: Type,
|
||||||
|
py_name: Option<&'static str>,
|
||||||
|
) {
|
||||||
|
self.register_builtin_py_impl(name, t, Immutable, Private, py_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_builtin_const(&mut self, name: &str, vis: Visibility, obj: ValueObj) {
|
fn register_builtin_const(&mut self, name: &str, vis: Visibility, obj: ValueObj) {
|
||||||
|
@ -359,10 +364,22 @@ impl Context {
|
||||||
|
|
||||||
fn init_builtin_consts(&mut self) {
|
fn init_builtin_consts(&mut self) {
|
||||||
// TODO: this is not a const, but a special property
|
// TODO: this is not a const, but a special property
|
||||||
self.register_builtin_immutable_private_var("__name__", Str);
|
self.register_builtin_immutable_private_var("__name__", Str, Some("__name__"));
|
||||||
self.register_builtin_immutable_private_var("license", mono("_sitebuiltins._Printer"));
|
self.register_builtin_immutable_private_var(
|
||||||
self.register_builtin_immutable_private_var("credits", mono("_sitebuiltins._Printer"));
|
"license",
|
||||||
self.register_builtin_immutable_private_var("copyright", mono("_sitebuiltins._Printer"));
|
mono("_sitebuiltins._Printer"),
|
||||||
|
Some("license"),
|
||||||
|
);
|
||||||
|
self.register_builtin_immutable_private_var(
|
||||||
|
"credits",
|
||||||
|
mono("_sitebuiltins._Printer"),
|
||||||
|
Some("credits"),
|
||||||
|
);
|
||||||
|
self.register_builtin_immutable_private_var(
|
||||||
|
"copyright",
|
||||||
|
mono("_sitebuiltins._Printer"),
|
||||||
|
Some("copyright"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// see std/prelude.er
|
/// see std/prelude.er
|
||||||
|
|
|
@ -165,7 +165,17 @@ impl Context {
|
||||||
};
|
};
|
||||||
// already defined as const
|
// already defined as const
|
||||||
if sig.is_const() {
|
if sig.is_const() {
|
||||||
let vi = self.decls.remove(ident.inspect()).unwrap();
|
let vi = self.decls.remove(ident.inspect()).unwrap_or_else(|| {
|
||||||
|
VarInfo::new(
|
||||||
|
body_t.clone(),
|
||||||
|
Mutability::Const,
|
||||||
|
sig.vis(),
|
||||||
|
VarKind::Declared,
|
||||||
|
None,
|
||||||
|
self.impl_of(),
|
||||||
|
py_name,
|
||||||
|
)
|
||||||
|
});
|
||||||
self.locals.insert(ident.name.clone(), vi);
|
self.locals.insert(ident.name.clone(), vi);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
11
compiler/erg_compiler/lib/pystd/datetime.d.er
Normal file
11
compiler/erg_compiler/lib/pystd/datetime.d.er
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.Date = 'date': ClassType
|
||||||
|
.Date.today!: () => .Date
|
||||||
|
.Date.min: .Date
|
||||||
|
.Date.max: .Date
|
||||||
|
.Time = 'time': ClassType
|
||||||
|
.DateTime = 'dateTime': ClassType
|
||||||
|
.DateTime.today!: () => .DateTime
|
||||||
|
.DateTime.now!: (tz := .TZInfo or NoneType) => .DateTime
|
||||||
|
.TimeDelta = 'timedelta': ClassType
|
||||||
|
.TZInfo = 'tzinfo': ClassType
|
||||||
|
.TimeZone = 'timezone': ClassType
|
Loading…
Add table
Add a link
Reference in a new issue