Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Compiler/NFFrontEnd/NFBinding.mo
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ public
record RAW_BINDING
Absyn.Exp bindingExp;
InstNode scope;
Integer propagatedLevels;
Integer originLevel;
SourceInfo info;
end RAW_BINDING;

record UNTYPED_BINDING
Expression bindingExp;
Boolean isProcessing;
InstNode scope;
Integer propagatedLevels;
Integer originLevel;
SourceInfo info;
end UNTYPED_BINDING;

record TYPED_BINDING
Expression bindingExp;
Type bindingType;
Variability variability;
Integer propagatedLevels;
Integer originLevel;
SourceInfo info;
end TYPED_BINDING;

Expand All @@ -75,20 +75,21 @@ public
function fromAbsyn
input Option<Absyn.Exp> bindingExp;
input SCode.Each eachPrefix;
input Integer level;
input InstNode scope;
input SourceInfo info;
output Binding binding;
algorithm
binding := match bindingExp
local
Absyn.Exp exp;
Integer pd;
Integer lvl;

case SOME(exp)
algorithm
pd := if SCode.eachBool(eachPrefix) then -1 else 0;
lvl := if SCode.eachBool(eachPrefix) then -level else level;
then
RAW_BINDING(exp, scope, pd, info);
RAW_BINDING(exp, scope, lvl, info);

else UNBOUND();
end match;
Expand Down Expand Up @@ -189,9 +190,9 @@ public
output Boolean isEach;
algorithm
isEach := match binding
case RAW_BINDING() then binding.propagatedLevels == -1;
case UNTYPED_BINDING() then binding.propagatedLevels == -1;
case TYPED_BINDING() then binding.propagatedLevels == -1;
case RAW_BINDING() then binding.originLevel < 0;
case UNTYPED_BINDING() then binding.originLevel < 0;
case TYPED_BINDING() then binding.originLevel < 0;
else false;
end match;
end isEach;
Expand Down
8 changes: 7 additions & 1 deletion Compiler/NFFrontEnd/NFBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import NFComponent.Component;
import Expression = NFExpression;
import NFInstNode.InstNode;
import NFInstNode.InstNodeType;
import NFMod.Modifier;
import NFModifier.Modifier;
import Type = NFType;
import BuiltinFuncs = NFBuiltinFuncs;
import Pointer;
Expand Down Expand Up @@ -237,6 +237,7 @@ constant InstNode STATESELECT_NEVER =
STATESELECT_NEVER_BINDING,
NFComponent.CONSTANT_ATTR,
Absyn.dummyInfo)),
0,
STATESELECT_NODE);

constant ComponentRef STATESELECT_NEVER_CREF =
Expand All @@ -252,6 +253,7 @@ constant InstNode STATESELECT_AVOID =
STATESELECT_AVOID_BINDING,
NFComponent.CONSTANT_ATTR,
Absyn.dummyInfo)),
0,
STATESELECT_NODE);

constant ComponentRef STATESELECT_AVOID_CREF =
Expand All @@ -267,6 +269,7 @@ constant InstNode STATESELECT_DEFAULT =
STATESELECT_DEFAULT_BINDING,
NFComponent.CONSTANT_ATTR,
Absyn.dummyInfo)),
0,
STATESELECT_NODE);

constant ComponentRef STATESELECT_DEFAULT_CREF =
Expand All @@ -282,6 +285,7 @@ constant InstNode STATESELECT_PREFER =
STATESELECT_PREFER_BINDING,
NFComponent.CONSTANT_ATTR,
Absyn.dummyInfo)),
0,
STATESELECT_NODE);

constant ComponentRef STATESELECT_PREFER_CREF =
Expand All @@ -297,6 +301,7 @@ constant InstNode STATESELECT_ALWAYS =
STATESELECT_ALWAYS_BINDING,
NFComponent.CONSTANT_ATTR,
Absyn.dummyInfo)),
0,
STATESELECT_NODE);

constant ComponentRef STATESELECT_ALWAYS_CREF =
Expand All @@ -321,6 +326,7 @@ constant InstNode TIME =
Binding.UNBOUND(),
NFComponent.INPUT_ATTR,
Absyn.dummyInfo)),
0,
InstNode.EMPTY_NODE());

constant ComponentRef TIME_CREF = ComponentRef.CREF(TIME, {}, Type.REAL(), Origin.CREF, ComponentRef.EMPTY());
Expand Down
10 changes: 5 additions & 5 deletions Compiler/NFFrontEnd/NFBuiltinFuncs.mo
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,39 @@ constant Component INT_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NO

constant InstNode INT_PARAM = InstNode.COMPONENT_NODE("i",
Visibility.PUBLIC,
Pointer.createImmutable(INT_COMPONENT), InstNode.EMPTY_NODE());
Pointer.createImmutable(INT_COMPONENT), 0, InstNode.EMPTY_NODE());

