SaffronValueCompile1:
Module =
Begin
the polymorphic operators must provide their own type checking; all others call CompileAndTypeCheckExpression.
for
Exp.sum:
AbstractProduction [ Exp.left, AddOp, Exp.right ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
CastIntegerValue[
if IsPlus[AddOp]
then Add[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]]
else Sub[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]],
GetIntrinsicIntegerTypes[cs]]
where lhs ← DemandNumber[uncheckedLhs]
where rhs ← DemandNumber[uncheckedRhs]
where uncheckedRhs ← EvaluateExpression[Exp.right, lc, fl, cs, targetType]
where uncheckedLhs ← EvaluateExpression[Exp.left, lc, fl, cs, targetType]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree2>
where result ←
if And[And[Static[lhs], Static[rhs]], And[ConformsToInteger[lhsType], ConformsToInteger[rhsType]]]
we're not going to try simulating REAL arithmetic just now.
then CastIntegerValue[
if IsPlus[AddOp]
then Add[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]]
else Sub[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]],
GetIntrinsicIntegerTypes[cs]]
else
(MakeRuntimeValue[code, targetType
]
-- is targetType
correct here?
where code ← ConcatProgramFragments[ConcatProgramFragments[pushLHS, pushRHS], op]
where pushLHS ← Code[lhs]
where pushRHS ← Code[rhs]
where op ←
if IsPlus[AddOp]
then MakePGAdd[]
else MakePGSubtract[]
)
where lhsType ← Type[lhs]
where rhsType ← Type[rhs]
where lhs ← DemandNumber[uncheckedLhs]
where rhs ← DemandNumber[uncheckedRhs]
where <uncheckedRhs, contextTree2> ←
CompileExpression[Exp.right, contextTree1, cs, targetType]
where <uncheckedLhs, contextTree1> ←
CompileExpression[Exp.left, contextTree, cs, targetType]
the targetTypes in the calls should be fixed...
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Arithmetic expression used as l-value"]
;
for
Exp.unarysum:
AbstractProduction [ AddOp, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
CastIntegerValue[
if IsPlus[AddOp]
then RetrieveIntegerValue[rhs]
else Neg[RetrieveIntegerValue[rhs]],
GetIntrinsicIntegerTypes[cs]]
where rhs ← DemandNumber[uncheckedRhs]
where uncheckedRhs ← EvaluateExpression[Exp, lc, fl, cs, targetType]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ←
if And[Static[rhs], ConformsToInteger[rhsType]]
then CastIntegerValue[
if IsPlus[AddOp]
then RetrieveIntegerValue[rhs]
else Neg[RetrieveIntegerValue[rhs]],
GetIntrinsicIntegerTypes[cs]]
else
(MakeRuntimeValue[code, targetType
]
-- is targetType
correct here?
where code ←
if IsPlus[AddOp]
then ConcatProgramFragments[pushRHS, MakePGNoOp[]]
else ConcatProgramFragments[pushRHS, MakePGNegate[]]
where pushRHS ← Code[rhs]
)
where rhsType ← Type[rhs]
where rhs ← DemandNumber[uncheckedRhs]
where <uncheckedRhs, contextTree1> ←
CompileExpression[Exp, contextTree, cs, targetType]
the targetTypes in the calls should be fixed...
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Arithmetic expression used as l-value"]
;
for
Exp.product:
AbstractProduction [ Exp.left, MultOp, Exp.right ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
CastIntegerValue[
if IsTimes[MultOp]
then Mul[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]]
else
if IsDivide[MultOp]
then Div[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]]
else Mod[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]],
GetIntrinsicIntegerTypes[cs]]
where lhs ← DemandNumber[uncheckedLhs]
where rhs ← DemandNumber[uncheckedRhs]
where uncheckedRhs ← EvaluateExpression[Exp.right, lc, fl, cs, targetType]
where uncheckedLhs ← EvaluateExpression[Exp.left, lc, fl, cs, targetType]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree2>
where result ←
if And[And[Static[lhs], Static[rhs]], And[ConformsToInteger[lhsType], ConformsToInteger[rhsType]]]
then CastIntegerValue[
if IsTimes[MultOp]
then Mul[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]]
else
if IsDivide[MultOp]
then Div[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]]
else Mod[RetrieveIntegerValue[lhs], RetrieveIntegerValue[rhs]],
GetIntrinsicIntegerTypes[cs]]
else
(MakeRuntimeValue[code, targetType
]
-- is targetType
correct here?
where code ← ConcatProgramFragments[ConcatProgramFragments[pushLHS, pushRHS], op]
where pushLHS ← Code[lhs]
where pushRHS ← Code[rhs]
where op ←
if IsTimes[MultOp]
then MakePGMultiply[]
else
if IsDivide[MultOp]
then MakePGDivide[]
else MakePGMod[]
)
we're not going to try simulating REAL arithmetic just now.
where lhsType ← Type[lhs]
where rhsType ← Type[rhs]
where lhs ← DemandNumber[uncheckedLhs]
where rhs ← DemandNumber[uncheckedRhs]
where <uncheckedRhs, contextTree2> ←
CompileExpression[Exp.right, contextTree1, cs, targetType]
where <uncheckedLhs, contextTree1> ←
CompileExpression[Exp.left, contextTree, cs, targetType]
the targetTypes in the calls should be fixed...
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Arithmetic expression used as l-value"]
;
for
Exp.or:
AbstractProduction [ Exp.left, Exp.right ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
MakeStaticBoolean[Or[BooleanValue[lhs], BooleanValue[rhs]], boolean]
where rhs ← EvaluateAndTypeCheckExpression[Exp.right, lc, fl, cs, boolean]
where lhs ← EvaluateAndTypeCheckExpression[Exp.left, lc, fl, cs, boolean]
where boolean ← GetIntrinsicBooleanType[cs]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree2>
where result ←
if And[Static[lhs], Static[rhs]]
then MakeStaticBoolean[Or[BooleanValue[lhs], BooleanValue[rhs]], boolean]
else
(MakeRuntimeValue[code, boolean
]
where code ← ConcatProgramFragments[ConcatProgramFragments[pushLHS, pushRHS], op]
where pushLHS ← Code[lhs]
where pushRHS ← Code[rhs]
where op ← MakePGOr[]
)
where <rhs, contextTree2> ←
CompileAndTypeCheckExpression[Exp.right, contextTree1, cs, boolean]
where <lhs, contextTree1> ←
CompileAndTypeCheckExpression[Exp.left, contextTree, cs, boolean]
where boolean ← GetIntrinsicBooleanType[cs]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["OR expression used as l-value"]
for
Exp.and:
AbstractProduction [ Exp.left, Exp.right ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
MakeStaticBoolean[And[BooleanValue[lhs], BooleanValue[rhs]], boolean]
where rhs ← EvaluateAndTypeCheckExpression[Exp.right, lc, fl, cs, boolean]
where lhs ← EvaluateAndTypeCheckExpression[Exp.left, lc, fl, cs, boolean]
where boolean ← GetIntrinsicBooleanType[cs]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree2>
where result ←
if And[Static[lhs], Static[rhs]]
then MakeStaticBoolean[And[BooleanValue[lhs], BooleanValue[rhs]], boolean]
else
(MakeRuntimeValue[code, boolean
]
where code ← ConcatProgramFragments[ConcatProgramFragments[pushLHS, pushRHS], op]
where pushLHS ← Code[lhs]
where pushRHS ← Code[rhs]
where op ← MakePGAnd[]
)
where <rhs, contextTree2> ←
CompileAndTypeCheckExpression[Exp.right, contextTree1, cs, boolean]
where <lhs, contextTree1> ←
CompileAndTypeCheckExpression[Exp.left, contextTree, cs, boolean]
where boolean ← GetIntrinsicBooleanType[cs]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["AND expression used as l-value"]
for
Exp.not:
AbstractProduction [ Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
MakeStaticBoolean[Not[BooleanValue[rhs]], boolean]
where rhs ← EvaluateAndTypeCheckExpression[Exp, lc, fl, cs, boolean]
where boolean ← GetIntrinsicBooleanType[cs]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ←
if Static[rhs]
then MakeStaticBoolean[Not[BooleanValue[rhs]], boolean]
else
(MakeRuntimeValue[code, boolean
]
where code ← ConcatProgramFragments[Code[rhs], MakePGNot[]]
)
where <rhs, contextTree1> ←
CompileAndTypeCheckExpression[Exp, contextTree, cs, boolean]
where boolean ← GetIntrinsicBooleanType[cs]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["NOT expression used as l-value"]
for
Exp.relation:
AbstractProduction [ Exp, Relation ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["relation"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["relation"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Relation used as l-value"]
for
Exp.ifthenelse:
AbstractProduction [ Exp.cond, Exp.thenpart, Exp.elsepart ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
if BooleanValue[EvaluateAndTypeCheckExpression[Exp.cond, lc, fl, cs, boolean]]
then EvaluateAndTypeCheckExpression[Exp.thenpart, lc, fl, cs, targetType]
else EvaluateAndTypeCheckExpression[Exp.elsepart, lc, fl, cs, targetType]
where boolean ← GetIntrinsicBooleanType[cs]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree4>
where <result, contextTree4> ←
if Static[condition]
then
if BooleanValue[condition]
then CompileAndTypeCheckExpression[Exp.thenpart, contextTree1, cs, targetType]
else CompileAndTypeCheckExpression[Exp.elsepart, contextTree1, cs, targetType]
else
(<MakeRuntimeValue[code, targetType
], contextTree3>
-- is targetType
correct here?
where code ← MakePGTest[Code[condition], Code[thenPart], Code[elsePart]]
where <elsePart, contextTree3> ← CompileAndTypeCheckExpression[Exp.elsepart, contextTree2, cs, targetType]
where <thenPart, contextTree2> ← CompileAndTypeCheckExpression[Exp.thenpart, contextTree1, cs, targetType]
)
where <condition, contextTree1> ← CompileAndTypeCheckExpression[Exp.cond, contextTree, cs, booleanType]
where booleanType ← GetIntrinsicBooleanType[cs]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["IF expression used as l-value"]
for
Exp.select:
AbstractProduction [ SelectHead, SelectExpList, Exp.default ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["select"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["select"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["SELECT expression used as l-value"]
for
Exp.assign:
AbstractProduction [ Exp.lhs, Exp.rhs ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeTrash[targetType]
where err ← Error["Exp.assign should never be evaluated!"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeRuntimeValue[code, tgn]
where code ← ConcatProgramFragments[Code[rhsValue], storeTOS]
where storeTOS ←
if PFDIsLocal[lvalue]
then MakePGStoreLocal[lvalue]
else MakePGStoreIndirect[lvalue]
where <rhsValue, contextTree1> ←
CompileAndTypeCheckExpression[Exp.rhs, contextTree, cs, tgn]
where <lvalue, tgn> ← CompileLValue[Exp.lhs, contextTree, cs]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Assignment expression used as l-value"]
for
Exp.multiassign:
AbstractProduction [ ExpList, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeTrash[targetType]
where err ← Error["Exp.multiassign should never be evaluated!"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["multiassign"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Multiple assignment expression used as l-value"]
for
Exp.id:
AbstractProduction [ Id ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← result
where result ←
if Static[value]
then value
else (MakeDummy[""]
where err ← Error["blat"])
do we need to do a type check here?
where <access, tgn, initialization, value> ← DemandConstantField[field2]
where field2 ←
if FieldExists[field1]
then field1
else LookupNameInContextRib[Id, ParentRib[lc]]
where field1 ← LookupNameInFieldList[fl, Id]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where contextTree1 ← FakeDamageContextTree[contextTree]
where result ← CompileLValueIntoRValue[expAsLValue, contextTree]
where <expAsLValue, tgn> ← CompileLValue[tree, contextTree, cs]
let CompileLValue[tree, contextTree, cs] ← GetPathToName[contextTree, Id]
for
Exp.num:
AbstractProduction [ Num ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← result
where result ← CastIntegerValue[integerValue, GetIntrinsicIntegerTypes[cs]]
where integerValue ← IntegerValueFromLiteral[Num]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← CastIntegerValue[integerValue, GetIntrinsicIntegerTypes[cs]]
where integerValue ← IntegerValueFromLiteral[Num]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Number literal used as l-value"]
for
Exp.string:
AbstractProduction [ String ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["string"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["string"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["String literal used as l-value"]
for
Exp.flnum:
AbstractProduction [ Flnum ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["flnum"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["flnum"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["REAL literal used as l-value"]
for
Exp.char:
AbstractProduction [ Char ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["char"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["char"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Character literal used as l-value"]
for
Exp.atom:
AbstractProduction [ Atom ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["atom"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["atom"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Character literal used as l-value"]
for
Exp.narrow:
AbstractProduction [ Exp, OptType, Catch ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["narrow"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["narrow"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["NARROW expression used as l-value"]
for
Exp.loophole:
AbstractProduction [ Exp, OptType ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["loophole"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["loophole"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["LOOPHOLE expression used as l-value"]
for
Exp.apply:
AbstractProduction [ Exp.rator, Exp.rand, Catch ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["apply"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["apply"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Apply expression used as l-value"]
for
Exp.qualifier:
AbstractProduction [ Exp, Qualifier ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["qualifier"]
let CompileExpression[tree, contextTree, cs, targetType] ←
CompileQualifiedExpression[Qualifier, value, contextTree1, cs, targetType]
where <value, contextTree1> ← CompileAndTypeCheckExpression[Exp, contextTree, cs, top]
where top ← GetTop[cs]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Qualifier l-value not implemented yet!!!!!!!!!"]
for
Exp.explist:
AbstractProduction [ ExpList ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["explist"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["explist"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["ExpList l-value not implemented yet!!!!!!!!!"]
for
Exp.prefixop:
AbstractProduction [ PrefixOp, OrderList ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["prefixop"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["prefixop"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["PrefixOp expression used as l-value"]
for
Exp.val:
AbstractProduction [ OrderList ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["val"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["val"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Val expression used as l-value"]
for
Exp.all:
AbstractProduction [ OrderList ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["all"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["all"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["ALL expression used as l-value"]
for
Exp.new:
AbstractProduction [ New, TypeExp, Initialization, Catch ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeTrash[targetType]
where err ← Error["Should not be evaluating Exp.new!"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["new"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["NEW expression used as l-value"]
for
Exp.cons:
AbstractProduction [ Cons, ExpList, Catch ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeTrash[targetType]
where err ← Error["Should not be evaluating Exp.cons!"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["cons"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["CONS expression used as l-value"]
for
Exp.listcons:
AbstractProduction [ ListCons, ExpList ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeTrash[targetType]
where err ← Error["Should not be evaluating Exp.listcons!"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["listcons"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["ListCons expression used as l-value"]
for
Exp.nil:
AbstractProduction [ ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["nil"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["nil"]
where contextTree1 ← FakeDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["NIL expression used as l-value"]
End;
SaffronValueCompile2: Module = Begin
for
Exp.typeop:
AbstractProduction [ TypeOp, TypeExp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ←
if TypeOpIsCode[TypeOp]
then ( MakeDummy[""]
where err ← Error["EvaluateExpression not implemented for code Exp.typeop"]
)
else
if TypeOpIsFirst[TypeOp]
then EvaluateFirstOfTypeExpression[TypeExp, lc, fl, cs, targetType]
else
if TypeOpIsLast[TypeOp]
then EvaluateLastOfTypeExpression[TypeExp, lc, fl, cs, targetType]
else
if TypeOpIsNil[TypeOp]
then ( MakeDummy[""]
where err ← Error["EvaluateExpression not implemented for nil Exp.typeop"]
)
else ( MakeDummy[""]
where err ← Error["in EvaluateExpression for Exp.typeop"]
)
let CompileExpression[tree, contextTree, cs, targetType] ←
if TypeOpIsCode[TypeOp]
then ( <dummy, contextTree1>
where dummy ← MakeDummy[""]
where contextTree1 ← FakeDamageContextTree[contextTree]
where err ← Error["CompileExpression not implemented for code Exp.typeop"]
)
else
if TypeOpIsFirst[TypeOp]
then ( <first, contextTree1>
where contextTree1 ← FakeDamageContextTree[contextTree]
where first ← CompileFirstOfTypeExpression[TypeExp, contextTree, cs, targetType]
)
else
if TypeOpIsLast[TypeOp]
then ( <last, contextTree1>
where contextTree1 ← FakeDamageContextTree[contextTree]
where last ← CompileLastOfTypeExpression[TypeExp, contextTree, cs, targetType]
)
else
if TypeOpIsNil[TypeOp]
then ( <dummy, contextTree1>
where dummy ← MakeDummy[""]
where contextTree1 keDamageContextTree[contextTree]
where err ← Error["CompileExpression not implemented for nil Exp.typeop"]
)
else ( <dummy, contextTree1>
where dummy ← MakeDummy[""]
where contextTree1 ← FakeDamageContextTree[contextTree]
where err ← Error["in CompileExpression for Exp.typeop"]
)
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["TypeOp expression used as l-value"]
;
for
Exp.size:
AbstractProduction [ TypeExp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["size"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["size"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["SIZE expression used as l-value"]
for
Exp.size2:
AbstractProduction [ TypeExp, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["size2"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["size2"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["SIZE2 expression used as l-value"]
;
for
Exp.bits:
AbstractProduction [ TypeExp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["bits"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["bits"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["BITS expression used as l-value"]
;
for
Exp.bits2:
AbstractProduction [ TypeExp, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["bits2"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["bits2"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["BITS2 expression used as l-value"]
for
Exp.bytes:
AbstractProduction [ TypeExp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["bytes"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["bytes"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["BYTES expression used as l-value"]
for
Exp.bytes2:
AbstractProduction [ TypeExp, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["bytes2"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["bytes2"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["BYTES2 expression used as l-value"]
for
Exp.units:
AbstractProduction [ TypeExp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["units"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["units"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["UNITS expression used as l-value"]
for
Exp.units2:
AbstractProduction [ TypeExp, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["units2"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["units2"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["UNITS2 expression used as l-value"]
for
Exp.words:
AbstractProduction [ TypeExp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["words"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["words"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["WORDS expression used as l-value"]
for
Exp.words2:
AbstractProduction [ TypeExp, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["words2"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["words2"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["WORDS2 expression used as l-value"]
for
Exp.istype:
AbstractProduction [ Exp, TypeExp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["istype"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["istype"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["ISTYPE expression used as l-value"]
for
Exp.address:
AbstractProduction [ Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["address"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["address"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["@ expression used as l-value"]
for
Exp.descriptor:
AbstractProduction [ DescList ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["descriptor"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["descriptor"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Descriptor used as l-value"]
for
Exp.error:
AbstractProduction [ ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["error"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["error"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["ERROR used as l-value"]
for
Exp.transfer:
AbstractProduction [ TransferOp, Exp ]
let EvaluateExpression[tree, lc, fl, cs, targetType] ← MakeDummy["transfer"]
let CompileExpression[tree, contextTree, cs, targetType] ← <result, contextTree1>
where result ← MakeDummy["transfer"]
where contextTree1 keDamageContextTree[contextTree]
let CompileLValue[tree, contextTree, cs] ← <pfd, tgn>
where pfd ← EmptyPFD[]
where tgn ← GetIntrinsicBooleanType[cs] -- any type will do...
where err ← Error["Transfer expression used as l-value"]
;
for
Num.decimal:
AbstractProduction [Decimalnum]
let IntegerValueFromLiteral[tree] ← ParseIntegerLiteral[digits, 10]
where digits ← RopeFromDecimalnum[Decimalnum];
for
Num.octal:
AbstractProduction [Octalnum]
let IntegerValueFromLiteral[tree] ← ParseIntegerLiteral[digits, 8]
where digits ← RopeFromOctalnum[Octalnum];
for
Num.hex:
AbstractProduction [
Hexnum]
let IntegerValueFromLiteral[tree] ← ParseIntegerLiteral[digits, 16]
where digits ← RopeFromHexnum[Hexnum];
for
AddOp.plus:
AbstractProduction []
let IsPlus[tree] ← True[]
let IsMinus[tree] ← False[];
for
AddOp.minus:
AbstractProduction []
let IsPlus[tree] ← False[]
let IsMinus[tree] ← True[];
for
MultOp.times:
AbstractProduction []
let IsTimes[tree] ← True[]
let IsDivide[tree] ← False[]
let IsMod[tree] ← False[];
for
MultOp.divide:
AbstractProduction []
let IsTimes[tree] ← False[]
let IsDivide[tree] ← True[]
let IsMod[tree] ← False[];
for
MultOp.mod:
AbstractProduction []
let IsTimes[tree] ← False[]
let IsDivide[tree] ← False[]
let IsMod[tree] ← True[];
for
Relop.eq:
AbstractProduction []
let GetRelationOp[tree] ← RelationOp.eq;
for
Relop.ne:
AbstractProduction []
let GetRelationOp[tree] ← RelationOp.ne;
for
Relop.lt:
AbstractProduction []
let GetRelationOp[tree] ← RelationOp.lt;
for
Relop.le:
AbstractProduction []
let GetRelationOp[tree] ← RelationOp.le;
for
Relop.gt:
AbstractProduction []
let GetRelationOp[tree] ← RelationOp.gt;
for
Relop.ge:
AbstractProduction []
let GetRelationOp[tree] ← RelationOp.ge;
for
Initialization.empty:
AbstractProduction []
let InitializationIsEmpty[tree] ← True[]
let InitializationIsBinding[tree] ← False[]
let InitializationIsAssignment[tree] ← False[]
let Compile[tree, contextTree, cs] ← <contextTree1, trash>
where trash ←
let GetInitialValue[tree] ← MakeDummy["Initialization.empty"]
;
for
Initialization.binding:
AbstractProduction [InitialValue]
let InitializationIsEmpty[tree] ← False[]
let InitializationIsBinding[tree] ← True[]
let InitializationIsAssignment[tree] ← False[]
let GetInitialValue[tree] ← GetInitialValue[InitialValue]
;
for
Initialization.assignment:
AbstractProduction [InitialValue]
let InitializationIsEmpty[tree] ← False[]
let InitializationIsBinding[tree] ← False[]
let InitializationIsAssignment[tree] ← True[]
let GetInitialValue[tree] ← GetInitialValue[InitialValue]
;
for
InitialValue.trash:
AbstractProduction []
let GetInitialValue[tree] ← MakeDummy["InitialValue.trash"]
;
for
InitialValue.code:
AbstractProduction []
let GetInitialValue[tree] ← MakeDummy["InitialValue.code"]
;
for
InitialValue.exp:
AbstractProduction [Exp]
let GetInitialValue[tree] ← MakeUnparsedValue[Exp]
;
for
InitialValue.block:
AbstractProduction [Checked, Inline, Block]
let GetInitialValue[tree] ← MakeDummy["InitialValue.block"]
;
for
InitialValue.machinecode:
AbstractProduction [Checked, CodeList]
let GetInitialValue[tree] ← MakeDummy["InitialValue.machinecode"]
;
for
TypeOp.code:
AbstractProduction []
let TypeOpIsCode[tree] ← True[]
let TypeOpIsFirst[tree] ← False[]
let TypeOpIsLast[tree] ← False[]
let TypeOpIsNil[tree] ← False[];
for
TypeOp.
first:
AbstractProduction []
let TypeOpIsCode[tree] ← False[]
let TypeOpIsFirst[tree] ← True[]
let TypeOpIsLast[tree] ← False[]
let TypeOpIsNil[tree] ← False[];
for
TypeOp.
last:
AbstractProduction []
let TypeOpIsCode[tree] ← False[]
let TypeOpIsFirst[tree] ← False[]
let TypeOpIsLast[tree] ← True[]
let TypeOpIsNil[tree] ← False[];
for
TypeOp.
nil:
AbstractProduction []
let TypeOpIsCode[tree] ← False[]
let TypeOpIsFirst[tree] ← False[]
let TypeOpIsLast[tree] ← False[]
let TypeOpIsNil[tree] ← True[];
for
Qualifier.prefixop:
AbstractProduction [PrefixOp]
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
for
Qualifier.
typeop:
AbstractProduction [TypeOp]
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
for
Qualifier.
size:
AbstractProduction []
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
for
Qualifier.
bits:
AbstractProduction []
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
for
Qualifier.
bytes:
AbstractProduction []
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
for
Qualifier.
units:
AbstractProduction []
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
for
Qualifier.
words:
AbstractProduction []
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
for
Qualifier.
apply:
AbstractProduction [ExpList, Catch]
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.apply"],
FakeDamageContextTree[contextTree]
>
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ←
if IsTransferTGN[expType]
then (<value, contextTree1>
where value ← MakeDummy["Qualifier.prefixop"]
where contextTree1 ← FakeDamageContextTree[contextTree]
)
else if IsArrayTGN[expType]
then (<value, contextTree1>
where value ← MakeDummy["Qualifier.prefixop"]
where contextTree1 ← FakeDamageContextTree[contextTree]
)
else (<value, contextTree1>
where value ← MakeDummy["Qualifier.prefixop"]
where contextTree1 ← FakeDamageContextTree[contextTree]
)
where expType ← Type[expValue]
;
for
Qualifier.
select:
AbstractProduction [Id]
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
for
Qualifier.
indirect:
AbstractProduction []
let CompileQualifiedExpression[tree, expValue, contextTree, cs, targetType] ← <
MakeDummy["Qualifier.prefixop"],
FakeDamageContextTree[contextTree]
>
;
End;