mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
...
This commit is contained in:
parent
1490e9db73
commit
db321abdae
@ -1,6 +1,6 @@
|
|||||||
add_rules("mode.debug", "mode.release")
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
set_languages("c11", "c++17")
|
set_languages("c11")
|
||||||
|
|
||||||
root_dir = "../"
|
root_dir = "../"
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ add_includedirs(root_dir .. "include")
|
|||||||
-- Define the shared library target for pocketpy
|
-- Define the shared library target for pocketpy
|
||||||
target("pocketpy")
|
target("pocketpy")
|
||||||
set_kind("shared")
|
set_kind("shared")
|
||||||
add_files(root_dir .. "src2/pocketpy_c.cpp")
|
add_files(root_dir .. "src2/pocketpy_c.c")
|
||||||
|
|
||||||
-- Define the shared library target
|
-- Define the shared library target
|
||||||
target("test")
|
target("test")
|
||||||
|
@ -88,6 +88,7 @@ OPCODE(LOOP_CONTINUE)
|
|||||||
OPCODE(LOOP_BREAK)
|
OPCODE(LOOP_BREAK)
|
||||||
OPCODE(GOTO)
|
OPCODE(GOTO)
|
||||||
/**************************/
|
/**************************/
|
||||||
|
OPCODE(EVAL)
|
||||||
OPCODE(CALL)
|
OPCODE(CALL)
|
||||||
OPCODE(CALL_TP)
|
OPCODE(CALL_TP)
|
||||||
OPCODE(RETURN_VALUE)
|
OPCODE(RETURN_VALUE)
|
||||||
|
@ -499,6 +499,11 @@ __NEXT_STEP:;
|
|||||||
frame->jump_abs_break(index);
|
frame->jump_abs_break(index);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
|
TARGET(EVAL){
|
||||||
|
DEF_SNAME(eval);
|
||||||
|
_0 = builtins->attr(eval);
|
||||||
|
TOP() = call(_0, TOP());
|
||||||
|
} DISPATCH();
|
||||||
TARGET(CALL)
|
TARGET(CALL)
|
||||||
_0 = vectorcall(
|
_0 = vectorcall(
|
||||||
byte.arg & 0xFFFF, // ARGC
|
byte.arg & 0xFFFF, // ARGC
|
||||||
|
@ -344,7 +344,9 @@ namespace pkpy{
|
|||||||
|
|
||||||
|
|
||||||
void FStringExpr::_load_simple_expr(CodeEmitContext* ctx, Str expr){
|
void FStringExpr::_load_simple_expr(CodeEmitContext* ctx, Str expr){
|
||||||
// TODO: pre compile this into a function
|
// name or name.name
|
||||||
|
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(".");
|
int dot = expr.index(".");
|
||||||
if(dot < 0){
|
if(dot < 0){
|
||||||
ctx->emit(OP_LOAD_NAME, StrName(expr.sv()).index, line);
|
ctx->emit(OP_LOAD_NAME, StrName(expr.sv()).index, line);
|
||||||
@ -354,6 +356,11 @@ namespace pkpy{
|
|||||||
ctx->emit(OP_LOAD_NAME, name.index, line);
|
ctx->emit(OP_LOAD_NAME, name.index, line);
|
||||||
ctx->emit(OP_LOAD_ATTR, attr.index, line);
|
ctx->emit(OP_LOAD_ATTR, attr.index, line);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
int index = ctx->add_const(py_var(ctx->vm, expr));
|
||||||
|
ctx->emit(OP_LOAD_CONST, index, line);
|
||||||
|
ctx->emit(OP_EVAL, BC_NOARG, line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FStringExpr::emit(CodeEmitContext* ctx){
|
void FStringExpr::emit(CodeEmitContext* ctx){
|
||||||
|
@ -57,3 +57,7 @@ assert f'{obj.b:10}' == '123 '
|
|||||||
assert f'{obj.b:>10}' == ' 123'
|
assert f'{obj.b:>10}' == ' 123'
|
||||||
assert f'{obj.b:1}' == '123'
|
assert f'{obj.b:1}' == '123'
|
||||||
assert f'{obj.b:10s}' == '123 '
|
assert f'{obj.b:10s}' == '123 '
|
||||||
|
|
||||||
|
a = [(1,2), 3, obj]
|
||||||
|
assert f'{a[0][1]}' == '2'
|
||||||
|
assert f'abc{a[-1].b:10}==={1234}' == 'abc123 ===1234'
|
Loading…
x
Reference in New Issue
Block a user