hokusai-zero 0.2.6.pre.pinephone6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fadc5b1cf6e75bc57d76dcca297a97521e64a744858ef0cafbf53e2e7d259373
4
- data.tar.gz: 010f5c1f195932e39b8f5061cbab13bc55ce88485bec86dadb6a5ec0754feb2b
3
+ metadata.gz: 608b618b6ed01eea7db698a5e8d18d7916d8e06ef9227b6ce0b24a9e9e744d24
4
+ data.tar.gz: f0ae7f8a0e94aa8056989af6090a8e734dc1674880a3b138338d6f15a55500d0
5
5
  SHA512:
6
- metadata.gz: 4e0bdc4ecaa1609324e3ca7a2ba3dadd7ca9ef145ee67c49d66a9fc8c76b5971f1d61f14f806124c7e0c5564a0420af50619dd44da64828a8e041ed47cf35a6d
7
- data.tar.gz: 63f2644bd086280547eea3497df85f274e9dd6304314de84c77839eb4bbd49b903506afb87aae47a230e2861cb80201e1c296c864869b8fbf4a5dca0999c3abc
6
+ metadata.gz: 42dad85dbcaf2e3a5bf5af87cfb608b18be65b978cdeac5fe13aa6f27c944ae0661aa3c92045d296e65065049482f66d4a02d27a187950a18fa5060857b0712b
7
+ data.tar.gz: ae90ae51b1025fe9f991b05ef632b7ff4f354c541f34ad507c8c8e90ac8cd80ee35e759ae82cb45f2d8060530572c9dba468a6433b76ec76b64df4705fb45991
data/ast/src/core/ast.c CHANGED
@@ -194,26 +194,18 @@ int hoku_ast_event_compare(const void* a, const void* b, void* udata)
194
194
 
195
195
  int hoku_ast_add_prop(hoku_ast* component, hoku_ast_prop* prop)
196
196
  {
197
- if (hashmap_set(component->props, prop) == NULL)
198
- {
199
- return -1;
200
- }
201
-
197
+ hashmap_set(component->props, prop);
202
198
  return 0;
203
199
  }
204
200
 
205
201
  hoku_ast_prop* hoku_ast_get_prop(hoku_ast* component, hoku_ast_prop* prop)
206
202
  {
207
- return hashmap_get(component->props, prop);
203
+ return (hoku_ast_prop*)hashmap_get(component->props, prop);
208
204
  }
209
205
 
210
206
  int hoku_ast_add_event(hoku_ast* component, hoku_ast_event* event)
211
207
  {
212
- if (hashmap_set(component->events, event) == NULL)
213
- {
214
- return -1;
215
- }
216
-
208
+ hashmap_set(component->events, event);
217
209
  return 0;
218
210
  }
219
211
 
data/ast/src/core/hml.c CHANGED
@@ -88,6 +88,10 @@ void hoku_dump(hoku_ast* c, int level)
88
88
  hoku_dump(sibling, level);
89
89
  }
90
90
 
91
+ if (c->else_relations != NULL)
92
+ {
93
+ hoku_dump(c->else_relations->next_child, level);
94
+ }
91
95
  return;
92
96
  }
93
97
 
@@ -180,15 +184,31 @@ element 1
180
184
  hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
