Przeglądaj źródła

Fix list creation in stmts

develop-theo
Sebeck10 2 lat temu
rodzic
commit
137b55bfa0
10 zmienionych plików z 80 dodań i 66 usunięć
  1. +2
    -0
      boot.mc
  2. +17
    -31
      ccmeta.leg
  3. +6
    -4
      tests-parsimony/001.c
  4. +10
    -3
      tests-parsimony/002.c
  5. +7
    -3
      tests-parsimony/003.c
  6. +3
    -6
      tests-parsimony/004.c
  7. +11
    -6
      tests-parsimony/005.c
  8. +15
    -8
      tests-parsimony/006.c
  9. +8
    -5
      tests-parsimony/007.c
  10. +1
    -0
      tests-parsimony/projExample.c

+ 2
- 0
boot.mc Wyświetl plik

@ -44,4 +44,6 @@
last(s) {
s[length(s)-1];
}
nil;
}

+ 17
- 31
ccmeta.leg Wyświetl plik

@ -30,7 +30,7 @@
_DO(PostDecVariable) _DO(PostDecMember) _DO(PostDecIndex) \
_DO(GetVariable) _DO(GetMember) _DO(SetMember) _DO(GetIndex) _DO(SetIndex) \
_DO(Return) _DO(Break) _DO(Continue) _DO(Throw) _DO(Try) \
_DO(Quote) _DO(Append) /* _DO(Quasiquote) _DO(Unquote) */ \
_DO(Quote) /* _DO(Quasiquote) _DO(Unquote) */ \
DO_C_PROTOS()
#define META_PROTO_MAX t_Try
@ -1316,7 +1316,7 @@ oop outputProgram= 0;
# yylval == null => "pseudo" op, e.g., change language -- ignored by REPL
# yylval == 0 => end of input file while in META mode only
start = m:metaCatch { yylval = m }
start = m:metaCatch { yylval= m }
| s:externalDeclaration { yylval= s }
error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 }
@ -1356,7 +1356,7 @@ hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hex
constant = characterConstant
| floatingConstant
| integerConstant
#| META_AT m:meta_exp { $$ = m }
| META_AT m:mvalue
@ -1453,9 +1453,9 @@ sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #"
# 6.5.1
primaryExpression = stringLiteral | constant | id
| META_AT ( META_LCB x:mstmts
| x:mvalue
)
| META_AT ( META_LCB x:mstmts
| x:mvalue
)
| l:LPAREN x:expression r:RPAREN { $$= new_C_subexpr(l, x, r) }
| l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= new_C_subexpr(l, x, r) }
@ -1836,7 +1836,7 @@ typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } -
initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) }
| assignmentExpression
| META_AT m:meta_exp { $$ = m }
| META_AT m:mvalue
initializerList = { listBegin() }
( d:designation { listAppend(d) }
@ -1880,7 +1880,6 @@ labeledStatement = i:id c:COLON
| d:DEFAULT c:COLON s:statement { $$= new_C_default(d, c, s) }
# 6.8.2
# todo add meta or list meta (@@ for list of things)
compoundStatement = @{ C_scopeBegin() }
l:LCURLY { listBegin() }
@ -2165,24 +2164,24 @@ _FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float1
# 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 m:mstmts { map_append(outputProgram, m) ; $$ = null }
| m:mvalue { $$ = m }
| META_LCB s:mstmts { map_append(outputProgram, s); $$ = null }
)
mvalue = i:META_IDENT { $$ = eval(globals, newGetVariable(i)) }
mvalue = i:META_IDENT { $$ = eval(globals, newGetVariable(i)) }
| META_LPAREN ( i:MO_OPERATION
#| i:meta_block usefull ?
| i:meta_exp
) META_RPAREN { $$ = eval(globals, i) }
) META_RPAREN { $$ = eval(globals, i) }
mstmts = { listBegin() } ( s:meta_stmt { eval(globals, s) } )* meta_endSTMTS
mstmts = ( s:eval_stmt )* ( META_NIL META_SEMICOLON META_RCB { $$ = null }
| META_RCB { $$ = s }
)
meta_endSTMTS = (META_NIL META_SEMICOLON )? META_RCB { listEnd(); $$ = null }
| META_DAT META_SEMICOLON META_RCB { $$ = listEnd() }
eval_stmt = s:meta_stmt { $$ = eval(globals, s) }
meta_stmt = s:meta_block { $$ = s }
| a:meta_append { $$ = a }
| META_SEMICOLON { $$ = null }
| l:META_IDENT p:meta_paramList e:meta_block { $$ = newFunc(l, p, e, null) }
| META_IF META_LPAREN c:meta_exp META_RPAREN t:meta_stmt META_ELSE f:meta_stmt { $$ = newIf(c, t, f ) }
@ -2200,8 +2199,6 @@ meta_stmt = s:meta_block
| t:meta_try { $$ = t }
| e:meta_exp META_SEMICOLON { $$ = e }
meta_append = META_DAT META_DOT META_APPEND META_LPAREN s:meta_exp META_RPAREN META_SEMICOLON { $$ = newUnary(Append_proto, s) }
meta_block = META_LCB m:meta_makeMap
( s:meta_stmt { map_append(m, s) }
) *
@ -2405,7 +2402,7 @@ 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) }
| MO_STRING i:stringLiteral { $$ = newUnary(Quote_proto ,i) }
)
# META_OPERATORS = MO_INITIALIZER | MO_CONSTANT | MO_STATEMENT | MO_INTEGER | MO_DECLARATION | MO_STRING
@ -2415,18 +2412,12 @@ 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_] --
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_] --
#META_FUN = 'fun' ![a-zA-Z0-9_] --
#META_SYNTAX = 'syntax' ![a-zA-Z0-9_] --
META_VAR = 'var' ![a-zA-Z0-9_] --
@ -2891,11 +2882,6 @@ oop eval(oop scope, oop ast)
oop obj = map_get(ast, rhs_symbol);
return obj;
}
case t_Append: {
oop obj = eval(scope, map_get(ast, rhs_symbol));
listAppend(obj);
return null;
}
#if 0
case t_Quasiquote: {
oop obj = map_get(ast, rhs_symbol);

+ 6
- 4
tests-parsimony/001.c Wyświetl plik

@ -11,7 +11,9 @@
}
enum foo { FOO, BAR, BAZ };
char *x[] = @(newCinitializer([newCstring("X"), comma, newCstring("Y")]));
int i = @(newCint("42"));
int i = @({ __proto__: Token, text: "14" });
char *foos[] = { "FOO", "BAR", "BAZ" };
char *x[] = @(newCinitializer([newCstring("X"), comma, newCstring("Y")]));
int i = @(newCint("42"));
char *c = @(newCstring("42"));
int i = @({ __proto__: Token, text: "14" });
char *foos[] = { "FOO", "BAR", "BAZ" };

