Skip to content

Commit

Permalink
- Susan now:
Browse files Browse the repository at this point in the history
  - translates case local names into function wide local names
    and has nicer name prefixes to have more easily distinguishable origins of the generated identifiers
  - respects full 'hasindex' semantics with a new keyword 'from' added that is used instead of indexOffset= option
    new syntax is:
    lst |> elem hasindex myIndex3 from 3 => '<%elem%><%myIndex3%>'
    the 'from' keyword is optional (and can only together with 'hasindex'); default is 0
  - does not hide implicitly scoped patterned matched record fields in 'if' expressions (only directly tested implicitly scoped values was visible after 'then' till now)
  - has much better 'let' scoping, to be continued ...
  - has better emptiness testing of Texts in 'if' expressions (does direct Text value test for emptiness instead of translating it to string) 
  - reports better errors for options; mainly does not allow a typo in option names and non-sense options are errors now

- SimCodeC.tpl
  - rewritten to respect the new 'hasindex' ['from'] syntax
  - fixed a typo 'seprator' -> 'separator'
  - in template initRecordMembers()  fixed RECORD  to RECORD(__)
  - in template patternMatch() in case PAT_CALL(__) fixed placement of empty= option (to be removed later entirely for this context)



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7192 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
pavolpr committed Nov 25, 2010
1 parent 0f60972 commit 6c08226
Show file tree
Hide file tree
Showing 16 changed files with 20,156 additions and 22,740 deletions.
24,717 changes: 11,565 additions & 13,152 deletions Compiler/SimCodeC.mo

Large diffs are not rendered by default.

7,915 changes: 3,670 additions & 4,245 deletions Compiler/SimCodeCSharp.mo

Large diffs are not rendered by default.

4,553 changes: 2,227 additions & 2,326 deletions Compiler/SimCodeFMU.mo

Large diffs are not rendered by default.

1,771 changes: 991 additions & 780 deletions Compiler/TplAbsyn.mo

Large diffs are not rendered by default.

1,145 changes: 477 additions & 668 deletions Compiler/TplCodegen.mo

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Compiler/TplMain.mo
Expand Up @@ -319,9 +319,9 @@ input Pa.Li inSusan;", true, true, "typedIdentsEx", notPassedCnt);
TplAbsyn.SOME_MATCH(TplAbsyn.BIND_AS_MATCH("v_hej",TplAbsyn.STRING_MATCH("Hej"))),
TplAbsyn.BIND_MATCH("v_jokes")
},
{ ("v_hej",TplAbsyn.STRING_TYPE()),
("v_jokes",TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE()))
},
//{ ("v_hej",TplAbsyn.STRING_TYPE()),
// ("v_jokes",TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE()))
//},
{
TplAbsyn.MM_ASSIGN({"txt"},
TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
Expand All @@ -333,8 +333,8 @@ input Pa.Li inSusan;", true, true, "typedIdentsEx", notPassedCnt);
TplAbsyn.SOME_MATCH(TplAbsyn.BIND_MATCH("v_hej")),
TplAbsyn.REST_MATCH()
},
{ ("v_hej",TplAbsyn.STRING_TYPE())
},
//{ ("v_hej",TplAbsyn.STRING_TYPE())
//},
{
TplAbsyn.MM_ASSIGN({"txt"},
TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
Expand All @@ -351,7 +351,7 @@ input Pa.Li inSusan;", true, true, "typedIdentsEx", notPassedCnt);
TplAbsyn.NONE_MATCH(),
TplAbsyn.REST_MATCH()
},
{ },
//{ },
{
TplAbsyn.MM_ASSIGN({"txt"},
TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
Expand Down Expand Up @@ -506,7 +506,8 @@ typedIdents(TypedIdents decls) <>=
TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("id")),
TplAbsyn.STR_TOKEN(Tpl.ST_STRING(";"))
},"\"","\""
)
),
NONE()
),
{ ("separator", SOME(TplAbsyn.STR_TOKEN(Tpl.ST_NEW_LINE())))
}
Expand Down
103 changes: 82 additions & 21 deletions Compiler/TplParser.mo
Expand Up @@ -2894,12 +2894,13 @@ algorithm
Tpl.StringToken st;
TplAbsyn.Expression exp, bexp, lexp;
list<TplAbsyn.Expression> expLst;
list<TplAbsyn.EscOption> opts;
list<TplAbsyn.EscOption> opts, indexOffsetOption;

