Browse Source

refactor: 提取VirtualMathCore模块

提取核心运行模组为VirtualMathCore的动态库
SongZihuan 4 years ago
parent
commit
aa78dd7e52
85 changed files with 55 additions and 20 deletions
  1. 5 13
      CMakeLists.txt
  2. 20 0
      VirtulMathCore/CMakeLists.txt
  3. 0 0
      VirtulMathCore/file/file.c
  4. 0 0
      VirtulMathCore/gc/freeze.c
  5. 0 0
      VirtulMathCore/gc/gc.c
  6. 0 0
      VirtulMathCore/gc/set.c
  7. 0 0
      VirtulMathCore/include/__macro.h
  8. 0 1
      VirtulMathCore/include/__virtualmath.h
  9. 0 0
      VirtulMathCore/include/clib.h
  10. 0 0
      VirtulMathCore/include/file.h
  11. 0 0
      VirtulMathCore/include/gc.h
  12. 0 0
      VirtulMathCore/include/grammar.h
  13. 0 0
      VirtulMathCore/include/handler.h
  14. 1 1
      VirtulMathCore/include/inter.h
  15. 0 0
      VirtulMathCore/include/lexical.h
  16. 0 0
      VirtulMathCore/include/macro.h
  17. 0 0
      VirtulMathCore/include/mem.h
  18. 0 0
      VirtulMathCore/include/ofunc.h
  19. 0 0
      VirtulMathCore/include/parameter.h
  20. 0 0
      VirtulMathCore/include/run.h
  21. 0 0
      VirtulMathCore/include/statement.h
  22. 0 0
      VirtulMathCore/include/syntax.h
  23. 0 0
      VirtulMathCore/include/token.h
  24. 0 0
      VirtulMathCore/include/value.h
  25. 0 0
      VirtulMathCore/include/var.h
  26. 15 0
      VirtulMathCore/include/virtualmath.h
  27. 0 0
      VirtulMathCore/memory/mem.c
  28. 0 0
      VirtulMathCore/ofunc/c_lib/manager.c
  29. 0 0
      VirtulMathCore/ofunc/include/__base.h
  30. 0 0
      VirtulMathCore/ofunc/include/__ofunc.h
  31. 0 0
      VirtulMathCore/ofunc/include/bool.h
  32. 0 0
      VirtulMathCore/ofunc/include/dict.h
  33. 0 0
      VirtulMathCore/ofunc/include/dictiter.h
  34. 0 0
      VirtulMathCore/ofunc/include/error_.h
  35. 0 0
      VirtulMathCore/ofunc/include/function.h
  36. 0 0
      VirtulMathCore/ofunc/include/io.h
  37. 0 0
      VirtulMathCore/ofunc/include/list.h
  38. 0 0
      VirtulMathCore/ofunc/include/listiter.h
  39. 0 0
      VirtulMathCore/ofunc/include/num.h
  40. 0 0
      VirtulMathCore/ofunc/include/object.h
  41. 0 0
      VirtulMathCore/ofunc/include/pass.h
  42. 0 0
      VirtulMathCore/ofunc/include/str.h
  43. 0 0
      VirtulMathCore/ofunc/include/sys.h
  44. 0 0
      VirtulMathCore/ofunc/include/vobject.h
  45. 0 0
      VirtulMathCore/ofunc/src/__ofunc.c
  46. 0 0
      VirtulMathCore/ofunc/src/bool.c
  47. 0 0
      VirtulMathCore/ofunc/src/dict.c
  48. 0 0
      VirtulMathCore/ofunc/src/dictiter.c
  49. 0 0
      VirtulMathCore/ofunc/src/error_.c
  50. 0 0
      VirtulMathCore/ofunc/src/function.c
  51. 0 0
      VirtulMathCore/ofunc/src/io.c
  52. 0 0
      VirtulMathCore/ofunc/src/list.c
  53. 0 0
      VirtulMathCore/ofunc/src/listiter.c
  54. 0 0
      VirtulMathCore/ofunc/src/num.c
  55. 0 0
      VirtulMathCore/ofunc/src/object.c
  56. 0 0
      VirtulMathCore/ofunc/src/pass.c
  57. 0 0
      VirtulMathCore/ofunc/src/str.c
  58. 0 0
      VirtulMathCore/ofunc/src/sys.c
  59. 0 0
      VirtulMathCore/ofunc/src/vobject.c
  60. 0 0
      VirtulMathCore/parser/__grammar.c
  61. 0 0
      VirtulMathCore/parser/grammar.c
  62. 0 0
      VirtulMathCore/parser/include/__grammar.h
  63. 0 0
      VirtulMathCore/parser/include/__token.h
  64. 0 0
      VirtulMathCore/parser/lexical.c
  65. 0 0
      VirtulMathCore/parser/syntax.c
  66. 0 0
      VirtulMathCore/parser/token.c
  67. 0 0
      VirtulMathCore/signalhandler/handler.c
  68. 0 0
      VirtulMathCore/src/__run.c
  69. 0 0
      VirtulMathCore/src/include/__run.h
  70. 0 0
      VirtulMathCore/src/inter.c
  71. 0 0
      VirtulMathCore/src/ofunc.c
  72. 0 0
      VirtulMathCore/src/parameter.c
  73. 0 0
      VirtulMathCore/src/run.c
  74. 0 0
      VirtulMathCore/src/runbranch.c
  75. 0 0
      VirtulMathCore/src/runcall.c
  76. 0 0
      VirtulMathCore/src/runfile.c
  77. 0 0
      VirtulMathCore/src/runoperation.c
  78. 0 0
      VirtulMathCore/src/statement.c
  79. 0 0
      VirtulMathCore/src/value.c
  80. 0 0
      VirtulMathCore/src/var.c
  81. 3 2
      VirtulMathCore/src/virtualmath.c
  82. 1 1
      argument/argument.c
  83. 1 0
      include/arguement.h
  84. 6 0
      include/hellovm.h
  85. 3 2
      main.c

