Browse Source

supporting decorator to macro in pyi

update PikaObj.pyi

use @PIKA_C_MACRO_IF to cut sysobj
pikastech 3 năm trước cách đây
mục cha
commit
04da2b93b6

+ 19 - 8
package/PikaStdLib/PikaStdLib.pyi

@@ -1,11 +1,16 @@
-from typing import List
-
+from PikaObj import *
 
 class MemChecker:
     def max(self): ...
     def now(self): ...
+
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def getMax(self) -> float: ...
+
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def getNow(self) -> float: ...
+
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def resetMax(self): ...
 
 
@@ -13,9 +18,6 @@ class SysObj:
     @staticmethod
     def type(arg: any) -> any: ...
 
-    @staticmethod
-    def remove(argPath: str): ...
-
     @staticmethod
     def int(arg: any) -> int: ...
 
@@ -35,6 +37,7 @@ class SysObj:
     def print(*val): ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def printNoEnd(val: any): ...
 
     @staticmethod
@@ -50,18 +53,23 @@ class SysObj:
     def len(arg: any) -> int: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def list() -> any: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def dict() -> any: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def hex(val: int) -> str: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def ord(val: str) -> int: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def chr(val: int) -> str: ...
 
     @staticmethod
@@ -71,21 +79,27 @@ class SysObj:
     def cformat(fmt: str, *var) -> str: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def id(obj: any) -> int: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def open(path: str, mode: str) -> object: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def dir(obj: object) -> list: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def exec(code: str): ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def getattr(obj: object, name: str) -> any: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def setattr(obj: object, name: str, val: any): ...
 
 
@@ -96,6 +110,3 @@ class RangeObj:
 class StringObj:
     def __next__(self) -> any: ...
 
-
-class PikaObj:
-    ...

+ 1 - 1
port/linux/config/pika_config_syntax_level_minimal.h

@@ -1,3 +1,3 @@
-#define PIKA_SYNTAX_LEVEL PIKA_SYNTAX_LEVEL_MINIMAL
+#define PIKA_NANO_ENABLE 1
 #define PIKA_STACK_BUFF_SIZE 1024 * 1024
 #define PIKA_ASSERT_ENABLE 1

+ 3 - 1
port/linux/package/pikascript/PikaObj.pyi

@@ -15,4 +15,6 @@ class any:
 
 
 def printNoEnd(val: any): ...
-def abstractmethod(funcobj): ...
+def abstractmethod(fn): ...
+def PIKA_C_MACRO_IF(fn): ...
+def PIKA_C_MACRO_IFDEF(fn): ...

+ 10 - 0
port/linux/package/pikascript/PikaStdDevice.pyi

@@ -102,24 +102,31 @@ class Time(BaseDev):
     def sleep(self, s: float):
         """Sleep for s seconds."""
 
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def time(self) -> float:
         """Get the current time."""
 
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def time_ns(self) -> int:
         """Get the current time in nanoseconds."""
 
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def gmtime(self, unix_time: float):
         """Convert unix time to struct_time."""
 
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def localtime(self, unix_time: float):
         """Convert unix time to struct_time."""
 
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def mktime(self) -> int:
         """Convert struct_time to unix time."""
 
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def asctime(self):
         """Convert struct_time to string."""
 
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def ctime(self, unix_time: float):
         """Convert unix time to string."""
 
@@ -130,6 +137,7 @@ class Time(BaseDev):
     def sleep_ms(self, ms: int): ...
 
     @abstractmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def platformGetTick(): ...
 
 
@@ -442,8 +450,10 @@ class CAN(BaseDev):
 
 
 class BaseDev:
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def addEventCallBack(self, eventCallback: any): 
         """ Add an event callback. """
 
     @abstractmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def platformGetEventId(self): ...

+ 19 - 8
port/linux/package/pikascript/PikaStdLib.pyi

@@ -1,11 +1,16 @@
-from typing import List
-
+from PikaObj import *
 
 class MemChecker:
     def max(self): ...
     def now(self): ...
+
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def getMax(self) -> float: ...
+
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def getNow(self) -> float: ...
+
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def resetMax(self): ...
 
 
@@ -13,9 +18,6 @@ class SysObj:
     @staticmethod
     def type(arg: any) -> any: ...
 
