Savtis 2 years ago
parent
commit
dd349ddb8a

+ 10 - 8
src/main.py

@@ -1,16 +1,10 @@
 #!/usr/bin/python3
+
 from sys import path, argv
-import os
 
 path.append(__file__ + '_src/py')
 path.append(__file__.removesuffix('main.py') + 'ompl_src/py')
 
-import ctypes
-import cdll_class
-import script_loader as sl
-import error_list
-import error_class
-import output
 
 def main():
     output.color_println('cyan', output.LOGO)
@@ -18,8 +12,16 @@ def main():
         error_class.call_error('script_not_specified')
     sl.loader(argv[1])
     a = cdll_class.C_Library('lexer', ctypes.c_int)
-    print(a.other('create_token_from_line', ctypes.c_int));
+    #print(a.other('create_token_from_line', ctypes.c_int))
+    a.Main()
 
 
 if __name__ == '__main__':
+    import output
+    import error_class
+    import error_list
+    import script_loader as sl
+    import cdll_class
+    import ctypes
+    import os
     main()

+ 5 - 0
src/ompl_src/c/bitwise.c

@@ -0,0 +1,5 @@
+#include "bitwise.h"
+
+byte get_bit(byte bit_array, byte index_from_right_to_left) {
+  return (bit_array & (1 << (index_from_right_to_left - 1))) != 0;
+}

+ 7 - 50
src/ompl_src/c/lexer.c

@@ -1,6 +1,7 @@
 #include "bool.h"
-#include "token.h"
+#include "bitwise.h"
 #include "elif.h"
+#include "token.h"
 #include <stdio.h>
 #include <stdlib.h>
 #define MISC 0
@@ -10,56 +11,12 @@
 
 int cursor_pos = 0;
 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, BOOL include) {
-  int size;
-  if (include) size = end - (--start);
-  else 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, BOOL include, unsigned char type, BOOL is_const) {
-  char *str = get_middle(char_line, start, end, include);
-  if (!str)
-    return 1;
-  token *t = (token *)malloc(sizeof(token));
-  if (!t) {
-    free(str);
-    return 2;
-  }
-  if (is_const) t->value=str;
-  if ()
-  if (!token_start)
-    token_head = t;
-  elif (!token_head)
-    token_start->chain = token_head = t;
-  else {
-    token_head->chain = t;
-    token_head = t;
-  }
-  return 0;
-}
+char *char_line = NULL;
 
 char get_next_char(BOOL skip_spaces) {
   if (skip_spaces) {
-    while (char_line[cursor_pos] != 0 & char_line[cursor_pos] <= 32) cursor_pos++; {
-    }
+    while (char_line[cursor_pos] != 0 & char_line[cursor_pos] <= 32)
+      cursor_pos++;
   }
   char buffer = char_line[cursor_pos];
   cursor_pos++;
@@ -79,10 +36,10 @@ int Main(char *line) {
       }
       elif (mode == STR) {
         mode = MISC;
-        create_token_from_line(cursor_buffer, cursor_pos, false);
+        // create_token_from_line(cursor_buffer, cursor_pos, false);
       }
     }
-    //elif ('')
+    // elif ('')
   }
   return 0;
 }

+ 25 - 0
src/ompl_src/c/str.c

@@ -0,0 +1,25 @@
+#include "str.h"
+#include "bool.h"
+#include <stdlib.h>
+
+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, BOOL include) {
+  int size;
+  if (include)
+    size = end - (--start);
+  else
+    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;
+}

+ 30 - 0
src/ompl_src/c/token.c

@@ -0,0 +1,30 @@
+#include "token.h"
+#include "bool.h"
+#include "elif.h"
+#include "str.h"
+#include <stdlib.h>
+
+token *token_head = NULL;
+token *token_start = NULL;
+
+int create_token_from_line(int start, int end, BOOL include, unsigned char type,
+                           BOOL is_const) {
+  char *str = get_middle(char_line, start, end, include);
+  if (!str)
+    return 1;
+  token *t = (token *)malloc(sizeof(token));
+  if (!t) {
+    free(str);
+    return 2;
+  }
+  if (is_const)
+    t->value = str;
+  if (!token_start)
+    token_head = t;
+  elif (!token_head) token_start->chain = token_head = t;
+  else {
+    token_head->chain = t;
+    token_head = t;
+  }
+  return 0;
+}

+ 6 - 3
src/ompl_src/py/cdll_class.py

@@ -1,15 +1,18 @@
 from ctypes import *
 from os import path
 
+
 class C_Library(object):
-    lib_dir:str = path.dirname(__file__) + '/../lib/'
+    lib_dir: str = path.dirname(__file__) + '/../lib/'
+
     def __init__(self, file_name: str, retype: type):
         self.path: str = file_name
-        self.lib: _DLLT = cdll.LoadLibrary(C_Library.lib_dir + file_name + '.so')
+        self.lib: _DLLT = cdll.LoadLibrary(
+            C_Library.lib_dir + file_name + '.so')
         self.lib.Main.restype = retype
 
     def Main(self, *args):
-        return self.lib.main(*args)
+        return self.lib.Main(*args)
 
     def destructor(self):
         self.lib.destructor()

+ 2 - 1
src/ompl_src/py/output.py

@@ -24,7 +24,8 @@ COLOR_CODES = {
 
 
 def color_print(color_name: str, text: str, underline: bool = False):
-    print(f'\033[{4 if underline else ""};{COLOR_CODES[color_name]}m{text}\033[0m', end='')
+    print(
+        f'\033[{4 if underline else ""};{COLOR_CODES[color_name]}m{text}\033[0m', end='')
 
 
 def color_println(color_name: str, text: str, underline: bool = False):