git.fiddlerwoaroof.com
Browse code

Fix the C code and the ASDF compilation stuff

Fernando Borretti authored on 26/10/2013 17:36:54
Showing 3 changed files
... ...
@@ -16,13 +16,13 @@
16 16
 
17 17
 (defmethod perform ((o load-op) (c c->so)) t)
18 18
 
19
-(defparameter +c-flags+ "-Wall -Wextra -c -fPIC -O3 -ansi")
19
+(defparameter +c-flags+ "-Wall -Wextra -c -fPIC -O0 -ansi")
20 20
 (defparameter +linker-flags+ "-lyaml")
21 21
 
22 22
 (defun comp (file out)
23
-  (format t "clang ~A -o out.o ~A; clang out.o -shared -o ~A ~A"
23
+  (format t "cc ~A -o out.o ~A && cc out.o -shared -o ~A ~A && rm out.o"
24 24
           (namestring file) +c-flags+ (namestring out) +linker-flags+)
25
-  (format nil "clang ~A -o out.o ~A && clang out.o -shared -o ~A ~A && rm out.o"
25
+  (format nil "cc ~A -o out.o ~A && cc out.o -shared -o ~A ~A && rm out.o"
26 26
           (namestring file) +c-flags+ (namestring out) +linker-flags+))
27 27
 
28 28
 (defmethod perform ((o compile-op) (c c->so))
... ...
@@ -35,9 +35,10 @@
35 35
                                          (component-pathname c)))
36 36
                          (make-pathname :name "yaml_wrapper"
37 37
                                         :type "so"
38
-                                        :directory '(:relative :up)
39 38
                                         :defaults
40
-                                        (component-pathname c))))))
39
+                                        (merge-pathnames
40
+                                         (make-pathname :directory '(:relative :up))
41
+                                         (component-pathname c)))))))
41 42
       (error 'operation-error :component c :operation o)
42 43
       t))
43 44
 
... ...
@@ -10,13 +10,13 @@ TokenList createTokenList(void) {
10 10
   return list;
11 11
 }
12 12
 
13
-void appendToken(TokenList list, Token tok) {
14
-  if((list.len + 1) == list.cap) {
15
-    list.cap += LIST_CHUNK_SIZE;
16
-    list.data = (Token*)realloc(list.data,list.cap);
13
+void appendToken(TokenList* list, Token tok) {
14
+  if((list->len + 1) == list->cap) {
15
+    list->cap += LIST_CHUNK_SIZE;
16
+    list->data = (Token*)realloc(list->data,list->cap);
17 17
   }
18
-  list.len++;
19
-  list.data[list.len] = tok;
18
+  list->data[list->len] = tok;
19
+  list->len++;
20 20
 }
21 21
 
22 22
 void destroyTokenList(TokenList list) {
... ...
@@ -33,20 +33,20 @@ DocumentList createDocumentList(void) {
33 33
   return docs;
34 34
 }
35 35
 
36
-DocumentList err(const char* msg) {
36
+DocumentList tok_err(const char* msg) {
37 37
   /* Signals a tokenization error */
38 38
   DocumentList docs;
39 39
   docs.err = msg;
40 40
   return docs;
41 41
 }
42 42
 
43
-void appendDocument(DocumentList docs, TokenList list) {
44
-  if((docs.len + 1) == docs.cap) {
45
-    docs.cap += LIST_CHUNK_SIZE;
46
-    docs.data = (TokenList*)realloc(docs.data,docs.cap);
43
+void appendDocument(DocumentList* docs, TokenList list) {
44
+  if((docs->len + 1) == docs->cap) {
45
+    docs->cap += LIST_CHUNK_SIZE;
46
+    docs->data = (TokenList*)realloc(docs->data,docs->cap);
47 47
   }
48
-  docs.len++;
49
-  docs.data[docs.len] = list;
48
+  docs->data[docs->len] = list;
49
+  docs->len++;
50 50
 }
51 51
 
52 52
 void destroyDocumentList(DocumentList docs) {
... ...
@@ -63,17 +63,19 @@ DocumentList tokenize(const char* str, size_t len) {
63 63
   yaml_event_t  event;
64 64
   DocumentList docs = createDocumentList();
65 65
 
66
-  if(!yaml_parser_initialize(&parser))
67
-    return err("Could not initialize parser.");
68 66
   if(str == NULL)
69
-    return err("Can't parse a null string.");
70
-  docs.data[0] = createTokenList();
67
+    return tok_err("Can't parse a null string.");
68
+  if(len == 0)
69
+    return tok_err("Can't parse a string with length zero.");
70
+  if(!yaml_parser_initialize(&parser))
71
+    return tok_err("Could not initialize parser.");
72
+  appendDocument(&docs, createTokenList());
71 73
   yaml_parser_set_input_string(&parser, (const unsigned char*)str, len);
72 74
 
73 75
   while(event.type != YAML_STREAM_END_EVENT) {
74 76
     Token tok;
75 77
     if(!yaml_parser_parse(&parser, &event)) {
76
-      return err("Parsing error"/*parser.error*/);
78
+      return tok_err("Parsing error"/*parser.error*/);
77 79
     }
78 80
     tok.type = event.type;
79 81
     switch(event.type) {
... ...
@@ -86,15 +88,15 @@ DocumentList tokenize(const char* str, size_t len) {
86 88
       break;
87 89
     case YAML_DOCUMENT_START_EVENT:
88 90
       /* Add a new document to the list */
89
-      appendDocument(docs,createTokenList());
91
+      appendDocument(&docs,createTokenList());
90 92
       break;
91 93
     default:
92 94
       /* The token only carries type information */
93 95
       break;
94 96
     }
97
+    appendToken(&docs.data[docs.len-1],tok);
95 98
     if(event.type != YAML_STREAM_END_EVENT)
96 99
       yaml_event_delete(&event);
97
-    appendToken(docs.data[docs.len-1],tok);
98 100
   }
99 101
   yaml_event_delete(&event);
100 102
   
... ...
@@ -21,7 +21,7 @@ typedef struct {
21 21
 } TokenList;
22 22
 
23 23
 TokenList createTokenList(void);
24
-void appendToken(TokenList list, Token tok);
24
+void appendToken(TokenList* list, Token tok);
25 25
 void destroyTokenList(TokenList list);
26 26
 
27 27
 /* DocumentList */
... ...
@@ -34,8 +34,8 @@ typedef struct {
34 34
 } DocumentList;
35 35
 
36 36
 DocumentList createDocumentList(void);
37
-DocumentList err(const char* msg);
38
-void appendDocument(DocumentList docs, TokenList list);
37
+DocumentList tok_err(const char* msg);
38
+void appendDocument(DocumentList* docs, TokenList list);
39 39
 void destroyDocumentList(DocumentList docs);
40 40
 
41 41
 /* Tokenization */