pikastech 3 vuotta sitten
vanhempi
sitoutus
5fa138c9c1

+ 6 - 2
package/PikaStdLib/PikaStdLib_SysObj.c

@@ -631,11 +631,15 @@ static enum shell_state __obj_shellLineHandler_input(PikaObj* self,
 }
 
 char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
-    struct ShellConfig cfg = {.prefix = "", .context = NULL};
+    struct ShellConfig cfg = {
+        .prefix = "",
+        .context = NULL,
+        .handler = __obj_shellLineHandler_input,
+    };
     if (tuple_getSize(info) > 0) {
         __platform_printf("%s", tuple_getStr(info, 0));
     }
-    _temp_obj_shellLineProcess(self, __obj_shellLineHandler_input, &cfg);
+    _temp_obj_shellLineProcess(self, &cfg);
     char* res = obj_cacheStr(self, arg_getStr(cfg.context));
     arg_deinit(cfg.context);
     return res;

+ 6 - 2
port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c

@@ -631,11 +631,15 @@ static enum shell_state __obj_shellLineHandler_input(PikaObj* self,
 }
 
 char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
-    struct ShellConfig cfg = {.prefix = "", .context = NULL};
+    struct ShellConfig cfg = {
+        .prefix = "",
+        .context = NULL,
+        .handler = __obj_shellLineHandler_input,
+    };
     if (tuple_getSize(info) > 0) {
         __platform_printf("%s", tuple_getStr(info, 0));
     }
-    _temp_obj_shellLineProcess(self, __obj_shellLineHandler_input, &cfg);
+    _temp_obj_shellLineProcess(self, &cfg);
     char* res = obj_cacheStr(self, arg_getStr(cfg.context));
     arg_deinit(cfg.context);
     return res;

+ 4 - 7
src/PikaObj.c

@@ -876,7 +876,6 @@ enum shell_state _do_obj_runChar(PikaObj* self,
                                  char inputChar,
                                  ShellConfig* cfg) {
     char* rxBuff = cfg->lineBuff;
-    int is_in_block = cfg->inBlock;
     char* input_line = NULL;
 #if !(defined(__linux) || defined(_WIN32))
     __platform_printf("%c", inputChar);
@@ -900,7 +899,7 @@ enum shell_state _do_obj_runChar(PikaObj* self,
         __platform_printf("\r\n");
 #endif
         /* still in block */
-        if (is_in_block) {
+        if (cfg->blockBuffName != NULL && cfg->inBlock) {
             /* load new line into buff */
             Args buffs = {0};
             char _n = '\n';
@@ -922,7 +921,7 @@ enum shell_state _do_obj_runChar(PikaObj* self,
             __clearBuff(rxBuff, PIKA_LINE_BUFF_SIZE);
             return SHELL_STATE_CONTINUE;
         }
-        if (0 != strGetSize(rxBuff)) {
+        if (cfg->blockBuffName != NULL && 0 != strGetSize(rxBuff)) {
             /* go in block */
             if (rxBuff[strGetSize(rxBuff) - 1] == ':') {
                 cfg->inBlock = PIKA_TRUE;
@@ -1032,9 +1031,7 @@ void obj_shellLineProcess(PikaObj* self, ShellConfig* cfg) {
     }
 }
 
-void _temp_obj_shellLineProcess(PikaObj* self,
-                                sh_handler __lineHandler_fun,
-                                ShellConfig* cfg) {
+void _temp_obj_shellLineProcess(PikaObj* self, ShellConfig* cfg) {
     /* init the shell */
     _obj_runChar_beforeRun(self, cfg);
 
@@ -1062,7 +1059,7 @@ static enum shell_state __obj_shellLineHandler_REPL(PikaObj* self,
 
 void pikaScriptShell(PikaObj* self) {
     ShellConfig cfg = {
-        .handler= __obj_shellLineHandler_REPL,
+        .handler = __obj_shellLineHandler_REPL,
         .prefix = ">>> ",
         .blockBuffName = "@sh0",
     };

+ 1 - 3
src/PikaObj.h

@@ -263,9 +263,7 @@ struct ShellConfig {
 
 void obj_shellLineProcess(PikaObj* self, ShellConfig* cfg);
 
-void _temp_obj_shellLineProcess(PikaObj* self,
-                                sh_handler __lineHandler_fun,
-                                struct ShellConfig* cfg);
+void _temp_obj_shellLineProcess(PikaObj* self, ShellConfig* cfg);
 
 /*
     need implament :

+ 26 - 6
test/pikaMain-test.cpp

@@ -1114,11 +1114,11 @@ TEST(pikaMain, class_arg) {
     __platform_printf("BEGIN\r\n");
     Args* buffs = New_strBuff();
     char* pikaAsm = Parser_linesToAsm(buffs,
-                                          "class Test(TinyObj):\n"
-                                          "    x = 1\n"
-                                          "\n"
-                                          "test = Test()\n"
-                                          "print(test.x)\n");
+                                      "class Test(TinyObj):\n"
+                                      "    x = 1\n"
+                                      "\n"
+                                      "test = Test()\n"
+                                      "print(test.x)\n");
     printf("%s", pikaAsm);
     pikaVM_runAsm(pikaMain, pikaAsm);
     /* assert */
@@ -1842,7 +1842,6 @@ TEST(pikaMain, builtin_hex) {
 }
 #endif
 
-
 #if !PIKA_NANO_ENABLE
 TEST(pikaMain, builtin_ord) {
     /* init */
@@ -1932,6 +1931,27 @@ TEST(pikaMain, REPL_push_mode) {
     EXPECT_EQ(pikaMemNow(), 0);
 }
 
+#if 0
+TEST(pikaMain, REPL_input) {
+    /* init */
+    pikaMemInfo.heapUsedMax = 0;
+    /* run */
+    PikaObj* self = newRootObj("pikaMain", New_PikaMain);
+    __platform_printf("BEGIN\r\n");
+    char lines[] =
+        "res = input('input:\\n')\n"
+        "1234\n"
+        "print(res)\n";
+    for (size_t i = 0; i < strGetSize(lines); i++) {
+        obj_runChar(self, lines[i]);
+    }
+    /* assert */
+    /* deinit */
+    obj_deinit(self);
+    EXPECT_EQ(pikaMemNow(), 0);
+}
+#endif
+
 #if PIKA_SYNTAX_SLICE_ENABLE
 TEST(pikaMain, int_from_bytes) {
     /* init */