-    @staticmethod
-    def remove(argPath: str): ...
-
     @staticmethod
     def int(arg: any) -> int: ...
 
@@ -35,6 +37,7 @@ class SysObj:
     def print(*val): ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def printNoEnd(val: any): ...
 
     @staticmethod
@@ -50,18 +53,23 @@ class SysObj:
     def len(arg: any) -> int: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def list() -> any: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def dict() -> any: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def hex(val: int) -> str: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def ord(val: str) -> int: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def chr(val: int) -> str: ...
 
     @staticmethod
@@ -71,21 +79,27 @@ class SysObj:
     def cformat(fmt: str, *var) -> str: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def id(obj: any) -> int: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def open(path: str, mode: str) -> object: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def dir(obj: object) -> list: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def exec(code: str): ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def getattr(obj: object, name: str) -> any: ...
 
     @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
     def setattr(obj: object, name: str, val: any): ...
 
 
@@ -96,6 +110,3 @@ class RangeObj:
 class StringObj:
     def __next__(self) -> any: ...
 
-
-class PikaObj:
-    ...

+ 11 - 0
port/linux/test/pikaMain-test.cpp

@@ -965,6 +965,7 @@ TEST(pikaMain, task_run_when) {
     EXPECT_EQ(pikaMemNow(), 0);
 }
 