case (chars, linfo, lesc, resc, _)
equation
(chars, linfo, exp) = expressionNoOptions(chars, linfo, lesc, resc);
(chars, linfo, exp, indexOffsetOption) = expressionNoOptions(chars, linfo, lesc, resc);
(chars, linfo, opts) = escapedOptions(chars, linfo, lesc, resc);
opts = listAppend(indexOffsetOption, opts);
//exp = makeEscapedExp(exp, listAppend(sopt,opts));
exp = makeEscapedExp(exp, opts);
then (chars, linfo, exp);
Expand Down Expand Up @@ -2980,7 +2981,7 @@ end escapedOptions;

/*
escOptionExp(lesc,resc):
'=' expressionNoOptions(lesc,resc):exp
'=' expressionLet(lesc,resc):exp
=> SOME(exp)
|
_ => NONE
Expand Down Expand Up @@ -3015,7 +3016,7 @@ algorithm
case ("=" :: chars, linfo, lesc, resc)
equation
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, exp) = expressionNoOptions(chars, linfo, lesc, resc);
(chars, linfo, exp) = expressionLet(chars, linfo, lesc, resc);
then (chars, linfo, SOME(exp));

case (chars, linfo, _, _)
Expand All @@ -3039,8 +3040,10 @@ public function expressionNoOptions
output list<String> outChars;
output LineInfo outLineInfo;
output TplAbsyn.Expression outExpression;
output list<TplAbsyn.EscOption> outIndexOffsetOption;
algorithm
(outChars, outLineInfo, outExpression) := matchcontinue (inChars, inLineInfo, inLeftEsc, inRightEsc)
(outChars, outLineInfo, outExpression, outIndexOffsetOption)
:= matchcontinue (inChars, inLineInfo, inLeftEsc, inRightEsc)
local
list<String> chars;
LineInfo linfo;
Expand All @@ -3054,21 +3057,23 @@ algorithm
TplAbsyn.Expression exp, bexp;
list<TplAbsyn.Expression> expLst;
list<TplAbsyn.EscOption> sopt, opts;


case (chars, linfo, lesc, resc)
equation
(chars, linfo, exp) = expressionLet(chars, linfo, lesc, resc);
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, exp) = mapTailOpt(chars, linfo, exp, lesc, resc);
then (chars, linfo, exp);
(chars, linfo, exp, outIndexOffsetOption)
= mapTailOpt(chars, linfo, exp, lesc, resc);
then (chars, linfo, exp, outIndexOffsetOption);

end matchcontinue;
end expressionNoOptions;

/*
mapTailOpt(headExp,lesc,resc):
'|>' matchBinding:mexp
indexedByOpt:idxNmOpt //TODO: 'hasindex' in TplAbsyn
indexedByOpt:idxNmOpt
'=>' expressionLet(lesc,resc):exp => MAP(headExp,mexp,exp)
|
_ => headExp
Expand All @@ -3083,8 +3088,9 @@ public function mapTailOpt
output list<String> outChars;
output LineInfo outLineInfo;
output TplAbsyn.Expression outExpression;
output list<TplAbsyn.EscOption> outIndexOffsetOption;
algorithm
(outChars, outLineInfo, outExpression) := matchcontinue (inChars, inLineInfo, inHeadExpression, inLeftEsc, inRightEsc)
(outChars, outLineInfo, outExpression, outIndexOffsetOption) := matchcontinue (inChars, inLineInfo, inHeadExpression, inLeftEsc, inRightEsc)
local
list<String> chars;
LineInfo linfo;
Expand All @@ -3106,15 +3112,15 @@ algorithm
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, mexp) = matchBinding(chars, linfo);
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, idxNmOpt) = indexedByOpt(chars, linfo);
(chars, linfo, idxNmOpt, outIndexOffsetOption) = indexedByOpt(chars, linfo, lesc, resc);
(chars, linfo) = interleaveExpectChar(chars, linfo, "=");
(chars, linfo) = expectChar(chars, linfo, ">");
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, exp) = expressionLet(chars, linfo, lesc, resc);
then (chars, linfo, TplAbsyn.MAP(headExp, mexp, exp) );
then (chars, linfo, TplAbsyn.MAP(headExp, mexp, exp, idxNmOpt), outIndexOffsetOption);

case (chars, linfo, headExp, _, _)
then (chars, linfo, headExp );
then (chars, linfo, headExp, {} );

end matchcontinue;
end mapTailOpt;
Expand All @@ -3129,12 +3135,16 @@ indexedByOpt:
public function indexedByOpt
input list<String> inChars;
input LineInfo inLineInfo;
input String inLeftEsc;
input String inRightEsc;

output list<String> outChars;
output LineInfo outLineInfo;
output Option<TplAbsyn.Ident> outIndexNameOpt;
output list<TplAbsyn.EscOption> outIndexOffsetOption;
algorithm
(outChars, outLineInfo, outIndexNameOpt) := matchcontinue (inChars, inLineInfo)
(outChars, outLineInfo, outIndexNameOpt, outIndexOffsetOption)
:= matchcontinue (inChars, inLineInfo, inLeftEsc, inRightEsc)
local
list<String> chars;
LineInfo linfo;
Expand All @@ -3149,19 +3159,67 @@ algorithm
list<TplAbsyn.Expression> expLst;
TplAbsyn.MatchingExp mexp;

case ("h"::"a"::"s"::"i"::"n"::"d"::"e"::"x":: chars, linfo)
case ("h"::"a"::"s"::"i"::"n"::"d"::"e"::"x":: chars, linfo, lesc, resc)
equation
afterKeyword(chars);
(chars, linfo) = interleave(chars, linfo);
(chars,linfo,id) = identifierNoOpt(chars,linfo);
then (chars, linfo, SOME(id) );
(chars,linfo,id) = identifierNoOpt(chars,linfo);
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, outIndexOffsetOption) = fromOpt(chars, linfo, lesc, resc);
then (chars, linfo, SOME(id), outIndexOffsetOption );

case (chars, linfo)
then (chars, linfo,NONE());
case (chars, linfo, lesc, resc)
then (chars, linfo, NONE(), {});

end matchcontinue;
end indexedByOpt;

/*
fromOpt:
'from' expression_base:expFrom
=> { ("$indexOffset", SOME(expFrom)) }
|
_ => {}
*/
public function fromOpt
input list<String> inChars;
input LineInfo inLineInfo;
input String inLeftEsc;
input String inRightEsc;

