Skip to content

Commit a397776

Browse files
committed
Implement basic class/object functionality in runtime.
1 parent 91d387d commit a397776

9 files changed

Lines changed: 265 additions & 92 deletions

File tree

py/emit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ typedef struct _emit_method_table_t {
5757
void (*store_global)(emit_t *emit, qstr qstr);
5858
void (*store_deref)(emit_t *emit, qstr qstr);
5959
void (*store_attr)(emit_t *emit, qstr qstr);
60-
void (*store_locals)(emit_t *emit);
6160
void (*store_subscr)(emit_t *emit);
61+
void (*store_locals)(emit_t *emit);
6262
void (*delete_fast)(emit_t *emit, qstr qstr, int local_num);
6363
void (*delete_name)(emit_t *emit, qstr qstr);
6464
void (*delete_global)(emit_t *emit, qstr qstr);

py/emitbc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,16 @@ static void emit_bc_store_attr(emit_t *emit, qstr qstr) {
348348
emit_write_byte_1_qstr(emit, PYBC_STORE_ATTR, qstr);
349349
}
350350

351-
static void emit_bc_store_locals(emit_t *emit) {
352-
emit_pre(emit, -1);
353-
emit_write_byte_1(emit, PYBC_STORE_LOCALS);
354-
}
355-
356351
static void emit_bc_store_subscr(emit_t *emit) {
357352
emit_pre(emit, -3);
358353
emit_write_byte_1(emit, PYBC_STORE_SUBSCR);
359354
}
360355

356+
static void emit_bc_store_locals(emit_t *emit) {
357+
// not needed for byte code
358+
emit_pre(emit, -1);
359+
}
360+
361361
static void emit_bc_delete_fast(emit_t *emit, qstr qstr, int local_num) {
362362
assert(local_num >= 0);
363363
emit_pre(emit, 0);
@@ -718,8 +718,8 @@ const emit_method_table_t emit_bc_method_table = {
718718
emit_bc_store_global,
719719
emit_bc_store_deref,
720720
emit_bc_store_attr,
721-
emit_bc_store_locals,
722721
emit_bc_store_subscr,
722+
emit_bc_store_locals,
723723
emit_bc_delete_fast,
724724
emit_bc_delete_name,
725725
emit_bc_delete_global,

py/emitcpy.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,17 @@ static void emit_cpy_store_attr(emit_t *emit, qstr qstr) {
352352
}
353353
}
354354

355-
static void emit_cpy_store_locals(emit_t *emit) {
356-
emit_pre(emit, -1, 1);
355+
static void emit_cpy_store_subscr(emit_t *emit) {
356+
emit_pre(emit, -3, 1);
357357
if (emit->pass == PASS_3) {
358-
printf("STORE_LOCALS\n");
358+
printf("STORE_SUBSCR\n");
359359
}
360360
}
361361

362-
static void emit_cpy_store_subscr(emit_t *emit) {
363-
emit_pre(emit, -3, 1);
362+
static void emit_cpy_store_locals(emit_t *emit) {
363+
emit_pre(emit, -1, 1);
364364
if (emit->pass == PASS_3) {
365-
printf("STORE_SUBSCR\n");
365+
printf("STORE_LOCALS\n");
366366
}
367367
}
368368

@@ -870,8 +870,8 @@ const emit_method_table_t emit_cpython_method_table = {
870870
emit_cpy_store_global,
871871
emit_cpy_store_deref,
872872
emit_cpy_store_attr,
873-
emit_cpy_store_locals,
874873
emit_cpy_store_subscr,
874+
emit_cpy_store_locals,
875875
emit_cpy_delete_fast,
876876
emit_cpy_delete_name,
877877
emit_cpy_delete_global,

py/emitnative.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,6 @@ static void emit_native_store_attr(emit_t *emit, qstr qstr) {
731731
assert(0);
732732
}
733733

734-
static void emit_native_store_locals(emit_t *emit) {
735-
// not supported
736-
assert(0);
737-
}
738-
739734
static void emit_native_store_subscr(emit_t *emit) {
740735
// depends on type of subject:
741736
// - integer, function, pointer to structure: error
@@ -749,6 +744,13 @@ static void emit_native_store_subscr(emit_t *emit) {
749744
emit_call(emit, RT_F_STORE_SUBSCR, rt_store_subscr);
750745
}
751746

747+
static void emit_native_store_locals(emit_t *emit) {
748+
// not needed
749+
vtype_kind_t vtype;
750+
emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
751+
emit_post(emit);
752+
}
753+
752754
static void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
753755
// not implemented
754756
// could support for Python types, just set to None (so GC can reclaim it)
@@ -1146,8 +1148,8 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
11461148
emit_native_store_global,
11471149
emit_native_store_deref,
11481150
emit_native_store_attr,
1149-
emit_native_store_locals,
11501151
emit_native_store_subscr,
1152+
emit_native_store_locals,
11511153
emit_native_delete_fast,
11521154
emit_native_delete_name,
11531155
emit_native_delete_global,

py/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int argc, char **argv) {
3333
py_parse_node_t pn = py_parse(lex, 0);
3434
if (pn != PY_PARSE_NODE_NULL) {
3535
//printf("----------------\n");
36-
parse_node_show(pn, 0);
36+
//parse_node_show(pn, 0);
3737
//printf("----------------\n");
3838
py_compile(pn);
3939
//printf("----------------\n");

0 commit comments

Comments
 (0)