sleep.engine

Class Block

public class Block extends Object implements Serializable

A Block is the fundamental unit of parsed and ready to execute sleep code.

To execute a block of code:

 ScriptInstance    script; // asume
 Block             code;   // assume
 
 ScriptEnvironment env   = script.getEnvironment();  
 Scalar            value = SleepUtils.runCode(code, env);
 

The variable value would contain the return value after the block was executed. It is recommended blocks only be run using SleepUtils.runCode() as there is a little bit of synchronization and cleanup that has to be done prior to and after executing a block of code.

See Also: Scalar ScriptEnvironment ScriptInstance

Field Summary
protected Stepfirst
our first step in this block
protected Steplast
our last step in this block
protected Stringsource
an identifier/tag/whatever identifying the source of this block (i.e. somescript.sl)
Constructor Summary
Block(String _src)
Method Summary
voidadd(Step n)
Scalarevaluate(ScriptEnvironment environment)
evaluates this block of code. please note that if the block has a return statement and the method clearReturn() is not called on the corresponding script environment chaos will ensue. use SleepUtils.runCode() to safely execute a block of code. don't call this method yourself. okay?
Scalarevaluate(ScriptEnvironment environment, Step start)
evaluates this block of code. please note that if the block has a return statement and the method clearReturn() is not called on the corresponding script environment chaos will ensue. use SleepUtils.runCode() to safely execute a block of code. don't call this method yourself. okay?
intgetApproximateLineNumber()
Returns an approximated line number for the steps in this block object... returns -1 if no code is in this block (unlikely)
StringgetApproximateLineRange()
Returns an approximate range of line numbers for the steps in this block object.
intgetHighLineNumber()
return the highest line number associated with this block
intgetLowLineNumber()
return the lowest line number associated with this block
StringgetSource()
Returns the source identifier for this block
StringgetSourceLocation()
Returns a string representation of where in the source code this block originated from
StringtoString(String prefix)
StringtoString()
Returns a string representation of the Abstract Syntax Tree (AST).

Field Detail

first

protected Step first
our first step in this block

last

protected Step last
our last step in this block

source

protected String source
an identifier/tag/whatever identifying the source of this block (i.e. somescript.sl)

Constructor Detail

Block

public Block(String _src)

Method Detail

add

public void add(Step n)

evaluate

public Scalar evaluate(ScriptEnvironment environment)
evaluates this block of code. please note that if the block has a return statement and the method clearReturn() is not called on the corresponding script environment chaos will ensue. use SleepUtils.runCode() to safely execute a block of code. don't call this method yourself. okay?

evaluate

public Scalar evaluate(ScriptEnvironment environment, Step start)
evaluates this block of code. please note that if the block has a return statement and the method clearReturn() is not called on the corresponding script environment chaos will ensue. use SleepUtils.runCode() to safely execute a block of code. don't call this method yourself. okay?

getApproximateLineNumber

public int getApproximateLineNumber()
Returns an approximated line number for the steps in this block object... returns -1 if no code is in this block (unlikely)

getApproximateLineRange

public String getApproximateLineRange()
Returns an approximate range of line numbers for the steps in this block object. Useful for formatting error messages in script warnings and such.

getHighLineNumber

public int getHighLineNumber()
return the highest line number associated with this block

getLowLineNumber

public int getLowLineNumber()
return the lowest line number associated with this block

getSource

public String getSource()
Returns the source identifier for this block

getSourceLocation

public String getSourceLocation()
Returns a string representation of where in the source code this block originated from

toString

public String toString(String prefix)

toString

public String toString()
Returns a string representation of the Abstract Syntax Tree (AST). An AST represents how the sleep parser interpreted a script string