mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
87bf0c9e7c
commit
0806b1aee1
@ -1470,7 +1470,7 @@ static void Compiler__dtor(Compiler* self) {
|
||||
if(!match(expected)) \
|
||||
return SyntaxError(self, \
|
||||
"expected '%s', got '%s'", \
|
||||
TokenSymbols[expected], \
|
||||
TokenSymbols[expected], \
|
||||
TokenSymbols[curr()->type]);
|
||||
#define consume_end_stmt() \
|
||||
if(!match_end_stmt(self)) return SyntaxError(self, "expected statement end")
|
||||
@ -1641,13 +1641,18 @@ static Error* pop_context(Compiler* self) {
|
||||
FuncDecl* func = ctx()->func;
|
||||
if(func) {
|
||||
// check generator
|
||||
c11__foreach(Bytecode, &func->code.codes, bc) {
|
||||
if(bc->op == OP_YIELD_VALUE) {
|
||||
Bytecode* codes = func->code.codes.data;
|
||||
int codes_length = func->code.codes.count;
|
||||
|
||||
for(int i = 0; i < codes_length; i++) {
|
||||
if(codes[i].op == OP_YIELD_VALUE) {
|
||||
func->type = FuncType_GENERATOR;
|
||||
c11__foreach(Bytecode, &func->code.codes, bc) {
|
||||
if(bc->op == OP_RETURN_VALUE && bc->arg == BC_NOARG) {
|
||||
return SyntaxError(self,
|
||||
"'return' with argument inside generator function");
|
||||
for(int j = 0; j < codes_length; j++) {
|
||||
if(codes[j].op == OP_RETURN_VALUE && codes[j].arg == BC_NOARG) {
|
||||
Error* err =
|
||||
SyntaxError(self, "'return' with argument inside generator function");
|
||||
err->lineno = c11__at(BytecodeEx, &func->code.codes_ex, j)->lineno;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -8,41 +8,21 @@
|
||||
#include "pocketpy/interpreter/vm.h"
|
||||
#include "pocketpy/compiler/compiler.h"
|
||||
|
||||
typedef struct {
|
||||
const char* source;
|
||||
const char* filename;
|
||||
int mode;
|
||||
int is_dynamic;
|
||||
} py_ExecKey;
|
||||
|
||||
static int py_ExecKey__cmp(const py_ExecKey* a, const py_ExecKey* b) {
|
||||
return memcmp(a, b, sizeof(py_ExecKey));
|
||||
}
|
||||
|
||||
static void py_ExecKey__ctor(py_ExecKey* key, const char* source, const char* filename,
|
||||
enum py_CompileMode mode, bool is_dynamic) {
|
||||
key->source = source;
|
||||
key->filename = filename;
|
||||
key->mode = mode;
|
||||
key->is_dynamic = is_dynamic;
|
||||
}
|
||||
|
||||
static bool _py_exec(const char* source,
|
||||
const char* filename,
|
||||
enum py_CompileMode mode,
|
||||
py_Ref module,
|
||||
bool is_dynamic) {
|
||||
VM* vm = pk_current_vm;
|
||||
// py_ExecKey cache_key;
|
||||
// py_ExecKey__ctor(&cache_key, source, filename, mode, is_dynamic);
|
||||
CodeObject co;
|
||||
SourceData_ src = SourceData__rcnew(source, filename, mode, is_dynamic);
|
||||
Error* err = pk_compile(src, &co);
|
||||
if(err) {
|
||||
py_exception(tp_SyntaxError, err->msg);
|
||||
py_BaseException__stpush(&vm->curr_exception, src, err->lineno, NULL);
|
||||
|
||||
py_BaseException__stpush(&vm->curr_exception, err->src, err->lineno, NULL);
|
||||
PK_DECREF(src);
|
||||
|
||||
PK_DECREF(err->src);
|
||||
free(err);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user