pikastech 3 лет назад
Родитель
Сommit
bce7f495c6

+ 2 - 1
port/linux/.vscode/c_cpp_properties.json

@@ -11,7 +11,8 @@
             "defines": [],
             "compilerPath": "/usr/bin/gcc",
             "cStandard": "c99",
-            "cppStandard": "c++14"
+            "cppStandard": "c++14",
+            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
         }
     ],
     "version": 4

+ 30 - 0
tools/pikaCompiler/Cargo.lock

@@ -2,6 +2,12 @@
 # It is not intended for manual editing.
 version = 3
 
+[[package]]
+name = "itoa"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
+
 [[package]]
 name = "libc"
 version = "0.2.125"
@@ -13,4 +19,28 @@ name = "rust-msc"
 version = "0.1.0"
 dependencies = [
  "libc",
+ "serde_json",
+]
+
+[[package]]
+name = "ryu"
+version = "1.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
+
+[[package]]
+name = "serde"
+version = "1.0.137"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
+
+[[package]]
+name = "serde_json"
+version = "1.0.81"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
 ]

+ 1 - 0
tools/pikaCompiler/Cargo.toml

@@ -10,5 +10,6 @@ path = "src/lib.rs"
 
 [dependencies]
 libc = "0.2"
+serde_json = "1.0"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

+ 9 - 1
tools/pikaCompiler/src/compiler.rs

@@ -102,7 +102,15 @@ impl Compiler {
         return Err(std::io::Error::from(std::io::ErrorKind::NotFound));
     }
 
-    pub fn __do_analize_file(mut self: Compiler, file_name: String, is_top_pkg: bool) -> Compiler {
+    pub fn analize_top_package(self: Compiler, file_name: String) -> Compiler {
+        return self.__do_analize_file(file_name, true);
+    }
+
+    pub fn analize_inner_package(self: Compiler, file_name: String) -> Compiler {
+        return self.__do_analize_file(file_name, false);
+    }
+
+    fn __do_analize_file(mut self: Compiler, file_name: String, is_top_pkg: bool) -> Compiler {
         /* open file */
         let file: std::result::Result<std::fs::File, std::io::Error>;
         if file_name == "main" {

+ 8 - 7
tools/pikaCompiler/src/entry.rs

@@ -1,9 +1,9 @@
 use crate::compiler::*;
+use crate::version_info::*;
 use std::fs::File;
 use std::io::prelude::*;
-use crate::version_info::*;
 
-pub fn pika_compiler_entry(){
+pub fn pika_compiler_entry() {
     /* new a version_info object */
     println!("(pikascript) packages installed:");
     let mut version_info = VersionInfo::new();
@@ -13,8 +13,9 @@ pub fn pika_compiler_entry(){
     println!("(pikascript) pika compiler:");
     /* new a compiler, sellect to path */
     let mut compiler = Compiler::new(String::from(""), String::from("pikascript-api/"));
+
     /* analyze file begin with main.py */
-    compiler = Compiler::__do_analize_file(compiler, String::from("main"), false);
+    compiler = Compiler::analize_inner_package(compiler, String::from("main"));
     /*
        Compile packages in requestment.txt, solve the packages
        as the top packages.
@@ -24,13 +25,13 @@ pub fn pika_compiler_entry(){
         if package.0 == "pikascript-core" {
             continue;
         }
-        compiler = Compiler::__do_analize_file(compiler, String::from(package.0), true);
+        compiler = Compiler::analize_top_package(compiler, String::from(package.0));
     }
 
     /* Compile packages in PikaStdLib */
-    compiler = Compiler::__do_analize_file(compiler, String::from("PikaStdTask"), true);
-    compiler = Compiler::__do_analize_file(compiler, String::from("PikaStdData"), true);
-    compiler = Compiler::__do_analize_file(compiler, String::from("PikaDebug"), true);
+    compiler = Compiler::analize_top_package(compiler, String::from("PikaStdTask"));
+    compiler = Compiler::analize_top_package(compiler, String::from("PikaStdData"));
+    compiler = Compiler::analize_top_package(compiler, String::from("PikaDebug"));
 
     // println!();