|
|
@ -37,8 +37,8 @@ |
|
|
|
|
|
|
|
#define DO_C_PROTOS() \ |
|
|
|
_DO(Comment) _DO(Token) \ |
|
|
|
_DO(C_declaration) _DO(C_string) \ |
|
|
|
_DO(C_if) _DO(C_int) _DO(C_float) _DO(C_char) _DO(C_id) _DO(C_while) _DO(C_do) _DO(C_for) \ |
|
|
|
_DO(C_declaration) _DO(C_stringLiteral) \ |
|
|
|
_DO(C_if) _DO(C_int) _DO(C_float) _DO(C_string) _DO(C_char) _DO(C_id) _DO(C_while) _DO(C_do) _DO(C_for) \ |
|
|
|
_DO(C_binary) _DO(C_initializer) _DO(C_range) _DO(C_conditional) _DO(C_index) \ |
|
|
|
_DO(C_designation) _DO(C_attribution) _DO(C_deref) _DO(C_block) _DO(C_call) _DO(C_subexpr) \ |
|
|
|
_DO(C_array) _DO(C_parameter) _DO(C_typeOf) _DO(C_unary) _DO(C_prefix) _DO(C_alignOf) \ |
|
|
@ -104,6 +104,8 @@ jb_record *jbs= NULL; |
|
|
|
|
|
|
|
// this is the global scope |
|
|
|
oop globals= 0; |
|
|
|
oop properties= 0; |
|
|
|
oop prop_enums= 0; |
|
|
|
|
|
|
|
#define DO_SYMBOLS() \ |
|
|
|
DO_PROTOS() _DO(__proto__) _DO(__name__) _DO(__default__) _DO(__arguments__) \ |
|
|
@ -455,12 +457,18 @@ char *unescape(char *s) |
|
|
|
return t; |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_string(oop str) { |
|
|
|
oop object = newObject(C_string_proto); |
|
|
|
oop new_C_stringLiteral(oop str) { |
|
|
|
oop object = newObject(C_stringLiteral_proto); |
|
|
|
map_set(object, text_symbol, str); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_string(char *s) { |
|
|
|
oop object = newObject(C_string_proto); |
|
|
|
map_set(object, value_symbol, makeString(s)); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_char(char *s) { |
|
|
|
oop object = newObject(C_char_proto); |
|
|
|
map_set(object, value_symbol, makeString(s)); |
|
|
@ -854,6 +862,9 @@ oop new_C_enumSpec(oop enumTok, oop id, oop leftCurly, oop enumeratorList, oop r |
|
|
|
map_set(object, leftCurly_symbol, leftCurly); |
|
|
|
map_set(object, enumList_symbol, enumeratorList); |
|
|
|
map_set(object, rightCurly_symbol, rightCurly); |
|
|
|
if (id != null) { |
|
|
|
map_set(prop_enums, map_get(id, identifier_symbol), object); |
|
|
|
} |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
@ -1297,7 +1308,89 @@ language printLang = C; |
|
|
|
|
|
|
|
oop outputProgram= 0; |
|
|
|
|
|
|
|
oop mapFunction(oop func, oop args) { |
|
|
|
oop searchType(char *type) |
|
|
|
{ |
|
|
|
ssize_t pos = map_intern_search(symbol_table, type ); |
|
|
|
if (pos >= 0) return get(symbol_table, Map, elements)[pos].key; |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
oop findMap(oop map) |
|
|
|
{ |
|
|
|
oop symbol_name = map_get(map, identifier_symbol); |
|
|
|
size_t size = map_size(properties); |
|
|
|
oop retType, ret; |
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
retType = map_get(map_keys(properties), makeInteger(i)); |
|
|
|
retType = map_get(properties, retType); |
|
|
|
size_t sizeType = map_size(retType); |
|
|
|
for (int k = 0; k < sizeType; k++) { |
|
|
|
ret = map_get(map_keys(retType), makeInteger(k)); |
|
|
|
if (ret == symbol_name) |
|
|
|
return map_get(retType, ret); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
oop selectFunction(oop type, oop map) |
|
|
|
{ |
|
|
|
oop enumList; |
|
|
|
oop filter = searchType(type->String.value); |
|
|
|
if (filter == null) |
|
|
|
return null; |
|
|
|
oop ret = findMap(map); |
|
|
|
oop name_Type = map_get(map_get(ret, __proto___symbol), __name___symbol); |
|
|
|
int number_type = get(name_Type, Symbol, prototype); |
|
|
|
switch (number_type) { |
|
|
|
case t_C_enumSpec : |
|
|
|
enumList = map_get(ret, enumList_symbol); |
|
|
|
size_t sizeType = map_size(enumList); |
|
|
|
for (int i=0; i<sizeType; i++) { |
|
|
|
oop singleton = map_get(enumList, makeInteger(i)); |
|
|
|
oop singletonType = map_get(map_get(singleton, __proto___symbol), __name___symbol); |
|
|
|
if (filter == singletonType) |
|
|
|
println(singletonType); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
printf("not find for number : %i\n", number_type); |
|
|
|
return null; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop rejectFunction(oop type, oop map) |
|
|
|
{ |
|
|
|
oop enumList; |
|
|
|
oop filter = searchType(type->String.value); |
|
|
|
if (filter == null) |
|
|
|
return null; |
|
|
|
oop ret = findMap(map); |
|
|
|
oop name_Type = map_get(map_get(ret, __proto___symbol), __name___symbol); |
|
|
|
int number_type = get(name_Type, Symbol, prototype); |
|
|
|
switch (number_type) { |
|
|
|
case t_C_enumSpec : |
|
|
|
enumList = map_get(ret, enumList_symbol); |
|
|
|
size_t sizeType = map_size(enumList); |
|
|
|
for (int i=0; i<sizeType; i++) { |
|
|
|
oop singleton = map_get(enumList, makeInteger(i)); |
|
|
|
oop singletonType = map_get(map_get(singleton, __proto___symbol), __name___symbol); |
|
|
|
if (filter != singletonType) |
|
|
|
println(singletonType); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
printf("not find for number : %i\n", number_type); |
|
|
|
return null; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop mapFunction(oop func, oop args) |
|
|
|
{ |
|
|
|
int size = map_size(args); |
|
|
|
for(int i = 0; i < size; i++) { |
|
|
|
oop singleValue = makeMap(); |
|
|
@ -1441,10 +1534,10 @@ hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ |
|
|
|
|
|
|
|
stringLiteral = { listBegin(); } |
|
|
|
( s:stringLiteralPart { listAppend(s) } |
|
|
|
)+ { $$= new_C_string(listEnd()) } |
|
|
|
)+ { $$= new_C_stringLiteral(listEnd()) } |
|
|
|
|
|
|
|
stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_char(yytext) } - |
|
|
|
| < 'L''"' sCharSequence '"' > { $$= new_C_char(yytext) } - |
|
|
|
stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_string(yytext) } - |
|
|
|
| < 'L''"' sCharSequence '"' > { $$= new_C_string(yytext) } - |
|
|
|
|
|
|
|
sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #" |
|
|
|
|
|
|
@ -2211,6 +2304,8 @@ meta_block = META_LCB m:meta_makeMap |
|
|
|
|
|
|
|
meta_exp = META_VAR l:meta_ident META_ASSIGN e:meta_exp { $$ = newDeclaration(l, e) } |
|
|
|
| META_FUNCMAP m:meta_funcMap {$$ = m} |
|
|
|
| META_FUNCSELECT s:meta_funcSelect {$$ = s } |
|
|
|
| META_FUNCREJECT s:meta_funcReject {$$ = s } |
|
|
|
# | META_SYNTAX l:META_IDENT p:meta_paramList q:META_IDENT e:meta_block { $$ = (map_append(p, q), newFunc(l, p, e, makeInteger(2))) } |
|
|
|
# | META_SYNTAX p:meta_paramList q:META_IDENT e:meta_block { $$ = (map_append(p, q), newFunc(null, p, e, makeInteger(2))) } |
|
|
|
# | META_SYNTAX l:META_IDENT p:meta_paramList e:meta_block { $$ = newFunc(l, p, e, makeInteger(1)) } |
|
|
@ -2221,6 +2316,10 @@ meta_exp = META_VAR l:meta_ident META_ASSIGN e:meta_exp |
|
|
|
| l:meta_syntax2 a:meta_argumentList s:meta_block { $$ = (map_append(a, s), apply(globals, globals, l, a, a)) } |
|
|
|
| c:meta_cond { $$ = c } |
|
|
|
|
|
|
|
meta_funcSelect = META_LPAREN t:tmpSelectString META_COMMA i:idOpt META_RPAREN { $$ = selectFunction(t, i) } |
|
|
|
meta_funcReject = META_LPAREN t:tmpSelectString META_COMMA i:idOpt META_RPAREN { $$ = rejectFunction(t, i) } |
|
|
|
|
|
|
|
tmpSelectString = < [a-zA-Z_]* > { $$ = makeString(unescape(yytext))} |
|
|
|
|
|
|
|
meta_ident = l:META_IDENT { $$ = l } |
|
|
|
# | META_AT n:meta_prefix { $$ = newUnary(Unquote_proto, n) } |
|
|
@ -2407,21 +2506,25 @@ MO_OPERATION = META_BACKTICK ( MO_INITIALIZER i:initializer { $$ = newU |
|
|
|
| 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) } |
|
|
|
) |
|
|
|
|
|
|
|
META_OPERATORS = MO_INITIALIZER | MO_CONSTANT | MO_STATEMENT | MO_INTEGER | MO_DECLARATION |
|
|
|
META_OPERATORS = MO_INITIALIZER | MO_CONSTANT | MO_STATEMENT | MO_INTEGER | MO_DECLARATION | MO_STRING |
|
|
|
|
|
|
|
MO_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] -- |
|
|
|
MO_CONSTANT = 'constant' ![(a-zA-Z0-9_] -- |
|
|
|
MO_STATEMENT = 'statement' ![(a-zA-Z0-9_] -- |
|
|
|
MO_INTEGER = 'integer' ![(a-zA-Z0-9_] -- |
|
|
|
MO_DECLARATION = 'declaration' ![(a-zA-Z0-9_] -- |
|
|
|
MO_STRING = 'string' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
|
|
|
|
|
|
############################ |
|
|
|
|
|
|
|
META_NIL = 'nil' ![a-zA-Z0-9_] -- |
|
|
|
META_FUNCMAP = 'map' ![a-zA-Z0-9_] -- |
|
|
|
META_FUNCSELECT = 'select' ![a-zA-Z0-9_] -- |
|
|
|
META_FUNCREJECT = 'reject' ![a-zA-Z0-9_] -- |
|
|
|
META_DAT = '@@' ![a-zA-Z0-9_] -- |
|
|
|
META_APPEND = 'append' ![a-zA-Z0-9_] -- |
|
|
|
|
|
|
@ -3685,9 +3788,12 @@ void outputNode(oop node) |
|
|
|
case t_C_float: |
|
|
|
outputNode(map_get(node, text_symbol)); |
|
|
|
break; |
|
|
|
case t_C_string: |
|
|
|
case t_C_stringLiteral: |
|
|
|
outputNode(map_get(node, text_symbol)); |
|
|
|
break; |
|
|
|
case t_C_string: |
|
|
|
outputNode(map_get(node, value_symbol)); |
|
|
|
break; |
|
|
|
case t_C_char: |
|
|
|
outputNode(map_get(node, value_symbol)); |
|
|
|
break; |
|
|
@ -4061,7 +4167,7 @@ void outputTree(oop node, int depth) |
|
|
|
CASE(float) |
|
|
|
OUT(text); |
|
|
|
break; |
|
|
|
CASE(string) |
|
|
|
CASE(stringLiteral) |
|
|
|
OUT(text); |
|
|
|
break; |
|
|
|
CASE(char) |
|
|
@ -4676,6 +4782,11 @@ int main(int argc, char **argv) |
|
|
|
DO_PROTOS() |
|
|
|
#undef _DO |
|
|
|
|
|
|
|
properties = makeMap(); |
|
|
|
prop_enums = makeMap(); |
|
|
|
map_set(properties, intern("enums"), prop_enums); |
|
|
|
map_set(globals, intern("properties"), properties); |
|
|
|
|
|
|
|
fixScope(globals); |
|
|
|
|
|
|
|
/* File scope */ |
|
|
|