181
185
  {
182
186
  char* ntype = ts_node_type(node);
187
+ if (ntype == NULL)
188
+ {
189
+ f_log(F_LOG_ERROR, "Node type is null!\n %s", template);
190
+ return NULL;
191
+ }
183
192
 
184
193
  if (strcmp(ntype, "name") == 0)
185
194
  {
186
195
  char* name = hoku_get_tag(node, template);
196
+ if (name == NULL)
197
+ {
198
+ f_log(F_LOG_ERROR, "Node name is null!\n%s", template);
199
+ return NULL;
200
+ }
187
201
  hoku_ast* init;
188
- hoku_ast_init(&init, name);
202
+ if (hoku_ast_init(&init, name) == -1)
203
+ {
204
+ f_log(F_LOG_ERROR, "Could not init ast for %s", name);
205
+ return NULL;
206
+ }
207
+
189
208
  free(name);
190
209
  int i = 0;
191
- TSNode sibling = ts_node_next_sibling(node);
210
+
211
+ TSNode sibling = ts_node_next_named_sibling(node);
192
212
 
193
213
  // a lateral walk across siblings
194
214
  // can be "attributes OR children"
@@ -196,46 +216,94 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
196
216
  {
197
217
  i++;
198
218
  char* stype = ts_node_type(sibling);
219
+ if (stype == NULL)
220
+ {
221
+ f_log(F_LOG_ERROR, "Sibling node type is null");
222
+ return NULL;
223
+ }
224
+
199
225
  if (strcmp(stype, "attributes") == 0)
200
226
  {
227
+ f_log(F_LOG_FINE, "Processing attributes for %s", init->type);
201
228
  // process attributes
202
- TSNode attribute = ts_node_child(sibling, 0);
229
+ TSNode attribute = ts_node_named_child(sibling, 0);
203
230
  while (!ts_node_is_null(attribute))
204
231
  {
205
232
  char* atype = ts_node_type(attribute);
233
+ if (atype == NULL)
234
+ {
235
+ f_log(F_LOG_ERROR, "attribute type is null");
236
+ return NULL;
237
+ }
206
238
  if (strcmp(atype, "prop") == 0)
207
239
  {
240
+ f_log(F_LOG_FINE, "Walking props");
208
241
  hoku_ast_prop* prop = hoku_ast_walk_prop(attribute, template, level + 1);
209
- hoku_ast_add_prop(init, prop);
242
+ if (prop == NULL)
243
+ {
244
+ f_log(F_LOG_ERROR, "Prop is null for attribute %s", attribute);
245
+ return NULL;
246
+ }
247
+ if (hoku_ast_add_prop(init, prop) == -1)
248
+ {
249
+ f_log(F_LOG_ERROR, "Couldn't add prop %s to %s", prop->name, init->type);
250
+ return NULL;
251
+ }
210
252
  }
211
253
  else if (strcmp(atype, "event") == 0)
212
254
  {
255
+ f_log(F_LOG_FINE, "Walking events");
213
256
  hoku_ast_event* event = hoku_ast_walk_event(attribute, template, level + 1);
214
- hoku_ast_add_event(init, event);
257
+ if (event == NULL)
258
+ {
259
+ f_log(F_LOG_ERROR, "Event is null for attribute %s", attribute);
260
+ return NULL;
261
+ }
262
+
263
+ f_log(F_LOG_FINE, "Adding event %s to ast", event->name);
264
+ if (hoku_ast_add_event(init, event) == -1)
265
+ {
266
+ f_log(F_LOG_ERROR, "Couldn't add event to %s", init->type);
267
+ return NULL;
268
+ }
215
269
  }
216
270
  else if (strcmp(atype, "style") == 0)
217
271
  {
218
-
219
272
  char* style_name = hoku_get_tag(attribute, template);
273
+ if (style_name == NULL)
274
+ {
275
+ f_log(F_LOG_ERROR, "Style tag name is NULL");
276
+ return NULL;
277
+ }
278
+ f_log(F_LOG_FINE, "prepending style name %s to ast", style_name);
220
279
  if (hoku_ast_style_list_prepend(init, style_name) != 0) return NULL;
280
+ free(style_name);
221
281
  }
222
282
  else
223
283
  {
224
284
  hoku_ast_set_error(init, "Expecting `event` or `prop`", attribute, hoku_get_tag(attribute, template));
225
285
  }
226
- attribute = ts_node_next_sibling(attribute);
286
+ attribute = ts_node_next_named_sibling(attribute);
227
287
  }
228
288
  }
229
289
  else if (strcmp(stype, "selectors") == 0)
230
290
  {
231
- TSNode sel = ts_node_child(sibling, 0);
291
+ f_log(F_LOG_FINE, "Walking selectors");
292
+ TSNode sel = ts_node_named_child(sibling, 0);
232
293
  while (!ts_node_is_null(sel))
233
294
  {
234
295
  char* seltype = ts_node_type(sel);
235
296
  char* seltag = hoku_get_tag(sel, template);
297
+ if (seltag == NULL)
298
+ {
299
+ f_log(F_LOG_ERROR, "selector tag is null!");
300
+ return NULL;
301
+ }
302
+
236
303
  if (strcmp(seltype, "id") == 0)
237
304
  {
238
- init->id = seltag;
305
+ init->id = strdup(seltag);
306
+ free(seltag);
239
307
  }
240
308
  else if (strcmp(seltype, "class") == 0)
241
309
  {
@@ -243,45 +311,66 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
243
311
  free(seltag);
244
312
  }
245
313
 
246
- sel = ts_node_next_sibling(sel);
314
+ f_log(F_LOG_FINE, "Getting next selector sibling");
315
+ sel = ts_node_next_named_sibling(sel);
247
316
  }
248
317
  }
249
318
  else if (strcmp(stype, "children") == 0)
250
319
  {
251
320
  TSNode child;
252
- uint32_t child_count = ts_node_child_count(sibling);
321
+ uint32_t child_count = ts_node_named_child_count(sibling);
322
+ f_log(F_LOG_DEBUG, "Walking %u children", child_count);
323
+
253
324
  init->child_len = (int) child_count;
254
325
  hoku_ast* sinit = NULL;
255
326
  for (uint32_t i=0; i<child_count; i++)
256
327
  {
257
- child = ts_node_child(sibling, i);
258
- char* ctypee = ts_node_type(child);
259
- hoku_ast* cchild = hoku_ast_walk_tree(child, template, level + 1);
260
- if (sinit == NULL)
261
- {
262
- sinit = cchild;
263
- }
264
- else
328
+ child = ts_node_named_child(sibling, i);
329
+ char* ctype = ts_node_type(child);
330
+ f_log(F_LOG_FINE, "Child: %s %d", ctype, i);
331
+ f_log(F_LOG_DEBUG, "Walking ast tree for %s (%d)", ctype, level);
332
+
333
+ if(strcmp(ctype, "else_macro") != 0)
265
334
  {
266
- hoku_ast_append_sibling(&sinit, cchild);
335
+
336
+ hoku_ast* cchild = hoku_ast_walk_tree(child, template, level + 1);
337
+ if (cchild == NULL)
338
+ {
339
+ f_log(F_LOG_ERROR, "Ast child is NULL");
340
+ return NULL;
341
+ }
342
+
343
+ if (sinit == NULL)
344
+ {
345
+ sinit = cchild;
346
+ }
347
+ else
348
+ {
349
+ f_log(F_LOG_FINE, "Appending sibling %s to %s", cchild->type, sinit->type);
350
+ hoku_ast_append_sibling(&sinit, cchild);
351
+ }
267
352
  }
268
353
  }
269
354
 
355
+ f_log(F_LOG_DEBUG, "Appending child %s to %s", sinit->type, init->type);
270
356
  hoku_ast_append_child(&init, sinit);
271
357
  }
272
358
 
273
359
  sibling = ts_node_next_sibling(sibling);
274
360
  }
275
361
 
362
+ f_log(F_LOG_DEBUG, "Returning ast %s", init->type);
276
363
  return init;
277
364
  }
278
365
  else if (strcmp(ntype, "element") == 0)
279
366
  {
367
+ f_log(F_LOG_FINE, "Walking element tree");
280
368
  TSNode child = ts_node_child(node, 0);
281
369
  return hoku_ast_walk_tree(child, template, level + 1);
282
370
  }
283
371
  else if (strcmp(ntype, "children") == 0)
284
372
  {
373
+ f_log(F_LOG_FINE, "Walking children tree");
285
374
  TSNode child = ts_node_child(node, 0);
286
375
  return hoku_ast_walk_tree(child, template, level + 1);
287
376
  }
@@ -289,19 +378,38 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
289
378
  {
290
379
  TSNode child = ts_node_named_child(node, 0);
291
380
  char* name = hoku_get_tag(child, template);
381
+ if (name == NULL)
382
+ {
383
+ f_log(F_LOG_ERROR, "for macro name is null!");
384
+ return NULL;
385
+ }
292
386
 
293
387
  TSNode sibling = ts_node_next_named_sibling(child);
294
388
  char* list_name = hoku_get_tag(sibling, template);
389
+ if (list_name == NULL)
390
+ {
391
+ f_log(F_LOG_ERROR, "for macro list name is null!");
392
+ return NULL;
393
+ }
394
+
295
395
  hoku_ast_loop* loop;
296
396
  if (hoku_ast_loop_init(&loop, name, list_name) == -1)
297
397
  {
398
+ f_log(F_LOG_ERROR, "Failed to initialize loop %s %s", name, list_name);
298
399
  return NULL;
299
400
  }
300
401
 
301
402
  free(name);
302
403
  free(list_name);
404
+
303
405
  TSNode children = ts_node_next_named_sibling(sibling);
406
+ f_log(F_LOG_DEBUG, "Walking loop children");
304
407
  hoku_ast* ast = hoku_ast_walk_tree(children, template, level + 1);
408
+ if (ast == NULL)
409
+ {
410
+ f_log(F_LOG_ERROR, "Loop ast is null");
411
+ return NULL;
412
+ }
305
413
 
306
414
  ast->loop = loop;
307
415
 
@@ -309,17 +417,32 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
309
417
  }
310
418
  else if (strcmp(ntype, "if_macro") == 0)
311
419
  {
420
+ f_log(F_LOG_DEBUG, "Handling if macro");
312
421
  TSNode child = ts_node_named_child(node, 0);
313
422
  hoku_ast_func_call* call = hoku_ast_walk_func(child, template, level);
423
+ if (call == NULL)
424
+ {
425
+ f_log(F_LOG_ERROR, "Func call for if macro is null");
426
+ return NULL;
427
+ }
314
428
 
315
429
  hoku_ast_condition* cond;
316
430
  if (hoku_ast_cond_init(&cond, call) == -1)
317
431
  {
432
+ f_log(F_LOG_ERROR, "Condition for if macro is null");
318
433
  return NULL;
319
434
  }
320
435
 
321
436
  TSNode ichildren = ts_node_next_named_sibling(child);
437
+
322
438
  hoku_ast* iast = hoku_ast_walk_tree(ichildren, template, level + 1);
439
+ if (iast == NULL)
440
+ {
441
+ f_log(F_LOG_ERROR, "If macro children ast is null");
442
+ return NULL;
443
+ }
444
+
445
+ f_log(F_LOG_FINE, "Walked if macro children");
323
446
  iast->cond = cond;
324
447
 
325
448
  TSNode echild = ts_node_next_named_sibling(node);
@@ -329,21 +452,35 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
329
452
 
330
453
  if (strcmp(etype, "else_macro") == 0)
331
454
  {
455
+ f_log(F_LOG_FINE, "Walking next else child");
456
+
332
457
  TSNode eechildren = ts_node_named_child(echild, 0);
333
- hoku_ast* oast = hoku_ast_walk_tree(eechildren, template, level + 1);
458
+ if (!ts_node_is_null(eechildren))
459
+ {
460
+ hoku_ast* oast = hoku_ast_walk_tree(eechildren, template, level + 1);
461
+ if (oast == NULL)
462
+ {
463
+ f_log(F_LOG_ERROR, "Else cond children ast is null");
464
+ return NULL;
465
+ }
334
466
 
335
- iast->else_relations = malloc(sizeof(hoku_ast*));
336
- if (iast->else_relations == NULL) return NULL;
467
+ iast->else_relations = malloc(sizeof(hoku_ast*));
468
+ if (iast->else_relations == NULL) return NULL;
337
469
 
338
- iast->else_relations->next_child = oast;
339
- iast->else_relations->next_sibling = NULL;
340
- }
470
+ iast->else_relations->next_child = oast;
471
+ iast->else_relations->next_sibling = NULL;
472
+ }
473
+ }
474
+ }
475
+ else
476
+ {
477
+ f_log(F_LOG_WARN, "If macro has no else children");
341
478
  }