// Default Real parameter.
constant Component REAL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
Type.REAL(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);

constant InstNode REAL_PARAM = InstNode.COMPONENT_NODE("r",
Visibility.PUBLIC,
Pointer.createImmutable(REAL_COMPONENT), InstNode.EMPTY_NODE());
Pointer.createImmutable(REAL_COMPONENT), 0, InstNode.EMPTY_NODE());

// Default Boolean parameter.
constant Component BOOL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
Type.BOOLEAN(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);

constant InstNode BOOL_PARAM = InstNode.COMPONENT_NODE("b",
Visibility.PUBLIC,
Pointer.createImmutable(BOOL_COMPONENT), InstNode.EMPTY_NODE());
Pointer.createImmutable(BOOL_COMPONENT), 0, InstNode.EMPTY_NODE());

// Default String parameter.
constant Component STRING_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
Type.STRING(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);

constant InstNode STRING_PARAM = InstNode.COMPONENT_NODE("s",
Visibility.PUBLIC,
Pointer.createImmutable(STRING_COMPONENT), InstNode.EMPTY_NODE());
Pointer.createImmutable(STRING_COMPONENT), 0, InstNode.EMPTY_NODE());

// Default enumeration(:) parameter.
constant Component ENUM_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
Type.ENUMERATION_ANY(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);

constant InstNode ENUM_PARAM = InstNode.COMPONENT_NODE("e",
Visibility.PUBLIC,
Pointer.createImmutable(ENUM_COMPONENT), InstNode.EMPTY_NODE());
Pointer.createImmutable(ENUM_COMPONENT), 0, InstNode.EMPTY_NODE());

