Browse Source

checking return codes for sen_compile_program* functions

Inderjit Gill 5 months ago
parent
commit
bc85457e05

+ 1
- 0
.gitignore View File

@@ -24,6 +24,7 @@ pids
24 24
 # Dependency directory
25 25
 /core/node_modules
26 26
 /core/test
27
+/core/test.exe
27 28
 /client/node_modules
28 29
 /client/www/node_modules
29 30
 coverage

+ 38
- 9
client/src/wasm.c View File

@@ -133,17 +133,28 @@ export int compile_to_render_packets(void) {
133 133
 
134 134
   sen_reset_vm(g_vm);
135 135
 
136
-  sen_program* program = NULL;
136
+  sen_result_program result_program;
137 137
 
138 138
   if (g_use_genotype_when_compiling) {
139 139
     sen_genotype* genotype = sen_deserialize_genotype(g_genotype_cursor);
140
-    program = sen_compile_program_with_genotype(g_source_buffer, genotype, g_e->word_lut,
141
-                                                MAX_PROGRAM_SIZE);
140
+    result_program         = sen_compile_program_with_genotype(g_source_buffer, genotype,
141
+                                                       g_e->word_lut, MAX_PROGRAM_SIZE);
142 142
     genotype_return_to_pool(genotype);
143
+
144
+    if (is_result_program_error(result_program)) {
145
+      SEN_ERROR("compile_to_render_packets");
146
+      return 0;
147
+    }
143 148
   } else {
144
-    program = sen_compile_program(g_source_buffer, g_e->word_lut, MAX_PROGRAM_SIZE);
149
+    result_program = sen_compile_program(g_source_buffer, g_e->word_lut, MAX_PROGRAM_SIZE);
150
+    if (is_result_program_error(result_program)) {
151
+      SEN_ERROR("compile_to_render_packets");
152
+      return 0;
153
+    }
145 154
   }
146 155
 
156
+  sen_program* program = result_program.result;
157
+
147 158
   vm_debug_info_reset(g_vm);
148 159
   bool res = vm_run(g_vm, g_e, program);
149 160
 
@@ -225,11 +236,19 @@ export i32 build_traits() {
225 236
 
226 237
   // TIMING_UNIT timing_a = get_timing();
227 238
 
228
-  sen_trait_list* trait_list = sen_compile_trait_list(g_source_buffer, g_e->word_lut);
229
-  bool            res        = sen_serialize_trait_list(trait_list, g_traits_cursor);
239
+  sen_result_trait_list result_trait_list =
240
+      sen_compile_trait_list(g_source_buffer, g_e->word_lut);
241
+  if (is_result_trait_list_error(result_trait_list)) {
242
+    SEN_ERROR("build_traits");
243
+    return -1;
244
+  }
245
+
246
+  sen_trait_list* trait_list = result_trait_list.result;
247
+
248
+  bool res = sen_serialize_trait_list(trait_list, g_traits_cursor);
230 249
   if (res == false) {
231 250
     SEN_ERROR("sen_serialize_trait_list returned false");
232
-    return 0;
251
+    return -1;
233 252
   }
234 253
 
235 254
   i32 num_traits = trait_list_count(trait_list);
@@ -420,7 +439,13 @@ export void unparse_with_genotype() {
420 439
 
421 440
   sen_genotype* genotype = sen_deserialize_genotype(g_genotype_cursor);
422 441
 
423
-  sen_unparse_with_genotype(g_out_source_cursor, g_source_buffer, genotype, g_e->word_lut);
442
+  sen_error err = sen_unparse_with_genotype(g_out_source_cursor, g_source_buffer, genotype,
443
+                                            g_e->word_lut);
444
+  if (is_error(err)) {
445
+    SEN_ERROR("unparse_with_genotype: sen_unparse_with_genotype");
446
+    genotype_return_to_pool(genotype);
447
+    return;
448
+  }
424 449
 
425 450
   genotype_return_to_pool(genotype);
426 451
 
@@ -430,7 +455,11 @@ export void unparse_with_genotype() {
430 455
 export void simplify_script() {
431 456
   debug_size_source_buffer();
432 457
 
433
-  sen_simplify_script(g_out_source_cursor, g_source_buffer, g_e->word_lut);
458
+  sen_error err = sen_simplify_script(g_out_source_cursor, g_source_buffer, g_e->word_lut);
459
+
460
+  if (is_error(err)) {
461
+    SEN_ERROR("simplify_script: sen_simplify_script");
462
+  }
434 463
 
435 464
   debug_size_out_source_buffer();
436 465
 }

+ 21
- 7
client/www/package-lock.json View File

@@ -3017,12 +3017,14 @@
3017 3017
         "balanced-match": {
3018 3018
           "version": "1.0.0",
3019 3019
           "bundled": true,
3020
-          "dev": true
3020
+          "dev": true,
3021
+          "optional": true
3021 3022
         },
3022 3023
         "brace-expansion": {
3023 3024
           "version": "1.1.11",
3024 3025
           "bundled": true,
3025 3026
           "dev": true,
3027
+          "optional": true,
3026 3028
           "requires": {
3027 3029
             "balanced-match": "^1.0.0",
3028 3030
             "concat-map": "0.0.1"
@@ -3037,17 +3039,20 @@
3037 3039
         "code-point-at": {
3038 3040
           "version": "1.1.0",
3039 3041
           "bundled": true,
3040
-          "dev": true
3042
+          "dev": true,
3043
+          "optional": true
3041 3044
         },
3042 3045
         "concat-map": {
3043 3046
           "version": "0.0.1",
3044 3047
           "bundled": true,
3045
-          "dev": true
3048
+          "dev": true,
3049
+          "optional": true
3046 3050
         },
3047 3051
         "console-control-strings": {
3048 3052
           "version": "1.1.0",
3049 3053
           "bundled": true,
3050
-          "dev": true
3054
+          "dev": true,
3055
+          "optional": true
3051 3056
         },
3052 3057
         "core-util-is": {
3053 3058
           "version": "1.0.2",
@@ -3164,7 +3169,8 @@
3164 3169
         "inherits": {
3165 3170
           "version": "2.0.3",
3166 3171
           "bundled": true,
3167
-          "dev": true
3172
+          "dev": true,
3173
+          "optional": true
3168 3174
         },
3169 3175
         "ini": {
3170 3176
           "version": "1.3.5",
@@ -3176,6 +3182,7 @@
3176 3182
           "version": "1.0.0",
3177 3183
           "bundled": true,
3178 3184
           "dev": true,
3185
+          "optional": true,
3179 3186
           "requires": {
3180 3187
             "number-is-nan": "^1.0.0"
3181 3188
           }
@@ -3190,6 +3197,7 @@
3190 3197
           "version": "3.0.4",
3191 3198
           "bundled": true,
3192 3199
           "dev": true,
3200
+          "optional": true,
3193 3201
           "requires": {
3194 3202
             "brace-expansion": "^1.1.7"
3195 3203
           }
@@ -3197,12 +3205,14 @@
3197 3205
         "minimist": {
3198 3206
           "version": "0.0.8",
3199 3207
           "bundled": true,
3200
-          "dev": true
3208
+          "dev": true,
3209
+          "optional": true
3201 3210
         },
3202 3211
         "minipass": {
3203 3212
           "version": "2.2.4",
3204 3213
           "bundled": true,
3205 3214
           "dev": true,
3215
+          "optional": true,
3206 3216
           "requires": {
3207 3217
             "safe-buffer": "^5.1.1",
3208 3218
             "yallist": "^3.0.0"
@@ -3221,6 +3231,7 @@
3221 3231
           "version": "0.5.1",
3222 3232
           "bundled": true,
3223 3233
           "dev": true,
3234
+          "optional": true,
3224 3235
           "requires": {
3225 3236
             "minimist": "0.0.8"
3226 3237
           }
@@ -3301,7 +3312,8 @@
3301 3312
         "number-is-nan": {
3302 3313
           "version": "1.0.1",
3303 3314
           "bundled": true,
3304
-          "dev": true
3315
+          "dev": true,
3316
+          "optional": true
3305 3317
         },
3306 3318
         "object-assign": {
3307 3319
           "version": "4.1.1",
@@ -3313,6 +3325,7 @@
3313 3325
           "version": "1.4.0",
3314 3326
           "bundled": true,
3315 3327
           "dev": true,
3328
+          "optional": true,
3316 3329
           "requires": {
3317 3330
             "wrappy": "1"
3318 3331
           }
@@ -3434,6 +3447,7 @@
3434 3447
           "version": "1.0.2",
3435 3448
           "bundled": true,
3436 3449
           "dev": true,
3450
+          "optional": true,
3437 3451
           "requires": {
3438 3452
             "code-point-at": "^1.0.0",
3439 3453
             "is-fullwidth-code-point": "^1.0.0",

+ 2
- 1
client/www/src/job.js View File

@@ -137,6 +137,7 @@ function request(type, data) {
137 137
       if (logToConsole) {
138 138
         console.log(`result ${type} id:${worker.getId()}`);
139 139
       }
140
+      // console.log(`job:request received: ${result}`);
140 141
       worker.release();
141 142
       resolve(result);
142 143
     }).catch(error => {
@@ -144,7 +145,7 @@ function request(type, data) {
144 145
         worker.release();
145 146
       }
146 147
       // handle error
147
-      console.error(`worker: error of ${error}`);
148
+      console.error(`worker (job:${type}): error of ${error}`);
148 149
       reject(error);
149 150
     });
150 151
   });

+ 7
- 2
client/www/src/store.js View File

@@ -70,8 +70,13 @@ function actionSetScript(state, { script }) {
70 70
     Job.request(jobBuildTraits, {
71 71
       script: newState.script,
72 72
       scriptHash: newState.scriptHash
73
-    }).then(({ traits }) => {
74
-      newState.traits = traits;
73
+    }).then(({ validTraits, traits }) => {
74
+      if (validTraits) {
75
+        newState.traits = traits;
76
+      } else {
77
+        newState.traits = [];
78
+      }
79
+
75 80
       resolveAsCurrentState(resolve, newState);
76 81
     }).catch(error => {
77 82
       // handle error

+ 15
- 12
client/www/src/worker.js View File

@@ -321,7 +321,7 @@ function render({ script /*, scriptHash*/, genotype }) {
321 321
   const wasmMemory = SeniWasm.instance.memory.buffer;
322 322
   const memory = wasmMemory.slice();
323 323
 
324
-  return [{ ok: true, logMessages }, { title, memory, buffers }];
324
+  return [{ logMessages }, { title, memory, buffers }];
325 325
 }
326 326
 
327 327
 function unparse({ script/*, scriptHash*/, genotype }) {
@@ -340,7 +340,7 @@ function unparse({ script/*, scriptHash*/, genotype }) {
340 340
 
341 341
   const logMessages = konsoleProxy.collectMessages();
342 342
 
343
-  return [{ ok: true, logMessages }, { script: newScript }];
343
+  return [{ logMessages }, { script: newScript }];
344 344
 }
345 345
 
346 346
 function buildTraits({ script /*, scriptHash */ }) {
@@ -348,15 +348,18 @@ function buildTraits({ script /*, scriptHash */ }) {
348 348
 
349 349
   SeniWasm.setString(SeniWasm.source_buffer, script);
350 350
 
351
-  // konsoleProxy.log('worker:buildTraits');
352 351
   const numTraits = SeniWasm.buildTraits();
353
-  // konsoleProxy.log(`built ${numTraits} traits`);
354 352
 
355
-  const traits = SeniWasm.getString(SeniWasm.traits_buffer);
353
+  const validTraits = numTraits === -1;
356 354
 
357
-  const logMessages = konsoleProxy.collectMessages();
355
+  let traits = [];
356
+
357
+  if (validTraits) {
358
+    traits = SeniWasm.getString(SeniWasm.traits_buffer);
359
+  }
358 360
 
359
-  return [{ ok: true, logMessages }, { traits }];
361
+  const logMessages = konsoleProxy.collectMessages();
362
+  return [{ logMessages }, { validTraits, traits }];
360 363
 }
361 364
 
362 365
 // transfers the contents of g_genotype_list from the wasm side
@@ -388,7 +391,7 @@ function createInitialGeneration({ populationSize, traits }) {
388 391
 
389 392
   const logMessages = konsoleProxy.collectMessages();
390 393
 
391
-  return [{ok: true, logMessages}, { genotypes }];
394
+  return [{ logMessages }, { genotypes }];
392 395
 }
393 396
 
394 397
 function singleGenotypeFromSeed({ seed, traits }) {
@@ -404,7 +407,7 @@ function singleGenotypeFromSeed({ seed, traits }) {
404 407
 
405 408
   const logMessages = konsoleProxy.collectMessages();
406 409
 
407
-  return [{ok: true, logMessages}, { genotype: genotypes[0] }];
410
+  return [{ logMessages }, { genotype: genotypes[0] }];
408 411
 }
409 412
 
410 413
 function simplifyScript({ script }) {
@@ -418,7 +421,7 @@ function simplifyScript({ script }) {
418 421
 
419 422
   const logMessages = konsoleProxy.collectMessages();
420 423
 
421
-      return [{ ok: true, logMessages }, { script: newScript }];
424
+  return [{ logMessages }, { script: newScript }];
422 425
 }
423 426
 
424 427
 function newGeneration({genotypes, populationSize, traits, mutationRate, rng}) {
@@ -438,7 +441,7 @@ function newGeneration({genotypes, populationSize, traits, mutationRate, rng}) {
438 441
 
439 442
   const logMessages = konsoleProxy.collectMessages();
440 443
 
441
-  return [{ok: true, logMessages }, { genotypes: newGenotypes }];
444
+  return [{ logMessages }, { genotypes: newGenotypes }];
442 445
 }
443 446
 
444 447
 const options = {
@@ -540,7 +543,6 @@ function messageHandler(type, data) {
540 543
 postMessage will always return an array of two items: [status, result]
541 544
 
542 545
 status = {
543
- ok: true
544 546
  error: { message: "something fucked up" }
545 547
  systemInitialised: true
546 548
  logMessages: []
@@ -563,6 +565,7 @@ addEventListener('message', e => {
563 565
       postMessage([status, result], transferrable);
564 566
     } else {
565 567
       const sendData = JSON.stringify([status, result]);
568
+      // console.log(`worker.js:sendData = ${sendData}`);
566 569
       postMessage(sendData);
567 570
     }
568 571
   } catch (error) {

+ 4
- 0
core/dist/.gitignore View File

@@ -0,0 +1,4 @@
1
+# Ignore everything in this directory
2
+*
3
+# Except this file
4
+!.gitignore

+ 52
- 25
core/src/seni/lib.c View File

@@ -54,9 +54,15 @@ sen_env* sen_allocate_env() {
54 54
 
55 55
 void sen_free_env(sen_env* env) { env_free(env); }
56 56
 
57
-sen_program* sen_compile_program(char* source, sen_word_lut* word_lut, i32 program_max_size) {
57
+sen_result_program sen_compile_program(char* source, sen_word_lut* word_lut,
58
+                                       i32 program_max_size) {
58 59
   sen_result_node result_node = parser_parse(word_lut, source);
59
-  sen_node*       ast         = result_node.result;
60
+  if (is_result_node_error(result_node)) {
61
+    SEN_ERROR("sen_compile_program: parser_parse error");
62
+    return result_program_error(result_node.error);
63
+  }
64
+
65
+  sen_node* ast = result_node.result;
60 66
 
61 67
   // ast_pretty_print(ast, word_lut);
62 68
 
@@ -66,22 +72,25 @@ sen_program* sen_compile_program(char* source, sen_word_lut* word_lut, i32 progr
66 72
 
67 73
   sen_program*       program        = program_construct(&compiler_config);
68 74
   sen_result_program result_program = compile_program(program, ast);
69
-  if (is_result_program_error(result_program)) {
70
-    SEN_ERROR("sen_compile_program: compile_program");
71
-    // todo: return an error here
72
-    return NULL;
73
-  }
74
-  program = result_program.result;
75 75
 
76 76
   parser_return_nodes_to_pool(ast);
77 77
 
78
-  return program;
78
+  if (is_result_program_error(result_program)) {
79
+    SEN_ERROR("sen_compile_program: compile_program");
80
+  }
81
+  return result_program;
79 82
 }
80 83
 
81
-sen_program* sen_compile_program_with_genotype(char* source, sen_genotype* genotype,
82
-                                               sen_word_lut* word_lut, i32 program_max_size) {
84
+sen_result_program sen_compile_program_with_genotype(char* source, sen_genotype* genotype,
85
+                                                     sen_word_lut* word_lut,
86
+                                                     i32           program_max_size) {
83 87
   sen_result_node result_node = parser_parse(word_lut, source);
84
-  sen_node*       ast         = result_node.result;
88
+  if (is_result_node_error(result_node)) {
89
+    SEN_ERROR("sen_compile_program_with_genotype: parser_parse error");
90
+    return result_program_error(result_node.error);
91
+  }
92
+
93
+  sen_node* ast = result_node.result;
85 94
 
86 95
   sen_compiler_config compiler_config;
87 96
   compiler_config.program_max_size = program_max_size;
@@ -91,21 +100,25 @@ sen_program* sen_compile_program_with_genotype(char* source, sen_genotype* genot
91 100
 
92 101
   sen_result_program result_program =
93 102
       compile_program_with_genotype(program, word_lut, ast, genotype);
103
+
104
+  parser_return_nodes_to_pool(ast);
105
+
94 106
   if (is_result_program_error(result_program)) {
95 107
     SEN_ERROR("sen_compile_program_with_genotype: compile_program_with_genotype");
96
-    // todo: return an error code here
97
-    return NULL;
98 108
   }
99 109
 
100
-  parser_return_nodes_to_pool(ast);
101
-
102
-  return result_program.result;
110
+  return result_program;
103 111
 }
104 112
 
105
-void sen_unparse_with_genotype(sen_cursor* out_cursor, char* source, sen_genotype* genotype,
106
-                               sen_word_lut* word_lut) {
113
+sen_error sen_unparse_with_genotype(sen_cursor* out_cursor, char* source,
114
+                                    sen_genotype* genotype, sen_word_lut* word_lut) {
107 115
   sen_result_node result_node = parser_parse(word_lut, source);
108
-  sen_node*       ast         = result_node.result;
116
+  if (is_result_node_error(result_node)) {
117
+    SEN_ERROR("sen_unparse_with_genotype: parser_parse error");
118
+    return result_node.error;
119
+  }
120
+
121
+  sen_node* ast = result_node.result;
109 122
 
110 123
   cursor_reset(out_cursor);
111 124
 
@@ -114,11 +127,18 @@ void sen_unparse_with_genotype(sen_cursor* out_cursor, char* source, sen_genotyp
114 127
   cursor_write_null(out_cursor);
115 128
 
116 129
   parser_return_nodes_to_pool(ast);
130
+
131
+  return NONE;
117 132
 }
118 133
 
119
-void sen_simplify_script(sen_cursor* out_cursor, char* source, sen_word_lut* word_lut) {
134
+sen_error sen_simplify_script(sen_cursor* out_cursor, char* source, sen_word_lut* word_lut) {
120 135
   sen_result_node result_node = parser_parse(word_lut, source);
121
-  sen_node*       ast         = result_node.result;
136
+  if (is_result_node_error(result_node)) {
137
+    SEN_ERROR("sen_simplify_script: parser_parse error");
138
+    return result_node.error;
139
+  }
140
+
141
+  sen_node* ast = result_node.result;
122 142
 
123 143
   cursor_reset(out_cursor);
124 144
 
@@ -127,6 +147,8 @@ void sen_simplify_script(sen_cursor* out_cursor, char* source, sen_word_lut* wor
127 147
   cursor_write_null(out_cursor);
128 148
 
129 149
   parser_return_nodes_to_pool(ast);
150
+
151
+  return NONE;
130 152
 }
131 153
 
132 154
 sen_genotype* sen_deserialize_genotype(sen_cursor* cursor) {
@@ -142,9 +164,14 @@ sen_genotype* sen_deserialize_genotype(sen_cursor* cursor) {
142 164
   return genotype;
143 165
 }
144 166
 
145
-sen_trait_list* sen_compile_trait_list(char* source, sen_word_lut* word_lut) {
167
+sen_result_trait_list sen_compile_trait_list(char* source, sen_word_lut* word_lut) {
146 168
   sen_result_node result_node = parser_parse(word_lut, source);
147
-  sen_node*       ast         = result_node.result;
169
+  if (is_result_node_error(result_node)) {
170
+    SEN_ERROR("sen_compile_trait_list: parser_parse error");
171
+    return result_trait_list_error(result_node.error);
172
+  }
173
+
174
+  sen_node* ast = result_node.result;
148 175
 
149 176
   sen_compiler_config compiler_config;
150 177
   compiler_config.program_max_size = MAX_TRAIT_PROGRAM_SIZE;
@@ -154,7 +181,7 @@ sen_trait_list* sen_compile_trait_list(char* source, sen_word_lut* word_lut) {
154 181
 
155 182
   parser_return_nodes_to_pool(ast);
156 183
 
157
-  return trait_list;
184
+  return result_trait_list_ok(trait_list);
158 185
 }
159 186
 
160 187
 bool sen_serialize_trait_list(sen_trait_list* trait_list, sen_cursor* cursor) {

+ 10
- 6
core/src/seni/lib.h View File

@@ -14,14 +14,18 @@ void    sen_reset_vm(sen_vm* vm);
14 14
 sen_env* sen_allocate_env();
15 15
 void     sen_free_env(sen_env* env);
16 16
 
17
-sen_program* sen_compile_program(char* source, sen_word_lut* word_lut, i32 program_max_size);
18
-sen_program* sen_compile_program_with_genotype(char* source, sen_genotype* genotype,
19
-                                               sen_word_lut* word_lut, i32 program_max_size);
20
-void sen_unparse_with_genotype(sen_cursor* out_cursor, char* source, sen_genotype* genotype,
21
-                               sen_word_lut* word_lut);
17
+sen_result_program sen_compile_program(char* source, sen_word_lut* word_lut,
18
+                                       i32 program_max_size);
19
+sen_result_program sen_compile_program_with_genotype(char* source, sen_genotype* genotype,
20
+                                                     sen_word_lut* word_lut,
21
+                                                     i32           program_max_size);
22
+sen_error          sen_unparse_with_genotype(sen_cursor* out_cursor, char* source,
23
+                                             sen_genotype* genotype, sen_word_lut* word_lut);
24
+
25
+sen_error sen_simplify_script(sen_cursor* out_cursor, char* source, sen_word_lut* word_lut);
22 26
 
23 27
 sen_genotype* sen_deserialize_genotype(sen_cursor* cursor);
24 28
 
25
-sen_trait_list* sen_compile_trait_list(char* source, sen_word_lut* word_lut);
29
+sen_result_trait_list sen_compile_trait_list(char* source, sen_word_lut* word_lut);
26 30
 bool            sen_serialize_trait_list(sen_trait_list* trait_list, sen_cursor* cursor);
27 31
 sen_trait_list* sen_deserialize_trait_list(sen_cursor* cursor);

+ 2
- 1
core/src/seni/result_functions.c View File

@@ -4,8 +4,9 @@ RESULT_STRUCT_FUNCTIONS(bool, bool)
4 4
 RESULT_STRUCT_FUNCTIONS(f32, f32)
5 5
 RESULT_STRUCT_FUNCTIONS(i32, i32)
6 6
 RESULT_STRUCT_FUNCTIONS(sen_bytecode*, bytecode)
7
+RESULT_STRUCT_FUNCTIONS(sen_fn_info*, fn_info)
7 8
 RESULT_STRUCT_FUNCTIONS(sen_node*, node)
8 9
 RESULT_STRUCT_FUNCTIONS(sen_program*, program)
9
-RESULT_STRUCT_FUNCTIONS(sen_fn_info*, fn_info)
10
+RESULT_STRUCT_FUNCTIONS(sen_trait_list*, trait_list)
10 11
 
11 12
 OPTION_STRUCT_FUNCTIONS(i32, i32)

+ 2
- 1
core/src/seni/types.h View File

@@ -56,8 +56,9 @@ RESULT_STRUCT(bool, bool)
56 56
 RESULT_STRUCT(f32, f32)
57 57
 RESULT_STRUCT(i32, i32)
58 58
 RESULT_STRUCT(sen_bytecode*, bytecode)
59
+RESULT_STRUCT(sen_fn_info*, fn_info)
59 60
 RESULT_STRUCT(sen_node*, node)
60 61
 RESULT_STRUCT(sen_program*, program)
61
-RESULT_STRUCT(sen_fn_info*, fn_info)
62
+RESULT_STRUCT(sen_trait_list*, trait_list)
62 63
 
63 64
 OPTION_STRUCT(i32, i32)

+ 21
- 8
core/src/test.c View File

@@ -595,9 +595,10 @@ void test_strtof(void) {
595 595
 
596 596
 #define VM_COMPILE(EXPR)                                                             \
597 597
   sen_systems_startup();                                                             \
598
-  sen_env*     e    = env_allocate();                                                \
599
-  sen_program* prog = sen_compile_program(EXPR, e->word_lut, 256);                   \
600
-  sen_vm*      vm =                                                                  \
598
+  sen_env*           e           = env_allocate();                                   \
599
+  sen_result_program prog_result = sen_compile_program(EXPR, e->word_lut, 256);      \
600
+  sen_program*       prog        = prog_result.result;                               \
601
+  sen_vm*            vm =                                                            \
601 602
       vm_allocate(STACK_SIZE, HEAP_SIZE, HEAP_MIN_SIZE, VERTEX_PACKET_NUM_VERTICES); \
602 603
   vm_debug_info_reset(vm);                                                           \
603 604
   vm_run(vm, e, prog)
@@ -1501,7 +1502,10 @@ void vm_compile_f32_with_2_genes(char* expr, int seed, f32 expected_res, f32 exp
1501 1502
   sen_env*      e        = env_allocate();
1502 1503
   sen_genotype* genotype = genotype_construct_initial_value(seed, expr);
1503 1504
 
1504
-  sen_program* prog = sen_compile_program_with_genotype(expr, genotype, e->word_lut, 256);
1505
+  sen_result_program prog_result =
1506
+      sen_compile_program_with_genotype(expr, genotype, e->word_lut, 256);
1507
+  sen_program* prog = prog_result.result;
1508
+
1505 1509
   sen_vm* vm = vm_allocate(STACK_SIZE, HEAP_SIZE, HEAP_MIN_SIZE, VERTEX_PACKET_NUM_VERTICES);
1506 1510
 
1507 1511
   TEST_ASSERT(genotype);
@@ -1534,7 +1538,10 @@ void vm_compile_f32_with_3_genes(char* expr, int seed, f32 expected_res, f32 exp
1534 1538
   sen_env*      e        = env_allocate();
1535 1539
   sen_genotype* genotype = genotype_construct_initial_value(seed, expr);
1536 1540
 
1537
-  sen_program* prog = sen_compile_program_with_genotype(expr, genotype, e->word_lut, 256);
1541
+  sen_result_program prog_result =
1542
+      sen_compile_program_with_genotype(expr, genotype, e->word_lut, 256);
1543
+  sen_program* prog = prog_result.result;
1544
+
1538 1545
   sen_vm* vm = vm_allocate(STACK_SIZE, HEAP_SIZE, HEAP_MIN_SIZE, VERTEX_PACKET_NUM_VERTICES);
1539 1546
 
1540 1547
   TEST_ASSERT(genotype);
@@ -1572,7 +1579,10 @@ void vm_compile_f32_with_4_genes(char* expr, int seed, f32 expected_res, f32 exp
1572 1579
   sen_env*      e        = env_allocate();
1573 1580
   sen_genotype* genotype = genotype_construct_initial_value(seed, expr);
1574 1581
 
1575
-  sen_program* prog = sen_compile_program_with_genotype(expr, genotype, e->word_lut, 256);
1582
+  sen_result_program prog_result =
1583
+      sen_compile_program_with_genotype(expr, genotype, e->word_lut, 256);
1584
+  sen_program* prog = prog_result.result;
1585
+
1576 1586
   sen_vm* vm = vm_allocate(STACK_SIZE, HEAP_SIZE, HEAP_MIN_SIZE, VERTEX_PACKET_NUM_VERTICES);
1577 1587
 
1578 1588
   TEST_ASSERT(genotype);
@@ -1939,8 +1949,10 @@ void test_serialization(void) {
1939 1949
 void test_serialization_program(void) {
1940 1950
   parser_subsystem_startup();
1941 1951
 
1942
-  sen_env*     env     = env_allocate();
1943
-  sen_program* program = sen_compile_program("(gen/int min: 2 max: 6)", env->word_lut, 256);
1952
+  sen_env*           env = env_allocate();
1953
+  sen_result_program prog_result =
1954
+      sen_compile_program("(gen/int min: 2 max: 6)", env->word_lut, 256);
1955
+  sen_program* program = prog_result.result;
1944 1956
 
1945 1957
   i32   buffer_size = 4096;
1946 1958
   char* buffer      = (char*)calloc(buffer_size, sizeof(char));
@@ -2252,6 +2264,7 @@ int main(void) {
2252 2264
   RUN_TEST(test_macro_pool);
2253 2265
   RUN_TEST(test_mathutil);
2254 2266
   RUN_TEST(test_parser);
2267
+  RUN_TEST(test_parser_failures);
2255 2268
   RUN_TEST(test_uv_mapper);
2256 2269
   RUN_TEST(test_colour);
2257 2270
   RUN_TEST(test_strtof);

+ 8
- 3
core/test_win.bat View File

@@ -2,10 +2,15 @@
2 2
 
3 3
 setlocal EnableDelayedExpansion
4 4
 
5
+
6
+pushd dist
7
+
5 8
 rem cl can expand wildcards
6
-set test_sources=src\test.c ..\core\src\lib\unity\unity.c ..\core\src\seni\*.c
9
+set test_sources=..\src\test.c ..\..\core\src\lib\unity\unity.c ..\..\core\src\seni\*.c
7 10
 
8 11
 rem https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically
9
-cl /nologo /W4 /wd4146 /wd4127 /wd4001 -Zi -Za /D_CRT_SECURE_NO_DEPRECATE /DSENI_BUILD_WINDOWS /TC !test_sources! /link /OUT:test.exe /I ..\core.src
12
+cl /I ..\..\core.src /nologo /W4 /wd4146 /wd4127 /wd4001 -Zi -Za /D_CRT_SECURE_NO_DEPRECATE /DSENI_BUILD_WINDOWS /TC !test_sources! /link /OUT:test.exe
13
+
14
+popd
10 15
 
11
-.\test.exe
16
+.\dist\test.exe

+ 10
- 5
docs/api.org View File

@@ -18,11 +18,16 @@
18 18
 
19 19
 * functions
20 20
 ** keywords
21
- | name  | description |
22
- |-------+-------------|
23
- | [[loop]]  |             |
24
- | [[fence]] |             |
25
- | [[nth]]   |             |
21
+ | name       | description |
22
+ |------------+-------------|
23
+ | [[loop]]       |             |
24
+ | [[fence]]      |             |
25
+ | [[nth]]        |             |
26
+ | address-of |             |
27
+ | fn-call    |             |
28
+ | define     |             |
29
+ | fn         |             |
30
+ |            |             |
26 31
 
27 32
 ** misc
28 33
 

+ 14
- 2
native/src/native.c View File

@@ -90,7 +90,13 @@ void execute_source(char* source) {
90 90
   //
91 91
   TIMING_UNIT compilation_start = get_timing();
92 92
 
93
-  sen_program* program = sen_compile_program(source, env->word_lut, MAX_PROGRAM_SIZE);
93
+  sen_program_result program_result =
94
+      sen_compile_program(source, env->word_lut, MAX_PROGRAM_SIZE);
95
+  if (is_result_program_error(result_program)) {
96
+    SEN_ERROR("execute_source");
97
+    return;
98
+  }
99
+  sen_program* program = program_result.result;
94 100
 
95 101
   TIMING_UNIT compilation_stop = get_timing();
96 102
 
@@ -236,7 +242,13 @@ void print_compiled_program(char* source) {
236 242
   sen_env* e = sen_allocate_env();
237 243
 
238 244
   // compile program
239
-  sen_program* program = sen_compile_program(source, e->word_lut, MAX_PROGRAM_SIZE);
245
+  sen_program_result program_result =
246
+      sen_compile_program(source, e->word_lut, MAX_PROGRAM_SIZE);
247
+  if (is_result_program_error(result_program)) {
248
+    SEN_ERROR("print_compiled_program");
249
+    return;
250
+  }
251
+  sen_program* program = program_result.result;
240 252
 
241 253
   // print
242 254
   printf("%s\n", source);