+ 5 - 13
CMakeLists.txt

@@ -3,20 +3,12 @@ PROJECT(VirtualMath C)
 SET(CMAKE_C_STANDARD 11)
 
 INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/parser/include)
-INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/include)
-INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/ofunc/include)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/VirtulMathCore/include)
 
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/memory MEM_LIST)
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/parser PASER_LIST)
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/src SRC_LIST)
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/file FILE_LIST)
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/gc GC_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/argument ARGUMENT_LIST)
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/ofunc/src OFUNC_LIST)
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/ofunc/c_lib CLIB_LIST)
-AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/signalhandler HANDLER_LIST)
 
 MESSAGE("project dir is ${PROJECT_SOURCE_DIR}")
-ADD_EXECUTABLE(VirtualMath main.c ${SRC_LIST} ${GC_LIST} ${PASER_LIST} ${MEM_LIST} ${FILE_LIST} ${ARGUMENT_LIST} ${OFUNC_LIST} ${HANDLER_LIST} ${CLIB_LIST})
-TARGET_LINK_LIBRARIES(VirtualMath dl)
+
+ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/VirtulMathCore)
+ADD_EXECUTABLE(VirtualMath main.c ${ARGUMENT_LIST})
+TARGET_LINK_LIBRARIES(VirtualMath VirtualMathCore)

+ 20 - 0
VirtulMathCore/CMakeLists.txt

@@ -0,0 +1,20 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
+PROJECT(VirtualMathCore C)
+SET(CMAKE_C_STANDARD 11)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/parser/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/ofunc/include)
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/memory MEM_LIST)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/parser PASER_LIST)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_LIST)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/file FILE_LIST)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/gc GC_LIST)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ofunc/src OFUNC_LIST)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ofunc/c_lib CLIB_LIST)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/signalhandler HANDLER_LIST)
+
+ADD_LIBRARY(VirtualMathCore SHARED ${SRC_LIST} ${GC_LIST} ${PASER_LIST} ${MEM_LIST} ${FILE_LIST} ${ARGUMENT_LIST} ${OFUNC_LIST} ${HANDLER_LIST} ${CLIB_LIST})
+TARGET_LINK_LIBRARIES(VirtualMathCore dl)

+ 0 - 0
file/file.c → VirtulMathCore/file/file.c


+ 0 - 0
gc/freeze.c → VirtulMathCore/gc/freeze.c


+ 0 - 0
gc/gc.c → VirtulMathCore/gc/gc.c


+ 0 - 0
gc/set.c → VirtulMathCore/gc/set.c


+ 0 - 0
include/__macro.h → VirtulMathCore/include/__macro.h


+ 0 - 1
include/__virtualmath.h → VirtulMathCore/include/__virtualmath.h

@@ -4,7 +4,6 @@
 #include "__macro.h"
 
 #include "mem.h"
-#include "arguement.h"
 #include "handler.h"
 #include "file.h"
 

+ 0 - 0
include/clib.h → VirtulMathCore/include/clib.h


+ 0 - 0
include/file.h → VirtulMathCore/include/file.h


+ 0 - 0
include/gc.h → VirtulMathCore/include/gc.h


+ 0 - 0
include/grammar.h → VirtulMathCore/include/grammar.h


+ 0 - 0
include/handler.h → VirtulMathCore/include/handler.h


+ 1 - 1
include/inter.h → VirtulMathCore/include/inter.h