+ 10
- 3
tests-parsimony/002.c Wyświetl plik

@ -2,11 +2,18 @@
saved = `initializer (1,2,"string",21<<1);
cons = `constant 2;
two = `integer 2;
nil;
}
@{print("6 outputs : \n");}
@{a = `constant 10;}
// char t = @(`constant @a); // fix me
@{
print("6 outputs : \n");
nil;
}
@{
a = `constant 10;
nil;
}
char t = @(`constant @a);
int i = @cons;
int q = @(`constant 10);
int k = @(`initializer (1,2,"stringy thingy",21<<1));

+ 7
- 3
tests-parsimony/003.c Wyświetl plik

@ -1,19 +1,23 @@
@{import("boot.mc");}
@{
nTimes = `constant 10;
forLoop = (`statement for (int i = 0; i < 10; ++i) printf("%d\n", i););
whileLoop = `statement while (i < 10) { printf("%d\n", i); ++il; };
useForLoop = 1;
nil;
}
int main()
{
@{
l = createList();
if (useForLoop) {
@@.append(forLoop);
append(l, forLoop);
} else {
@@.append(whileLoop);
append(l, whileLoop);
}
@@;
l;
};
return 0;
}

+ 3
- 6
tests-parsimony/004.c Wyświetl plik

@ -1,12 +1,10 @@
@{
num = `integer 21;
test = `initializer 2 * 10;
nil;
}
int x = @{
@@.append(`initializer 2 * @num);
@@;
};
int x = @{`initializer 2 * @num;};
int main() {
int i = @(`initializer 2 * @num);
@ -14,8 +12,7 @@ int main() {
int a = @{
num = `integer 21;
test = 2;
@@.append(`initializer @num);
@@;
`initializer 2 * @num;
};
return 0;
}

+ 11
- 6
tests-parsimony/005.c Wyświetl plik

@ -1,17 +1,22 @@
@{import("boot.mc");}
@{
@@.append(`declaration int a = 5;);
@@.append(`declaration int b = 2;);
l = createList();
append(l, `declaration int a = 5;);
append(l, `declaration int b = 2;);
l;
}
int main() {
@{
l = createList();
a = (`declaration int a = 2;);
@@.append(`declaration int c = 5;);
append(l, `declaration int c = 5;);
b = 5;
@@.append(`declaration int d = 2;);
@@.append(`statement for(int i =0; i < 10; i++) {
append(l, `declaration int d = 2;);
append(l, `statement for(int i =0; i < 10; i++) {
a = 2;
});
@@;
l;
};
}

+ 15
- 8
tests-parsimony/006.c Wyświetl plik

@ -1,28 +1,35 @@
@{import("boot.mc");}
@{
@@.append(`declaration int a = 5;);
l = createList();
append(l, `declaration int a = 5;);
a = (`declaration int a = 5;);
@@.append(`declaration int a = 5;);
@@;
append(l, `declaration int a = 5;);
l;
};
@a;
@{t = `integer 2;}
@{
t = `integer 2;
nil;
}
@(`declaration int abc = @t;);
int main() {
@a;
int b = 0;
@{
@@.append(`declaration int c = 0;);
l = createList();
append(l, `declaration int c = 0;);
x = (`declaration int d = 5;);
@@.append(x);
append(l, x);
if (1) {
if (1) {
x = (`declaration int d = 5;);
@@.append(x);
append(l, x);
}
}
@@;
l;
};
int e = 0;
return 0;

+ 8
- 5
tests-parsimony/007.c Wyświetl plik

@ -1,13 +1,16 @@
@{import("boot.mc");}
@{
@@.append(`declaration int a = 0;);
l = createList();
append(l, `declaration int a = 0;);
a = (`declaration int b = 0;);
@@.append(a);
append(l, a);
if (1) {
@@.append(`declaration int c = 0;);
append(l, `declaration int c = 0;);
} else {
@@.append(`declaration int c = 1;);
append(l, `declaration int c = 1;);
}
@@;
l;
};
@a;

+ 1
- 0
tests-parsimony/projExample.c Wyświetl plik

@ -5,6 +5,7 @@ enum foo { Closed = 0, ReadOnly = 1, WriteOnly = 2 };
@{
idToString(x) {{ __proto__: C_string, value: "\"" + string(x.name.identifier) + "\"" }}
notToken(x) { x.__proto__ != Token }
nil;
}
static char stateNames[] = { @(map(idToString, properties.enums.foo.enumList, notToken)) };

Ładowanie…
Anuluj
Zapisz