Jump to content

Execute SNUSP/D: Difference between revisions

m
Grammar
m (added tags)
m (Grammar)
Line 1:
{{implementation|SNUSP}}{{collection|RCSNUSP}}[[Category:D]]
This implementation includes all '''Bloated SNUSP''' commands, plus a minor custom feature : ''debugInput''. ''debugInput'' is a pattern to setup a pre-definedpredefined string for (I/O) input. That is, just before reading I/O input operation, if this string is not empty yet, a char is ''poppopped/taken'' from the string, instaedinstead of actually readreading from I/O. The pattern is '''debug['''<''string''>''']debug'''. Similar to the staringstarting point '$', this pattern is searched inside the source code before execution, but from bottom lines first.<br> <br>
The following are some notes.
 
*'''Memory'''
**The memory space is represented by a class ''Mem''. Since Bloated SNUSP allows memory pointer to move up and down, the memory space is a 2-dimensional space;
**Mem is internally represented as an associative array, with ''cfloat'' as key and ''int'' as value. Externally, the ''keys'' is aare integer 2-dimensional coordinates tuple (x,y), which actsact as a memory pointer. The tuple will convert to cfloat before accessing the associative array. The conversion is unique as long as the magnitude of x and y is less than 0x7fffff. The type of the memory cells is ''int'', it will be only interpreted as ''char''/''string'' during IO operation;
*'''Code Pointer'''
**This again is in a 2-dimensional space. The Codecode pointer CP structure containcontains the pointer position and moving direction. It also includes functionfunctions to get the ''command code'' in the SNUSP program source under the pointer position, and to manipulate its own position and direction;
**If CP gogoes out of the code space, no error is threwthrown. In this implementation, such a situation is treated as a sub-routine return (#);
*'''Core/Thread/Execution Unit''''
**This class is whichwhat actually executeexecutes the command. In fact, ''execute'' is the only non-trivial function (besidebesides the ''fwd'' short hand ) inside this class. Each Core owns a code pointer, a memory pointer (actually 2 int) and a cp call stack, and shared withshares the same ''CPU''. Via the CPU, each Core can accessed theaccess common resources like IO, Memory Space and Code Space(program) ;
**Since this implementation supportedsupports ''Bloated'' featurefeatures, aka thread execution, this class is a result of separating execution unit from ''CPU''.
*'''CPU'''
**CPU acts as a resource manager and thread execution scheduler(trivially).
Line 152:
private Core[] newcores ;
 
static int rnd(int b) { // return a random number between and includeincluding 0 and b
int a = 0 ;
if(a > b) { a = b ; b = 0 ; }
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.