Package components.program
Class Program1
java.lang.Object
components.program.ProgramSecondary
components.program.Program1
- All Implemented Interfaces:
Program,ProgramKernel,Standard<Program>
Program represented as a String, Map, and
Statement in the obvious way with implementations of primary methods.- Representation Invariant (concrete invariant of $this):
[$this.name is an IDENTIFIER] and [$this.context is a CONTEXT] and [$this.body is a BLOCK statement]- Abstraction Relation (interpretation mapping between $this and this):
this = ($this.name, $this.context, $this.body)
-
Nested Class Summary
Nested classes/interfaces inherited from interface components.program.Program
Program.Instruction -
Field Summary
Fields inherited from interface components.program.Program
INDENT_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclear()Resetsthisto an initial value.static voiddisassembleProgram(SimpleWriter out, int[] cp) Disassembles and outputs tooutthe given programcp.static voiddisassembleProgram(SimpleWriter out, int[] cp, int pc) Disassembles and outputs tooutthe given programcpmarking the location of the program counterpc.static voiddisassembleProgram(SimpleWriter out, Sequence<Integer> cp) Disassembles and outputs tooutthe given programcp.final Stringname()Returns the name ofthis.final StatementnewBody()Creates and returns aStatementwith a default initial value, of the dynamic type needed inswapBody.Creates and returns an emptyMap<String, Statement>of the dynamic type needed inswapContext.final ProgramReturns a new object with the same dynamic type asthis, having an initial value.final voidReplaces the name ofthiswithn.final voidExchanges the body ofthiswithb;bmust have the dynamic type returned bynewBody.final voidExchanges the context ofthiswithc;cmust have the dynamic type returned bynewContext.final voidtransferFrom(Program source) Setsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis.Methods inherited from class components.program.ProgramSecondary
equals, generatedCode, hashCode, parse, parse, prettyPrint, toString
-
Constructor Details
-
Program1
public Program1()No-argument constructor.
-
-
Method Details
-
newInstance
Description copied from interface:StandardReturns a new object with the same dynamic type asthis, having an initial value. If the typeThas a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initializethis.- Returns:
- new object "like"
thiswith an initial value
-
clear
Description copied from interface:StandardResetsthisto an initial value. If the typeThas a no-argument constructor, thenthissatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thenthissatisfies the contract of the constructor call that was used to initialize#this. -
transferFrom
Description copied from interface:StandardSetsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis. If the typeThas a no-argument constructor, thensourcesatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thensourcesatisfies the contract of the constructor call that was used to initialize#source.- Parameters:
source- object whose value is to be transferred
-
name
Description copied from interface:ProgramKernelReturns the name ofthis.- Returns:
- the name of
this
-
setName
Description copied from interface:ProgramKernelReplaces the name ofthiswithn.- Parameters:
n- the name replacing the old one
-
newContext
Description copied from interface:ProgramKernelCreates and returns an emptyMap<String, Statement>of the dynamic type needed inswapContext.- Returns:
- a new empty
Map<String, Statement>
-
swapContext
Description copied from interface:ProgramKernelExchanges the context ofthiswithc;cmust have the dynamic type returned bynewContext.- Parameters:
c- the context to be exchanged with that ofthis
-
newBody
Description copied from interface:ProgramKernelCreates and returns aStatementwith a default initial value, of the dynamic type needed inswapBody.- Returns:
- a new
Statement
-
swapBody
Description copied from interface:ProgramKernelExchanges the body ofthiswithb;bmust have the dynamic type returned bynewBody.- Parameters:
b- the body to be exchanged with that ofthis
-
disassembleProgram
Disassembles and outputs tooutthe given programcp.- Parameters:
out- the output streamcp- the compiled program- Updates:
out.content- Requires:
out.is_open and [cp is a valid compiled BL program]- Ensures:
out.content = #out.content * [disassembled cp]
-
disassembleProgram
Disassembles and outputs tooutthe given programcp.- Parameters:
out- the output streamcp- the compiled program- Updates:
out.content- Requires:
out.is_open and [cp is a valid compiled BL program]- Ensures:
out.content = #out.content * [disassembled cp]
-
disassembleProgram
Disassembles and outputs tooutthe given programcpmarking the location of the program counterpc.- Parameters:
out- the output streamcp- the compiled programpc- the program counter- Updates:
out.content- Requires:
out.is_open and [cp is a valid compiled BL program] and 0 <= pc < cp.length and [pc is the location of an instruction byte code in cp, that is, pc cannot be the location of an address]- Ensures:
out.content = #out.content * [disassembled cp with pc marked by an asterisk]
-