@@ -97,7 +97,7 @@ typedef enum ResultType ResultType;
 Inter *makeInter(char *out, char *error_, char *in, LinkValue *belong);
 void freeInter(Inter *inter, bool show_gc);
 void setBaseInterData(struct Inter *inter);
-void runCodeStdin(Inter *inter);
+void runCodeStdin(Inter *inter, char *hello_string);
 void runCodeFile(Inter *inter, char *file[]);
 bool runParser(char *code_file, Inter *inter, bool is_one, Statement **st);
 void mergeInter(Inter *new, Inter *base);

+ 0 - 0
include/lexical.h → VirtulMathCore/include/lexical.h


+ 0 - 0
include/macro.h → VirtulMathCore/include/macro.h


+ 0 - 0
include/mem.h → VirtulMathCore/include/mem.h


+ 0 - 0
include/ofunc.h → VirtulMathCore/include/ofunc.h


+ 0 - 0
include/parameter.h → VirtulMathCore/include/parameter.h


+ 0 - 0
include/run.h → VirtulMathCore/include/run.h


+ 0 - 0
include/statement.h → VirtulMathCore/include/statement.h


+ 0 - 0
include/syntax.h → VirtulMathCore/include/syntax.h


+ 0 - 0
include/token.h → VirtulMathCore/include/token.h


+ 0 - 0
include/value.h → VirtulMathCore/include/value.h


+ 0 - 0
include/var.h → VirtulMathCore/include/var.h


+ 15 - 0
VirtulMathCore/include/virtualmath.h

@@ -0,0 +1,15 @@
+#ifndef VIRTUALMATH_VIRTUALMATH_H
+#define VIRTUALMATH_VIRTUALMATH_H
+#include "__macro.h"
+
+#include "mem.h"
+#include "handler.h"
+#include "file.h"
+
+#include "gc.h"
+#include "value.h"
+#include "parameter.h"
+#include "inter.h"
+#include "run.h"
+
+#endif //VIRTUALMATH_VIRTUALMATH_H

+ 0 - 0
memory/mem.c → VirtulMathCore/memory/mem.c


+ 0 - 0
ofunc/c_lib/manager.c → VirtulMathCore/ofunc/c_lib/manager.c


+ 0 - 0
ofunc/include/__base.h → VirtulMathCore/ofunc/include/__base.h


+ 0 - 0
ofunc/include/__ofunc.h → VirtulMathCore/ofunc/include/__ofunc.h


+ 0 - 0
ofunc/include/bool.h → VirtulMathCore/ofunc/include/bool.h


+ 0 - 0
ofunc/include/dict.h → VirtulMathCore/ofunc/include/dict.h


+ 0 - 0
ofunc/include/dictiter.h → VirtulMathCore/ofunc/include/dictiter.h


+ 0 - 0
ofunc/include/error_.h → VirtulMathCore/ofunc/include/error_.h


+ 0 - 0
ofunc/include/function.h → VirtulMathCore/ofunc/include/function.h


+ 0 - 0
ofunc/include/io.h → VirtulMathCore/ofunc/include/io.h


+ 0 - 0
ofunc/include/list.h → VirtulMathCore/ofunc/include/list.h


+ 0 - 0
ofunc/include/listiter.h → VirtulMathCore/ofunc/include/listiter.h


+ 0 - 0
ofunc/include/num.h → VirtulMathCore/ofunc/include/num.h


+ 0 - 0
ofunc/include/object.h → VirtulMathCore/ofunc/include/object.h


+ 0 - 0
ofunc/include/pass.h → VirtulMathCore/ofunc/include/pass.h


+ 0 - 0
ofunc/include/str.h → VirtulMathCore/ofunc/include/str.h


+ 0 - 0
ofunc/include/sys.h → VirtulMathCore/ofunc/include/sys.h


+ 0 - 0
ofunc/include/vobject.h → VirtulMathCore/ofunc/include/vobject.h


+ 0 - 0
ofunc/src/__ofunc.c → VirtulMathCore/ofunc/src/__ofunc.c


+ 0 - 0
ofunc/src/bool.c → VirtulMathCore/ofunc/src/bool.c


+ 0 - 0
ofunc/src/dict.c → VirtulMathCore/ofunc/src/dict.c


+ 0 - 0
ofunc/src/dictiter.c → VirtulMathCore/ofunc/src/dictiter.c


+ 0 - 0
ofunc/src/error_.c → VirtulMathCore/ofunc/src/error_.c


+ 0 - 0
ofunc/src/function.c → VirtulMathCore/ofunc/src/function.c


+ 0 - 0
ofunc/src/io.c → VirtulMathCore/ofunc/src/io.c


+ 0 - 0
ofunc/src/list.c → VirtulMathCore/ofunc/src/list.c


