Browse Source

Fix code

develop-theo
Theo Souchon 2 years ago
parent
commit
3a5c167051
3 changed files with 38 additions and 38 deletions
  1. +28
    -36
      ccmeta.leg
  2. +9
    -0
      object.c
  3. +1
    -2
      tests-parsimony/objectExample.c

+ 28
- 36
ccmeta.leg View File

@ -125,10 +125,10 @@ oop union_last= 0;
DO_PROTOS() _DO(__proto__) _DO(__name__) _DO(__default__) _DO(__arguments__) \ 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(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(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(try) _DO(catch) _DO(finally) _DO(exception) \
_DO(__line__) _DO(__file__) \ _DO(__line__) _DO(__file__) \
_DO(comment) \
_DO(comment) \
_DO(text) _DO(ifTok) _DO(lparen) _DO(rparen) _DO(elseTok) _DO(identifier) _DO(semicolon) \ _DO(text) _DO(ifTok) _DO(lparen) _DO(rparen) _DO(elseTok) _DO(identifier) _DO(semicolon) \
_DO(whileTok) \ _DO(whileTok) \
_DO(doTok) _DO(forTok) _DO(initExpr) _DO(condExpr) _DO(incrExpr) _DO(firstSemi) _DO(secondSemi) \ _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, declarationL_symbol,declarationList);
map_set(object, rightCurly_symbol, rightCurly); map_set(object, rightCurly_symbol, rightCurly);
map_set(object, attribute2_symbol, attributeSpecifier2); 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); map_set(prog_unions, intern("last" ), object);
} else { } 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); map_set(program, intern("last"), object);
return object; return object;
@ -1268,11 +1268,12 @@ oop getSyntax(int n, oop func)
return getSyntaxId(n, key); return getSyntaxId(n, key);
} }
oop newCall(oop func, oop args)
oop newCall(oop func, oop args, oop keys)
{ {
oop call = newObject(Call_proto); oop call = newObject(Call_proto);
map_set(call, func_symbol, func); map_set(call, func_symbol, func);
map_set(call, args_symbol, args); map_set(call, args_symbol, args);
map_set(call, keys_symbol, keys);
return call; return call;
} }
@ -2202,8 +2203,8 @@ 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) }
| { 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 | META_LPAREN ( i:meta_exp ) META_RPAREN
) { $$= eval(globals, i) } ) { $$= 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 a:meta_argumentList { i = newInvoke(i, s, a) }
| META_DOT s:META_IDENT !meta_assignOp { i = newGetMap(GetMember_proto, i, s) } | 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) } | 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_PLUSPLUS { i = newPostIncrement(i) }
| META_MINUSMINUS { i = newPostDecrement(i) } | META_MINUSMINUS { i = newPostDecrement(i) }
) * { $$= i } ) * { $$= i }
@ -2360,14 +2361,12 @@ meta_paramList = META_LPAREN m:meta_makeMap
) ? ) ?
META_RPAREN { $$= m } 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) } meta_value = n:META_FLOAT { $$= newFloat(n) }
| n:meta_integer { $$= newInteger(n) } | n:meta_integer { $$= newInteger(n) }
@ -3149,28 +3148,21 @@ oop eval(oop scope, oop ast)
printBacktrace(ast); printBacktrace(ast);
exit(1); exit(1);
} }
oop keys = map_get(ast, keys_symbol);
oop args = map_get(ast, args_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<map_size(args); i++ ) {
oop varName = map_get(map_get(args, makeInteger(i)), intern("lhs"));
oop val = map_get(args, makeInteger(i));
if (varName != null ) {
map_set(nameArgs, varName , val);
} else {
map_set(newArgs , makeInteger(count++), val);
}
if (keys != null && map_size(keys) > 0) {
oop newArgs = makeMap();
for (int i = 0; i<map_size(args); i++) {
if (map_get(keys, makeInteger(i)) == null) map_append(newArgs, map_get(args, makeInteger(i)));
} }
for (int k = 0; k<map_size(nameArgs); k++) {
oop currentKey = map_get(map_keys(nameArgs), makeInteger(k));
for (int i = 0; i<map_size(paramFunc); i++) {
oop oopI = makeInteger(i);
if (map_get(paramFunc, oopI) == currentKey) {
map_set(newArgs, oopI, map_get(nameArgs, currentKey));
}
oop paramFunc = get(func, Function, param);
oop idKeys = map_keys(keys);
for (int k = 0; k<map_size(paramFunc); k++) {
oop oopK = makeInteger(k);
for (int i = 0; i<map_size(keys); i++) {
oop oopI = makeInteger(i);
if (map_get(keys, map_get(idKeys, oopI)) == map_get(paramFunc, oopK))
map_set(newArgs, oopK, map_get(args, map_get(idKeys, oopI)));
} }
} }
args = newArgs; args = newArgs;

+ 9
- 0
object.c View File

@ -546,6 +546,15 @@ oop map_append(oop map, oop value)
return map_set(map, makeInteger(map_size(map)), value); return map_set(map, makeInteger(map_size(map)), value);
} }
oop map_pop(oop map)
{ assert(map_isArray(map));
size_t size = get(map, Map, size);
if (size == 0) return null;
oop val = get(map, Map, elements)[--size].value;
set(map, Map, size, size);
return val;
}
oop makeArrayFromElement(oop elem, int repeat) oop makeArrayFromElement(oop elem, int repeat)
{ {
oop array= makeMapCapacity(repeat); oop array= makeMapCapacity(repeat);

+ 1
- 2
tests-parsimony/objectExample.c View File

@ -3,8 +3,7 @@
typedef long long int_t; typedef long long int_t;
typedef long double flt_t; typedef long double flt_t;
@beginObject(typeName = "typeName", objectName = "objectName")
@beginObject(typeName:"typeName", objectName:"objectName")
struct Integer { struct Integer {
int_t i; int_t i;

Loading…
Cancel
Save