From 3a5c16705171b978cf0cb8578969f8ec17c536fb Mon Sep 17 00:00:00 2001 From: Theo Souchon Date: Mon, 12 Dec 2022 16:40:38 +0900 Subject: [PATCH] Fix code --- ccmeta.leg | 64 +++++++++++++++------------------ object.c | 9 +++++ tests-parsimony/objectExample.c | 3 +- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/ccmeta.leg b/ccmeta.leg index a925522..6c8de2a 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -125,10 +125,10 @@ oop union_last= 0; DO_PROTOS() _DO(__proto__) _DO(__name__) _DO(__default__) _DO(__arguments__) \ _DO(name) _DO(body) _DO(param) _DO(key) _DO(value) _DO(condition) _DO(consequent) _DO(alternate) \ _DO(lhs) _DO(rhs) _DO(scope) _DO(args) _DO(expression) _DO(labels) _DO(statements) _DO(initialise) \ - _DO(update) _DO(this) _DO(fixed) _DO(operator) _DO(map) _DO(func) \ + _DO(update) _DO(this) _DO(fixed) _DO(operator) _DO(map) _DO(func) _DO(keys) \ _DO(try) _DO(catch) _DO(finally) _DO(exception) \ _DO(__line__) _DO(__file__) \ - _DO(comment) \ + _DO(comment) \ _DO(text) _DO(ifTok) _DO(lparen) _DO(rparen) _DO(elseTok) _DO(identifier) _DO(semicolon) \ _DO(whileTok) \ _DO(doTok) _DO(forTok) _DO(initExpr) _DO(condExpr) _DO(incrExpr) _DO(firstSemi) _DO(secondSemi) \ @@ -858,12 +858,12 @@ oop new_C_structSpec(oop structTok, oop attributeSpecifier1, oop id, oop leftCur map_set(object, declarationL_symbol,declarationList); map_set(object, rightCurly_symbol, rightCurly); map_set(object, attribute2_symbol, attributeSpecifier2); - if (strcmp(get(map_get(structTok, text_symbol), String, value), "union") == 0) { - map_set(prog_unions, map_get(id, identifier_symbol), object); + if (strcmp(get(map_get(structTok, text_symbol), String, value), "union") == 0 ) { + if (id != null) map_set(prog_unions, map_get(id, identifier_symbol), object); map_set(prog_unions, intern("last" ), object); } else { - map_set(prog_structs, map_get(id, identifier_symbol), object); - map_set(prog_structs, intern("last" ), object); + if (id != null) map_set(prog_structs, map_get(id, identifier_symbol), object); + map_set(prog_structs, intern("last" ), object); } map_set(program, intern("last"), object); return object; @@ -1268,11 +1268,12 @@ oop getSyntax(int n, oop func) return getSyntaxId(n, key); } -oop newCall(oop func, oop args) +oop newCall(oop func, oop args, oop keys) { oop call = newObject(Call_proto); map_set(call, func_symbol, func); map_set(call, args_symbol, args); + map_set(call, keys_symbol, keys); return call; } @@ -2202,8 +2203,8 @@ 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) } - | { i = is(Function, eval(globals, i)) == 1 ? apply(globals, globals, eval(globals, i), makeMap(), i) : i } +mvalue = ( i:META_IDENT { i= newGetVariable(i) } ( a:meta_argumentList { oop k = map_pop(a); i = newCall(i, a, k) } + | { i = is(Function, eval(globals, i)) == 1 ? newCall(i, makeMap(), null) : i } ) | META_LPAREN ( i:meta_exp ) META_RPAREN ) { $$= eval(globals, i) } @@ -2347,7 +2348,7 @@ meta_postfix = i:meta_value ( META_DOT s:META_IDENT a:meta_argumentList { i = newInvoke(i, s, a) } | META_DOT s:META_IDENT !meta_assignOp { i = newGetMap(GetMember_proto, i, s) } | META_LBRAC p:meta_exp META_RBRAC !meta_assignOp { i = newGetMap(GetIndex_proto, i, p) } - | a:meta_argumentList { i = (null != getSyntax(1, i)) ? apply(globals, globals, getSyntax(1, i), a, i) : newCall(i, a) } + | a:meta_argumentList { oop k = map_pop(a); i = newCall(i, a, k) } | META_PLUSPLUS { i = newPostIncrement(i) } | META_MINUSMINUS { i = newPostDecrement(i) } ) * { $$= i } @@ -2360,14 +2361,12 @@ meta_paramList = META_LPAREN m:meta_makeMap ) ? META_RPAREN { $$= m } -meta_argumentList = META_LPAREN m:meta_makeMap - ( e:meta_exp { map_append(m, e) } - ( META_COMMA e:meta_exp { map_append(m, e) } +meta_argumentList = META_LPAREN m:meta_makeMap n:meta_makeMap + ( (i:META_IDENT META_COLON { map_set(n, makeInteger(map_size(m)), i) })? e:meta_exp { map_append(m, e) } + ( META_COMMA (i:META_IDENT META_COLON { map_set(n, makeInteger(map_size(m)), i) })? e:meta_exp { map_append(m, e) } ) * ) ? - META_RPAREN { $$= m } - - + META_RPAREN { map_append(m, n); $$ = m } meta_value = n:META_FLOAT { $$= newFloat(n) } | n:meta_integer { $$= newInteger(n) } @@ -3149,28 +3148,21 @@ oop eval(oop scope, oop ast) printBacktrace(ast); exit(1); } + oop keys = map_get(ast, keys_symbol); oop args = map_get(ast, args_symbol); - oop paramFunc = get(func, Function, param); - if ( paramFunc != null ) { - oop nameArgs = makeMap(); - oop newArgs = makeMap(); - int count = 0; - for (int i = 0; i 0) { + oop newArgs = makeMap(); + for (int i = 0; i