Compare commits

...

4 Commits

Author SHA1 Message Date
blueloveTH
7ed09f927d try list 2024-06-30 15:32:40 +08:00
blueloveTH
391d26cdc5 some fix 2024-06-30 15:26:39 +08:00
blueloveTH
68e8536c89 some fix 2024-06-30 14:34:23 +08:00
blueloveTH
a6b3163635 some fix 2024-06-30 14:27:13 +08:00
11 changed files with 287 additions and 160 deletions

View File

@ -45,13 +45,25 @@ void py_newfloat(py_Ref, double);
void py_newbool(py_Ref, bool);
void py_newstr(py_Ref, const char*);
void py_newstrn(py_Ref, const char*, int);
void py_newStr_(py_Ref, py_Str);
// void py_newfstr(py_Ref, const char*, ...);
void py_newbytes(py_Ref, const unsigned char*, int);
void py_newnone(py_Ref);
void py_newnull(py_Ref);
void py_newtuple(py_Ref, int count);
/// Create a tuple with n UNINITIALIZED elements.
/// You should initialize all elements before using it.
void py_newtuple(py_Ref, int n);
/// Create a list.
void py_newlist(py_Ref);
/// Create a list with n UNINITIALIZED elements.
/// You should initialize all elements before using it.
void py_newlistn(py_Ref, int n);
// opaque types
void py_newdict(py_Ref);
void py_newset(py_Ref);
void py_newslice(py_Ref, const py_Ref start, const py_Ref stop, const py_Ref step);
// new style decl-based function
void py_newfunction(py_Ref out, py_CFunction, const char* sig);
@ -78,16 +90,6 @@ void py_newnotimplemented(py_Ref out);
/// @param slots number of slots. Use -1 to create a `__dict__`.
/// @param udsize size of your userdata. You can use `py_touserdata()` to get the pointer to it.
void py_newobject(py_Ref out, py_Type type, int slots, int udsize);
/************* Stack Values Creation *************/
void py_pushint(int64_t);
void py_pushfloat(double);
void py_pushbool(bool);
void py_pushstr(const char*);
void py_pushstrn(const char*, int);
void py_pushnone();
void py_pushnull();
/************* Type Cast *************/
int64_t py_toint(const py_Ref);
double py_tofloat(const py_Ref);
@ -110,8 +112,7 @@ bool py_istype(const py_Ref, py_Type);
/************* References *************/
#define py_arg(i) (py_Ref)((char*)argv+((i)<<4))
py_Ref py_getreg(int i);
void py_setreg(int i, const py_Ref val);
py_Ref py_reg(int i);
py_Ref py_getdict(const py_Ref self, py_Name name);
void py_setdict(py_Ref self, py_Name name, const py_Ref val);
@ -131,6 +132,10 @@ bool py_setattr(py_Ref self, py_Name name, const py_Ref val);
/// Deletes the attribute of the object.
bool py_delattr(py_Ref self, py_Name name);
bool py_getitem(const py_Ref self, const py_Ref key, py_Ref out);
bool py_setitem(py_Ref self, const py_Ref key, const py_Ref val);
bool py_delitem(py_Ref self, const py_Ref key);
/// Equivalent to `*dst = *src`.
void py_assign(py_Ref dst, const py_Ref src);
@ -164,7 +169,7 @@ py_Ref py_getmodule(const char* name);
int py_import(const char* name, py_Ref out);
/************* Errors *************/
py_Error* py_getlasterror();
py_Error* py_lasterror();
void py_Error__print(py_Error*);
/************* Operators *************/
@ -179,9 +184,16 @@ bool py_repr(const py_Ref, py_Ref out);
/// It consumes `argc + kwargc` arguments from the stack.
/// The result will be set to `vm->last_retval`.
int pk_vectorcall(int argc, int kwargc, bool op_call);
bool py_call(py_Ref f, ...);
bool py_callmethod(py_Ref self, py_Name name, ...);
/// Call a function.
/// It prepares the stack and then performs a `vectorcall(argc, 0, false)`.
/// The result will be set to `vm->last_retval`.
bool py_call(py_Ref f, int argc, py_Ref argv);
/// Call a method.
/// It prepares the stack and then performs a `vectorcall(argc+1, 0, false)`.
/// The result will be set to `vm->last_retval`.
bool py_callmethod(py_Ref self, py_Name name, int argc, py_Ref argv);
/// The return value of the most recent vectorcall.
py_Ref py_lastretval();
#define py_isnull(self) ((self)->type == 0)
@ -198,18 +210,9 @@ void py_list__setitem(py_Ref self, int i, const py_Ref val);
void py_list__delitem(py_Ref self, int i);
int py_list__len(const py_Ref self);
void py_list__append(py_Ref self, const py_Ref val);
void py_list__extend(py_Ref self, const py_Ref begin, const py_Ref end);
void py_list__clear(py_Ref self);
void py_list__insert(py_Ref self, int i, const py_Ref val);
// unchecked functions, if self is not a dict, the behavior is undefined
int py_dict__len(const py_Ref self);
bool py_dict__contains(const py_Ref self, const py_Ref key);
py_Ref py_dict__getitem(const py_Ref self, const py_Ref key);
void py_dict__setitem(py_Ref self, const py_Ref key, const py_Ref val);
void py_dict__delitem(py_Ref self, const py_Ref key);
void py_dict__clear(py_Ref self);
// internal functions
typedef struct pk_TypeInfo pk_TypeInfo;
pk_TypeInfo* pk_tpinfo(const py_Ref self);

