support if and while in main.py

This commit is contained in:
graduateDesign 2021-09-07 22:15:59 +08:00
parent 46882bd75a
commit 147141a479
8 changed files with 30 additions and 5 deletions

View File

@ -16,3 +16,7 @@ print('mem.max :')
mem.max() mem.max()
print('mem.now :') print('mem.now :')
mem.now() mem.now()
while True:
io1.low()
io1.off()

View File

@ -3,6 +3,8 @@
/* ******************************** */ /* ******************************** */
#include "PikaMain.h" #include "PikaMain.h"
#include "PikaStdLib_SysObj.h" #include "PikaStdLib_SysObj.h"
#include "io1_low.h"
#include "io1_off.h"
#include "STM32_GPIO.h" #include "STM32_GPIO.h"
#include "PikaStdLib_MemChecker.h" #include "PikaStdLib_MemChecker.h"
#include <stdio.h> #include <stdio.h>
@ -11,6 +13,8 @@
PikaObj *New_PikaMain(Args *args){ PikaObj *New_PikaMain(Args *args){
PikaObj *self = New_PikaStdLib_SysObj(args); PikaObj *self = New_PikaStdLib_SysObj(args);
obj_import(self, "io1_low", New_io1_low);
obj_import(self, "io1_off", New_io1_off);
obj_import(self, "STM32_GPIO", New_STM32_GPIO); obj_import(self, "STM32_GPIO", New_STM32_GPIO);
obj_newObj(self, "io1", "STM32_GPIO"); obj_newObj(self, "io1", "STM32_GPIO");
obj_import(self, "PikaStdLib_MemChecker", New_PikaStdLib_MemChecker); obj_import(self, "PikaStdLib_MemChecker", New_PikaStdLib_MemChecker);

File diff suppressed because one or more lines are too long

View File

@ -5,3 +5,7 @@ line = Arm2D.Line()
res = line.on() res = line.on()
line.off() line.off()
line.moveTo(20) line.moveTo(20)
while True:
line.off()
line.on()

View File

@ -111,6 +111,7 @@ impl ClassInfo {
script_fn.push_str("PikaObj * pikaScriptInit(){\r\n"); script_fn.push_str("PikaObj * pikaScriptInit(){\r\n");
script_fn.push_str(" PikaObj * pikaMain = newRootObj(\"pikaMain\", New_PikaMain);\r\n"); script_fn.push_str(" PikaObj * pikaMain = newRootObj(\"pikaMain\", New_PikaMain);\r\n");
script_fn.push_str(&self.script_list.content); script_fn.push_str(&self.script_list.content);
script_fn.push_str(" obj_run(pikaMain, \"\");\r\n");
script_fn.push_str(" return pikaMain;\r\n"); script_fn.push_str(" return pikaMain;\r\n");
script_fn.push_str("}\r\n\r\n"); script_fn.push_str("}\r\n\r\n");
return script_fn; return script_fn;

View File

@ -50,6 +50,17 @@ impl Compiler {
} }
if line.contains("(") && line.contains(")") { if line.contains("(") && line.contains(")") {
class_now.script_list.add(&line); class_now.script_list.add(&line);
return compiler;
}
if line.starts_with("if ") {
class_now.script_list.add(&line);
return compiler;
}
if line.starts_with("while ") {
class_now.script_list.add(&line);
return compiler;
} }
return compiler; return compiler;
} }
@ -101,6 +112,11 @@ impl Compiler {
class_now.push_method(line); class_now.push_method(line);
return compiler; return compiler;
} }
if file_name == "main" {
return Compiler::analyze_main_line(compiler, line);
}
if line.starts_with(" ") if line.starts_with(" ")
&& line.contains("(") && line.contains("(")
&& line.contains(")") && line.contains(")")
@ -124,10 +140,6 @@ impl Compiler {
return compiler; return compiler;
} }
if file_name == "main" {
return Compiler::analyze_main_line(compiler, line);
}
return compiler; return compiler;
} }
} }

Binary file not shown.