Manage C structures
- Posted by jmduro Sep 23, 2022
- 1060 views
I have updated my previous structure manager so that it can use C syntax. It is available here: http://jean-marc.duro.pagesperso-orange.fr/Structures_v0.1.0_2022-09-23.zip
Here is the example code:
include std/dll.e include std/machine.e include std/console.e include common.e include structs.e sequence myStructure = "struct _mydata {" & " int a;" & " float b;" & " char c;" & "} bar;" f_debug = open("debug.log", "w") debug_level = VERBOSE sequence struct = allocateStructure(myStructure) writeStructure(struct, {allocate_string("A string"), 12, 25.2} ) sequence s = readStructure(struct) printf(1, "s2[1] = %s, s2[2] = %d, s2[3] = %4.1f\n", {peek_string(s[1]), s[2], s[3]}) freeStructure(struct) close(f_debug) maybe_any_key()
The parser is ready for nested structures and unions (see decompose_struct.ex, result below) but the manager can only deal with simple structures yet: one level, no union, no nesting.
sequence myStructure = "struct _mydata {" & " int which_one;" & " union _data {" & " int a;" & " float b;" & " char c;" & " } foo;" & "} bar;"
vars =
[SU_TYPE] STRUCT
[SU_TYPE_NAME] "_mydata"
[SU_VAR_NAME] "bar"
[SU_BLOCK]
. [1] "int which_one;"
. [2]
. . [SU_TYPE] UNION
. . [SU_TYPE_NAME] "_data"
. . [SU_VAR_NAME] "foo"
. . [SU_BLOCK] {"int a;", "float b;", "char c;"}
Jean-Marc

