diff --git a/ccmeta.leg b/ccmeta.leg index 9900fca..80069df 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -1298,17 +1298,12 @@ language printLang = C; oop outputProgram= 0; oop mapFunction(oop func, oop args) { - oop mapValue = makeMap(); - int size = map_size(eval(globals, args)); + int size = map_size(args); for(int i = 0; i < size; i++) { - oop oopInt = makeInteger(i); - oop obj = map_get(map_get(args, value_symbol), oopInt); - oop test = makeMap(); - map_append(test, obj); - obj = newCall(func, test); - map_append(mapValue, obj); + oop singleValue = makeMap(); + map_append(singleValue, map_get(args, makeInteger(i))); + map_set(args, makeInteger(i), eval(globals, newCall(func, singleValue))); } - map_set(args, value_symbol, mapValue); return args; } @@ -2175,22 +2170,19 @@ metaCatch = META_AT ( m:mvalue { map_append ) -mvalue = { listBegin() } ( i:META_IDENT { listAppend(eval(globals, newGetVariable(i))) } - | META_LPAREN ( i:MO_OPERATION - | i:meta_block - | i:meta_exp - ) META_RPAREN { listAppend(eval(globals, i)) } - ) { $$ = listEnd() } +mvalue = i:META_IDENT { $$ = eval(globals, newGetVariable(i)) } + | META_LPAREN ( i:MO_OPERATION + #| i:meta_block usefull ? + | i:meta_exp + ) META_RPAREN { $$ = eval(globals, i) } -mstmts = { listBegin() } ( s:meta_stmt { eval(globals, s) } - | a:meta_append { eval(globals, a) } - )* - ( (META_NIL META_SEMICOLON )? META_RCB { listEnd(); $$ = null } - | META_DAT META_SEMICOLON META_RCB { $$ = listEnd() } - ) +mstmts = { listBegin() } ( s:meta_stmt { eval(globals, s) } )* meta_endSTMTS +meta_endSTMTS = (META_NIL META_SEMICOLON )? META_RCB { listEnd(); $$ = null } + | META_DAT META_SEMICOLON META_RCB { $$ = listEnd() } meta_stmt = s:meta_block { $$ = s } + | a:meta_append { $$ = a } | META_SEMICOLON { $$ = null } | l:META_IDENT p:meta_paramList e:meta_block { $$ = newFunc(l, p, e, null) } | META_IF META_LPAREN c:meta_exp META_RPAREN t:meta_stmt META_ELSE f:meta_stmt { $$ = newIf(c, t, f ) } @@ -2210,7 +2202,7 @@ meta_stmt = s:meta_block meta_append = META_DAT META_DOT META_APPEND META_LPAREN s:meta_exp META_RPAREN META_SEMICOLON { $$ = newUnary(Append_proto, s) } -meta_block = META_LCB m:meta_makeMap +meta_block = META_LCB m:meta_makeMap ( s:meta_stmt { map_append(m, s) } ) * ( s:meta_exp { map_append(m, s) } @@ -2333,7 +2325,7 @@ meta_postfix = i:meta_value | META_MINUSMINUS { i = newPostDecrement(i) } ) * { $$ = i } -meta_funcMap = META_LPAREN i:meta_value META_COMMA e:meta_exp META_RPAREN { mapFunction(i, e) } +meta_funcMap = META_LPAREN i:meta_value META_COMMA e:meta_exp META_RPAREN { $$ = mapFunction(i, eval(globals, e)) } meta_paramList = META_LPAREN m:meta_makeMap ( i:META_IDENT { map_append(m, i) } @@ -2693,7 +2685,6 @@ oop mulOperation(oop lhs, oop rhs) CASE(Float , Float ): return makeFloat(get(lhs, Float, _value) * get(rhs, Float, _value)); CASE(String , Integer): return string_mul(lhs, rhs); CASE(Integer, String ): return string_mul(rhs, lhs); - CASE(Undefined, Integer): return makeInteger(getInteger(rhs)); } runtimeError("multiplication between two incompatible types"); return NULL; // to prevent: control may reach end of non-void function diff --git a/testPars.sh b/testPars.sh new file mode 100755 index 0000000..d48ab90 --- /dev/null +++ b/testPars.sh @@ -0,0 +1,28 @@ +make +echo "\n" +echo "\n" +./ccmeta tests-parsimony/001.c +echo "\n" +echo "\n" +./ccmeta tests-parsimony/002.c +echo "\n" +echo "\n" +./ccmeta tests-parsimony/003.c +echo "\n" +echo "\n" +./ccmeta tests-parsimony/004.c +echo "\n" +echo "\n" +./ccmeta tests-parsimony/005.c +echo "\n" +echo "\n" +./ccmeta tests-parsimony/006.c +echo "\n" +echo "\n" +./ccmeta tests-parsimony/007.c +echo "\n" +echo "\n" +./ccmeta tests-parsimony/map.c +echo "\n" +echo "\n" +echo "ok !" \ No newline at end of file diff --git a/tests-parsimony/map.c b/tests-parsimony/map.c index e3325cc..abbb090 100644 --- a/tests-parsimony/map.c +++ b/tests-parsimony/map.c @@ -1,8 +1,16 @@ +enum foo { x, y, z }; + @{ - test(foo) { - foo * 10; + toChar(foo) { + "\""+foo+"\""; + } + square(foo) { + foo * foo; } + c = ["earth", "sky", "water"]; } -@{print(map(test, [1, 2, 3]));} +@{print(map(square, [100, 2, 3]));} + +@{print(map(toChar, c));}