diff --git a/ccmeta.leg b/ccmeta.leg index 55084ef..c689511 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -1332,6 +1332,15 @@ language printLang = C; oop outputProgram= 0; +oop everyExternalDeclaration(oop s) +{ + oop eed = map_get(globals, intern("everyExternalDeclaration")); + if (is(Function, eed)) { + s = apply(globals, globals, eed, makeArrayFromElement(s, 1), mrAST); + } + return s; +} + %} @@ -1341,7 +1350,7 @@ oop outputProgram= 0; # yylval == 0 => end of input file while in META mode only start = m:metaCatch { yylval= m } - | s:externalDeclaration { yylval= s } + | s:externalDeclaration { yylval= everyExternalDeclaration(s) } error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 } @@ -2193,8 +2202,9 @@ metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStack | META_LCB s:mstmts { map_append(outputProgram, s); $$= null } ) -mvalue = ( i:META_IDENT { i= newGetVariable(i) } - ( a:meta_argumentList { i = (null != getSyntax(1, i)) ? apply(globals, globals, getSyntax(1, i), a, i) : newCall(i, a) } )? +mvalue = ( i:META_IDENT { i= newGetVariable(i) } ( a:meta_argumentList { i = (null != getSyntax(1, i)) ? apply(globals, globals, getSyntax(1, i), a, i) : newCall(i, a) } + | { i = is(Function, eval(globals, i)) == 1 ? apply(globals, globals, eval(globals, i), makeMap(), i) : i } + ) | META_LPAREN ( i:meta_exp ) META_RPAREN ) { $$= eval(globals, i) } @@ -3451,6 +3461,9 @@ oop eval(oop scope, oop ast) DO_C_PROTOS(); break; #undef _DO + case t_Undefined: + case t_Function: + break; } printf("EVAL "); println(ast); @@ -4667,7 +4680,7 @@ int main(int argc, char **argv) map_set(globals, intern("exit" ), makeFunction(prim_exit, intern("exit" ), null, null, globals, null)); map_set(globals, intern("keys" ), makeFunction(prim_keys, intern("keys" ), null, null, globals, null)); - map_set(globals, intern("allKeys" ), makeFunction(prim_all_keys, intern("allKeys" ), null, null, globals, null)); + map_set(globals, intern("_keys" ), makeFunction(prim_all_keys, intern("_keys" ), null, null, globals, null)); map_set(globals, intern("values" ), makeFunction(prim_values, intern("values" ), null, null, globals, null)); map_set(globals, intern("length" ), makeFunction(prim_length, intern("length" ), null, null, globals, null)); map_set(globals, intern("print" ), makeFunction(prim_print, intern("print" ), null, null, globals, null)); @@ -4710,19 +4723,13 @@ int main(int argc, char **argv) enum_last = makeMap(); struct_last = makeMap(); union_last = makeMap(); - prog_objects = makeMap(); - objects_elements = makeMap(); - objects_last = makeMap(); map_set(prog_enums , intern("last" ), enum_last ); map_set(prog_structs , intern("last" ), struct_last ); map_set(prog_unions , intern("last" ), union_last ); - map_set(prog_objects , intern("elements" ), objects_elements ); - map_set(prog_objects , intern("last" ), objects_last ); map_set(program , intern("structs" ), prog_structs ); map_set(program , intern("unions" ), prog_unions ); map_set(program , intern("enums" ), prog_enums ); - map_set(program , intern("objects" ), prog_objects ); map_set(globals , intern("program" ), program ); fixScope(globals); diff --git a/parsimonyLibrary/boot.mc b/parsimonyLibrary/boot.mc index b415158..4a757fd 100644 --- a/parsimonyLibrary/boot.mc +++ b/parsimonyLibrary/boot.mc @@ -3,7 +3,7 @@ treeCopy(x) { l = {}; - k = allKeys(x); + k = _keys(x); if (k == null) { return clone(x); } else { diff --git a/parsimonyLibrary/fake-static-classes.mc b/parsimonyLibrary/fake-static-classes.mc index a9fb08b..da6af5b 100644 --- a/parsimonyLibrary/fake-static-classes.mc +++ b/parsimonyLibrary/fake-static-classes.mc @@ -1,7 +1,7 @@ -@(import("parsimonyLibrary/boot.mc")) +@import("parsimonyLibrary/boot.mc") @{ - + checkIdorDecl(x) { (x.identifier == null) ? x.declarators.identifier : x.identifier; } @@ -10,20 +10,25 @@ (x.identifier == null) ? x.text : x.identifier; } - object(x) { + program.objects = null; + + beginObject(x) { + program.objects = {}; + program.objects.elements = {}; + program.objects.last = null; x == null ? x = "oop" : x; program.objects.elements[length(program.objects.elements)] = x; program.objects.last = x; l = {}; enum = `declaration typedef enum {_} type_t;; - enum.semicolon.comment = getComment("\n"); + enum.semicolon.comment = getComment(" "); append(l, enum); obj = `declaration union object;; - obj.semicolon.comment = getComment("\n"); + obj.semicolon.comment = getComment(" "); append(l, treeCopy(obj)); type_obj = `declaration typedef union object *oop;; - type_obj.declarators[0].declarators.identifier = clone(x); - type_obj.semicolon.comment = getComment("\n"); + type_obj.declarators[0].declarators.identifier = x; + type_obj.semicolon.comment = getComment(" "); append(l, treeCopy(type_obj)); l; } @@ -46,6 +51,12 @@ nil; } + everyExternalDeclaration(s) { + if (program.objects) { + addObject() + } + s; + } getObjectMacro() { macro = `ed #define get(PTR, TYPE, FIELD) (_checkType(PTR, TYPE, __FILE__, __LINE__)->TYPE.FIELD) ; @@ -107,7 +118,6 @@ // func.compoundS.expression[0].declarators[0].rhs.paramTypeL[0].typeName.specifiers[0].name.identifier = string(x); // func.compoundS.expression[1].expression.rhs.identifier = string(x); // func.compoundS.expression[1].expression.lhs.lhs.identifier = "new" + string(x); - // for (i in program.structs[x].declarationL) { // if (i == 0) { continue; } // println(program.structs[x].declarationL[i]); @@ -116,7 +126,6 @@ // treeCopy(func); // } - endObject() { l = {}; objectUnion = `declaration union object { type_t type; };; @@ -152,13 +161,13 @@ append(l, treeCopy(func)); append(l, treeCopy(getObjectMacro())); append(l, treeCopy(setObjectMacro())); - for (i in program.unions.last.declarationL) { - if (i == 0) { continue; } - func = getGeneralObject(program.unions.last.declarationL[i].specifiers[0].name.identifier); - append(l, func); - // func = makeGeneralObject(program.unions.last.declarationL[i].specifiers[0].name.identifier); - // append(l, func); - } + // if (i == 0) { continue; } + // func = getGeneralObject(program.unions.last.declarationL[i].specifiers[0].name.identifier); + // append(l, func); + // // func = makeGeneralObject(program.unions.last.declarationL[i].specifiers[0].name.identifier); + // // append(l, func); + // } + program.objects = null; l; } diff --git a/tests-parsimony/objectExample.c b/tests-parsimony/objectExample.c index 1af2221..8c19b49 100644 --- a/tests-parsimony/objectExample.c +++ b/tests-parsimony/objectExample.c @@ -3,26 +3,27 @@ typedef long long int_t; typedef long double flt_t; -@object("OBJECT") + +@beginObject struct Integer { int_t i; }; -@addObject() struct Float { flt_t _value; }; -@addObject() struct String { char *value; }; -@addObject() struct Symbol { char *name; }; -@addObject() -@endObject() +struct foo { + char *name; +}; + +@endObject