@ -1343,11 +1343,19 @@ oop everyExternalDeclaration(oop s)
return s;
}
oop ensureId (oop s)
oop ensure(oop s, int id )
{
if (!is(Map, s) || map_get(s, __proto___symbol) != C_id_proto) {
fprintf(stderr, "Meta expression did not return required Id\n");
exit(1);
if (is(Map, s)) {
oop protoSymbol = map_get(s, __proto___symbol);
// int protoNumber = get(map_get(protoSymbol, __name___symbol), Symbol, prototype);
switch(id) {
case t_C_id: {
if (map_get(protoSymbol, __name___symbol) != map_get(C_id_proto, __name___symbol)) { // map_get for tree copy because __name__ : C_id != __name__ : C_id
fprintf(stderr, "Meta expression did not return required Id\n");
exit(1);
}
}
}
}
return s;
}
@ -1371,12 +1379,13 @@ error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 }
idOpt = id | {$$=newNullObject()}
id = <ID> { $$= new_C_id(yytext) } -
| META_AT META_LPAREN m:meta_exp META_RPAREN { $$= ensureId (eval(globals,m)) } -
id = <ID> { $$= new_C_id(yytext) } -
| META_AT META_LPAREN m:meta_exp META_RPAREN { $$= ensure(eval(globals,m), t_C_id ) } -
ID = <NAME> &{ !is_C_keyword(yytext) }
ID = <NAME> &{ !is_C_keyword(yytext) }
name = <NAME> { $$= new_C_id(yytext) } -
name = <NAME> { $$= new_C_id(yytext) } -
NAME = IDFIRST IDREST*
IDFIRST = [a-zA-Z_] | universalCharacterName | '$' &{gnu}
@ -1402,7 +1411,7 @@ hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hex
constant = characterConstant
| floatingConstant
| integerConstant
| META_AT m:mvalue
| META_AT m:mvalue
@ -2210,21 +2219,20 @@ _FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float128"
# the semicolon has to be explicit with no space eaten afterwards to prevent the
# input buffer from moving past it before redirecting input from the imported file
metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) ; $$= 0 }
| m:mvalue { map_append(outputProgram, m); $$= null }
| META_LCB s:mstmts { map_append(outputProgram, s); $$= null }
metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) ; $$= 0 }
| m:mvalue { map_append(outputProgram, m) ; $$= null }
| META_LCB s:mstmts { map_append(outputProgram, s) ; $$= null }
)
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 }
mvalue = ( i:META_IDENT { i= newGetVariable(i) } ( a:meta_argumentList { oop k = map_pop(a); i = newCall(i, a, k) } # call a function with argument
| { i = is(Function, eval(globals, i)) == 1 ? newCall(i, makeMap(), null) : i } # without
)
| META_LPAREN ( i:meta_exp ) META_RPAREN
) { $$= eval(globals, i) }
mstmts = ( s:eval_stmt )* META_RCB { $$= s } # return the last stmt
mstmts = ( s:eval_stmt )* META_RCB { $$= s }
eval_stmt = s:meta_stmt { $$= eval(globals, s) }
eval_stmt = s:meta_stmt { $$= eval(globals, s) } # evaluate each statement at the time
meta_stmt = s:meta_block { $$= s }
| META_SEMICOLON { $$= null }
@ -2439,15 +2447,15 @@ META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > { $$= make
#--------------------------------------------- Meta operator ----------------------------------------------#
MO_OPERATION = META_BACKTICK ( MO_INITIALIZER i:initializer { $$= newUnary(Quote_proto ,i) }
| MO_CONSTANT c:constant { $$= newUnary(Quote_proto ,c) }
| MO_STATEMENT c:statement { $$= newUnary(Quote_proto ,c ) }
| MO_INTEGER i:integerConstant { $$= newUnary(Quote_proto ,i) }
| MO_DECLARATION i:declaration { $$= newUnary(Quote_proto ,i ) }
| MO_STRING i:stringLiteral { $$= newUnary(Quote_proto ,i ) }
| MO_FUN i:functionDefinition { $$= newUnary(Quote_proto ,i ) }
| MO_ED i:externalDeclaration { $$= newUnary(Quote_proto ,i ) }
| MO_EXPRESSION i:expression { $$= newUnary(Quote_proto ,i ) }
MO_OPERATION = META_BACKTICK ( MO_INITIALIZER i:initializer { $$= newUnary(Quote_proto, i) }
| MO_CONSTANT c:constant { $$= newUnary(Quote_proto, c) }
| MO_STATEMENT s:statement { $$= newUnary(Quote_proto, s ) }
| MO_INTEGER i:integerConstant { $$= newUnary(Quote_proto, i) }
| MO_DECLARATION d:declaration { $$= newUnary(Quote_proto, d ) }
| MO_STRING s:stringLiteral { $$= newUnary(Quote_proto, s ) }
| MO_FUN f:functionDefinition { $$= newUnary(Quote_proto, f ) }
| MO_ED e:externalDeclaration { $$= newUnary(Quote_proto, e ) }
| MO_EXPRESSION e:expression { $$= newUnary(Quote_proto, e ) }
)
MO_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] --
@ -4711,7 +4719,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("_keys" ), makeFunction(prim_all_keys, intern("_keys" ), 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));