ソースを参照

Some corrections and comments

develop-theo
Theo Souchon 2年前
コミット
ad46f3fe61
4個のファイルの変更92行の追加49行の削除
  1. +35
    -27
      ccmeta.leg
  2. +39
    -4
      parsimonyLibrary/boot.mc
  3. +6
    -6
      parsimonyLibrary/dynamicObject.mc
  4. +12
    -12
      parsimonyLibrary/fake-static-classes.mc

+ 35
- 27
ccmeta.leg ファイルの表示

@ -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));

+ 39
- 4
parsimonyLibrary/boot.mc ファイルの表示

@ -14,13 +14,48 @@
}
}
getId(x) { { identifier: x, __proto__: C_id }; }
//------------ creation C structure ------------//
newId(x) { treeCopy({ identifier: x, __proto__: C_id }); }
newComment(com) { { text : com, __proto__: Comment }; }
getEnum(x) { { attributeL: null, expression: null, name: getId(x), __proto__: C_enum }; }
//--- Token ---//
newToken(txt, com) {
if (com == null) return { text: txt, comment: newComment(""), __proto__: Token };
{ text: txt, comment: newComment(com), __proto__: Token };
}
getComma() { { text: ",", comment: { text : " ", __proto__: Comment }, __proto__: Token }; }
newSemicolon(com) { newToken(";", com) }
newComma() { newToken(",", " "); }
newStar(com) { newToken("*", com); }
newBinary(com) { newToken("=", com); }
getComment(x) { { text : x, __proto__: Comment }; }
//--- Declaration ---//
newStruct() {
{
declarators: null,
specifier: null,
semicolon: newSemicolon("\n"),
__proto__: C_declaration
} // TO FIX
}
newDeclarators() {}
//--- TO FIX ---//
newEnum(x) { { attributeL: null, expression: null, name: newId(x), __proto__: C_enum }; }
newFunction() {}
//-------------------- end ---------------------//
// adding the element e at the end of the list l
append(s, e) {

+ 6
- 6
parsimonyLibrary/dynamicObject.mc ファイルの表示

@ -127,6 +127,7 @@ struct Object {
send(object, method)
{
// program.mem = newId(string(object));
rawSend = (`declaration send(obj, met););
rawSend.semicolon = null;
rawSend.declarators[0].paramTypeL[0].identifier = object;
@ -155,20 +156,19 @@ struct Object {
);
param.semicolon = null;
if (length(s.declarators.paramTypeL) > 0) {
append(s.declarators.paramTypeL, getComma());
append(s.declarators.paramTypeL, newComma());
append(s.declarators.paramTypeL, treeCopy(param));
} else {
s.declarators.paramTypeL = {};
s.declarators.paramTypeL[0] = treeCopy(param);
}
tmp = {};
tmp[0] = (`declaration struct @(getId(string(program.objects.currentClassName))) *self = (struct @(getId(string(program.objects.currentClassName))) *) __self;
tmp[0] = (`declaration struct @(treeCopy(newId(string(program.objects.currentClassName)))) *self = (struct @(newId(string(program.objects.currentClassName))) *) __self;
);
tmp[0].specifiers[0].name.identifier = string(program.objects.currentClassName);
tmp[0].declarators[0].rhs.typeName.specifiers[0].name.identifier = string(program.objects.currentClassName);
/////////////////////// FIX ME /////////////////////////////// MAYBE CONTEXT WITH GLOBAL
// tmp[0].specifiers[0].name.identifier = string(program.objects.currentClassName);
// tmp[0].declarators[0].rhs.typeName.specifiers[0].name.identifier = string(program.objects.currentClassName);
s.compoundS.expression = treeCopy(fusion(tmp, s.compoundS.expression));
// string(program.objects.currentClassName);
// s.declarators.paramTypeL
program.objects.function = "none";
return s;
}

+ 12
- 12
parsimonyLibrary/fake-static-classes.mc ファイルの表示

@ -26,27 +26,27 @@
l = {};
enum = `declaration typedef enum {_} type_t;;
enum.declarators[0].identifier = typeName;
enum.semicolon.comment = getComment(" ");
enum.semicolon.comment = newComment(" ");
program.objects.enum = treeCopy(enum);
append(l, program.objects.enum);
obj = `declaration union object;;
obj.semicolon.comment = getComment(" ");
obj.semicolon.comment = newComment(" ");
append(l, treeCopy(obj));
type_obj = `declaration typedef union object *oop;;
type_obj.declarators[0].declarators.identifier = objectName;
type_obj.semicolon.comment = getComment("\n\n");
type_obj.semicolon.comment = newComment("\n\n");
append(l, treeCopy(type_obj));
l;
}
// Function to add dynamically an object
addObject() {
structName = treeCopy(getEnum(program.last.name.identifier));
structName = treeCopy(newEnum(program.last.name.identifier));
l = length(program.enums.last.enumList);
if (string(program.objects.enum.specifiers[1].enumList[0].name.identifier) == "_" && l == 1) {
program.objects.enum.specifiers[1].enumList[0] = structName;
} else {
append(program.objects.enum.specifiers[1].enumList, getComma());
append(program.objects.enum.specifiers[1].enumList, newComma());
append(program.objects.enum.specifiers[1].enumList, structName);
}
for (i=length(program.last.declarationL); i>0; i--) {
@ -54,7 +54,7 @@
};
newType = `declaration int type;;
newType.specifiers[0].text = program.objects.enum.declarators[0].identifier;
newType.semicolon.comment = getComment("\n ");
newType.semicolon.comment = newComment("\n ");
program.last.declarationL[0] = treeCopy(newType);
nil;
}
@ -117,24 +117,24 @@
objectUnion = `declaration union object { int type; };;
objectUnion = treeCopy(objectUnion);
objectUnion.specifiers[0].declarationL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier;
objectUnion.semicolon.comment = getComment("\n");
objectUnion.semicolon.comment = newComment("\n");
obj = select(notToken, program.objects.enum.specifiers[1].enumList);
elt = treeCopy(`declaration struct nil nil;);
for (i in obj) {
len = length(objectUnion.specifiers[0].declarationL);
elt.specifiers[0].name.identifier = elt.declarators[0].identifier = obj[i].name.identifier;
objectUnion.specifiers[0].declarationL[len] = treeCopy(elt);
objectUnion.specifiers[0].declarationL[len].semicolon.comment = getComment(" ");
objectUnion.specifiers[0].declarationL[len].semicolon.comment = newComment(" ");
}
append(l, objectUnion);
isDef = `declaration int is(int type, int obj);;
isDef.declarators[0].paramTypeL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier;
isDef.declarators[0].paramTypeL[2].specifiers[0].text = program.objects.last;
isDef.semicolon.comment = getComment("\n");
isDef.semicolon.comment = newComment("\n");
append(l, isDef);
func = `fun int isFoo(int obj) { return is(foo, obj); };
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.last;
func.compoundS.rightCurly.comment = getComment("\n");
func.compoundS.rightCurly.comment = newComment("\n");
for (i in obj) {
func.declarators.declarators.identifier = "is" + string(obj[i].name.identifier);
func.compoundS.expression[0].expression.paramTypeL[0].identifier = obj[i].name.identifier;
@ -143,12 +143,12 @@
func = `fun int getType(int ptr) { assert(ptr); return ptr->type; };
func.specifiers[0].text = program.objects.enum.declarators[0].identifier;
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.last;
func.compoundS.rightCurly.comment = getComment("\n");
func.compoundS.rightCurly.comment = newComment("\n");
append(l, treeCopy(func));
func = `fun int is(int type, int obj) { return type == getType(obj); };
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier;
func.declarators.paramTypeL[2].specifiers[0].text = program.objects.last;
func.compoundS.rightCurly.comment = getComment("\n");
func.compoundS.rightCurly.comment = newComment("\n");
append(l, treeCopy(func));
append(l, treeCopy(getObjectMacro()));
append(l, treeCopy(setObjectMacro()));

読み込み中…
キャンセル
保存