// Integer(e)
constant Function INTEGER = Function.FUNCTION(Path.IDENT("Integer"),
Expand Down
3 changes: 2 additions & 1 deletion Compiler/NFFrontEnd/NFCall.mo
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ uniontype Call
outIters := {};
iter_scope := scope;
for Absiter in inIters loop
binding := Binding.fromAbsyn(Absiter.range, SCode.NOT_EACH(), iter_scope, info);
binding := Binding.fromAbsyn(Absiter.range, SCode.NOT_EACH(), 0, iter_scope, info);
binding := Inst.instBinding(binding);
(iter_scope, iter) := Inst.addIteratorToScope(Absiter.name, binding, info, iter_scope);
outIters := iter::outIters;
Expand Down Expand Up @@ -646,6 +646,7 @@ uniontype Call
algorithm
ty := match call
case TYPED_CALL(attributes = CallAttributes.CALL_ATTR(ty = ty)) then ty;
case TYPED_MAP_CALL() then call.ty;
else Type.UNKNOWN();
end match;
end typeOf;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFClass.mo
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
encapsulated package NFClass

import NFInstNode.InstNode;
import NFMod.Modifier;
import NFModifier.Modifier;
import NFStatement.Statement;
import SCode.Element;
import Type = NFType;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFComponent.mo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Binding = NFBinding;
import NFClass.Class;
import Dimension = NFDimension;
import NFInstNode.InstNode;
import NFMod.Modifier;
import NFModifier.Modifier;
import SCode.Element;
import SCode;
import Type = NFType;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFConvertDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import ExecStat.execStat;
import ElementSource;
import ComponentRef = NFComponentRef;
import Type = NFType;
import NFMod.Modifier;
import NFModifier.Modifier;
import Expression = NFExpression;
import NFComponent.Component;
import Prefixes = NFPrefixes;
Expand Down
80 changes: 80 additions & 0 deletions Compiler/NFFrontEnd/NFExpression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ public
Type ty;
end UNBOX;

record SUBSCRIPTED_EXP
Expression exp;
list<Expression> subscripts;
Type ty;
end SUBSCRIPTED_EXP;

record TUPLE_ELEMENT
Expression tupleExp;
Integer index;
Expand Down Expand Up @@ -393,6 +399,17 @@ public
then
compare(exp1.exp, e1);

case SUBSCRIPTED_EXP()
algorithm
SUBSCRIPTED_EXP(exp = e1, subscripts = expl) := exp2;
comp := compare(exp1.exp, e1);

if comp == 0 then
comp := compareList(exp1.subscripts, expl);
end if;
then
comp;

case TUPLE_ELEMENT()
algorithm
TUPLE_ELEMENT(tupleExp = e1, index = i) := exp2;
Expand Down Expand Up @@ -482,6 +499,7 @@ public
case IF() then typeOf(exp.trueBranch);
case CAST() then exp.ty;
case UNBOX() then exp.ty;
case SUBSCRIPTED_EXP() then exp.ty;
case TUPLE_ELEMENT() then exp.ty;
else Type.UNKNOWN();
end match;
Expand Down Expand Up @@ -564,6 +582,10 @@ public
then
CREF(Type.unliftArray(array.ty), cref);

case SUBSCRIPTED_EXP()
then SUBSCRIPTED_EXP(array.exp, listAppend(array.subscripts, {INTEGER(index)}), Type.unliftArray(array.ty));

else SUBSCRIPTED_EXP(array, {INTEGER(index)}, Type.unliftArray(typeOf(array)));
end match;
end arrayElement;

Expand Down Expand Up @@ -689,6 +711,7 @@ public

case UNBOX() then "UNBOX(" + toString(exp.exp) + ")";
case CAST() then "CAST(" + Type.toString(exp.ty) + ", " + toString(exp.exp) + ")";
case SUBSCRIPTED_EXP() then toString(exp.exp) + "[" + stringDelimitList(list(toString(e) for e in exp.subscripts), ", ") + "]";
case TUPLE_ELEMENT() then toString(exp.tupleExp) + "[" + intString(exp.index) + "]";

else anyString(exp);
Expand Down Expand Up @@ -769,6 +792,9 @@ public
case UNBOX()
then DAE.UNBOX(toDAE(exp.exp), Type.toDAE(exp.ty));

case SUBSCRIPTED_EXP()
then DAE.ASUB(toDAE(exp.exp), list(toDAE(s) for s in exp.subscripts));

case TUPLE_ELEMENT()
then DAE.TSUB(toDAE(exp.tupleExp), exp.index, Type.toDAE(exp.ty));

Expand All @@ -792,6 +818,7 @@ public
case RANGE() then Type.dimensionCount(exp.ty);
case SIZE(dimIndex = NONE()) then dimensionCount(exp.exp);
case CAST() then dimensionCount(exp.exp);
case SUBSCRIPTED_EXP() then Type.dimensionCount(exp.ty);
case TUPLE_ELEMENT() then Type.dimensionCount(exp.ty);
// TODO: Add more expressions.
else 0;
Expand Down Expand Up @@ -908,6 +935,9 @@ public
then
if referenceEq(exp.exp, e1) then exp else UNBOX(e1, exp.ty);

case SUBSCRIPTED_EXP()
then SUBSCRIPTED_EXP(map(exp.exp, func), list(map(e, func) for e in exp.subscripts), exp.ty);

case TUPLE_ELEMENT()
algorithm
e1 := map(exp.tupleExp, func);
Expand Down Expand Up @@ -995,6 +1025,18 @@ public
then
Call.TYPED_CALL(call.fn, args, call.attributes);

case Call.UNTYPED_MAP_CALL()
algorithm
e := map(call.exp, func);
then
Call.UNTYPED_MAP_CALL(call.ref, e, call.iters);

case Call.TYPED_MAP_CALL()
algorithm
e := map(call.exp, func);
then
Call.TYPED_MAP_CALL(call.fn, call.ty, e, call.iters);

end match;
end mapCall;

Expand Down Expand Up @@ -1114,6 +1156,13 @@ public

case CAST() then fold(exp.exp, func, arg);
case UNBOX() then fold(exp.exp, func, arg);

case SUBSCRIPTED_EXP()
algorithm
result := fold(exp.exp, func, arg);
then
List.fold(exp.subscripts, func, result);

case TUPLE_ELEMENT() then fold(exp.tupleExp, func, arg);

else arg;
Expand Down Expand Up @@ -1167,6 +1216,18 @@ public
then
();

case Call.UNTYPED_MAP_CALL()
algorithm
arg := fold(call.exp, func, arg);
then
();

case Call.TYPED_MAP_CALL()
algorithm
arg := fold(call.exp, func, arg);
then
();

end match;
end foldCall;

Expand Down Expand Up @@ -1345,6 +1406,13 @@ public
then
if referenceEq(exp.exp, e1) then exp else UNBOX(e1, exp.ty);

case SUBSCRIPTED_EXP()
algorithm
(e1, arg) := mapFold(exp.exp, func, arg);
(expl, arg) := List.map1Fold(exp.subscripts, mapFold, func, arg);
then
SUBSCRIPTED_EXP(e1, expl, exp.ty);

case TUPLE_ELEMENT()
algorithm
(e1, arg) := mapFold(exp.tupleExp, func, arg);
Expand Down Expand Up @@ -1437,6 +1505,18 @@ public
then
Call.TYPED_CALL(call.fn, args, call.attributes);

case Call.UNTYPED_MAP_CALL()
algorithm
(e, foldArg) := mapFold(call.exp, func, foldArg);
then
Call.UNTYPED_MAP_CALL(call.ref, e, call.iters);

case Call.TYPED_MAP_CALL()
algorithm
(e, foldArg) := mapFold(call.exp, func, foldArg);
then
Call.TYPED_MAP_CALL(call.fn, call.ty, e, call.iters);

end match;
end mapFoldCall;

Expand Down
Loading