mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
0310d46296
commit
b28ea2c35b
@ -150,12 +150,12 @@ union BitsCvtImpl<8>{
|
||||
BitsCvtImpl(NumberTraits<8>::float_t val): _float(val) {}
|
||||
BitsCvtImpl(NumberTraits<8>::int_t val): _int(val) {}
|
||||
|
||||
void print(){
|
||||
std::string s = std::bitset<64>(_int).to_string();
|
||||
std::cout << s.substr(0, 1) << '|';
|
||||
std::cout << s.substr(1, 11) << '|';
|
||||
std::cout << s.substr(12) << std::endl;
|
||||
}
|
||||
// void print(){
|
||||
// std::string s = std::bitset<64>(_int).to_string();
|
||||
// std::cout << s.substr(0, 1) << '|';
|
||||
// std::cout << s.substr(1, 11) << '|';
|
||||
// std::cout << s.substr(12) << std::endl;
|
||||
// }
|
||||
};
|
||||
|
||||
using BitsCvt = BitsCvtImpl<sizeof(void*)>;
|
||||
|
32
src/expr.cpp
32
src/expr.cpp
@ -6,6 +6,13 @@ namespace pkpy{
|
||||
return v >= INT16_MIN && v <= INT16_MAX;
|
||||
}
|
||||
|
||||
inline bool is_identifier(std::string_view s){
|
||||
if(s.empty()) return false;
|
||||
if(!isalpha(s[0]) && s[0] != '_') return false;
|
||||
for(char c: s) if(!isalnum(c) && c != '_') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int CodeEmitContext::get_loop() const {
|
||||
int index = curr_block_i;
|
||||
while(index >= 0){
|
||||
@ -402,21 +409,28 @@ namespace pkpy{
|
||||
}
|
||||
}
|
||||
// name or name.name
|
||||
PK_LOCAL_STATIC const std::regex pattern(R"(^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]*){0,1}$)");
|
||||
if(std::regex_match(expr.str(), pattern)){
|
||||
int dot = expr.index(".");
|
||||
if(dot < 0){
|
||||
bool is_fastpath = false;
|
||||
if(is_identifier(expr.sv())){
|
||||
ctx->emit_(OP_LOAD_NAME, StrName(expr.sv()).index, line);
|
||||
is_fastpath = true;
|
||||
}else{
|
||||
StrName name(expr.substr(0, dot).sv());
|
||||
StrName attr(expr.substr(dot+1).sv());
|
||||
ctx->emit_(OP_LOAD_NAME, name.index, line);
|
||||
ctx->emit_(OP_LOAD_ATTR, attr.index, line);
|
||||
int dot = expr.index(".");
|
||||
if(dot > 0){
|
||||
std::string_view a = expr.sv().substr(0, dot);
|
||||
std::string_view b = expr.sv().substr(dot+1);
|
||||
if(is_identifier(a) && is_identifier(b)){
|
||||
ctx->emit_(OP_LOAD_NAME, StrName(a).index, line);
|
||||
ctx->emit_(OP_LOAD_ATTR, StrName(b).index, line);
|
||||
is_fastpath = true;
|
||||
}
|
||||
}else{
|
||||
}
|
||||
}
|
||||
|
||||
if(!is_fastpath){
|
||||
int index = ctx->add_const_string(expr.sv());
|
||||
ctx->emit_(OP_FSTRING_EVAL, index, line);
|
||||
}
|
||||
|
||||
if(repr){
|
||||
ctx->emit_(OP_REPR, BC_NOARG, line);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user