feat: add zlib/hashlib

This commit is contained in:
Shunsuke Shibayama 2023-05-07 22:15:24 +09:00
parent 8abc675772
commit c3da319e9f
5 changed files with 62 additions and 9 deletions

View file

@ -1502,8 +1502,7 @@ impl Context {
.unwrap_or(vec![]);
let fallbacks = one.into_iter().chain(two.into_iter());
for typ_ctx in fallbacks {
if let Some(call_vi) =
typ_ctx.get_current_scope_var(&VarName::from_static("__call__"))
if let Some(call_vi) = typ_ctx.get_current_scope_var(&VarName::from_static("__call__"))
{
let instance = self.instantiate_def_type(&call_vi.t)?;
self.substitute_call(obj, attr_name, &instance, pos_args, kw_args)?;
@ -1511,7 +1510,9 @@ impl Context {
}
}
let hint = if self.subtype_of(instance, &ClassType) {
let acc = attr_name.as_ref().map_or(obj.to_string_notype(), |attr| obj.to_string_notype() + &attr.to_string());
let acc = attr_name.as_ref().map_or(obj.to_string_notype(), |attr| {
obj.to_string_notype() + &attr.to_string()
});
Some(switch_lang! {
"japanese" => format!("インスタンスを生成したい場合は、{acc}.newを使用してください"),
"simplified_chinese" => format!("如果要生成实例,请使用 {acc}.new"),

View file

@ -1970,12 +1970,9 @@ impl Context {
}
pub fn del(&mut self, ident: &hir::Identifier) -> CompileResult<()> {
let is_const = self.rec_get_var_info(
&ident.raw,
crate::AccessKind::Name,
&self.cfg.input,
self,
).map_ok_or(false, |vi| vi.muty.is_const());
let is_const = self
.rec_get_var_info(&ident.raw, crate::AccessKind::Name, &self.cfg.input, self)
.map_ok_or(false, |vi| vi.muty.is_const());
let is_builtin = self
.get_builtins()
.unwrap()

View file

@ -0,0 +1,18 @@
.algorithms_guaranteed: {Str; _}
.algorithms_available: {Str; _}
.HASH!: ClassType
.HASH!.
name: Str
digest_size: Nat
block_size: Nat
digest: (self: Ref(.HASH!)) -> Bytes
hexdigest: (self: Ref(.HASH!)) -> Str
update!: (self: RefMut(.HASH!), b: Bytes) => NoneType
.new: (name: Str, b := Bytes) -> .HASH!
.md5: (b: Bytes) -> .HASH!
.sha1: (b: Bytes) -> .HASH!
.sha224: (b: Bytes) -> .HASH!
.sha256: (b: Bytes) -> .HASH!
.sha512: (b: Bytes) -> .HASH!

View file

@ -0,0 +1,7 @@
.CookieError: ClassType
.BaseCookie!: ClassType
.SimpleCookie!: ClassType
.SimpleCookie! <: .BaseCookie!
.Morsel!: ClassType

View file

@ -0,0 +1,30 @@
.ZLIB_VERSION: Str
.ZLIB_RUNTIME_VERSION: Str
.Compress: ClassType
.Compress.
compress: (self: .Compress, data: Bytes) -> Bytes
flush: (self: .Compress, mode := Int) -> Bytes
copy: (self: .Compress) -> .Compress
.Decompress: ClassType
.Decompress.
unused_data: Bytes
unconsumed_tail: Bytes
eof: Bool
decompress: (self: .Decompress, data: Bytes, max_length := Nat) -> Bytes
flush: (self: .Decompress, length := Nat) -> Bytes
copy: (self: .Decompress) -> .Decompress
.Error = 'error': ClassType
.adler32: (data: Bytes, value := Int) -> Nat
.compress: (data: Bytes, level := -1..9, wbits := Int) -> Bytes
.compressobj: (
level := -1..9,
method := Int,
wbits := Int,
memLevel := Int,
strategy := Int
) -> .Compress
.crc32: (data: Bytes, value := Int) -> Nat
.decompress: (data: Bytes, wbits := Int, bufsize := Nat) -> Bytes
.decompressobj: (wbits := Int) -> .Decompress