+ 0 - 0
ofunc/src/listiter.c → VirtulMathCore/ofunc/src/listiter.c


+ 0 - 0
ofunc/src/num.c → VirtulMathCore/ofunc/src/num.c


+ 0 - 0
ofunc/src/object.c → VirtulMathCore/ofunc/src/object.c


+ 0 - 0
ofunc/src/pass.c → VirtulMathCore/ofunc/src/pass.c


+ 0 - 0
ofunc/src/str.c → VirtulMathCore/ofunc/src/str.c


+ 0 - 0
ofunc/src/sys.c → VirtulMathCore/ofunc/src/sys.c


+ 0 - 0
ofunc/src/vobject.c → VirtulMathCore/ofunc/src/vobject.c


+ 0 - 0
parser/__grammar.c → VirtulMathCore/parser/__grammar.c


+ 0 - 0
parser/grammar.c → VirtulMathCore/parser/grammar.c


+ 0 - 0
parser/include/__grammar.h → VirtulMathCore/parser/include/__grammar.h


+ 0 - 0
parser/include/__token.h → VirtulMathCore/parser/include/__token.h


+ 0 - 0
parser/lexical.c → VirtulMathCore/parser/lexical.c


+ 0 - 0
parser/syntax.c → VirtulMathCore/parser/syntax.c


+ 0 - 0
parser/token.c → VirtulMathCore/parser/token.c


+ 0 - 0
signalhandler/handler.c → VirtulMathCore/signalhandler/handler.c


+ 0 - 0
src/__run.c → VirtulMathCore/src/__run.c


+ 0 - 0
src/include/__run.h → VirtulMathCore/src/include/__run.h


+ 0 - 0
src/inter.c → VirtulMathCore/src/inter.c


+ 0 - 0
src/ofunc.c → VirtulMathCore/src/ofunc.c


+ 0 - 0
src/parameter.c → VirtulMathCore/src/parameter.c


+ 0 - 0
src/run.c → VirtulMathCore/src/run.c


+ 0 - 0
src/runbranch.c → VirtulMathCore/src/runbranch.c


+ 0 - 0
src/runcall.c → VirtulMathCore/src/runcall.c


+ 0 - 0
src/runfile.c → VirtulMathCore/src/runfile.c


+ 0 - 0
src/runoperation.c → VirtulMathCore/src/runoperation.c


+ 0 - 0
src/statement.c → VirtulMathCore/src/statement.c


+ 0 - 0
src/value.c → VirtulMathCore/src/value.c


+ 0 - 0
src/var.c → VirtulMathCore/src/var.c


+ 3 - 2
src/virtualmath.c → VirtulMathCore/src/virtualmath.c

@@ -20,12 +20,13 @@ void runCodeFile(Inter *inter, char *file[]) {
     }
 }
 
-void runCodeStdin(Inter *inter) {
+void runCodeStdin(Inter *inter, char *hello_string) {
     Statement *pst = NULL;
     Result result;
     bool should_break = false;
     setResultCore(&result);
-    printf("%s", HelloString);
+    if (hello_string != NULL)
+        printf("%s", hello_string);
     while (!should_break){
         if (ferror(stdin) || feof(stdin))
             clearerr(stdin);

+ 1 - 1
argument/argument.c

@@ -1,4 +1,4 @@
-#include "__virtualmath.h"
+#include "hellovm.h"
 
 char *HelloString = "Welcome To VirtualMath ("__TIME__", "__DATE__") \n"
 #ifdef __linux__

+ 1 - 0
include/arguement.h

@@ -1,5 +1,6 @@
 #ifndef VIRTUALMATH_ARGUEMENT_H
 #define VIRTUALMATH_ARGUEMENT_H
+#include "virtualmath.h"
 
 extern char *HelloString;
 struct Args{

+ 6 - 0
include/hellovm.h

@@ -0,0 +1,6 @@
+#ifndef VIRTUALMATH_HELLOVM_H
+#define VIRTUALMATH_HELLOVM_H
+#include "virtualmath.h"
+#include "arguement.h"
+
+#endif //VIRTUALMATH_HELLOVM_H

+ 3 - 2
main.c

@@ -1,4 +1,5 @@
-#include "__virtualmath.h"
+#include "hellovm.h"
+
 int main(int argc, char *argv[]) {
     Inter *inter = NULL;
 
@@ -16,7 +17,7 @@ int main(int argc, char *argv[]) {
     inter = makeInter(args.out_file, args.error_file, args.in_file, NULL);
     runCodeFile(inter, argv + optind);
     if (args.run_commandLine)
-        runCodeStdin(inter);
+        runCodeStdin(inter, HelloString);
     freeInter(inter, true);
     return 0;
 }