View File

@ -251,16 +251,13 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
if(ti->m__getitem__) {
if(!ti->m__getitem__(2, SECOND(), SECOND())) goto __ERROR;
} else {
if(!py_callmethod(SECOND(), __getitem__, TOP())) goto __ERROR;
// // [a, b] -> [?, a, b]
// PUSH(TOP()); // [a, b, b]
// *SECOND() = *THIRD(); // [a, a, b]
// bool ok = py_getunboundmethod(SECOND(), __getitem__, false, THIRD(),
// SECOND()); if(!ok) {
// // __getitem__ not found
// goto __ERROR;
// }
// py_vectorcall(2, 0, );
// [a, b] -> [?, a, b]
PUSH(TOP()); // [a, b, b]
*SECOND() = *THIRD(); // [a, a, b]
bool ok = py_getunboundmethod(SECOND(), __getitem__, false, THIRD(), SECOND());
// [__getitem__, self, b]
if(!ok) goto __ERROR;
vectorcall_opcall(2);
}
DISPATCH();
}
@ -387,18 +384,21 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
// [x]
py_Ref f = py_getdict(&self->builtins, pk_id_long);
assert(f != NULL);
if(!py_call(f, TOP())) goto __ERROR;
if(!py_call(f, 1, TOP())) goto __ERROR;
*TOP() = self->last_retval;
DISPATCH();
}
case OP_BUILD_IMAG: {
py_Ref _0 = py_getdict(&self->builtins, pk_id_complex);
assert(_0 != NULL);
py_TValue zero;
py_newint(&zero, 0);
if(!py_call(_0, &zero, TOP())) goto __ERROR;
*TOP() = self->last_retval;
// [x]
py_Ref f = py_getdict(&self->builtins, pk_id_complex);
assert(f != NULL);
py_TValue tmp = *TOP();
*TOP() = *f; // [complex]
py_newnull(SP()++); // [complex, NULL]
py_newint(SP()++, 0); // [complex, NULL, 0]
*SP()++ = tmp; // [complex, NULL, 0, x]
vectorcall_opcall(2); // [complex(x, 0)]
DISPATCH();
}
case OP_BUILD_BYTES: {
@ -419,46 +419,62 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
PUSH(&tmp);
DISPATCH();
}
// case OP_BUILD_LIST: {
// PyVar _0 = VAR(STACK_VIEW(byte.arg).to_list());
// STACK_SHRINK(byte.arg);
// PUSH(_0);
// DISPATCH();
// }
// case OP_BUILD_DICT: {
// if(byte.arg == 0) {
// PUSH(VAR(Dict()));
// DISPATCH()
// }
// PyVar _0 = VAR(STACK_VIEW(byte.arg).to_list());
// _0 = call(_t(tp_dict), _0);
// STACK_SHRINK(byte.arg);
// PUSH(_0);
// DISPATCH();
// }
// case OP_BUILD_SET: {
// PyVar _0 = VAR(STACK_VIEW(byte.arg).to_list());
// _0 = call(builtins->attr()[pk_id_set], _0);
// STACK_SHRINK(byte.arg);
// PUSH(_0);
// DISPATCH();
// }
// case OP_BUILD_SLICE: {
// PyVar _2 = POPX(); // step
// PyVar _1 = POPX(); // stop
// PyVar _0 = POPX(); // start
// PUSH(VAR(Slice(_0, _1, _2)));
// DISPATCH();
// }
// case OP_BUILD_STRING: {
// SStream ss;
// ArgsView view = STACK_VIEW(byte.arg);
// for(PyVar obj: view)
// ss << py_str(obj);
// STACK_SHRINK(byte.arg);
// PUSH(VAR(ss.str()));
// DISPATCH();
// }
case OP_BUILD_LIST: {
py_TValue tmp;
py_newlistn(&tmp, byte.arg);
py_TValue* begin = SP() - byte.arg;
for(int i = 0; i < byte.arg; i++) {
py_list__setitem(&tmp, i, begin + i);
}
SP() = begin;
PUSH(&tmp);
DISPATCH();
}
case OP_BUILD_DICT: {
py_TValue* begin = SP() - byte.arg;
py_Ref tmp = py_pushtmp();
py_newdict(tmp);
for(int i = 0; i < byte.arg; i += 2) {
if(!py_setitem(tmp, begin + i, begin + i + 1)) goto __ERROR;
}
SP() = begin;
PUSH(tmp);
DISPATCH();
}
case OP_BUILD_SET: {
py_TValue* begin = SP() - byte.arg;
py_Ref tmp = py_pushtmp();
py_newset(tmp);
for(int i = 0; i < byte.arg; i++) {
if(!py_callmethod(tmp, pk_id_add, 1, begin + i)) goto __ERROR;
}
SP() = begin;
PUSH(tmp);
DISPATCH();
}
case OP_BUILD_SLICE: {
// [start, stop, step]
py_TValue tmp;
py_newslice(&tmp, THIRD(), SECOND(), TOP());
STACK_SHRINK(3);
PUSH(&tmp);
DISPATCH();
}
case OP_BUILD_STRING: {
py_TValue* begin = SP() - byte.arg;
py_Ref tmp = py_pushtmp();
pk_SStream ss;
pk_SStream__ctor(&ss);
for(int i = 0; i < byte.arg; i++) {
if(!py_str(begin + i, tmp)) goto __ERROR;
py_Str* item = py_touserdata(tmp);
pk_SStream__write_Str(&ss, item);
}
SP() = begin;
py_newStr_(tmp, pk_SStream__submit(&ss));
PUSH(tmp);
DISPATCH();
}
/**************************** */
case OP_RETURN_VALUE: {
self->last_retval = byte.arg == BC_NOARG ? POPX() : self->None;

View File

@ -3,9 +3,7 @@
#include "pocketpy/common/sstream.h"
#include "pocketpy/pocketpy.h"
static unsigned char* pk_default_import_file(const char* path){
return NULL;
}
static unsigned char* pk_default_import_file(const char* path) { return NULL; }
static void pk_default_stdout(const char* fmt, ...) {
va_list args;
@ -23,7 +21,12 @@ static void pk_default_stderr(const char* fmt, ...){
fflush(stderr);
}
void pk_TypeInfo__ctor(pk_TypeInfo *self, py_Name name, py_Type base, PyObject* obj, const py_TValue* module, bool subclass_enabled){
void pk_TypeInfo__ctor(pk_TypeInfo* self,
py_Name name,
py_Type base,
PyObject* obj,
const py_TValue* module,
bool subclass_enabled) {
memset(self, 0, sizeof(pk_TypeInfo));
self->name = name;
@ -36,9 +39,7 @@ void pk_TypeInfo__ctor(pk_TypeInfo *self, py_Name name, py_Type base, PyObject*
c11_vector__ctor(&self->annotated_fields, sizeof(py_Name));
}
void pk_TypeInfo__dtor(pk_TypeInfo *self){
c11_vector__dtor(&self->annotated_fields);
}
void pk_TypeInfo__dtor(pk_TypeInfo* self) { c11_vector__dtor(&self->annotated_fields); }
void pk_VM__ctor(pk_VM* self) {
self->top_frame = NULL;
@ -65,26 +66,39 @@ void pk_VM__ctor(pk_VM* self){
pk_ManagedHeap__ctor(&self->heap, self);
ValueStack__ctor(&self->stack);
self->True = (py_TValue){.type=tp_bool, .is_ptr=true, .extra=1,
self->True = (py_TValue){
.type = tp_bool,
.is_ptr = true,
.extra = 1,
._obj = pk_ManagedHeap__gcnew(&self->heap, tp_bool, 0, 0),
};
self->False = (py_TValue){.type=tp_bool, .is_ptr=true, .extra=0,
self->False = (py_TValue){
.type = tp_bool,
.is_ptr = true,
.extra = 0,
._obj = pk_ManagedHeap__gcnew(&self->heap, tp_bool, 0, 0),
};
self->None = (py_TValue){.type=tp_none_type, .is_ptr=true,
self->None = (py_TValue){
.type = tp_none_type,
.is_ptr = true,
._obj = pk_ManagedHeap__gcnew(&self->heap, tp_none_type, 0, 0),
};
self->NotImplemented = (py_TValue){.type=tp_not_implemented_type, .is_ptr=true,
self->NotImplemented = (py_TValue){
.type = tp_not_implemented_type,
.is_ptr = true,
._obj = pk_ManagedHeap__gcnew(&self->heap, tp_not_implemented_type, 0, 0),
};
self->Ellipsis = (py_TValue){.type=tp_ellipsis, .is_ptr=true,
self->Ellipsis = (py_TValue){
.type = tp_ellipsis,
.is_ptr = true,
._obj = pk_ManagedHeap__gcnew(&self->heap, tp_ellipsis, 0, 0),
};
/* Init Builtin Types */
// 0: unused
pk_TypeInfo__ctor(c11_vector__emplace(&self->types), 0, 0, NULL, NULL, false);
#define validate(t, expr) if(t != (expr)) abort()
#define validate(t, expr) \
if(t != (expr)) abort()
validate(tp_object, pk_VM__new_type(self, "object", 0, NULL, true));
validate(tp_type, pk_VM__new_type(self, "type", 1, NULL, false));
@ -95,6 +109,9 @@ void pk_VM__ctor(pk_VM* self){
validate(tp_str, pk_VM__new_type(self, "str", tp_object, NULL, false));
validate(tp_list, pk_VM__new_type(self, "list", tp_object, NULL, false));
pk_TypeInfo* ti = c11__at(pk_TypeInfo, &self->types, tp_list);
ti->dtor = (void (*)(void*))c11_vector__dtor;
validate(tp_tuple, pk_VM__new_type(self, "tuple", tp_object, NULL, false));
validate(tp_slice, pk_VM__new_type(self, "slice", tp_object, NULL, false));
@ -118,7 +135,8 @@ void pk_VM__ctor(pk_VM* self){
validate(tp_classmethod, pk_VM__new_type(self, "classmethod", tp_object, NULL, false));
validate(tp_none_type, pk_VM__new_type(self, "NoneType", tp_object, NULL, false));
validate(tp_not_implemented_type, pk_VM__new_type(self, "NotImplementedType", tp_object, NULL, false));
validate(tp_not_implemented_type,
pk_VM__new_type(self, "NotImplementedType", tp_object, NULL, false));
validate(tp_ellipsis, pk_VM__new_type(self, "ellipsis", tp_object, NULL, false));
validate(tp_op_call, pk_VM__new_type(self, "__op_call", tp_object, NULL, false));
@ -132,14 +150,22 @@ void pk_VM__ctor(pk_VM* self){
self->builtins = *py_newmodule("builtins", NULL);
/* Setup Public Builtin Types */
py_Type public_types[] = {
tp_object, tp_type,
tp_int, tp_float, tp_bool, tp_str,
tp_list, tp_tuple,
tp_slice, tp_range,
tp_bytes, tp_dict, tp_property,
tp_exception, tp_stop_iteration, tp_syntax_error
};
py_Type public_types[] = {tp_object,
tp_type,
tp_int,
tp_float,
tp_bool,
tp_str,
tp_list,
tp_tuple,
tp_slice,
tp_range,
tp_bytes,
tp_dict,
tp_property,
tp_exception,
tp_stop_iteration,
tp_syntax_error};
for(int i = 0; i < PK_ARRAY_COUNT(public_types); i++) {
py_Type t = public_types[i];
@ -154,9 +180,7 @@ void pk_VM__ctor(pk_VM* self){
}
void pk_VM__dtor(pk_VM* self) {
if(self->__dynamic_func_decl){
PK_DECREF(self->__dynamic_func_decl);
}
if(self->__dynamic_func_decl) { PK_DECREF(self->__dynamic_func_decl); }
// destroy all objects
pk_ManagedHeap__dtor(&self->heap);
// clear frames
@ -181,7 +205,11 @@ void pk_VM__pop_frame(pk_VM* self){
Frame__delete(frame);
}
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const py_TValue* module, bool subclass_enabled){
py_Type pk_VM__new_type(pk_VM* self,
const char* name,
py_Type base,
const py_TValue* module,
bool subclass_enabled) {
py_Type type = self->types.count;
pk_TypeInfo* ti = c11_vector__emplace(&self->types);
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, -1, sizeof(py_Type));

View File

@ -5,7 +5,7 @@
#include "pocketpy/interpreter/vm.h"
py_Error* py_getlasterror(){
py_Error* py_lasterror(){
return pk_current_vm->last_error;
}

13
src/public/py_dict.c Normal file
View File

@ -0,0 +1,13 @@
#include "pocketpy/pocketpy.h"
#include "pocketpy/common/utils.h"
#include "pocketpy/objects/object.h"
#include "pocketpy/interpreter/vm.h"
void py_newdict(py_Ref out){
}
void py_newset(py_Ref out){
}

59
src/public/py_list.c Normal file
View File

@ -0,0 +1,59 @@
#include "pocketpy/pocketpy.h"
#include "pocketpy/common/utils.h"
#include "pocketpy/objects/object.h"
#include "pocketpy/interpreter/vm.h"
typedef c11_vector List;
void py_newlist(py_Ref out) {
pk_VM* vm = pk_current_vm;
PyObject* obj = pk_ManagedHeap__gcnew(&vm->heap, tp_list, 0, sizeof(List));
List* userdata = PyObject__value(obj);
c11_vector__ctor(userdata, sizeof(py_TValue));
out->type = tp_list;
out->is_ptr = true;
out->_obj = obj;
}
void py_newlistn(py_Ref out, int n) {
py_newlist(out);
List* userdata = py_touserdata(out);
c11_vector__reserve(userdata, n);
userdata->count = n;
}
py_Ref py_list__getitem(const py_Ref self, int i) {
List* userdata = py_touserdata(self);
return c11__at(py_TValue, userdata, i);
}
void py_list__setitem(py_Ref self, int i, const py_Ref val) {
List* userdata = py_touserdata(self);
c11__setitem(py_TValue, userdata, i, *val);
}
void py_list__delitem(py_Ref self, int i) {
List* userdata = py_touserdata(self);
c11_vector__erase(py_TValue, userdata, i);
}
int py_list__len(const py_Ref self) {
List* userdata = py_touserdata(self);
return userdata->count;
}
void py_list__append(py_Ref self, const py_Ref val) {
List* userdata = py_touserdata(self);
c11_vector__push(py_TValue, userdata, *val);
}
void py_list__clear(py_Ref self) {
List* userdata = py_touserdata(self);
c11_vector__clear(userdata);
}
void py_list__insert(py_Ref self, int i, const py_Ref val) {
List* userdata = py_touserdata(self);
c11_vector__insert(py_TValue, userdata, i, *val);
}

View File

@ -12,7 +12,7 @@ bool py_str(const py_Ref val, py_Ref out) { return 0; }
bool py_repr(const py_Ref val, py_Ref out) {
const pk_TypeInfo* ti = pk_tpinfo(val);
if(ti->m__repr__) return ti->m__repr__(1, val, out);
bool ok = py_callmethod(val, __repr__);
bool ok = py_callmethod(val, __repr__, 0, NULL);
if(ok) {
*out = pk_current_vm->last_retval;
return true;
@ -25,3 +25,9 @@ bool py_getattr(const py_Ref self, py_Name name, py_Ref out) { return true; }
bool py_setattr(py_Ref self, py_Name name, const py_Ref val) { return -1; }
bool py_delattr(py_Ref self, py_Name name) { return -1; }
bool py_getitem(const py_Ref self, const py_Ref key, py_Ref out) { return -1; }
bool py_setitem(py_Ref self, const py_Ref key, const py_Ref val) { return -1; }
bool py_delitem(py_Ref self, const py_Ref key) { return -1; }

View File

@ -4,14 +4,10 @@
#include "pocketpy/objects/object.h"
#include "pocketpy/interpreter/vm.h"
py_Ref py_getreg(int i){
py_Ref py_reg(int i){
return pk_current_vm->reg + i;
}
void py_setreg(int i, const py_Ref val){
pk_current_vm->reg[i] = *val;
}
py_Ref py_getdict(const py_Ref self, py_Name name){
assert(self && self->is_ptr);
return pk_NameDict__try_get(PyObject__dict(self->_obj), name);

View File

@ -39,6 +39,16 @@ void py_newstrn(py_Ref out, const char* data, int size) {
out->_obj = obj;
}
void py_newStr_(py_Ref out, py_Str input){
pk_ManagedHeap* heap = &pk_current_vm->heap;
PyObject* obj = pk_ManagedHeap__gcnew(heap, tp_str, 0, sizeof(py_Str));
py_Str* userdata = PyObject__value(obj);
*userdata = input;
out->type = tp_str;
out->is_ptr = true;
out->_obj = obj;
}
void py_newbytes(py_Ref out, const unsigned char* data, int size) {
pk_ManagedHeap* heap = &pk_current_vm->heap;
// 4 bytes size + data
@ -85,6 +95,13 @@ void py_newnotimplemented(py_Ref out) {
*out = vm->NotImplemented;
}
void py_newslice(py_Ref out, const py_Ref start, const py_Ref stop, const py_Ref step){
py_newobject(out, tp_slice, 3, 0);
py_setslot(out, 0, start);
py_setslot(out, 1, stop);
py_setslot(out, 2, step);
}
void py_newobject(py_Ref out, py_Type type, int slots, int udsize){
pk_ManagedHeap* heap = &pk_current_vm->heap;
PyObject* obj = pk_ManagedHeap__gcnew(heap, type, slots, udsize);
@ -92,19 +109,3 @@ void py_newobject(py_Ref out, py_Type type, int slots, int udsize){
out->is_ptr = true;
out->_obj = obj;
}
void py_pushint(int64_t val) { py_newint(pk_current_vm->stack.sp++, val); }
void py_pushfloat(double val) { py_newfloat(pk_current_vm->stack.sp++, val); }
void py_pushbool(bool val) { py_newbool(pk_current_vm->stack.sp++, val); }
void py_pushstr(const char* val) { py_newstr(pk_current_vm->stack.sp++, val); }
void py_pushstrn(const char* val, int size) { py_newstrn(pk_current_vm->stack.sp++, val, size); }
void py_pushnone() { py_newnone(pk_current_vm->stack.sp++); }
void py_pushnull() { py_newnull(pk_current_vm->stack.sp++); }

View File

@ -47,11 +47,11 @@ int py_eval(const char* source, py_Ref out) {
PK_UNREACHABLE();
}
bool py_call(py_Ref callable, ...){
bool py_call(py_Ref f, int argc, py_Ref argv){
return -1;
}
bool py_callmethod(py_Ref self, py_Name name, ...){
bool py_callmethod(py_Ref self, py_Name name, int argc, py_Ref argv){
return -1;
}
@ -59,6 +59,10 @@ int pk_vectorcall(int argc, int kwargc, bool op_call){
return -1;
}
py_Ref py_lastretval(){
return &pk_current_vm->last_retval;
}
bool py_getunboundmethod(const py_Ref self, py_Name name, bool fallback, py_Ref out, py_Ref out_self){
return -1;
}
@ -67,3 +71,4 @@ pk_TypeInfo* pk_tpinfo(const py_Ref self){
pk_VM* vm = pk_current_vm;
return c11__at(pk_TypeInfo, &vm->types, self->type);
}

View File

@ -25,16 +25,16 @@ int main(int argc, char** argv) {
#endif
py_initialize();
const char* source = "1, 'a'";
const char* source = "[1, 'a']";
py_Ref r0 = py_getreg(0);
py_Ref r0 = py_reg(0);
if(py_eval(source, r0)){
py_Error* err = py_getlasterror();
py_Error* err = py_lasterror();
py_Error__print(err);
}else{
// handle the result
py_Ref _0 = py_tuple__getitem(r0, 0);
py_Ref _1 = py_tuple__getitem(r0, 1);
py_Ref _0 = py_list__getitem(r0, 0);
py_Ref _1 = py_list__getitem(r0, 1);
int _L0 = py_toint(_0);
const char* _L1 = py_tostr(_1);
printf("%d, %s\n", _L0, _L1);