output list<String> outChars;
output LineInfo outLineInfo;
output list<TplAbsyn.EscOption> outIndexOffsetOption;
algorithm
(outChars, outLineInfo, outIndexOffsetOption)
:= matchcontinue (inChars, inLineInfo, inLeftEsc, inRightEsc)
local
list<String> chars;
LineInfo linfo;
String c, lesc, resc;
Boolean isD;
TplAbsyn.Ident id;
TplAbsyn.PathIdent name;
TplAbsyn.TypedIdents fields,inargs,outargs;
TplAbsyn.TypeSignature ts;
Tpl.StringToken st;
TplAbsyn.Expression exp, bexp;
list<TplAbsyn.Expression> expLst;
TplAbsyn.MatchingExp mexp;

case ("f"::"r"::"o"::"m":: chars, linfo, lesc, resc)
equation
afterKeyword(chars);
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, exp) = expression_base(chars, linfo, lesc, resc);
then (chars, linfo, {(TplAbsyn.indexOffsetOptionId, SOME(exp))} );

case (chars, linfo, lesc, resc)
then (chars, linfo,{});

end matchcontinue;
end fromOpt;


/*
expressionLet(lesc,resc):
Expand Down Expand Up @@ -3199,8 +3257,10 @@ algorithm
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, lexp) = letExp(chars, linfo, lesc, resc);
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, expLst) = concatLetExp_rest(chars, linfo, lesc, resc);
then (chars, linfo, TplAbsyn.TEMPLATE(lexp :: expLst, "let", "")); //TODO: ?? to be a LET_EXPRESSION ??
(chars, linfo, exp) = expressionLet(chars, linfo, lesc, resc);

//(chars, linfo, expLst) = concatLetExp_rest(chars, linfo, lesc, resc);
then (chars, linfo, TplAbsyn.LET(lexp, exp));

case (chars, linfo, lesc, resc)
equation
Expand All @@ -3218,6 +3278,7 @@ concatLetExp_rest(lesc,resc):
expression(lesc,resc):exp
=> {exp}
*/
/*
public function concatLetExp_rest
input list<String> inChars;
input LineInfo inLineInfo;
Expand Down Expand Up @@ -3259,7 +3320,7 @@ algorithm
end matchcontinue;
end concatLetExp_rest;

*/

/*
must not fail - not optional, at least one must match
Expand Down

0 comments on commit 6c08226

Please sign in to comment.