+#if !PIKA_NANO_ENABLE
 TEST(pikaMain, task_run_period_until) {
     /* init */
     pikaMemInfo.heapUsedMax = 0;
@@ -1017,6 +1018,7 @@ TEST(pikaMain, task_run_period_until) {
     obj_deinit(pikaMain);
     EXPECT_EQ(pikaMemNow(), 0);
 }
+#endif
 
 TEST(pikaMain, fun_call) {
     /* init */
@@ -1356,6 +1358,7 @@ TEST(pikaMain, class_demo_1_file) {
     EXPECT_EQ(pikaMemNow(), 0);
 }
 
+#if !PIKA_NANO_ENABLE
 TEST(pikaMain, get_native_method) {
     /* init */
     pikaMemInfo.heapUsedMax = 0;
@@ -1373,6 +1376,7 @@ TEST(pikaMain, get_native_method) {
     obj_deinit(pikaMain);
     EXPECT_EQ(pikaMemNow(), 0);
 }
+#endif
 
 TEST(pikaMain, hex_list) {
     /* init */
@@ -1816,6 +1820,7 @@ TEST(pikaMain, CModule__str__) {
     EXPECT_EQ(pikaMemNow(), 0);
 }
 
+#if !PIKA_NANO_ENABLE
 TEST(pikaMain, builtin_hex) {
     /* init */
     pikaMemInfo.heapUsedMax = 0;
@@ -1837,7 +1842,10 @@ TEST(pikaMain, builtin_hex) {
     obj_deinit(self);
     EXPECT_EQ(pikaMemNow(), 0);
 }
+#endif
 
+
+#if !PIKA_NANO_ENABLE
 TEST(pikaMain, builtin_ord) {
     /* init */
     pikaMemInfo.heapUsedMax = 0;
@@ -1852,7 +1860,9 @@ TEST(pikaMain, builtin_ord) {
     obj_deinit(self);
     EXPECT_EQ(pikaMemNow(), 0);
 }
+#endif
 
+#if !PIKA_NANO_ENABLE
 TEST(pikaMain, builtin_chr) {
     /* init */
     pikaMemInfo.heapUsedMax = 0;
@@ -1867,6 +1877,7 @@ TEST(pikaMain, builtin_chr) {
     obj_deinit(self);
     EXPECT_EQ(pikaMemNow(), 0);
 }
+#endif
 
 TEST(pikaMain, iteral_oct) {
     /* init */

+ 5 - 1
port/linux/test/sysObj-test.cpp

@@ -29,6 +29,7 @@ TEST(sysObj, noMethod) {
     EXPECT_EQ(pikaMemNow(), 0);
 }
 
+#if !PIKA_NANO_ENABLE
 TEST(sysObj, getattr) {
     char* lines =
         "class Test:\n"
@@ -50,7 +51,9 @@ TEST(sysObj, getattr) {
     obj_deinit(pikaMain);
     EXPECT_EQ(pikaMemNow(), 0);
 }
+#endif
 
+#if !PIKA_NANO_ENABLE
 TEST(sysObj, setattr) {
     char* lines =
         "class Test:\n"
@@ -71,4 +74,5 @@ TEST(sysObj, setattr) {
     /* deinit */
     obj_deinit(pikaMain);
     EXPECT_EQ(pikaMemNow(), 0);
-}
+}
+#endif

+ 3 - 1
src/PikaObj.pyi

@@ -15,4 +15,6 @@ class any:
 
 
 def printNoEnd(val: any): ...
-def abstractmethod(funcobj): ...
+def abstractmethod(fn): ...
+def PIKA_C_MACRO_IF(fn): ...
+def PIKA_C_MACRO_IFDEF(fn): ...

+ 16 - 0
src/pika_config_valid.h

@@ -50,6 +50,22 @@
         #include "pika_config.h"
     #endif
 
+    /* default pika_nano_enabled */
+    #ifndef PIKA_NANO_ENABLE
+        #define PIKA_NANO_ENABLE 0
+    #endif
+
+    #if PIKA_NANO_ENABLE
+        #ifndef PIKA_OPTIMIZE
+            #define PIKA_OPTIMIZE PIKA_OPTIMIZE_SIZE
+        #endif
+
+        /* default syntax support level */
+        #ifndef PIKA_SYNTAX_LEVEL
+            #define PIKA_SYNTAX_LEVEL PIKA_SYNTAX_LEVEL_MINIMAL
+        #endif
+    #endif
+
     /* default optimize */
     #ifndef PIKA_OPTIMIZE
         #define PIKA_OPTIMIZE PIKA_OPTIMIZE_SIZE

+ 6 - 0
tools/pikaCompiler/PikaObj.pyi

@@ -13,3 +13,9 @@ def print(val: any):
 
 def set(argPath: str, val: any):
     pass
+
+class any:
+    pass
+
+def PIKA_C_MACRO_IF(fun: any):
+    pass

+ 4 - 6
tools/pikaCompiler/PikaStdLib.pyi

@@ -1,7 +1,5 @@
-# api
 from PikaObj import *
 
-
 class MemChecker(TinyObj):
     def max(self): ...
     def now(): ...
@@ -9,29 +7,29 @@ class MemChecker(TinyObj):
     def getNow() -> float: ...
     def resetMax(): ...
 
-
 class SysObj(BaseObj):
     def type(arg: any): ...
     def remove(argPath: str): ...
     def int(arg: any) -> int: ...
     def float(arg: any) -> float: ...
     def str(arg: any) -> str: ...
+    @PIKA_C_MACRO_IF("!PIKA_NODE_ENABLE")
     def iter(arg: any) -> any: ...
+    @staticmethod
     def range(a1: int, a2: int) -> any: ...
+    @staticmethod
+    @PIKA_C_MACRO_IF("!PIKA_NODE_ENABLE")
     def __setitem__(obj: any, key: any, val: any, obj_str: str): ...
     def __getitem__(obj: any, key: any) -> any: ...
     def print(self, *val): ...
 
-
 class RangeObj(TinyObj):
     def __next__() -> any:
         pass
 
-
 class StringObj(TinyObj):
     def __next__() -> any:
         pass
 
-
 class PikaObj(TinyObj):
     pass

+ 15 - 107
tools/pikaCompiler/src/class_info.rs

@@ -1,3 +1,4 @@
+use crate::decorator::Decorator;
 use crate::import_info::ImportInfo;
 use crate::method_info::MethodInfo;
 use crate::my_string;
@@ -68,21 +69,28 @@ impl ClassInfo {
         };
         return Some(new_class_info);
     }
-    fn __push_method_or_constructor(&mut self, method_define: String, is_constructor: bool) {
-        let method_info =
+
+    fn __push_method_or_constructor(
+        &mut self,
+        method_define: String,
+        is_constructor: bool,
+        decorator_list: Vec<Decorator>,
+    ) {
+        let mut method_info =
             match MethodInfo::new(&self.this_class_name, method_define, is_constructor) {
                 Some(method) => method,
                 None => return,
             };
+        method_info.set_decorator_list(decorator_list);
         self.method_list
             .entry(method_info.name.clone())
             .or_insert(method_info);
     }
-    pub fn push_method(&mut self, method_define: String) {
-        return self.__push_method_or_constructor(method_define, false);
+    pub fn push_method(&mut self, method_define: String, decorator_list: Vec<Decorator>) {
+        return self.__push_method_or_constructor(method_define, false, decorator_list);
     }
-    pub fn push_constructor(&mut self, method_define: String) {
-        return self.__push_method_or_constructor(method_define, true);
+    pub fn push_constructor(&mut self, method_define: String, decorator_list: Vec<Decorator>) {
+        return self.__push_method_or_constructor(method_define, true, decorator_list);
     }
     // pub fn push_import(&mut self, import_define: String, file_name: &String) {
     //     let import_info = match ImportInfo::new(&self.this_class_name, import_define, &file_name) {
@@ -188,9 +196,7 @@ impl ClassInfo {
         new_class_fn.push_str(&new_class_fn_head);
         let derive = format!("    PikaObj *self = New_{}(args);\n", self.super_class_name);
         new_class_fn.push_str(&derive);
-        for (_, import_info) in self.import_list.iter() {
-            new_class_fn.push_str(&import_info.import_fn());
-        }
+
         for (_, object_info) in self.object_list.iter() {
             new_class_fn.push_str(&object_info.new_object_fn());
         }
@@ -216,101 +222,3 @@ impl ClassInfo {
         return method_fn_declear;
     }
 }
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn test_analyse() {
-        assert_eq!(
-            ClassInfo::new(
-                &String::from("Pkg"),
-                &String::from("class Test(SuperTest):"),
-                false
-            )
-            .unwrap()
-            .this_class_name,
-            "Pkg_Test"
-        );
-        assert_eq!(
-            ClassInfo::new(
-                &String::from("Pkg"),
-                &String::from("class Test(SuperTest):"),
-                false
-            )
-            .unwrap()
-            .super_class_name,
-            "Pkg_SuperTest"
-        );
-    }
-    #[test]
-    fn test_push_method() {
-        let mut class_info = ClassInfo::new(
-            &String::from("Pkg"),
-            &String::from("class Test(SuperTest):"),
-            false,
-        )
-        .unwrap();
-        class_info.push_method(String::from("def test(data: str)-> str:"));
-        assert_eq!(
-            class_info.method_list.get("test").unwrap().class_name,
-            "Pkg_Test"
-        );
-        assert_eq!(class_info.method_list.get("test").unwrap().name, "test");
-        assert_eq!(
-            class_info
-                .method_list
-                .get("test")
-                .as_ref()
-                .unwrap()
-                .return_type
-                .as_ref()
-                .unwrap()
-                .to_string(),
-            "str"
-        );
-        assert_eq!(
-            class_info
-                .method_list
-                .get("test")
-                .as_ref()
-                .unwrap()
-                .arg_list
-                .as_ref()
-                .unwrap()
-                .to_string(),
-            "data:str"
-        );
-    }
-    #[test]
-    fn test_push_object() {
-        let mut class_info = ClassInfo::new(
-            &String::from("Pkg"),
-            &String::from("class Test(SuperTest):"),
-            false,
-        )
-        .unwrap();
-        class_info.push_object(String::from("testObj = TestObj()"), &"Pkg".to_string());
-        assert_eq!(
-            class_info.object_list.get("testObj").unwrap().class_name,
-            "Pkg_Test"
-        );
-        assert_eq!(
-            class_info.object_list.get("testObj").unwrap().name,
-            "testObj"
-        );
-        assert_eq!(
-            class_info
-                .object_list
-                .get("testObj")
-                .unwrap()
-                .import_class_name,
-            "Pkg_TestObj"
-        );
-        assert_eq!(
-            class_info.object_list.get("testObj").unwrap().name,
-            "testObj"
-        );
-    }
-}

+ 34 - 18
tools/pikaCompiler/src/compiler.rs

@@ -1,4 +1,5 @@
 use crate::class_info::ClassInfo;
+use crate::decorator::Decorator;
 // use crate::my_string;
 // use crate::script::Script;
 use std::collections::BTreeMap;
@@ -20,9 +21,10 @@ pub struct Compiler {
     pub dist_path: String,
     pub source_path: String,
     pub class_list: BTreeMap<String, ClassInfo>,
-    pub class_now_name: Option<String>,
-    pub package_now_name: Option<String>,
+    pub class_name_now: Option<String>,
+    pub package_name_now: Option<String>,
     pub compiled_list: LinkedList<String>,
+    pub decorator_list_now: Vec<Decorator>,
 }
 
 impl Compiler {
@@ -30,10 +32,11 @@ impl Compiler {
         let compiler = Compiler {
             dist_path: dist_path.clone(),
             source_path: source_path.clone(),
-            class_now_name: None,
+            class_name_now: None,
             class_list: BTreeMap::new(),
-            package_now_name: None,
+            package_name_now: None,
             compiled_list: LinkedList::new(),
+            decorator_list_now: Vec::new(),
         };
         return compiler;
     }
@@ -61,7 +64,7 @@ impl Compiler {
                 .unwrap(),
             ),
         };
-        compiler.class_now_name = Some(class_name.clone());
+        compiler.class_name_now = Some(class_name.clone());
 
         if line.starts_with("import ") || line.starts_with("from ") {
             let tokens: Vec<&str> = line.split(' ').collect();
@@ -188,10 +191,7 @@ impl Compiler {
             /* print info */
             match suffix {
                 "py" => {
-                    println!(
-                        "  scaning {}{}.{}...",
-                        self.source_path, file_name, suffix
-                    );
+                    println!("  scaning {}{}.{}...", self.source_path, file_name, suffix);
                 }
                 "pyi" => {
                     println!(
@@ -232,7 +232,7 @@ impl Compiler {
             self.class_list
                 .entry(package_name.clone())
                 .or_insert(package_now);
-            self.package_now_name = Some(package_name.clone());
+            self.package_name_now = Some(package_name.clone());
         }
 
         let lines: Vec<&str> = file_str.split('\n').collect();
@@ -270,6 +270,16 @@ impl Compiler {
             return compiler;
         }
 
+        if line.starts_with("@") || line.starts_with("    @") {
+            let stmt = line.replace("@", "").replace(" ", "");
+            let decorator_this = match Decorator::new(stmt) {
+                Some(s) => s,
+                None => return compiler,
+            };
+            compiler.decorator_list_now.push(decorator_this);
+            return compiler;
+        }
+
         /* analyse class stmt */
         if line.starts_with("class") {
             /* create a new class */
@@ -284,7 +294,7 @@ impl Compiler {
                 .class_list
                 .entry(class_name.clone())
                 .or_insert(class_now);
-            compiler.class_now_name = Some(class_name.clone());
+            compiler.class_name_now = Some(class_name.clone());
 
             /* the class in to package can be import in runtime */
             if is_top_pkg {
@@ -292,13 +302,17 @@ impl Compiler {
                     Solve the class as method of top package
                         the package is a class in main.py and the class is a method of the class in main.py.
                 */
-                let package_now_name = match compiler.package_now_name.clone() {
+                let package_now_name = match compiler.package_name_now.clone() {
                     Some(s) => s,
                     None => return compiler,
                 };
                 let package_now = compiler.class_list.get_mut(&package_now_name).unwrap();
                 let package_new_object_method = format!("def {}()->any:", class_name_without_file);
-                package_now.push_constructor(package_new_object_method);
+                package_now.push_constructor(
+                    package_new_object_method,
+                    compiler.decorator_list_now.clone(),
+                );
+                compiler.decorator_list_now.clear();
             }
 
             return compiler;
@@ -306,12 +320,13 @@ impl Compiler {
 
         /* analyse function define */
         if line.starts_with("def ") {
-            let package_now_name = match compiler.package_now_name.clone() {
+            let package_now_name = match compiler.package_name_now.clone() {
                 Some(s) => s,
                 None => return compiler,
             };
             let package_now = compiler.class_list.get_mut(&package_now_name).unwrap();
-            package_now.push_method(line);
+            package_now.push_method(line, compiler.decorator_list_now.clone());
+            compiler.decorator_list_now.clear();
             return compiler;
         }
 
@@ -320,9 +335,10 @@ impl Compiler {
             let line = line.strip_prefix("    ").unwrap().to_string();
             let class_now = compiler
                 .class_list
-                .get_mut(&compiler.class_now_name.clone().unwrap())
+                .get_mut(&compiler.class_name_now.clone().unwrap())
                 .unwrap();
-            class_now.push_method(line);
+            class_now.push_method(line, compiler.decorator_list_now.clone());
+            compiler.decorator_list_now.clear();
             return compiler;
         }
 
@@ -334,7 +350,7 @@ impl Compiler {
             let line = line.strip_prefix("    ").unwrap().to_string();
             let class_now = compiler
                 .class_list
-                .get_mut(&compiler.class_now_name.clone().unwrap())
+                .get_mut(&compiler.class_name_now.clone().unwrap())
                 .unwrap();
             class_now.push_object(line, &file_name);
             return compiler;

+ 0 - 6
tools/pikaCompiler/src/import_info.rs

@@ -27,11 +27,5 @@ impl ImportInfo {
     //         import_class_name: import_class_name,
     //     });
     // }
-    pub fn import_fn(&self) -> String {
-        return format!(
-            "    obj_import(self, \"{}\", New_{});\n",
-            self.import_class_name, self.import_class_name
-        );
-    }
 }
 

+ 1 - 0
tools/pikaCompiler/src/lib.rs

@@ -11,6 +11,7 @@ mod py_type;
 mod script;
 mod version_info;
 mod entry;
+mod decorator;
 
 use entry::*;
 

+ 1 - 0
tools/pikaCompiler/src/main.rs

@@ -10,6 +10,7 @@ mod py_type;
 mod script;
 mod version_info;
 mod entry;
+mod decorator;
 use entry::*;
 
 fn main() {

+ 28 - 6
tools/pikaCompiler/src/method_info.rs

@@ -1,4 +1,5 @@
 use crate::arg_list::ArgList;
+use crate::decorator::Decorator;
 use crate::my_string;
 use crate::py_type::PyType;
 
@@ -9,6 +10,7 @@ pub struct MethodInfo {
     pub arg_list: Option<ArgList>,
     pub return_type: Option<PyType>,
     pub is_constructor: bool,
+    pub decorator_list: Vec<Decorator>,
 }
 
 impl MethodInfo {
@@ -37,6 +39,7 @@ impl MethodInfo {
             return_type: return_type,
             class_name: class_name.clone(),
             is_constructor: is_constructor,
+            decorator_list: Vec::new(),
         };
         return Some(method_info);
     }
@@ -53,12 +56,33 @@ impl MethodInfo {
         if self.is_constructor {
             class_define_method = String::from("class_defineConstructor");
         }
-        let define = format!(
-            "    {}(self, \"{}({}){}\", {}_{}Method);\n",
-            class_define_method, self.name, arg_list, return_token, self.class_name, self.name
+
+        let mut define = String::from("");
+
+        for decorator in &self.decorator_list {
+            define.push_str(decorator.gen_before().as_str());
+        }
+
+        define.push_str(
+            format!(
+                "    {}(self, \"{}({}){}\", {}_{}Method);\n",
+                class_define_method, self.name, arg_list, return_token, self.class_name, self.name
+            )
+            .as_str(),
         );
+
+        let mut decorator_list_reverse = self.decorator_list.clone();
+        decorator_list_reverse.reverse();
+        for decorator in decorator_list_reverse {
+            define.push_str(decorator.gen_after().as_str());
+        }
+
         return define;
     }
+    pub fn set_decorator_list(&mut self, decorator_list: Vec<Decorator>) {
+        self.decorator_list = decorator_list;
+    }
+
     pub fn method_api_name(&self) -> String {
         return format!(
             "void {}_{}Method(PikaObj *self, Args *args)",
@@ -87,9 +111,7 @@ impl MethodInfo {
             None => "".to_string(),
         };
         let return_impl = match &self.return_type {
-            Some(x) => {
-                x.return_fn()
-            },
+            Some(x) => x.return_fn(),
             None => "".to_string(),
         };
         let return_type_in_c = match &self.return_type {