Quellcode durchsuchen

Simplification + functions without parenthesis

develop-theo
Theo Souchon vor 2 Jahren
Ursprung
Commit
d984397ce8
4 geänderte Dateien mit 50 neuen und 33 gelöschten Zeilen
  1. +17
    -10
      ccmeta.leg
  2. +1
    -1
      parsimonyLibrary/boot.mc
  3. +25
    -16
      parsimonyLibrary/fake-static-classes.mc
  4. +7
    -6
      tests-parsimony/objectExample.c

+ 17
- 10
ccmeta.leg Datei anzeigen

@ -1332,6 +1332,15 @@ language printLang = C;
oop outputProgram= 0; 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 # yylval == 0 => end of input file while in META mode only
start = m:metaCatch { yylval= m } start = m:metaCatch { yylval= m }
| s:externalDeclaration { yylval= s }
| s:externalDeclaration { yylval= everyExternalDeclaration(s) }
error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 } 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 } | 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 | META_LPAREN ( i:meta_exp ) META_RPAREN
) { $$= eval(globals, i) } ) { $$= eval(globals, i) }
@ -3451,6 +3461,9 @@ oop eval(oop scope, oop ast)
DO_C_PROTOS(); DO_C_PROTOS();
break; break;
#undef _DO #undef _DO
case t_Undefined:
case t_Function:
break;
} }
printf("EVAL "); printf("EVAL ");
println(ast); 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("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("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("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("length" ), makeFunction(prim_length, intern("length" ), null, null, globals, null));
map_set(globals, intern("print" ), makeFunction(prim_print, intern("print" ), 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(); enum_last = makeMap();
struct_last = makeMap(); struct_last = makeMap();
union_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_enums , intern("last" ), enum_last );
map_set(prog_structs , intern("last" ), struct_last ); map_set(prog_structs , intern("last" ), struct_last );
map_set(prog_unions , intern("last" ), union_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("structs" ), prog_structs );
map_set(program , intern("unions" ), prog_unions ); map_set(program , intern("unions" ), prog_unions );
map_set(program , intern("enums" ), prog_enums ); map_set(program , intern("enums" ), prog_enums );
map_set(program , intern("objects" ), prog_objects );
map_set(globals , intern("program" ), program ); map_set(globals , intern("program" ), program );
fixScope(globals); fixScope(globals);

+ 1
- 1
parsimonyLibrary/boot.mc Datei anzeigen

@ -3,7 +3,7 @@
treeCopy(x) { treeCopy(x) {
l = {}; l = {};
k = allKeys(x);
k = _keys(x);
if (k == null) { if (k == null) {
return clone(x); return clone(x);
} else { } else {

+ 25
- 16
parsimonyLibrary/fake-static-classes.mc Datei anzeigen

@ -1,7 +1,7 @@
@(import("parsimonyLibrary/boot.mc"))
@import("parsimonyLibrary/boot.mc")
@{ @{
checkIdorDecl(x) { checkIdorDecl(x) {
(x.identifier == null) ? x.declarators.identifier : x.identifier; (x.identifier == null) ? x.declarators.identifier : x.identifier;
} }
@ -10,20 +10,25 @@
(x.identifier == null) ? x.text : x.identifier; (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; x == null ? x = "oop" : x;
program.objects.elements[length(program.objects.elements)] = x; program.objects.elements[length(program.objects.elements)] = x;
program.objects.last = x; program.objects.last = x;
l = {}; l = {};
enum = `declaration typedef enum {_} type_t;; enum = `declaration typedef enum {_} type_t;;
enum.semicolon.comment = getComment("\n");
enum.semicolon.comment = getComment(" ");
append(l, enum); append(l, enum);
obj = `declaration union object;; obj = `declaration union object;;
obj.semicolon.comment = getComment("\n");
obj.semicolon.comment = getComment(" ");
append(l, treeCopy(obj)); append(l, treeCopy(obj));
type_obj = `declaration typedef union object *oop;; 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)); append(l, treeCopy(type_obj));
l; l;
} }
@ -46,6 +51,12 @@
nil; nil;
} }
everyExternalDeclaration(s) {
if (program.objects) {
addObject()
}
s;
}
getObjectMacro() { getObjectMacro() {
macro = `ed #define get(PTR, TYPE, FIELD) (_checkType(PTR, TYPE, __FILE__, __LINE__)->TYPE.FIELD) 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[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.rhs.identifier = string(x);
// func.compoundS.expression[1].expression.lhs.lhs.identifier = "new" + string(x); // func.compoundS.expression[1].expression.lhs.lhs.identifier = "new" + string(x);
// for (i in program.structs[x].declarationL) { // for (i in program.structs[x].declarationL) {
// if (i == 0) { continue; } // if (i == 0) { continue; }
// println(program.structs[x].declarationL[i]); // println(program.structs[x].declarationL[i]);
@ -116,7 +126,6 @@
// treeCopy(func); // treeCopy(func);
// } // }
endObject() { endObject() {
l = {}; l = {};
objectUnion = `declaration union object { type_t type; };; objectUnion = `declaration union object { type_t type; };;
@ -152,13 +161,13 @@
append(l, treeCopy(func)); append(l, treeCopy(func));
append(l, treeCopy(getObjectMacro())); append(l, treeCopy(getObjectMacro()));
append(l, treeCopy(setObjectMacro())); 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; l;
} }

+ 7
- 6
tests-parsimony/objectExample.c Datei anzeigen

@ -3,26 +3,27 @@
typedef long long int_t; typedef long long int_t;
typedef long double flt_t; typedef long double flt_t;
@object("OBJECT")
@beginObject
struct Integer { struct Integer {
int_t i; int_t i;
}; };
@addObject()
struct Float { struct Float {
flt_t _value; flt_t _value;
}; };
@addObject()
struct String { struct String {
char *value; char *value;
}; };
@addObject()
struct Symbol { struct Symbol {
char *name; char *name;
}; };
@addObject()
@endObject()
struct foo {
char *name;
};
@endObject

Laden…
Abbrechen
Speichern