diff --git a/parsimonyLibrary/boot.mc b/parsimonyLibrary/boot.mc index 4a757fd..64b3d63 100644 --- a/parsimonyLibrary/boot.mc +++ b/parsimonyLibrary/boot.mc @@ -22,10 +22,12 @@ getComment(x) { { text : x, __proto__: Comment }; } + // adding the element e at the end of the list l append(s, e) { s[length(s)] = e; } + // If g then we add a filter on the application of the function f to each element of seq map(f, seq, g) { out = {}; if (g) { @@ -44,6 +46,7 @@ notToken(x) { x.__proto__ != Token } + // Select element e of s if the the result of the application of f on e is true select(f, s) { out = {}; for (i in s) { @@ -53,6 +56,7 @@ out; } + // Select element e of s if the the result of the application of f on e is false reject(f, s) { out = {}; for (i in s) { @@ -62,6 +66,7 @@ out; } + // Get the last element of s last(s) { s[length(s)-1]; } diff --git a/parsimonyLibrary/fake-static-classes.mc b/parsimonyLibrary/fake-static-classes.mc index 5e6c6ff..ad1ecb0 100644 --- a/parsimonyLibrary/fake-static-classes.mc +++ b/parsimonyLibrary/fake-static-classes.mc @@ -2,16 +2,19 @@ @{ + // allows you to retrieve the type if it is pre-existing or created during compilation checkIdorDecl(x) { (x.identifier == null) ? x.declarators.identifier : x.identifier; } + // allows you to retrieve the type if it is pre-existing or created during compilation checkIdorText(x) { (x.identifier == null) ? x.text : x.identifier; } program.objects = null; + // Initialisation of the object beginObject(objectName, typeName) { program.objects = {}; program.objects.elements = {}; @@ -31,11 +34,12 @@ append(l, treeCopy(obj)); type_obj = `declaration typedef union object *oop;; type_obj.declarators[0].declarators.identifier = objectName; - type_obj.semicolon.comment = getComment(" "); + type_obj.semicolon.comment = getComment("\n\n"); append(l, treeCopy(type_obj)); l; } + // Function to add dynamically an object addObject() { structName = treeCopy(getEnum(program.last.name.identifier)); l = length(program.enums.last.enumList); @@ -55,21 +59,26 @@ nil; } + // Function triggered each time we met a struct everyExternalDeclaration(s) { if (program.objects) { addObject() } s; } + + // Functions to get the macro getObjectMacro() { macro = `ed #define get(PTR, TYPE, FIELD) (_checkType(PTR, TYPE, __FILE__, __LINE__)->TYPE.FIELD) ; macro; } + // Functions to get the macro setObjectMacro() { macro = `ed #define set(PTR, TYPE, FIELD, VALUE) (_checkType(PTR, TYPE, __FILE__, __LINE__)->TYPE.FIELD = VALUE) ; + macro.text = macro.text + "\n"; macro; } @@ -102,9 +111,11 @@ treeCopy(func); } + // Function to set up element useful to the programmer endObject() { l = {}; objectUnion = `declaration union object { int type; };; + objectUnion = treeCopy(objectUnion); objectUnion.specifiers[0].declarationL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier; objectUnion.semicolon.comment = getComment("\n"); obj = select(notToken, program.objects.enum.specifiers[1].enumList);