mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
...
This commit is contained in:
parent
0bd413b337
commit
b4c221095f
17
src/ceval.h
17
src/ceval.h
@ -588,6 +588,23 @@ __NEXT_STEP:;
|
|||||||
const Str& spec = CAST(Str&, co_consts[byte.arg]);
|
const Str& spec = CAST(Str&, co_consts[byte.arg]);
|
||||||
PUSH(format(spec, _0));
|
PUSH(format(spec, _0));
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
|
/*****************************************/
|
||||||
|
TARGET(INC_FAST)
|
||||||
|
_0 = frame->_locals[byte.arg];
|
||||||
|
if(_0 == PY_NULL) vm->NameError(co->varnames[byte.arg]);
|
||||||
|
frame->_locals[byte.arg] = VAR(CAST(i64, _0) + 1);
|
||||||
|
DISPATCH();
|
||||||
|
TARGET(DEC_FAST)
|
||||||
|
_0 = frame->_locals[byte.arg];
|
||||||
|
if(_0 == PY_NULL) vm->NameError(co->varnames[byte.arg]);
|
||||||
|
frame->_locals[byte.arg] = VAR(CAST(i64, _0) - 1);
|
||||||
|
DISPATCH();
|
||||||
|
// TARGET(INC_GLOBAL)
|
||||||
|
// _name = StrName(byte.arg);
|
||||||
|
// _0 = frame->f_globals().try_get(_name);
|
||||||
|
// if(_0 == nullptr) vm->NameError(_name);
|
||||||
|
// frame->f_globals().try_set()
|
||||||
|
|
||||||
#if !PK_ENABLE_COMPUTED_GOTO
|
#if !PK_ENABLE_COMPUTED_GOTO
|
||||||
#if DEBUG_EXTRA_CHECK
|
#if DEBUG_EXTRA_CHECK
|
||||||
default: throw std::runtime_error(fmt(OP_NAMES[byte.op], " is not implemented"));
|
default: throw std::runtime_error(fmt(OP_NAMES[byte.op], " is not implemented"));
|
||||||
|
@ -736,6 +736,36 @@ __SUBSCR_END:
|
|||||||
case TK("try"): compile_try_except(); break;
|
case TK("try"): compile_try_except(); break;
|
||||||
case TK("pass"): consume_end_stmt(); break;
|
case TK("pass"): consume_end_stmt(); break;
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
|
case TK("++"):{
|
||||||
|
consume(TK("@id"));
|
||||||
|
StrName name(prev().sv());
|
||||||
|
switch(name_scope()){
|
||||||
|
case NAME_LOCAL:
|
||||||
|
int namei = ctx()->add_varname(name);
|
||||||
|
ctx()->emit(OP_INC_FAST, namei, prev().line);
|
||||||
|
break;
|
||||||
|
case NAME_GLOBAL:
|
||||||
|
ctx()->emit(OP_INC_GLOBAL, name.index, prev().line);
|
||||||
|
break;
|
||||||
|
default: SyntaxError(); break;
|
||||||
|
}
|
||||||
|
consume_end_stmt();
|
||||||
|
}
|
||||||
|
case TK("--"):{
|
||||||
|
consume(TK("@id"));
|
||||||
|
StrName name(prev().sv());
|
||||||
|
switch(name_scope()){
|
||||||
|
case NAME_LOCAL:
|
||||||
|
int namei = ctx()->add_varname(name);
|
||||||
|
ctx()->emit(OP_DEC_FAST, namei, prev().line);
|
||||||
|
break;
|
||||||
|
case NAME_GLOBAL:
|
||||||
|
ctx()->emit(OP_DEC_GLOBAL, name.index, prev().line);
|
||||||
|
break;
|
||||||
|
default: SyntaxError(); break;
|
||||||
|
}
|
||||||
|
consume_end_stmt();
|
||||||
|
}
|
||||||
case TK("assert"):
|
case TK("assert"):
|
||||||
EXPR_TUPLE(false);
|
EXPR_TUPLE(false);
|
||||||
ctx()->emit(OP_ASSERT, BC_NOARG, kw_line);
|
ctx()->emit(OP_ASSERT, BC_NOARG, kw_line);
|
||||||
|
19
src/lexer.h
19
src/lexer.h
@ -21,6 +21,7 @@ constexpr const char* kTokens[] = {
|
|||||||
/*****************************************/
|
/*****************************************/
|
||||||
".", ",", ":", ";", "#", "(", ")", "[", "]", "{", "}",
|
".", ",", ":", ";", "#", "(", ")", "[", "]", "{", "}",
|
||||||
"**", "=", ">", "<", "...", "->", "?", "@", "==", "!=", ">=", "<=",
|
"**", "=", ">", "<", "...", "->", "?", "@", "==", "!=", ">=", "<=",
|
||||||
|
"++", "--",
|
||||||
/** SPEC_BEGIN **/
|
/** SPEC_BEGIN **/
|
||||||
"$goto", "$label",
|
"$goto", "$label",
|
||||||
/** KW_BEGIN **/
|
/** KW_BEGIN **/
|
||||||
@ -411,7 +412,13 @@ struct Lexer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case '=': add_token_2('=', TK("="), TK("==")); return true;
|
case '=': add_token_2('=', TK("="), TK("==")); return true;
|
||||||
case '+': add_token_2('=', TK("+"), TK("+=")); return true;
|
case '+':
|
||||||
|
if(matchchar('+')){
|
||||||
|
add_token(TK("++"));
|
||||||
|
}else{
|
||||||
|
add_token_2('=', TK("+"), TK("+="));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case '>': {
|
case '>': {
|
||||||
if(matchchar('=')) add_token(TK(">="));
|
if(matchchar('=')) add_token(TK(">="));
|
||||||
else if(matchchar('>')) add_token_2('=', TK(">>"), TK(">>="));
|
else if(matchchar('>')) add_token_2('=', TK(">>"), TK(">>="));
|
||||||
@ -425,9 +432,13 @@ struct Lexer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case '-': {
|
case '-': {
|
||||||
if(matchchar('=')) add_token(TK("-="));
|
if(matchchar('-')){
|
||||||
else if(matchchar('>')) add_token(TK("->"));
|
add_token(TK("--"));
|
||||||
else add_token(TK("-"));
|
}else{
|
||||||
|
if(matchchar('=')) add_token(TK("-="));
|
||||||
|
else if(matchchar('>')) add_token(TK("->"));
|
||||||
|
else add_token(TK("-"));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case '!':
|
case '!':
|
||||||
|
@ -115,4 +115,9 @@ OPCODE(RE_RAISE)
|
|||||||
/**************************/
|
/**************************/
|
||||||
OPCODE(SETUP_DOCSTRING)
|
OPCODE(SETUP_DOCSTRING)
|
||||||
OPCODE(FORMAT_STRING)
|
OPCODE(FORMAT_STRING)
|
||||||
|
/**************************/
|
||||||
|
OPCODE(INC_FAST)
|
||||||
|
OPCODE(DEC_FAST)
|
||||||
|
OPCODE(INC_GLOBAL)
|
||||||
|
OPCODE(DEC_GLOBAL)
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user