SaffronBlockCompileMethods.ThreeC4
James Rauen, August 10, 1988 7:02:59 am PDT
Last edited by: James Rauen August 25, 1988 1:54:12 pm PDT
Include [ SaffronBaseDecls, SaffronTreeDecls, SaffronAG, SaffronProgramGraphDecls ];
SaffronBlockCompile: Module = Begin
for Block: AbstractProduction [Scope, ExitList]
let CompileFrameBlock[tree, transferType, parentTree, pg, cs] ← <newTree, code, pg1>
where newTree ← AddSubContextTree[parentTree, childTree]
where <childTree, code, pg1> ← InternalCompileBlock[tree, lc1, fl, pg, cs]
where fl ← CreateEmptyFieldList[] -- add transfer bindings to field list!!
where lc1 ← CreateEmptyContext[Rib[parentTree], True[]]
let Compile[tree, parentTree, pg, cs] ← <newTree, code, pg1>
where newTree ← AddSubContextTree[parentTree, childTree]
where <childTree, code, pg1> ← InternalCompileBlock[tree, lc1, fl, pg, cs]
where fl ← CreateEmptyFieldList[]
where lc1 ← CreateEmptyContext[Rib[parentTree], False[]]
let InternalCompileBlock[tree, localContext, fl, pg, cs] ←
CompileScope[Scope, lc1, fl, pg, cs]
where lc1 ← FakeDamageContext[localContext] -- add exit list to lc!!
;
for Scope: AbstractProduction [BindList, Catch, OptDecList, StatementList]
let CompileScope[tree, localContext, fl, pg, cs] ← <contextTree3, pf3, pg2>
where pf3 ← ConcatProgramFragments[pf1, pf2]
where <contextTree3, pf2, pg2> ← Compile[StatementList, contextTree2, pg1, cs]
where <contextTree2, pf1, pg1> ← Compile[OptDecList, contextTree1, pg, cs]
where contextTree1 ← EmptyContextTree[rib]
where rib ← FreezeLocalContext[localContext3, blockTGN]
where <localContext3, blockTGN> ←
CreateBlockTGN[localContext2, FreezeFieldList[fieldList4]]
where <fieldList4, localContext2> ←
AnalyzeDependencies[dependencyGraph, fieldList3, localContext1, cs]
where dependencyGraph ← BuildDependencyGraph[fieldList3, localContext1]
where fieldList3 ← DiscernSpecianatedTGNs[fieldList2, localContext1]
where fieldList2 ← LookupIdentifierTGNs[fieldList1, localContext1]
where <fieldList1, localContext1> ←
AddDeclarationsToFieldList[OptDecList, fl, localContext, cs]
;
for DefBody: AbstractProduction [ BindList, DecList ]
let MakeContextTree[tree, contextRib, paintRecords, cs] ← contextTree2
maybe here we should gritch if there's any code.
where <contextTree2, pf1, pg1> ← Compile[DecList, contextTree1, pg, cs]
where pg ← CreateEmptyProgramGraph[]
where contextTree1 ← EmptyContextTree[rib]
where rib ← FreezeLocalContext[localContext3, interfaceTGN]
where <localContext3, interfaceTGN> ←
CreateInterfaceContentsTGN[localContext2, FreezeFieldList[fieldList4]]
where <fieldList4, localContext2> ←
AnalyzeDependencies[dependencyGraph, fieldList3, localContext1, cs]
where dependencyGraph ← BuildDependencyGraph[fieldList3, localContext1]
where fieldList3 ← DiscernSpecianatedTGNs[fieldList2, localContext1]
where fieldList2 ← LookupIdentifierTGNs[fieldList1, localContext1]
where <fieldList1, localContext1> ←
AddDeclarationsToFieldList[DecList, CreateEmptyFieldList[], localContext, cs]
where localContext ← CreateEmptyContext[contextRib, True[]]
;
End;
SaffronDeclarationCompile: Module = Begin
for OptDecList.absent: AbstractProduction []
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
;
for OptDecList.present: AbstractProduction [DecList]
let Compile[tree, contextTree, pg, cs] ← Compile[DecList, contextTree, pg, cs]
;
for DecList.one: AbstractProduction [Declaration]
let Compile[tree, contextTree, pg, cs] ← Compile[Declaration, contextTree, pg, cs]
;
for DecList.many: AbstractProduction [DecList.head, DecList.tail]
let Compile[tree, contextTree, pg, cs] ← <contextTree2, pf3, pg2>
where pf3 ← ConcatProgramFragments[pf1, pf2]
where <contextTree2, pf2, pg2> ← Compile[DecList.tail, contextTree1, pg1, cs]
where <contextTree1, pf1, pg1> ← Compile[DecList.head, contextTree, pg, cs]
;
for Declaration.opaquetype: AbstractProduction [ IdentList, Access, OptSize ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
;
for Declaration.type: AbstractProduction [ IdentList, Access.id, Access.type, TypeExp, Default ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
;
for Declaration.value: AbstractProduction [ IdentList, Access, Entry, ReadOnly, TypeExp, Initialization ]
let Compile[tree, contextTree, pg, cs] ← <contextTree1, pf, pg1>
where pf ←
if IsTrash[initialValue]
then MakePGNoOp[]
else (ConcatProgramFragments[pushInitialValue, storeInitialValue]
where pushInitialValue ← Code[initialValue]
where storeInitialValue ←
MakeCodeToStoreTOSInVariousLocalFrameSlots[IdentList, contextTree1]
)
where <contextTree1, initialValue, pg1> ←
CompileInitialization[Initialization, contextTree, pg, cs, targetType]
where targetType ← FieldType[anyCorrespondingField]
where anyCorrespondingField ← FindAFieldCorrespondingToDeclaration[contextTree, DeclarationPTreeVal[tree]]
;
for Initialization.empty: AbstractProduction []
let CompileInitialization[tree, contextTree, pg, cs, targetType] ← <
FakeDamageContextTree[contextTree],
CompileDefaultInitialization[targetType],
FakeDamageProgramGraph[pg] >
;
for Initialization.binding: AbstractProduction [InitialValue]
let CompileInitialization[tree, contextTree, pg, cs, targetType] ←
CompileInitialization[InitialValue, contextTree, pg, cs, targetType]
;
for Initialization.assignment: AbstractProduction [InitialValue]
let CompileInitialization[tree, contextTree, pg, cs, targetType] ←
CompileInitialization[InitialValue, contextTree, pg, cs, targetType]
;
for InitialValue.trash: AbstractProduction []
let CompileInitialization[tree, contextTree, pg, cs, targetType] ← <
FakeDamageContextTree[contextTree],
MakeTrash[targetType],
FakeDamageProgramGraph[pg] >
;
for InitialValue.code: AbstractProduction []
let CompileInitialization[tree, contextTree, pg, cs, targetType] ← <
FakeDamageContextTree[contextTree],
MakeTrash[targetType],
FakeDamageProgramGraph[pg] >
where err ← Error["CompileInitialization for InitialValue.code not yet implemented."]
;
for InitialValue.exp: AbstractProduction [Exp]
let CompileInitialization[tree, contextTree, pg, cs, targetType] ← <contextTree1, value, pg1>
where <value, contextTree1> ← CompileExpression[Exp, contextTree, cs, targetType]
where pg1 ← FakeDamageProgramGraph[pg]
important note for documentation: CompileExpression never adds anything to the program graph!!!
;
for InitialValue.block: AbstractProduction [Checked, Inline, Block]
let CompileInitialization[tree, contextTree, pg, cs, targetType] ← <contextTree1, value, pg2>
where pg2 ← AddSubroutineProcedureGraphToProgramGraph[procedureGraph, pg1]
where value ← MakeTransferValue[targetType, procedureGraph]
where procedureGraph ← MakeProcedureGraph[blockCode]
where <contextTree1, blockCode, pg1> ← CompileFrameBlock[Block, targetType, contextTree, pg, cs]
warning: we're doing nothing about Checked or Inline!!
note: there's a lot of stuff going on here.
;
for InitialValue.machinecode: AbstractProduction [Checked, CodeList]
let CompileInitialization[tree, contextTree, pg, cs, targetType] ← <
FakeDamageContextTree[contextTree],
MakeTrash[targetType],
FakeDamageProgramGraph[pg] >
where err ← Error["CompileInitialization for InitialValue.machinecode not yet implemented."]
;
for IdentList.one: AbstractProduction [Ident]
let MakeCodeToStoreTOSInVariousLocalFrameSlots[tree, contextTree] ←
MakeCodeToStoreTOSInVariousLocalFrameSlots[Ident, contextTree]
;
for IdentList.many: AbstractProduction [IdentList.head, IdentList.tail]
let MakeCodeToStoreTOSInVariousLocalFrameSlots[tree, ct] ← pf4
where pf4 ← ConcatProgramFragments[ConcatProgramFragments[pf1, pf2], pf3]
where pf3 ← MakeCodeToStoreTOSInVariousLocalFrameSlots[IdentList.tail, ct]
where pf2 ← MakePGNoOp[] -- this should be MakePGDuplicate!!!
where pf1 ← MakeCodeToStoreTOSInVariousLocalFrameSlots[IdentList.head, ct]
;
for Ident.id: AbstractProduction [Id]
let MakeCodeToStoreTOSInVariousLocalFrameSlots[tree, contextTree] ← pf
where pf ← MakePGStoreLocal[pfd]
where <pfd, tgn> ← GetPathToName[contextTree, Id]
;
for Ident.idposition: AbstractProduction [Id, Position]
let MakeCodeToStoreTOSInVariousLocalFrameSlots[tree, contextTree] ← pf
where pf ← MakePGStoreLocal[pfd]
where <pfd, tgn> ← GetPathToName[contextTree, Id]
;
End;
SaffronStatementCompile: Module = Begin
for StatementList.empty: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
;
for StatementList.more: AbstractProduction [ StatementList, Statement ]
let Compile[tree, contextTree, pg, cs] ← <contextTree2, pf3, pg2>
where pf3 ← ConcatProgramFragments[pf1, pf2]
where <contextTree2, pf2, pg2> ← Compile[Statement, contextTree1, pg1, cs]
where <contextTree1, pf1, pg1> ← Compile[StatementList, contextTree, pg, cs]
;
Conditionals: IF...THEN and IF...THEN...ELSE
for Statement.ifthen: AbstractProduction [ Exp, Statement ]
let Compile[tree, contextTree, pg, cs] ← <contextTree2, code, pg1>
where code ← MakePGTest[Code[testValue], ifTrueCode, ifFalseCode]
where ifFalseCode ← MakePGNoOp[]
where <contextTree2, ifTrueCode, pg1> ← Compile[Statement, contextTree1, pg, cs]
where <testValue, contextTree1> ←
CompileAndTypeCheckExpression[Exp, contextTree, cs, booleanType]
where booleanType ← GetIntrinsicBooleanType[cs]
;
For conditionals, if the test is a static value, do we want to actually compile both arms of the conditional? Right now I am, but it's trivial to change these methods to only compile an arm if it is needed.
for Statement.ifthenelse:AbstractProduction [ Exp, Statement.thenpart, Statement.elsepart ]
let Compile[tree, contextTree, pg, cs] ← <contextTree3, code, pg2>
where code ← MakePGTest[testCode, ifTrueCode, ifFalseCode]
where <contextTree3, ifFalseCode, pg2> ← Compile[Statement.elsepart, contextTree2, pg1, cs]
where <contextTree2, ifTrueCode, pg1> ← Compile[Statement.thenpart, contextTree1, pg, cs]
where testCode ← Code[testValue]
where <testValue, contextTree1> ←
CompileAndTypeCheckExpression[Exp, contextTree, cs, booleanType]
where booleanType ← GetIntrinsicBooleanType[cs]
why doesn't this work???
let Compile[tree, contextTree, pg, cs] ← <contextTree2, code>
where code ← if Static[testValue]
then if BooleanValue[testValue]
then ifTrueCode
else ifFalseCode
else MakePGTest[testCode, ifTrueCode, ifFalseCode]
where <contextTree3, ifFalseCode> ← Compile[Statement.elsepart, contextTree2, cs]
where <contextTree2, ifTrueCode> ← Compile[Statement.thenpart, contextTree1, cs]
where testCode ← Code[testValue]
where <testValue, contextTree1> ←
CompileAndTypeCheckExpression[Exp, contextTree, cs, booleanType]
where booleanType ← GetIntrinsicBooleanType[cs]
;
for Statement.select: AbstractProduction [ SelectHead, SelectStmtList, OptStatement ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.select not implemented yet."]
;
for Statement.exp: AbstractProduction [ Exp ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.exp not implemented yet."]
;
for Statement.assign: AbstractProduction [ Exp.lhs, Exp.rhs ]
let Compile[tree, contextTree, pg, cs] ← <contextTree1, code, FakeDamageProgramGraph[pg]>
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]
;
for Statement.multiassign: AbstractProduction [ ExpList, Exp ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.multiassign not implemented yet."]
;
for Statement.block: AbstractProduction [ Checked, Block ]
let Compile[tree, contextTree, pg, cs] ← Compile[Block, contextTree, pg, cs]
Note: We have no notion of trusted/safe/unsafe program graphs yet. (I wonder what we're going to do with MACHINE CODE...) So the Checked argument is ignored.
;
for Statement.loopcontrol: AbstractProduction [ ForClause, DoTest, Scope, DoExit ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.loopcontrol not implemented yet."]
;
for Statement.exit: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.exit not implemented yet."]
;
for Statement.loop: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.loop not implemented yet."]
;
for Statement.goto: AbstractProduction [ Id ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.goto not implemented yet."]
;
for Statement.return: AbstractProduction [ OptArgs ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.return not implemented yet."]
;
for Statement.transfer: AbstractProduction [ Transfer, Exp ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.transfer not implemented yet."]
;
for Statement.free: AbstractProduction [ Free, Exp, Catch ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.free not implemented yet."]
;
for Statement.wait: AbstractProduction [ Exp ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.wait not implemented yet."]
;
for Statement.error: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.error not implemented yet."]
;
for Statement.stop: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.stop not implemented yet."]
;
for Statement.null: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
;
for Statement.resume: AbstractProduction [ OptArgs ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.resume not implemented yet."]
;
for Statement.reject: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.reject not implemented yet."]
;
for Statement.continue: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.continue not implemented yet."]
;
for Statement.retry: AbstractProduction [ ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.retry not implemented yet."]
;
for Statement.getstate: AbstractProduction [ Exp ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.getstate not implemented yet."]
;
for Statement.setstate: AbstractProduction [ Exp ]
let Compile[tree, contextTree, pg, cs] ← <
FakeDamageContextTree[contextTree],
MakePGNoOp[],
FakeDamageProgramGraph[pg] >
where err ← Error["Compile for Statement.setstate not implemented yet."]
;
End.