Skip to content

Commit 0daf46c

Browse files
committed
fix for_loop runError in module
1 parent 21cf379 commit 0daf46c

File tree

9 files changed

+145
-154
lines changed

9 files changed

+145
-154
lines changed

package/PikaStdLib/PikaStdLib_SysObj.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
141141
/* object */
142142
if (argType_isObject(arg_getType(arg))) {
143143
PikaObj* arg_obj = arg_getPtr(arg);
144+
NewFun _clsptr = obj_getPtr(arg_obj, "_clsptr");
145+
if (_clsptr == New_PikaStdLib_RangeObj) {
146+
/* found RangeObj, return directly */
147+
return arg_copy(arg);
148+
}
144149
// pikaVM_runAsm(arg_obj,
145150
// "B0\n"
146151
// "0 RUN __iter__\n"
@@ -162,9 +167,10 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
162167

163168
Arg* PikaStdLib_SysObj_range(PikaObj* self, int a1, int a2) {
164169
/* set template arg to create rangeObj */
165-
obj_setInt(self, "_r1", a1);
166-
obj_setInt(self, "_r2", a2);
167-
return arg_newMetaObj(New_PikaStdLib_RangeObj);
170+
Arg* obj_arg = arg_newDirectObj(New_PikaStdLib_RangeObj);
171+
obj_setInt(arg_getPtr(obj_arg), "a1", a1);
172+
obj_setInt(arg_getPtr(obj_arg), "a2", a2);
173+
return obj_arg;
168174
}
169175

170176
Arg* PikaStdLib_SysObj___get__(PikaObj* self, Arg* key, Arg* obj) {

package/PikaStdLib/PikaStdTask_Task.c

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ void PikaStdTask_Task_call_period_ms(PikaObj* self,
109109
void PikaStdTask_Task_run_once(PikaObj* self) {
110110
/* transfer the tick to pikaMain */
111111
obj_setInt(__pikaMain, "__tick", obj_getInt(self, "tick"));
112-
PIKA_PYTHON_BEGIN
113112
/* clang-format off */
114113
PIKA_PYTHON(
115114
len = __calls.len()
@@ -150,68 +149,73 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
150149
)
151150
/* clang-format on */
152151
const uint8_t bytes[] = {
153-
0x00, 0x02, /* instruct array size */
152+
0x60, 0x02, /* instruct array size */
154153
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0d, 0x00, 0x00, 0x83, 0x11, 0x00,
155154
0x00, 0x04, 0x16, 0x00, 0x00, 0x85, 0x1b, 0x00, 0x00, 0x04, 0x1d, 0x00,
156155
0x20, 0x85, 0x1b, 0x00, 0x20, 0x01, 0x0d, 0x00, 0x10, 0x02, 0x28, 0x00,
157-
0x00, 0x02, 0x2e, 0x00, 0x00, 0x04, 0x33, 0x00, 0x00, 0x01, 0x37, 0x00,
158-
0x00, 0x01, 0x3b, 0x00, 0x00, 0x04, 0x3f, 0x00, 0x00, 0x04, 0x46, 0x00,
159-
0x00, 0x82, 0x4d, 0x00, 0x00, 0x04, 0x5a, 0x00, 0x00, 0x0d, 0x5a, 0x00,
160-
0x00, 0x07, 0x5c, 0x00, 0x11, 0x81, 0x0d, 0x00, 0x11, 0x05, 0x1b, 0x00,
161-
0x01, 0x08, 0x5e, 0x00, 0x01, 0x07, 0x61, 0x00, 0x02, 0x8e, 0x61, 0x00,
162-
0x11, 0x81, 0x1d, 0x00, 0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x5e, 0x00,
163-
0x01, 0x07, 0x61, 0x00, 0x12, 0x81, 0x63, 0x00, 0x12, 0x01, 0x5a, 0x00,
164-
0x02, 0x02, 0x6b, 0x00, 0x02, 0x04, 0x16, 0x00, 0x02, 0x85, 0x61, 0x00,
165-
0x02, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x61, 0x00, 0x11, 0x01, 0x1d, 0x00,
166-
0x11, 0x05, 0x61, 0x00, 0x01, 0x08, 0x5e, 0x00, 0x01, 0x07, 0x61, 0x00,
167-
0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x73, 0x00, 0x02, 0x08, 0x5e, 0x00,
168-
0x02, 0x07, 0x61, 0x00, 0x13, 0x81, 0x63, 0x00, 0x13, 0x01, 0x5a, 0x00,
169-
0x03, 0x02, 0x6b, 0x00, 0x03, 0x04, 0x7a, 0x00, 0x03, 0x82, 0x7a, 0x00,
170-
0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x61, 0x00,
171-
0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x7f, 0x00, 0x02, 0x08, 0x5e, 0x00,
172-
0x02, 0x07, 0x61, 0x00, 0x13, 0x81, 0x63, 0x00, 0x13, 0x01, 0x5a, 0x00,
173-
0x03, 0x02, 0x6b, 0x00, 0x03, 0x04, 0x7f, 0x00, 0x03, 0x85, 0x5c, 0x00,
174-
0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x61, 0x00, 0x12, 0x01, 0x16, 0x00,
175-
0x12, 0x03, 0x84, 0x00, 0x02, 0x08, 0x5e, 0x00, 0x02, 0x07, 0x61, 0x00,
176-
0x13, 0x81, 0x63, 0x00, 0x13, 0x01, 0x5a, 0x00, 0x03, 0x02, 0x6b, 0x00,
177-
0x03, 0x04, 0x84, 0x00, 0x03, 0x85, 0x5c, 0x00, 0x03, 0x04, 0x1d, 0x00,
178-
0x01, 0x8b, 0x61, 0x00, 0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x5c, 0x00,
179-
0x01, 0x08, 0x5e, 0x00, 0x01, 0x07, 0x61, 0x00, 0x12, 0x81, 0x16, 0x00,
180-
0x12, 0x03, 0x7f, 0x00, 0x02, 0x08, 0x5e, 0x00, 0x02, 0x07, 0x61, 0x00,
181-
0x03, 0x82, 0x7f, 0x00, 0x03, 0x07, 0x61, 0x00, 0x14, 0x81, 0x63, 0x00,
182-
0x14, 0x01, 0x5a, 0x00, 0x04, 0x02, 0x6b, 0x00, 0x04, 0x04, 0x7a, 0x00,
183-
0x04, 0x82, 0x7a, 0x00, 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00,
184-
0x02, 0x8b, 0x61, 0x00, 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x84, 0x00,
185-
0x02, 0x08, 0x5e, 0x00, 0x02, 0x07, 0x61, 0x00, 0x13, 0x81, 0x63, 0x00,
186-
0x13, 0x01, 0x5a, 0x00, 0x03, 0x02, 0x6b, 0x00, 0x03, 0x04, 0x7a, 0x00,
187-
0x03, 0x85, 0x8e, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x61, 0x00,
188-
0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x8e, 0x00, 0x01, 0x08, 0x5e, 0x00,
189-
0x01, 0x07, 0x61, 0x00, 0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x84, 0x00,
190-
0x02, 0x08, 0x5e, 0x00, 0x02, 0x07, 0x61, 0x00, 0x13, 0x81, 0x90, 0x00,
191-
0x23, 0x01, 0x63, 0x00, 0x23, 0x01, 0x5a, 0x00, 0x13, 0x02, 0x6b, 0x00,
192-
0x03, 0x08, 0x97, 0x00, 0x03, 0x07, 0x61, 0x00, 0x04, 0x82, 0x7a, 0x00,
193-
0x14, 0x81, 0x63, 0x00, 0x14, 0x01, 0x5a, 0x00, 0x24, 0x01, 0x90, 0x00,
194-
0x24, 0x01, 0x84, 0x00, 0x14, 0x08, 0x99, 0x00, 0x14, 0x03, 0x63, 0x00,
195-
0x04, 0x02, 0x9b, 0x00, 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00,
196-
0x00, 0x86, 0xa3, 0x00, 0x00, 0x8c, 0x33, 0x00, /* instruct array */
197-
0xa6, 0x00, /* const pool size */
156+
0x00, 0x02, 0x2e, 0x00, 0x00, 0x04, 0x33, 0x00, 0x00, 0x82, 0x37, 0x00,
157+
0x00, 0x04, 0x44, 0x00, 0x00, 0x0d, 0x44, 0x00, 0x00, 0x07, 0x46, 0x00,
158+
0x11, 0x81, 0x0d, 0x00, 0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x48, 0x00,
159+
0x01, 0x07, 0x4b, 0x00, 0x02, 0x8e, 0x00, 0x00, 0x11, 0x81, 0x1d, 0x00,
160+
0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x48, 0x00, 0x01, 0x07, 0x4b, 0x00,
161+
0x12, 0x81, 0x4d, 0x00, 0x12, 0x01, 0x44, 0x00, 0x22, 0x01, 0x44, 0x00,
162+
0x22, 0x05, 0x4b, 0x00, 0x12, 0x08, 0x55, 0x00, 0x12, 0x05, 0x4b, 0x00,
163+
0x02, 0x02, 0x57, 0x00, 0x02, 0x04, 0x16, 0x00, 0x02, 0x85, 0x4b, 0x00,
164+
0x02, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x4b, 0x00, 0x11, 0x01, 0x1d, 0x00,
165+
0x11, 0x05, 0x4b, 0x00, 0x01, 0x08, 0x48, 0x00, 0x01, 0x07, 0x4b, 0x00,
166+
0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x61, 0x00, 0x02, 0x08, 0x48, 0x00,
167+
0x02, 0x07, 0x4b, 0x00, 0x13, 0x81, 0x4d, 0x00, 0x13, 0x01, 0x44, 0x00,
168+
0x23, 0x01, 0x44, 0x00, 0x23, 0x05, 0x4b, 0x00, 0x13, 0x08, 0x55, 0x00,
169+
0x13, 0x05, 0x4b, 0x00, 0x03, 0x02, 0x57, 0x00, 0x03, 0x04, 0x68, 0x00,
170+
0x03, 0x82, 0x68, 0x00, 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00,
171+
0x02, 0x8b, 0x4b, 0x00, 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x6d, 0x00,
172+
0x02, 0x08, 0x48, 0x00, 0x02, 0x07, 0x4b, 0x00, 0x13, 0x81, 0x4d, 0x00,
173+
0x13, 0x01, 0x44, 0x00, 0x23, 0x01, 0x44, 0x00, 0x23, 0x05, 0x4b, 0x00,
174+
0x13, 0x08, 0x55, 0x00, 0x13, 0x05, 0x4b, 0x00, 0x03, 0x02, 0x57, 0x00,
175+
0x03, 0x04, 0x6d, 0x00, 0x03, 0x85, 0x46, 0x00, 0x03, 0x04, 0x1d, 0x00,
176+
0x02, 0x8b, 0x4b, 0x00, 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x72, 0x00,
177+
0x02, 0x08, 0x48, 0x00, 0x02, 0x07, 0x4b, 0x00, 0x13, 0x81, 0x4d, 0x00,
178+
0x13, 0x01, 0x44, 0x00, 0x23, 0x01, 0x44, 0x00, 0x23, 0x05, 0x4b, 0x00,
179+
0x13, 0x08, 0x55, 0x00, 0x13, 0x05, 0x4b, 0x00, 0x03, 0x02, 0x57, 0x00,
180+
0x03, 0x04, 0x72, 0x00, 0x03, 0x85, 0x46, 0x00, 0x03, 0x04, 0x1d, 0x00,
181+
0x01, 0x8b, 0x4b, 0x00, 0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x46, 0x00,
182+
0x01, 0x08, 0x48, 0x00, 0x01, 0x07, 0x4b, 0x00, 0x12, 0x81, 0x16, 0x00,
183+
0x12, 0x03, 0x6d, 0x00, 0x02, 0x08, 0x48, 0x00, 0x02, 0x07, 0x4b, 0x00,
184+
0x03, 0x82, 0x6d, 0x00, 0x03, 0x07, 0x4b, 0x00, 0x14, 0x81, 0x4d, 0x00,
185+
0x14, 0x01, 0x44, 0x00, 0x24, 0x01, 0x44, 0x00, 0x24, 0x05, 0x4b, 0x00,
186+
0x14, 0x08, 0x55, 0x00, 0x14, 0x05, 0x4b, 0x00, 0x04, 0x02, 0x57, 0x00,
187+
0x04, 0x04, 0x68, 0x00, 0x04, 0x82, 0x68, 0x00, 0x03, 0x85, 0x1b, 0x00,
188+
0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x4b, 0x00, 0x12, 0x01, 0x16, 0x00,
189+
0x12, 0x03, 0x72, 0x00, 0x02, 0x08, 0x48, 0x00, 0x02, 0x07, 0x4b, 0x00,
190+
0x13, 0x81, 0x4d, 0x00, 0x13, 0x01, 0x44, 0x00, 0x23, 0x01, 0x44, 0x00,
191+
0x23, 0x05, 0x4b, 0x00, 0x13, 0x08, 0x55, 0x00, 0x13, 0x05, 0x4b, 0x00,
192+
0x03, 0x02, 0x57, 0x00, 0x03, 0x04, 0x68, 0x00, 0x03, 0x85, 0x7c, 0x00,
193+
0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x4b, 0x00, 0x11, 0x01, 0x1d, 0x00,
194+
0x11, 0x05, 0x7c, 0x00, 0x01, 0x08, 0x48, 0x00, 0x01, 0x07, 0x4b, 0x00,
195+
0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x72, 0x00, 0x02, 0x08, 0x48, 0x00,
196+
0x02, 0x07, 0x4b, 0x00, 0x13, 0x81, 0x7e, 0x00, 0x23, 0x01, 0x4d, 0x00,
197+
0x23, 0x01, 0x44, 0x00, 0x33, 0x01, 0x44, 0x00, 0x33, 0x05, 0x4b, 0x00,
198+
0x23, 0x08, 0x55, 0x00, 0x23, 0x05, 0x4b, 0x00, 0x13, 0x02, 0x57, 0x00,
199+
0x03, 0x08, 0x85, 0x00, 0x03, 0x07, 0x4b, 0x00, 0x04, 0x82, 0x68, 0x00,
200+
0x14, 0x81, 0x4d, 0x00, 0x14, 0x01, 0x44, 0x00, 0x24, 0x01, 0x7e, 0x00,
201+
0x24, 0x01, 0x72, 0x00, 0x14, 0x08, 0x55, 0x00, 0x14, 0x03, 0x4d, 0x00,
202+
0x04, 0x02, 0x87, 0x00, 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00,
203+
0x00, 0x86, 0x8f, 0x00, 0x00, 0x8c, 0x33, 0x00, /* instruct array */
204+
0x92, 0x00, /* const pool size */
198205
0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x2e, 0x6c, 0x65, 0x6e,
199206
0x00, 0x6c, 0x65, 0x6e, 0x00, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x6d, 0x6f,
200207
0x64, 0x65, 0x00, 0x30, 0x00, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x69, 0x6e,
201208
0x64, 0x65, 0x78, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74,
202-
0x65, 0x72, 0x00, 0x5f, 0x6c, 0x30, 0x00, 0x5f, 0x72, 0x31, 0x00, 0x5f,
203-
0x72, 0x32, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61, 0x32, 0x00, 0x5f, 0x6c,
204-
0x30, 0x2e, 0x61, 0x31, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e,
205-
0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x3d, 0x3d,
206-
0x00, 0x31, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x00, 0x5f,
207-
0x5f, 0x67, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x61, 0x6c, 0x77, 0x61, 0x79,
208-
0x73, 0x00, 0x74, 0x6f, 0x64, 0x6f, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x00,
209-
0x70, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x5f, 0x6d, 0x73, 0x00, 0x33, 0x00,
210-
0x5f, 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f,
211-
0x5f, 0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const
212-
pool */
209+
0x65, 0x72, 0x00, 0x5f, 0x6c, 0x30, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x5f,
210+
0x5f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00,
211+
0x3d, 0x3d, 0x00, 0x31, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73,
212+
0x00, 0x2b, 0x00, 0x5f, 0x5f, 0x73, 0x6c, 0x69, 0x63, 0x65, 0x5f, 0x5f,
213+
0x00, 0x61, 0x6c, 0x77, 0x61, 0x79, 0x73, 0x00, 0x74, 0x6f, 0x64, 0x6f,
214+
0x00, 0x77, 0x68, 0x65, 0x6e, 0x00, 0x70, 0x65, 0x72, 0x69, 0x6f, 0x64,
215+
0x5f, 0x6d, 0x73, 0x00, 0x33, 0x00, 0x5f, 0x5f, 0x74, 0x69, 0x63, 0x6b,
216+
0x00, 0x3e, 0x00, 0x5f, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d,
217+
0x31, 0x00, /* const pool */
213218
};
214-
PIKA_PYTHON_END
215219
pikaVM_runByteCode(__pikaMain, (uint8_t*)bytes);
216220
}
217221

port/linux/.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"program": "${workspaceFolder}/build/test/pikascript_test",
1212
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
1313
"args": [
14-
// "--gtest_filter=module.cmodule_import"
14+
// "--gtest_filter=VM*"
1515
],
1616
"stopAtEntry": false,
1717
"cwd": "${workspaceFolder}",

port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
141141
/* object */
142142
if (argType_isObject(arg_getType(arg))) {
143143
PikaObj* arg_obj = arg_getPtr(arg);
144+
NewFun _clsptr = obj_getPtr(arg_obj, "_clsptr");
145+
if (_clsptr == New_PikaStdLib_RangeObj) {
146+
/* found RangeObj, return directly */
147+
return arg_copy(arg);
148+
}
144149
// pikaVM_runAsm(arg_obj,
145150
// "B0\n"
146151
// "0 RUN __iter__\n"
@@ -162,9 +167,10 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
162167

163168
Arg* PikaStdLib_SysObj_range(PikaObj* self, int a1, int a2) {
164169
/* set template arg to create rangeObj */
165-
obj_setInt(self, "_r1", a1);
166-
obj_setInt(self, "_r2", a2);
167-
return arg_newMetaObj(New_PikaStdLib_RangeObj);
170+
Arg* obj_arg = arg_newDirectObj(New_PikaStdLib_RangeObj);
171+
obj_setInt(arg_getPtr(obj_arg), "a1", a1);
172+
obj_setInt(arg_getPtr(obj_arg), "a2", a2);
173+
return obj_arg;
168174
}
169175

170176
Arg* PikaStdLib_SysObj___get__(PikaObj* self, Arg* key, Arg* obj) {

0 commit comments

Comments
 (0)