mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
This commit is contained in:
parent
1e3849319e
commit
897456c2f6
@ -204,3 +204,11 @@ class staticmethod:
|
||||
|
||||
def type@__repr__(self):
|
||||
return "<class '" + self.__name__ + "'>"
|
||||
|
||||
def help(obj):
|
||||
if hasattr(obj, '__func__'):
|
||||
obj = obj.__func__
|
||||
if hasattr(obj, '__doc__'):
|
||||
print(obj.__doc__)
|
||||
else:
|
||||
print("No docstring found")
|
||||
|
@ -543,6 +543,10 @@ __NEXT_STEP:;
|
||||
_error(StrName(byte.arg), msg);
|
||||
} DISPATCH();
|
||||
TARGET(RE_RAISE) _raise(); DISPATCH();
|
||||
/*****************************************/
|
||||
TARGET(SETUP_DOCSTRING)
|
||||
TOP()->attr().set(__doc__, co_consts[byte.arg]);
|
||||
DISPATCH();
|
||||
#if !PK_ENABLE_COMPUTED_GOTO
|
||||
#if DEBUG_EXTRA_CHECK
|
||||
default: throw std::runtime_error(fmt(OP_NAMES[byte.op], " is not implemented"));
|
||||
|
@ -922,7 +922,20 @@ __SUBSCR_END:
|
||||
}
|
||||
compile_block_body();
|
||||
pop_context();
|
||||
|
||||
PyObject* docstring = nullptr;
|
||||
if(decl->code->codes.size()>=2 && decl->code->codes[0].op == OP_LOAD_CONST && decl->code->codes[1].op == OP_POP_TOP){
|
||||
PyObject* c = decl->code->consts[decl->code->codes[0].arg];
|
||||
if(is_type(c, vm->tp_str)){
|
||||
decl->code->codes[0].op = OP_NO_OP;
|
||||
decl->code->codes[1].op = OP_NO_OP;
|
||||
docstring = c;
|
||||
}
|
||||
}
|
||||
ctx()->emit(OP_LOAD_FUNCTION, ctx()->add_func_decl(decl), prev().line);
|
||||
if(docstring != nullptr){
|
||||
ctx()->emit(OP_SETUP_DOCSTRING, ctx()->add_const(docstring), prev().line);
|
||||
}
|
||||
// add decorators
|
||||
for(auto it=decorators.rbegin(); it!=decorators.rend(); ++it){
|
||||
(*it)->emit(ctx());
|
||||
|
@ -110,4 +110,5 @@ OPCODE(EXCEPTION_MATCH)
|
||||
OPCODE(RAISE)
|
||||
OPCODE(RE_RAISE)
|
||||
/**************************/
|
||||
OPCODE(SETUP_DOCSTRING)
|
||||
#endif
|
@ -394,6 +394,7 @@ const StrName __set__ = StrName::get("__set__");
|
||||
const StrName __getattr__ = StrName::get("__getattr__");
|
||||
const StrName __setattr__ = StrName::get("__setattr__");
|
||||
const StrName __call__ = StrName::get("__call__");
|
||||
const StrName __doc__ = StrName::get("__doc__");
|
||||
|
||||
const StrName m_eval = StrName::get("eval");
|
||||
const StrName m_self = StrName::get("self");
|
||||
|
Loading…
x
Reference in New Issue
Block a user