Savtis 2 yıl önce
ebeveyn
işleme
d3d04f563f
4 değiştirilmiş dosya ile 90 ekleme ve 13 silme
  1. 10 9
      src/main.py
  2. 62 0
      src/ombs_src/c/lexer.c
  3. 7 4
      src/ombs_src/py/cdll_class.py
  4. 11 0
      src/ombs_src/py/lexer.py

+ 10 - 9
src/main.py

@@ -1,19 +1,20 @@
 #!/usr/bin/python3
+import ctypes
+import cdll_class
+import script_loader as sl
+import error_list
+import error_class
+import output
+import sys
+import os
+sys.path.append('ombs_src/py')
+
 
 def main():
-    import sys
-    import os
-    sys.path.append('ombs_src/py')
-    import output
-    import error_class
-    import error_list
     output.color_println('cyan', output.LOGO)
     if len(sys.argv) < 2:
         error_class.call_error('script_not_specified')
-    import script_loader as sl
     sl.loader(sys.argv[1])
-    import cdll_class
-    import ctypes
     # a = cdll_class.C_Library('./lib.so', ctypes.c_int)
 
 

+ 62 - 0
src/ombs_src/c/lexer.c

@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#define true 1
+#define false 0
+#define STR 0
+#define VAR 1
+#define MISC 2
+
+typedef struct token {
+  char *str;
+  char type;
+  struct token *chain;
+} token;
+
+char *spec = "()[]!&^|<>~%?=+-";
+char *char_line;
+token *token_start = NULL;
+token *token_head = NULL;
+
+int get_str_size(char *str) {
+  int size = 0;
+  for (char *s = str; *s != '\0'; s++)
+    size++;
+  return size;
+}
+
+char *get_middle(char *str, int start, int end) {
+  int size = end - start + 1;
+  char *str2 = (char *)malloc(sizeof(char) * size + 1);
+  if (!str2)
+    return NULL;
+  for (int i = 0; i < size; i++)
+    str2[i] = str[start + i];
+  str2[size] = 0;
+  return str2;
+}
+
+int create_token_from_line(int start, int end) {
+  char *str = get_middle(char_line, start, end);
+  if (!str)
+    return 1;
+  token *t = (token *)malloc(sizeof(token));
+  if (!t)
+    return 2;
+  if (!token_start)
+    token_head = t;
+  else if (!token_head)
+    token_start->chain = token_head = t;
+  else {
+    token_head->chain = t;
+    token_head = t;
+  }
+  return 0;
+}
+
+int Main(char *line) {
+  int start = 0;
+  char mode = MISC;
+  for (int c = 0; c < get_str_size(line); c++) {
+  }
+  return 0;
+}

+ 7 - 4
src/ombs_src/py/cdll_class.py

@@ -5,11 +5,14 @@ class C_Library(object):
     def __init__(self, path: str, retype: type):
         self.path: str = path
         self.lib: _DLLT = cdll.LoadLibrary(path)
-        self.lib.main.restype = retype
-        self.func = self.lib.main
+        self.lib.Main.restype = retype
 
-    def main(self, *args):
-        return self.func(*args)
+    def Main(self, *args):
+        return self.lib.main(*args)
+
+    def destructor(self):
+        self.lib.destructor()
+        del self.lib.destructor
 
     def other(self, name: str, retype: type, *args):
         local_func = getattr(self.lib, name)

+ 11 - 0
src/ombs_src/py/lexer.py

@@ -0,0 +1,11 @@
+from ctypes import *
+import cdll_class as CC
+
+
+class Token(Structure):
+    _fields_ = [('type', c_byte),
+                ('str', c_char_p)]
+
+
+def lexer():
+    CC.C_Library('./lib/lexer.c', c_void_p)