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
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
Resetsthis
to an initial value.static void
disassembleProgram
(SimpleWriter out, int[] cp) Disassembles and outputs toout
the given programcp
.static void
disassembleProgram
(SimpleWriter out, int[] cp, int pc) Disassembles and outputs toout
the given programcp
marking the location of the program counterpc
.static void
disassembleProgram
(SimpleWriter out, Sequence<Integer> cp) Disassembles and outputs toout
the given programcp
.final String
name()
Returns the name ofthis
.final Statement
newBody()
Creates and returns aStatement
with a default initial value, of the dynamic type needed inswapBody
.Creates and returns an emptyMap<String, Statement>
of the dynamic type needed inswapContext
.final Program
Returns a new object with the same dynamic type asthis
, having an initial value.final void
Replaces the name ofthis
withn
.final void
Exchanges the body ofthis
withb
;b
must have the dynamic type returned bynewBody
.final void
Exchanges the context ofthis
withc
;c
must have the dynamic type returned bynewContext
.final void
transferFrom
(Program source) Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must 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:Standard
Returns a new object with the same dynamic type asthis
, having an initial value. If the typeT
has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT
. IfT
does 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"
this
with an initial value
-
clear
Description copied from interface:Standard
Resetsthis
to an initial value. If the typeT
has a no-argument constructor, thenthis
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thenthis
satisfies the contract of the constructor call that was used to initialize#this
. -
transferFrom
Description copied from interface:Standard
Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
. If the typeT
has a no-argument constructor, thensource
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thensource
satisfies 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:ProgramKernel
Returns the name ofthis
.- Returns:
- the name of
this
-
setName
Description copied from interface:ProgramKernel
Replaces the name ofthis
withn
.- Parameters:
n
- the name replacing the old one
-
newContext
Description copied from interface:ProgramKernel
Creates and returns an emptyMap<String, Statement>
of the dynamic type needed inswapContext
.- Returns:
- a new empty
Map<String, Statement>
-
swapContext
Description copied from interface:ProgramKernel
Exchanges the context ofthis
withc
;c
must have the dynamic type returned bynewContext
.- Parameters:
c
- the context to be exchanged with that ofthis
-
newBody
Description copied from interface:ProgramKernel
Creates and returns aStatement
with a default initial value, of the dynamic type needed inswapBody
.- Returns:
- a new
Statement
-
swapBody
Description copied from interface:ProgramKernel
Exchanges the body ofthis
withb
;b
must have the dynamic type returned bynewBody
.- Parameters:
b
- the body to be exchanged with that ofthis
-
disassembleProgram
Disassembles and outputs toout
the 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 toout
the 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 toout
the given programcp
marking 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]
-