342
-
343
479
  return iast;
344
480
  }
345
481
  else if (strcmp(ntype, "for_if_macro") == 0)
346
482
  {
483
+ f_log(F_LOG_DEBUG, "Handling for/if macro");
347
484
  TSNode child = ts_node_named_child(node, 0);
348
485
  char* name = hoku_get_tag(child, template);
349
486
 
@@ -394,6 +531,7 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
394
531
  }
395
532
  else
396
533
  {
534
+ f_log(F_LOG_WARN, "Unsupported type %s", ntype);
397
535
  return NULL;
398
536
  }
399
537
  }
@@ -412,6 +550,11 @@ hoku_style_attribute* hoku_walk_style_attributes(TSNode node, char* template)
412
550
  TSNode value_node = ts_node_next_named_sibling(attribute_name_node);
413
551
  char* value_node_type = ts_node_type(value_node);
414
552
 
553
+ if (value_node_type == NULL || attribute_name == NULL)
554
+ {
555
+ return NULL;
556
+ }
557
+
415
558
  enum HOKU_STYLE_TYPE type;
416
559
  char* value = NULL;
417
560
  char* function_name = NULL;
@@ -571,26 +714,35 @@ int hoku_style_from_template(hoku_style** out, char* template)
571
714
  int hoku_ast_from_template(hoku_ast** out, char* type, char* template)
