wip
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix list pointer arithmetic

autumn 37b36c2b 06466d18

+122 -16
+2 -3
crone/core/list.h
··· 25 25 } 26 26 ++list->capacity; 27 27 /*=====================================*/ 28 - 29 28 list->data = realloc(list->data, list->element_size * list->capacity); 30 29 if (list->data == NULL) { CRASH("failed realloc: list"); } 31 30 } 32 31 33 - memcpy(list->data + (list->count - 1) * list->element_size, item, list->element_size); 32 + memcpy((uint8_t*)list->data + (list->count - 1) * list->element_size, item, list->element_size); 34 33 } 35 34 36 35 void *list_element(list list, size_t index) { 37 - return list.data + index * list.element_size; 36 + return (uint8_t*)list.data + index * list.element_size; 38 37 } 39 38 40 39 void list_cleanup(list list) {
+46 -11
crone/lang/interpreter.c
··· 11 11 OP(OUTER_SPACE) \ 12 12 OP(TERM) \ 13 13 OP(INNER_SPACE) \ 14 + OP(PUNCTUATION) \ 14 15 OP(BLOCK) \ 15 16 16 17 #define COMMA_SEPARATED(VALUE) VALUE, ··· 42 43 list subparses; 43 44 } parse; 44 45 45 - const char *spaces = " "; 46 + const char *spaces = " "; 46 47 47 48 void print_parse(parse p, size_t indent) { 48 49 size_t space_count = 4 * indent; ··· 50 51 space_count = strlen(spaces); 51 52 } 52 53 fwrite(spaces, 1, space_count, stderr); 53 - fprintf(stderr, "parsed as %s: \"", state_names[p.parsed_as]); 54 - print_substring(p.start, p.length); 55 - fprintf(stderr, "\"\n"); 54 + fprintf(stderr, "%s[", state_names[p.parsed_as]); 55 + if (p.parsed_as != BLOCK) { 56 + print_substring(p.start, p.length); 57 + } else { 58 + fprintf(stderr, "%lu", p.subparses.count); 59 + } 60 + fprintf(stderr, "]\n"); 56 61 } 57 62 58 - inline void transition(list *l, parse *p, char *end_position, parser_state next_state) { 63 + void transition(list *l, parse *p, char *end_position, parser_state next_state) { 59 64 p->length = (size_t)end_position - (size_t)(p->start); 60 65 list_append(l,p); 61 66 p->start = end_position; ··· 65 70 // TODO UNICODE 66 71 67 72 list/*subparses*/ parse_crone(string crone_script, size_t *p_position) { 68 - list parses = list_allocate(512, sizeof(parse)); 73 + list parses = list_allocate(128, sizeof(parse)); 69 74 70 75 parse current_parse; 71 76 ··· 78 83 79 84 for (; (*p_position) < crone_script.length; ++(*p_position)) { 80 85 char _char = crone_script.data[*p_position]; 86 + 81 87 switch (current_parse.parsed_as) { 82 88 case OUTER_SPACE: 83 89 if (_char == '}') { 84 90 NEXT(INVALID); 91 + } else if (_char == '{') { 92 + NEXT(BLOCK); 93 + } else if (_char == ';') { 94 + NEXT(PUNCTUATION); 85 95 } else if (!isspace(_char)) { 86 96 NEXT(TERM); 87 97 } ··· 90 100 if (_char == '{') { 91 101 NEXT(BLOCK); 92 102 } else if (_char == ';') { 93 - ++(*p_position); 94 - NEXT(OUTER_SPACE); 103 + NEXT(PUNCTUATION); 95 104 } else if (_char == '}') { 96 105 NEXT(INVALID); 97 106 } else if (!isspace(_char)) { ··· 106 115 } else if (_char == '{') { 107 116 NEXT(BLOCK); 108 117 } else if (_char == ';') { 109 - NEXT(OUTER_SPACE); 110 - ++(*p_position); 118 + NEXT(PUNCTUATION); 111 119 } 112 120 break; 113 121 case BLOCK: ··· 115 123 current_parse.subparses = parse_crone(crone_script, p_position); 116 124 NEXT(OUTER_SPACE); 117 125 break; 126 + case PUNCTUATION: 127 + if (isspace(_char)) { 128 + NEXT(OUTER_SPACE); 129 + } else if (_char == '}') { 130 + NEXT(INVALID); 131 + } else if (_char == '{') { 132 + NEXT(BLOCK); 133 + } else if (_char != ';') { 134 + NEXT(TERM); 135 + } 136 + break; 118 137 case INVALID: 119 138 return parses; 120 - break; 139 + break; 121 140 } 122 141 } 123 142 ··· 140 159 } 141 160 } 142 161 162 + void cleanup_parses(list parses) { 163 + for (int i = 0; i < parses.count; ++i) { 164 + parse p = *(parse*)list_element(parses, i); 165 + if (p.parsed_as == BLOCK) { 166 + cleanup_parses(p.subparses); 167 + } 168 + } 169 + list_cleanup(parses); 170 + } 171 + 143 172 void execute_crone(string crone_script) { 144 173 size_t position = 0; 145 174 list parses = parse_crone(crone_script, &position); 146 175 147 176 print_parses(parses, 0); 177 + 178 + if (position < crone_script.length) { 179 + fprintf(stderr, "warning: early exit @ %lu / %lu\n", position, crone_script.length); 180 + } 181 + 182 + cleanup_parses(parses); 148 183 } 149 184 150 185 /*
+73 -1
crone/lang/parseme.cr
··· 16 16 17 17 term4 term5; 18 18 19 - term6 { block2 } 19 + v{verbatim syntax?} 20 + 21 + verbatim{alternate option} 22 + 23 + trimmed v{ lets you put some spaces on the edges, for readability } 24 + 25 + hex FF0000; 26 + 27 + no reason you {can't} keep writing after {a block}; 28 + 29 + extraneous punctuation;;; 30 + 31 + sob ;_; 32 + 33 + 34 + here are some more terms { and a block } 35 + 36 + and some more terms with no block; 37 + 38 + some terms 39 + with whitespace; 40 + 41 + 42 + deep nesting { 43 + deeep nesting { 44 + deeeep nesting { 45 + asdf { 46 + asdff { 47 + asdfff { 48 + foo { 49 + bar { 50 + baz { 51 + qwertyuiopasdfghjklzxcvbnm { 52 + ; 53 + } 54 + } 55 + } 56 + } 57 + } 58 + } 59 + 60 + asdfasdf { 61 + asdfasdfasdf asdf { 62 + 63 + } 64 + } 65 + } 66 + } 67 + } 68 + } 69 + 70 + 71 + let's do some blocks { 72 + waow; 73 + 74 + this is a block { 75 + inside a block { 76 + another block; 77 + 78 + with content; 79 + 80 + including { this block } 81 + } 82 + 83 + 84 + !!!;;; 85 + 86 + !! 87 + 88 + 89 + !; 90 + } 91 + } 20 92
+1 -1
makefile
··· 10 10 LINKS = -lX11 -lvulkan 11 11 HEADERS = -I $(PROJECT_NAME)/interface 12 12 ERRORS = -Wfatal-errors -Wall -Werror=use-after-free -Wno-unused-variable -Wpedantic 13 - %_dev: VERSION_FLAGS = -Og -DDO_VALIDATION 13 + %_dev: VERSION_FLAGS = -Og -DDO_VALIDATION -fsanitize=address,undefined 14 14 %_release: VERSION_FLAGS = -O3 15 15 FLAGS = -std=c23 $(ERRORS) $(VERSION_FLAGS) $(HEADERS) -DUSE_X11 16 16