mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
1ff6f92b94
commit
a4eecdaa84
@ -76,7 +76,7 @@ def sorted(iterable, reverse=False, key=None):
|
||||
return a
|
||||
|
||||
##### str #####
|
||||
def str@split(self, sep):
|
||||
def __f(self, sep):
|
||||
if sep == "":
|
||||
return list(self)
|
||||
res = []
|
||||
@ -90,8 +90,9 @@ def str@split(self, sep):
|
||||
++i
|
||||
res.append(self)
|
||||
return res
|
||||
str.split = __f
|
||||
|
||||
def str@format(self, *args):
|
||||
def __f(self, *args):
|
||||
if '{}' in self:
|
||||
for i in range(len(args)):
|
||||
self = self.replace('{}', str(args[i]), 1)
|
||||
@ -99,8 +100,9 @@ def str@format(self, *args):
|
||||
for i in range(len(args)):
|
||||
self = self.replace('{'+str(i)+'}', str(args[i]))
|
||||
return self
|
||||
str.format = __f
|
||||
|
||||
def str@strip(self, chars=None):
|
||||
def __f(self, chars=None):
|
||||
chars = chars or ' \t\n\r'
|
||||
i = 0
|
||||
while i < len(self) and self[i] in chars:
|
||||
@ -109,6 +111,7 @@ def str@strip(self, chars=None):
|
||||
while j >= 0 and self[j] in chars:
|
||||
--j
|
||||
return self[i:j+1]
|
||||
str.strip = __f
|
||||
|
||||
##### list #####
|
||||
list.__repr__ = lambda self: '[' + ', '.join([repr(i) for i in self]) + ']'
|
||||
@ -130,18 +133,18 @@ def __qsort(a: list, L: int, R: int, key):
|
||||
__qsort(a, L, j, key)
|
||||
__qsort(a, i, R, key)
|
||||
|
||||
def list@sort(self, reverse=False, key=None):
|
||||
def __f(self, reverse=False, key=None):
|
||||
if key is None:
|
||||
key = lambda x:x
|
||||
__qsort(self, 0, len(self)-1, key)
|
||||
if reverse:
|
||||
self.reverse()
|
||||
list.sort = __f
|
||||
|
||||
def staticmethod(f):
|
||||
return f # no effect
|
||||
|
||||
def type@__repr__(self):
|
||||
return "<class '" + self.__name__ + "'>"
|
||||
|
||||
type.__repr__ = lambda self: "<class '" + self.__name__ + "'>"
|
||||
|
||||
def help(obj):
|
||||
if hasattr(obj, '__func__'):
|
||||
@ -150,3 +153,6 @@ def help(obj):
|
||||
print(obj.__doc__)
|
||||
else:
|
||||
print("No docstring found")
|
||||
|
||||
|
||||
del __f
|
@ -924,15 +924,9 @@ __SUBSCR_END:
|
||||
}
|
||||
|
||||
void compile_function(const std::vector<Expr_>& decorators={}){
|
||||
Str obj_name;
|
||||
Str decl_name;
|
||||
consume(TK("@id"));
|
||||
decl_name = prev().str();
|
||||
if(!ctx()->is_compiling_class && match(TK("@"))){
|
||||
consume(TK("@id"));
|
||||
obj_name = decl_name;
|
||||
decl_name = prev().str();
|
||||
}
|
||||
FuncDecl_ decl = push_f_context(decl_name);
|
||||
consume(TK("("));
|
||||
if (!match(TK(")"))) {
|
||||
@ -965,14 +959,8 @@ __SUBSCR_END:
|
||||
ctx()->emit(OP_CALL, 1, (*it)->line);
|
||||
}
|
||||
if(!ctx()->is_compiling_class){
|
||||
if(obj_name.empty()){
|
||||
auto e = make_expr<NameExpr>(decl_name, name_scope());
|
||||
e->emit_store(ctx());
|
||||
} else {
|
||||
ctx()->emit(OP_LOAD_GLOBAL, StrName(obj_name).index, prev().line);
|
||||
int index = StrName(decl_name).index;
|
||||
ctx()->emit(OP_STORE_ATTR, index, prev().line);
|
||||
}
|
||||
auto e = make_expr<NameExpr>(decl_name, name_scope());
|
||||
e->emit_store(ctx());
|
||||
}else{
|
||||
int index = StrName(decl_name).index;
|
||||
ctx()->emit(OP_STORE_CLASS_ATTR, index, prev().line);
|
||||
|
Loading…
x
Reference in New Issue
Block a user