572
715
  {
573
716
  hoku_ast* init;
574
- if (hoku_ast_init(&init, type) == -1) return -1;
717
+ if (hoku_ast_init(&init, type) == -1)
718
+ {
719
+ f_log(F_LOG_ERROR, "AST initialization failed.");
720
+ return -1;
721
+ }
575
722
 
576
723
  hoku_style* style = NULL;
577
724
 
725
+ f_log(F_LOG_FINE, "Initializing parser.");
578
726
  TSParser* parser = ts_parser_new();
579
727
  if (parser == NULL)
580
728
  {
729
+ f_log(F_LOG_ERROR, "Parser initialization failed.");
581
730
  free(init);
582
731
  return -1;
583
732
  }
584
733
 
734
+ f_log(F_LOG_FINE, "Parsing document.");
585
735
  ts_parser_set_language(parser, tree_sitter_hml());
586
736
  TSTree* tree = ts_parser_parse_string(parser, NULL, template, strlen(template));
587
737
  if (tree == NULL)
588
738
  {
739
+ f_log(F_LOG_ERROR, "TS Parser tree is NULL.");
589
740
  ts_parser_delete(parser);
590
741
  free(init);
591
742
  return -1;
592
743
  }
593
744
 
745
+ f_log(F_LOG_FINE, "Getting tree root node.");
594
746
  TSNode document = ts_tree_root_node(tree);
595
747
  if (strcmp(ts_node_type(document), "document") != 0)
596
748
  {
@@ -599,16 +751,20 @@ int hoku_ast_from_template(hoku_ast** out, char* type, char* template)
599
751
  return 0;
600
752
  }
601
753
 
754
+ f_log(F_LOG_FINE, "Getting document template (first child)");
602
755
  TSNode templ = ts_node_named_child(document, 0);
603
756
  if (strcmp(ts_node_type(templ), "template") != 0 && strcmp(ts_node_type(templ), "style_template") != 0)
604
757
  {
758
+ f_log(F_LOG_DEBUG, "Document not expected.");
605
759
  hoku_ast_set_error(init, "Expecting template", templ, hoku_get_tag(templ, template));
606
760
  *out = init;
607
761
  return 0;
608
762
  }
609
763
 
764
+ f_log(F_LOG_FINE, "Checking style template");
610
765
  if (strcmp(ts_node_type(templ), "style_template") == 0)
611
766
  {
767
+ f_log(F_LOG_DEBUG, "Walking style template.");
612
768
  style = hoku_walk_style_template(templ, template);
613
769
  templ = ts_node_next_named_sibling(templ);
614
770
 
@@ -623,39 +779,55 @@ int hoku_ast_from_template(hoku_ast** out, char* type, char* template)
623
779
  TSNode child = ts_node_named_child(templ, 0);
624
780
  hoku_ast* roots = NULL;
625
781
  char* ntype = ts_node_type(child);
782
+ f_log(F_LOG_FINE, "init vars, %p, %p", child, ntype);
626
783
 
784
+ f_log(F_LOG_DEBUG, "Walking template tree for");
627
785
  while (!ts_node_is_null(child))
628
786
  {
629
- hoku_ast* children;
630
- children = hoku_ast_walk_tree(child, template, 0);
787
+ ntype = ts_node_type(child);
631
788
 
632
- if (children == NULL)
789
+ if (strcmp(ntype, "else_macro") != 0)
633
790
  {
634
- char* ntype = ts_node_type(child);
635
- }
791
+ hoku_ast* children;
792
+ children = hoku_ast_walk_tree(child, template, 0);
636
793
 
637
- if (roots == NULL)
638
- {
639
- roots = children;
640
- }
641
- else
642
- {
643
- hoku_ast_append_sibling(&roots, children);
794
+ f_log(F_LOG_DEBUG, "Walked template children, %p", children);
795
+
796
+ if (children == NULL)
797
+ {
798
+ f_log(F_LOG_WARN, "Children are NULL");
799
+ char* ntype = ts_node_type(child);
800
+ }
801
+
802
+ if (roots == NULL)
803
+ {
804
+ f_log(F_LOG_DEBUG, "Setting roots to children");
805
+ roots = children;
806
+ }
807
+ else
808
+ {
809
+ f_log(F_LOG_FINE, "Appending children as siblings to root ast.");
810
+ hoku_ast_append_sibling(&roots, children);
811
+ }
644
812
  }
645
813
 
814
+ f_log(F_LOG_DEBUG, "Assigning next sibling.");
646
815
  child = ts_node_next_named_sibling(child);
647
816
  }
648
817
 
818
+ f_log(F_LOG_DEBUG, "Appending root ast to init ast");
649
819
  hoku_ast_append_child(&init, roots);
650
820
 
651
821
  templ = ts_node_next_named_sibling(templ);
652
822
  if (!ts_node_is_null(templ) && strcmp(ts_node_type(templ), "style_template") == 0)
653
823
  {
824
+ f_log(F_LOG_FINE, "walking style template\n");
654
825
  style = hoku_walk_style_template(templ, template);
655
826
  }
656
827
 
657
828
  init->styles = style;
658
829
 
830
+ f_log(F_LOG_FINE, "delete tree and parser");
659
831
  ts_tree_delete(tree);
660
832
  ts_parser_delete(parser);
661
833
 
data/ast/src/core/hml.h CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "style.h"
5
5
  #include "ast.h"
6
+ #include "log.h"
6
7
 
7
8
  int hoku_style_from_template(hoku_style** out, char* template);
8
9
  int hoku_ast_from_template(hoku_ast** out, char* type, char* template);
@@ -0,0 +1,87 @@
1
+ #ifndef FLASHLIGHT_LOG
2
+ #define FLASHLIGHT_LOG
3
+ #include "log.h"
4
+
5
+ void f_default_on_log_message(f_log_message msg)
6
+ {
7
+ if (msg.level & f_logger_get_level())
8
+ {
9
+ switch(msg.level)
10
+ {
11
+ case F_LOG_FINE: {
12
+ fprintf(stderr, ANSI_COLOR_YELLOW " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
13
+ break;
14
+ }
15
+ case F_LOG_DEBUG: {
16
+ fprintf(stderr, ANSI_COLOR_CYAN " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
17
+ break;
18
+ }
19
+ case F_LOG_INFO: {
20
+ fprintf(stderr, ANSI_COLOR_BLUE " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
21
+ break;
22
+ }
23
+ case F_LOG_WARN: {
24
+ fprintf(stderr, ANSI_COLOR_YELLOW " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
25
+ break;
26
+ }
27
+ case F_LOG_ERROR: {
28
+ fprintf(stderr, ANSI_COLOR_MAGENTA " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
29
+ break;
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ void f_logger_set_level(enum F_LOG_LEVEL level)
36
+ {
37
+ f_log_level = level;
38
+ }
39
+
40
+ void f_logger_set_cb(f_logger_cb cb, volatile void* payload)
41
+ {
42
+ f_log_cb = cb;
43
+ f_log_payload = payload;
44
+ }
45
+
46
+ f_logger_cb f_logger_get_cb()
47
+ {
48
+ return f_log_cb;
49
+ }
50
+
51
+ volatile void* f_logger_get_payload()
52
+ {
53
+ return f_log_payload;
54
+ }
55
+
56
+ enum F_LOG_LEVEL f_logger_get_level()
57
+ {
58
+ return f_log_level;
59
+ }
60
+
61
+ void f_log(enum F_LOG_LEVEL level, char* fmt, ...)
62
+ {
63
+ time_t t = time(NULL);
64
+ struct tm* tm = localtime(&t);
65
+ char datetime[64];
66
+ strftime(datetime, sizeof(datetime), "%c", tm);
67
+ char message[500];
68
+ volatile void* payload = f_logger_get_payload();
69
+
70
+ va_list args;
71
+ va_start(args, fmt);
72
+ vsprintf(message, fmt, args);
73
+ va_end(args);
74
+
75
+ f_log_message msg = {datetime, level, message};
76
+
77
+ if (f_log_cb == NULL)
78
+ {
79
+ f_default_on_log_message(msg);
80
+ }
81
+ else
82
+ {
83
+ f_log_cb(msg, payload);
84
+ }
85
+ }
86
+
87
+ #endif
@@ -0,0 +1,41 @@
1
+ #ifndef FLASHLIGHT_LOG_H
2
+ #define FLASHLIGHT_LOG_H
3
+ #include <time.h>
4
+ #include <stdio.h>
5
+ #include <stdarg.h>
6
+
7
+ #define ANSI_COLOR_YELLOW "\x1b[33m"
8
+ #define ANSI_COLOR_BLUE "\x1b[34m"
9
+ #define ANSI_COLOR_MAGENTA "\x1b[35m"
10
+ #define ANSI_COLOR_CYAN "\x1b[36m"
11
+ #define ANSI_COLOR_RESET "\x1b[0m"
12
+
13
+ enum F_LOG_LEVEL
14
+ {
15
+ F_LOG_ERROR = 1 << 0,
16
+ F_LOG_WARN = 1 << 1,
17
+ F_LOG_INFO = 1 << 2,
18
+ F_LOG_DEBUG = 1 << 3,
19
+ F_LOG_FINE = 1 << 4
20
+ };
21
+
22
+ typedef struct FLogMessage
23
+ {
24
+ char* datetime;
25
+ enum F_LOG_LEVEL level;
26
+ char* message;
27
+ } f_log_message;
28
+
29
+ typedef void (*f_logger_cb)(f_log_message message, volatile void* payload);
30
+ static volatile f_logger_cb f_log_cb = NULL;
31
+ static volatile enum F_LOG_LEVEL f_log_level = F_LOG_ERROR;
32
+ static volatile void* f_log_payload = NULL;
33
+
34
+ void f_logger_set_level(enum F_LOG_LEVEL level);
35
+ void f_logger_set_cb(f_logger_cb cb, volatile void* payload);
36
+ f_logger_cb f_logger_get_cb();
37
+ enum F_LOG_LEVEL f_logger_get_level();
38
+ volatile void* f_logger_get_payload();
39
+ void f_log(enum F_LOG_LEVEL level, char* fmt, ...);
40
+
41
+ #endif
data/ast/test/parser.c CHANGED
@@ -1,3 +1,4 @@
1
+ #include "../src/core/log.c"
1
2
  #include "../src/core/ast.c"
2
3
  #include "../src/core/style.c"
3
4
  #include "../src/core/hml.c"
data/ext/extconf.rb CHANGED
@@ -54,10 +54,10 @@ md4c.activate
54
54
  pre = "#{__dir__}/.."
55
55
  cwd = "#{__dir__}"
56
56
 
57
- files = %w[ast/src/core/hml.c ast/src/core/ast.c ast/rc/core/style.c ast/src/core/input.c ast/src/core/component.c ast/src/core/util.c ast/src/core/text.c grammar/src/parser.c grammar/src/scanner.c ast/include/hashmap.c]
58
- objects = %w[hml.o ast.o style.o input.o component.o util.o text.o parser.o scanner.o hashmap.o]
57
+ files = %w[ast/src/core/log.c ast/src/core/hml.c ast/src/core/ast.c ast/rc/core/style.c ast/src/core/input.c ast/src/core/component.c ast/src/core/util.c ast/src/core/text.c grammar/src/parser.c grammar/src/scanner.c ast/include/hashmap.c]
58
+ objects = %w[log.o hml.o ast.o style.o input.o component.o util.o text.o parser.o scanner.o hashmap.o]
59
59
  libraries = [File.expand_path("#{tree_sitter.path}/lib/libtree-sitter.a"), File.expand_path("#{md4c.path}/lib/libmd4c.#{md4cext}")]
60
- src_files = ["#{tree_sitter.path}/lib/libtree-sitter.a", "#{md4c.path}/lib/libmd4c.#{md4cext}", "#{pre}/ast/src/core/hml.c", "#{pre}/ast/src/core/ast.c", "#{pre}/ast/src/core/style.c", "#{pre}/ast/src/core/input.c", "#{pre}/ast/src/core/component.c", "#{pre}/ast/src/core/util.c", "#{pre}/ast/src/core/text.c", "#{pre}/grammar/src/parser.c", "#{pre}/grammar/src/scanner.c", "#{pre}/ast/include/hashmap.c"]
60
+ src_files = ["#{tree_sitter.path}/lib/libtree-sitter.a", "#{md4c.path}/lib/libmd4c.#{md4cext}", "#{pre}/ast/src/core/log.c", "#{pre}/ast/src/core/hml.c", "#{pre}/ast/src/core/ast.c", "#{pre}/ast/src/core/style.c", "#{pre}/ast/src/core/input.c", "#{pre}/ast/src/core/component.c", "#{pre}/ast/src/core/util.c", "#{pre}/ast/src/core/text.c", "#{pre}/grammar/src/parser.c", "#{pre}/grammar/src/scanner.c", "#{pre}/ast/include/hashmap.c"]
61
61
  if MiniPortile.windows?
62
62
  cflags = "-shared -Wall -Wl,--export-all-symbols -Wl,--enable-auto-import"
63
63
  mkdir = "mkdir #{pre}\\vendor\\lib"
data/hokusai.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'hokusai-zero'
3
- s.version = '0.2.6-pinephone6'
3
+ s.version = '0.2.7'
4
4
  s.licenses = ['MIT']
5
5
  s.summary = "A Ruby library for writing GUI applications"
6
6
  s.authors = ["skinnyjames"]
@@ -122,12 +122,11 @@ Hokusai::Backends::RaylibBackend.run(Demos::Counter) do |config|
122
122
  # end
123
123
 
124
124
  config.after_load do
125
- font = Hokusai::Backends::RaylibBackend::Font.sdf("#{__dir__}/assets/OpenSans-Regular.ttf", 260)
125
+ font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/OpenSans-Regular.ttf", 160)
126
126
  Hokusai.fonts.register "opensans", font
127
127
  Hokusai.fonts.activate "opensans"
128
128
  end
129
129
 
130
- config.fps = 40
131
130
  config.width = 500
132
131
  config.height = 500
133
132
  config.title = "Counter application"
@@ -119,15 +119,15 @@ module Demos
119
119
  end
120
120
  end
121
121
 
122
- Hokusai::Backends::RaylibBackend.run(Demos::Spreadsheet::App) do |config|
123
- config.after_load do
124
- font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
125
- Hokusai.fonts.register "inter", font
126
- Hokusai.fonts.activate "inter"
122
+ Hokusai::Backends::SDLBackend.run(Demos::Spreadsheet::App) do |config|
123
+ # config.after_load do
124
+ # font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
125
+ # Hokusai.fonts.register "inter", font
126
+ # Hokusai.fonts.activate "inter"
127
127
 
128
- font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/Delius-Regular.ttf", 160)
129
- Hokusai.fonts.register "dohyeon", font
130
- end
128
+ # font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/Delius-Regular.ttf", 160)
129
+ # Hokusai.fonts.register "dohyeon", font
130
+ # end
131
131
 
132
132
  config.fps = 60
133
133
  config.width = 800
@@ -135,7 +135,7 @@ Hokusai::Backends::RaylibBackend.run(Demos::Spreadsheet::App) do |config|
135
135
  config.title = "Spreadsheet application"
136
136
 
137
137
 
138
- config.config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT | Raylib::FLAG_WINDOW_TRANSPARENT
139
- config.window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_WINDOW_UNDECORATED | Raylib::FLAG_WINDOW_TRANSPARENT
140
- config.background = Raylib::BLANK
138
+ # config.config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT | Raylib::FLAG_WINDOW_TRANSPARENT
139
+ # config.window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_WINDOW_UNDECORATED | Raylib::FLAG_WINDOW_TRANSPARENT
140
+ # config.background = Raylib::BLANK
141
141
  end
@@ -240,9 +240,9 @@ module Demos
240
240
  end
241
241
  end
242
242
  end
243
-
244
- Hokusai::Backends::RaylibBackend.run(Demos::TicTacToe::App) do |config|
245
- config.width = 500
246
- config.height = 500
247
- config.title = "Tic Tac Trollio"
248
- end
243
+ #
244
+ # Hokusai::Backends::SDLBackend.run(TicTacToe::App) do |config|
245
+ # config.width = 500
246
+ # config.height = 500
247
+ # config.title = "Tic Tac Trollio"
248
+ # end
@@ -146,8 +146,26 @@ module LibHokusai
146
146
  :max
147
147
  ]
148
148
 
149
+ def self.set_log_level(symbol)
150
+ case symbol
151
+ when :fine
152
+ LibHokusai.f_logger_set_level(1 | 2 | 4 | 8 | 16)
153
+ when :debug
154
+ LibHokusai.f_logger_set_level(1 | 2 | 4 | 8)
155
+ when :info
156
+ LibHokusai.f_logger_set_level(1 | 2 | 4)
157
+ when :warn
158
+ LibHokusai.f_logger_set_level(1 | 2)
159
+ when :error
160
+ LibHokusai.f_logger_set_level(1)
161
+ end
162
+ end
163
+
164
+ enum :log_level, [:error, 1, :warn, 2, :info, 4, :debug, 8, :fine, 16]
165
+
149
166
  # fun hashmap_iter(map : Hashmap, i : LibC::SizeT*, item : Void**) : Bool
150
167
  # ast methods
168
+ attach_function :f_logger_set_level, [:log_level], :void
151
169
  attach_function :hoku_ast_prop_init, [:pointer, :string], :int
152
170
  attach_function :hoku_ast_class_list_includes, [:pointer, :string], :int
153
171
  attach_function :hoku_ast_get_prop, [HmlAst.by_ref, HmlAstProp.by_ref], HmlAstProp.by_ref
@@ -20,7 +20,7 @@ module Hokusai::Backends
20
20
  uniform vec4 colDiffuse;
21
21
 
22
22
  // NOTE: Add your custom variables here
23
- const float smoothing = 1.0/16.0;
23
+ const float smoothing = 1.0/32.0;
24
24
 
25
25
  void main()
26
26
  {
@@ -118,10 +118,15 @@ module Hokusai
118
118
  child.update
119
119
  end
120
120
  end
121
-
122
- def has_ast?(ast, index)
123
- if portal = children![index]&.node&.portal&.portal
124
- return portal.ast.object_id == ast.object_id
121
+ def has_ast?(ast, index, elsy = false)
122
+ if elsy
123
+ if portal = children![index]&.node&.portal
124
+ return portal.ast.object_id == ast.object_id
125
+ end
126
+ else
127
+ if portal = children![index]&.node&.portal&.portal
128
+ return portal.ast.object_id == ast.object_id
129
+ end
125
130
  end
126
131
 
127
132
  false
@@ -19,8 +19,8 @@ module Hokusai
19
19
  portal.ast.children.each_with_index do |child, index|
20
20
  next unless child.has_if_condition?
21
21
 
22
- child_present = ->(child) do
23
- meta.has_ast?(child, index)
22
+ child_present = ->(child, elsy) do
23
+ meta.has_ast?(child, index, elsy)
24
24
  end
25
25
 
26
26
  if child.if.args.size > 0
@@ -33,11 +33,11 @@ module Hokusai
33
33
 
34
34
  if !!visible
35
35
  if child.else_condition_active?
36
- meta.child_delete(index) if child_present.call(child)
36
+ meta.child_delete(index) if child_present.call(child, false)
37
37
  child.else_active = 0
38
38
  end
39
39
 
40
- unless child_present.call(child)
40
+ unless child_present.call(child, true)
41
41
  portal = Node.new(child, Node.new(child))
42
42
  node = child_block_klass.compile("root", portal)
43
43
  node.add_styles(target.class)
@@ -52,8 +52,9 @@ module Hokusai
52
52
  child_block = NodeMounter.new(node, child_block_klass, [stack], previous_providers: providers).mount(context: context, providers: providers)
53
53
 
54
54
  UpdateEntry.new(child_block, block, target).register(context: context, providers: providers)
55
-
55
+ pp [meta.has_ast?(child, index, false), "shouldn't be here?"]
56
56
  meta.children!.insert(index, child_block)
57
+ pp ["children", meta.children!.size, meta.children!.map(&:class)]
57
58
 
58
59
  child_block.public_send(:before_updated) if child_block.respond_to?(:before_updated)
59
60
  child_block.update
@@ -61,7 +62,7 @@ module Hokusai
61
62
  end
62
63
  elsif !visible
63
64
  if !child.has_else_condition? || (child.has_else_condition? && !child.else_condition_active?)
64
- if (child_present.call(child))
65
+ if (child_present.call(child, true))
65
66
  meta.child_delete(index)
66
67
  end
67
68
  end
data/xmake.lua CHANGED
@@ -119,6 +119,7 @@ target("hokusai")
119
119
  add_links("$(projectdir)/vendor/lib/libtree-sitter.a")
120
120
  add_links("$(projectdir)/vendor/lib/libmd4c.a")
121
121
  add_files(
122
+ "ast/src/core/log.c",
122
123
  "ast/src/core/hml.c",
123
124
  "ast/src/core/ast.c",
124
125
  "ast/src/core/style.c",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hokusai-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.pre.pinephone6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - skinnyjames
@@ -103,6 +103,8 @@ files:
103
103
  - ast/src/core/hml.h
104
104
  - ast/src/core/input.c
105
105
  - ast/src/core/input.h
106
+ - ast/src/core/log.c
107
+ - ast/src/core/log.h
106
108
  - ast/src/core/style.c
107
109
  - ast/src/core/style.h
108
110
  - ast/src/core/text.c