RiscAssemblerParser: Control Module; RiscAssemblerToken: Module = Begin { "NOOP" "GOTO" ":" ";" "." } : SimpleTokens; id: GenericToken = "tokenID"; End; RiscAssemblerCG: Module = Begin goal: NonTerminal Builds Program; for goal _ program Build program; program: NonTerminal Builds Program; for program.list _ list "." Build Program.list[list]; list: NonTerminal Builds List; for list.statement _ statement Build List.statement[statement]; for list.dangle _ statement ";" Build List.dangle[statement]; for list.cons _ statement ";" list Build List.cons[statement, list]; statement: NonTerminal Builds Statement; for statement.label _ label ":" statement Build Statement.label[label, statement]; for statement.op _ op Build Statement.op[op]; for statement.oprand _ op rand Build Statement.oprand[op, rand]; label: NonTerminal Builds Label; for label.id _ id Build Label.id[id]; op: NonTerminal Builds Op; for op.noop _ "NOOP" Build Op.noop[]; for op.goto _ "GOTO" Build Op.goto[]; rand: NonTerminal Builds Rand; for rand.id _ id Build Rand.id[id]; End; RiscAssemblerAG: Module = Begin Program.list: AbstractProduction [ List ]; List.statement: AbstractProduction [ Statement ]; List.dangle: AbstractProduction [ Statement ]; List.cons: AbstractProduction [ Statement, List ]; Statement.label: AbstractProduction [ Label, Statement ]; Statement.op: AbstractProduction [ Op ]; Statement.oprand: AbstractProduction [ Op, Rand ]; Label.id: AbstractProduction [ id ]; Op.noop: AbstractProduction [ ]; Op.goto: AbstractProduction [ ]; Rand.id: AbstractProduction [ id ]; End; RiscAssemblerDoit: Module = Begin for Program.list: AbstractProduction [ List ] let Assemble[tree] _ < codeBody, symbolTable, nextAddress > where codeBody _ CodeSequence[List, symbolTable] where < symbolTable, nextAddress > _ SymbolTable[List, initialTable, initialAddress] where initialAddress _ CodeOrigin[] where initialTable _ InitialSymbolTable[] ; for List.statement: AbstractProduction [ Statement ] let SymbolTable[tree, initialTable, initialAddress] _ SymbolTable[Statement, initialTable, initialAddress] let CodeSequence[tree, symbolTable] _ CodeSequence[Statement, symbolTable] ; for List.dangle: AbstractProduction [ Statement ] let SymbolTable[tree, initialTable, initialAddress] _ SymbolTable[Statement, initialTable, initialAddress] let CodeSequence[tree, symbolTable] _ CodeSequence[Statement, symbolTable] ; for List.cons: AbstractProduction [ Statement, List ] let SymbolTable[tree, initialTable, initialAddress] _ SymbolTable[List, newTable, nextAddress] where < newTable, nextAddress> _ SymbolTable[Statement, initialTable, initialAddress] let CodeSequence[tree, symbolTable] _ CodeConcat[first, rest] where rest _ CodeSequence[List, symbolTable] where first _ CodeSequence[Statement, symbolTable] ; for Statement.label: AbstractProduction [ Label, Statement ] let SymbolTable[tree, initialTable, initialAddress] _ SymbolTable[Statement, newTable, nextAddress] where newTable _ SymbolConcat[initialTable, entry] where entry _ NotePosition[Label, initialAddress, definedAt] where nextAddress _ Succ[initialAddress] where definedAt _ SourcePosition[Label] where len _ SourceLength[Label] let CodeSequence[tree, symbolTable] _ CodeSequence[Statement, symbolTable] ; for Statement.op: AbstractProduction [ Op ] let SymbolTable[tree, initialTable, initialAddress] _ < newTable, nextAddress > where newTable _ SymbolCopy[initialTable] where nextAddress _ Succ[initialAddress] let CodeSequence[tree, symbolTable] _ InstructionSequence[segment] where segment _ Instruction[Op] ; for Statement.oprand: AbstractProduction [ Op, Rand ] let SymbolTable[tree, initialTable, initialAddress] _ < newTable, nextAddress > where newTable _ SymbolCopy[initialTable] where nextAddress _ Succ[initialAddress] let CodeSequence[tree, symbolTable] _ InstructionSequence[segment] where segment _ InstructionRand[Op, label] where label _ Index[Rand, symbolTable] ; for Label.id: AbstractProduction [ id ] let NotePosition[tree, address, definedAt] _ NewLabel[id, address, definedAt] ; for Op.noop: AbstractProduction [ ] let Instruction[tree] _ Code[Opcode.noop] let InstructionRand[tree, index] _ CodeRandFirewall[Opcode.noop, index] ; for Op.goto: AbstractProduction [ ] let Instruction[tree] _ CodeFirewall[Opcode.goto] let InstructionRand[tree, index] _ CodeRand[Opcode.goto, index] ; for Rand.id: AbstractProduction [ id ] let Index[tree, symbolTable] _ SymbolIndex[symbolTable, id] ; End; RiscAssemblerAT: Module = Begin Program: AbstractType [ Assemble ]; List: AbstractType [ SymbolTable, CodeSequence ]; Statement: AbstractType [ SymbolTable, CodeSequence ]; Label: AbstractType [ NotePosition ]; Op: AbstractType [ Instruction, InstructionRand ]; Rand: AbstractType [ Index ]; End; RiscAssemblerTree: Module = Begin Assemble: TreeRecursiveFunction [ Tree ] Returns [ EncodingSequence.program, Table.all, INT.nextAddress ]; SymbolTable: TreeRecursiveFunction [ Tree, Table.old, INT.first ] Returns [ Table.new, INT.next ]; NotePosition: TreeRecursiveFunction [ Tree, INT.address, INT.definedAt ] Returns [ LabelInstance.id ]; CodeSequence: TreeRecursiveFunction [ Tree, Table ] Returns [ EncodingSequence.list ]; Instruction: TreeRecursiveFunction [ Tree ] Returns [ Encoding.instr ]; InstructionRand: TreeRecursiveFunction [ Tree, LabelInstance.id ] Returns [ Encoding.instr ]; Index: TreeRecursiveFunction [ Tree, Table ] Returns [ LabelInstance.index ]; End; RiscAssemblerBase: Module = Begin INT: CedarType; ROPE: CedarType From Rope; LabelInstance: CedarType From RiscAssembler; Encoding: CedarType From RiscAssembler; EncodingSequence: CedarType From RiscAssembler; Table: CedarType From RedBlackTree; Succ: CedarFunction [ INT.val ] Returns [ INT.succ ] From RiscAssembler; Opcode: EnumeratedBaseType = { noop, goto }; CodeConcat: BaseFunction [ EncodingSequence.left, EncodingSequence.right ] Returns [ EncodingSequence.list ]; InstructionSequence: BaseFunction [ Encoding.instr ] Returns [ EncodingSequence.list ]; Code: BaseFunction [ Opcode.op ] Returns [ Encoding.instr ]; CodeFirewall: BaseFunction [ Opcode.op ] Returns [ Encoding.instr ]; CodeRand: BaseFunction [ Opcode.op, LabelInstance.index ] Returns [ Encoding.instr ]; CodeRandFirewall: BaseFunction [ Opcode.op, LabelInstance.index ] Returns [ Encoding.instr ]; SymbolCopy: BaseFunction [ Table.old ] Returns [ Table.new ] SharedReps [ Table.old ]; SymbolConcat: BaseFunction [ Table.old, LabelInstance.entry ] Returns [ Table.new ] SharedReps [ Table.old ]; CodeOrigin: BaseFunction [ ] Returns [ INT.origin ]; InitialSymbolTable: BaseFunction [ ] Returns [ Table.new ]; NewLabel: BaseFunction [ id, INT.address, INT.definedAt ] Returns [ LabelInstance.id ]; SymbolIndex: BaseFunction [ Table, id.label ] Returns [ LabelInstance.index ]; End. δRiscAssembler.ThreeC4 Copyright Σ 1987 by Xerox Corporation. All rights reserved. Bill Jackson (bj) May 27, 1987 7:49:06 pm PDT Lucy Hederman July 15, 1987 4:52:11 pm PDT Tokens Program: AbstractType[ ]; List: AbstractType[ ]; Statement: AbstractType[ ]; Label: AbstractType[ ]; Op: AbstractType[ ]; Rand: AbstractType[ ]; Program List We might want to issue a warning here about the null statement! Statement Label There's a lie here in that the "initialTable" is being augmented with an entry for the new symbol which contains only the text, but that can be fixed later... Op Rand Recursive Functions the primary (synthesis) operation of the assembler, produces a code sequence, a symbol table, and the length of the code sequence (represented as start+len=last+1). Note that this is a two pass operations where the symbol table is constructed in pass 1, and the code sequence is produced in pass 2 (where children recieve the symbol table as an inherited value). the operation which produces values for symbols by synthesizing representations (virtual addresses in INT's) as values for symbolic labels a noop which provides us with the ability to recognize positions of GenericTokens(id) the gradual synthesis of the module/program via concatenation of Instruction Sequences. the encoding of a primitive operation for the "machine". the encoding of a primitive operation (with operand) for the "machine". the virtual program counter for instructions. Cedar Primitives Base Functions eof... Κ ‡•StyleDefΫBeginStyle (cedar) AttachStyle (codeTab30) (set up the fancy tabs) {code 30 mm flushLeft tabStop} StyleRule (codeTab35) (set up the fancy tabs) {code 35 mm flushLeft tabStop} StyleRule (codeTab40) (set up the fancy tabs) {code 40 mm flushLeft tabStop} StyleRule (codeTab45) (set up the fancy tabs) {code 45 mm flushLeft tabStop} StyleRule EndStyle˜ codetab35™K™Nš’œ˜"N˜—š£œ˜Nš’ œ˜Nš’œ˜"N˜—š£œ˜Nš’ œ˜Nš’œ˜N˜—š£ œ˜ Nš’ œ˜Nš’œ˜N˜—š£œ˜ Nš’ œ#˜/Nš’œ˜N˜—š£œ˜Nš’ œ#˜/Nš’œ˜N˜—š£ œ˜ Nš’ œ˜Nš’œ ¦œ˜Nš’ œ˜N˜—š£ œ˜ Nš’ œ#˜/Nš’œ ¦œ˜Nš’ œ˜N˜—š£ œ˜ Nš’ œ˜Nš’œ¦œ ˜N˜—š£œ˜Nš’ œ˜Nš’œ ¦œ˜N˜—š£œ˜ Nš’ œ¦œ ¦œ ˜/Nš’œ˜N˜—š£ œ˜ Nš’ œ˜ Nš’œ˜ N˜——N˜—K˜K™K˜—…—Ζ,1