java.lang.Object
com.wyu4.snowberryjam.compiler.LocalStorage
- Direct Known Subclasses:
Compiler
This class stores and handles anything related to compiling and running a
source file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicReference<String> The description of the projectprivate static final List<BiConsumer<String, String>> The error listenersThe input listeners/subscribersprivate static final org.slf4j.Loggerprivate static AtomicReference<org.slf4j.Logger> private static final AtomicBooleanIf the runtime was manually stopped prematurely by the userprivate static final AtomicReference<String> Atomically stores the project nameprivate static final AtomicIntegerThe runtime pointer indexprivate static final List<BiConsumer<String, String>> The print listenersprivate static final AtomicBooleanThe running propertyprivate static final BodyStackStores tasks starting from index 0Stores threadsTHe variable listenersStores variablesA new copy of the variables.private static final List<BiConsumer<String, String>> The warn listeners -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCachedValue(Cached value) static voidaddErrorListener(BiConsumer<String, String> consumer) Add a error listenerstatic voidaddInputSubscription(Consumer<String> consumer) Add an input subscription.static voidaddPrintListener(BiConsumer<String, String> consumer) Add a print listenerstatic voidaddVariableListener(String name, Consumer<Object> consumer) Add a variable listener.static voidaddWarnListener(BiConsumer<String, String> consumer) Add a warn listenerstatic ExecutableTask[]Recieve a deep copy of the tasks inside a stackstatic ThreadcreateThread(Runnable run) Create a thread and store it inTHREADSprotected static voidcreateVariable(String name, Object value) Create a variable and store it inVARIABLESstatic voidSend an error statement to the development console.static voidSend an error statement and stack trace to the development console.static voidflush()Flush all the contents of theLocalStorage.protected static StringformatMessage(Object message, Object... args) Format a message by replacing instances of"{}"with a corresponding argumentstatic StringGet a default project template.private static org.slf4j.LoggerGet the logger with the current project name.static intGet the pointer index.static ObjectGet the raw value of a stored variableGet all of variable names.static voidstatic booleanCheck if the stack is runningstatic voidSend a print statement to the runtime console.private static voidprivate static voidReset the pointer index to 0, and release all cached data.static voidrunStack()RunSTACKstatic voidSend a user input.protected static voidsetDescription(String description) Set the description of the project.protected static voidSet the project namestatic voidsetVariable(String name, Object newValue) Override the contents of a variable inVARIABLESprotected static voidstackAdd(ExecutableTask element) Add a task toSTACKstatic voidstopRun()Stop the current runstatic voidSend a print statement to the runtime console.
-
Field Details
-
logger
-
inputLogger
private static final org.slf4j.Logger inputLogger -
VARIABLES
Stores variables -
VARIABLES_COPY
A new copy of the variables. This is used during the runtime. -
THREADS
Stores threads -
STACK
Stores tasks starting from index 0 -
NAME
Atomically stores the project name -
DESCRIPTION
The description of the project -
PRINT_LISTENERS
The print listeners -
WARN_LISTENERS
The warn listeners -
ERROR_LISTENERS
The error listeners -
INPUT_LISTENERS
The input listeners/subscribers -
CACHED_VALUES
-
VARIABLE_LISTENERS
THe variable listeners -
pointer
The runtime pointer index -
running
The running property -
manualStop
If the runtime was manually stopped prematurely by the user
-
-
Constructor Details
-
LocalStorage
public LocalStorage()
-
-
Method Details
-
getDefaultSource
Get a default project template.- Returns:
Stringcontaining a valid default empty project.
-
getRaw
Get the raw value of a stored variable- Parameters:
name- The name of a variable- Returns:
- The value of the variable as an
Object - Throws:
NullPointerException- If the variable was not created- See Also:
-
getVariableNames
Get all of variable names.- Returns:
Setwith created variable names
-
copyStack
Recieve a deep copy of the tasks inside a stack- Returns:
- An array of the tasks in a stack
- See Also:
-
flush
public static void flush()Flush all the contents of theLocalStorage. This includesSTACK,VARIABLES, andTHREADS(after interrupting them). -
createThread
Create a thread and store it inTHREADS- Parameters:
run- The code to run in the thread- Returns:
- A
Threadobject initialized withrun
-
setVariable
Override the contents of a variable inVARIABLES- Parameters:
name- The name of the (already created) variablenewValue- The new value- Throws:
NullPointerException- If the variable was not created- See Also:
-
runStack
public static void runStack()RunSTACK- See Also:
-
stopRun
public static void stopRun()Stop the current run -
isRunning
public static boolean isRunning()Check if the stack is running- Returns:
trueif the LocalStorage is running the stack, otherwisefalse.
-
setName
Set the project name- Parameters:
name- Project name
-
setDescription
Set the description of the project.- Parameters:
description- Description of the project
-
createVariable
Create a variable and store it inVARIABLES- Parameters:
name- The name of the variablevalue- The value of the variable- Throws:
IllegalStateException- A variable with the same name already exists
-
stackAdd
Add a task toSTACK- Parameters:
element- A task- See Also:
-
increasePointer
public static void increasePointer() -
getPointer
public static int getPointer()Get the pointer index.- Returns:
- The current pointer index.
-
resetPointer
private static void resetPointer()Reset the pointer index to 0, and release all cached data. -
releaseCache
private static void releaseCache() -
getLogger
private static org.slf4j.Logger getLogger()Get the logger with the current project name. Creates a new logger with every name change.- Returns:
- The current logger
- See Also:
-
sendInput
Send a user input.- Parameters:
input-Stringinput
-
print
Send a print statement to the runtime console.- Parameters:
message- Message to send (arguments can be inserted by adding "{}" in the message)args- Arguments to append in the message- See Also:
-
warn
Send a print statement to the runtime console.- Parameters:
message- Message to send (arguments can be inserted by adding "{}" in the message)args- Arguments to append in the message- See Also:
-
error
Send an error statement to the development console.- Parameters:
error- Message to send (arguments can be inserted by adding "{}" in the message).- See Also:
-
error
Send an error statement and stack trace to the development console.- Parameters:
error- Error to sende- Exception to send (used to print stack trace)- See Also:
-
formatMessage
Format a message by replacing instances of"{}"with a corresponding argument- Parameters:
message- Messageargs- Arguments- Returns:
- Formatted string
- See Also:
-
addPrintListener
Add a print listener- Parameters:
consumer- Consumer to run when something is printed- See Also:
-
addWarnListener
Add a warn listener- Parameters:
consumer- Consumer to run when something is warned- See Also:
-
addErrorListener
Add a error listener- Parameters:
consumer- Consumer to run when something is errored- See Also:
-
addVariableListener
Add a variable listener. This listener is triggered when the variable with the corresponding name is changed.- Parameters:
name- Variable nameconsumer- The consumer to run- See Also:
-
addInputSubscription
Add an input subscription. Consumers are removed from the subscription list after they are run.- Parameters:
consumer- Consumer to run when user inputs something
-
addCachedValue
-