Execute SNUSP/D: Difference between revisions

Content added Content deleted
m (added tags)
m (Grammar)
Line 1: Line 1:
{{implementation|SNUSP}}{{collection|RCSNUSP}}[[Category:D]]
{{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-defined string for (I/O) input. That is, just before reading I/O input operation, if this string is not empty yet, a char is ''pop/taken'' from the string, instaed of actually read from I/O. The pattern is '''debug['''<''string''>''']debug'''. Similar to the staring point '$', this pattern is searched inside the source code before execution, but from bottom lines first.<br> <br>
This implementation includes all '''Bloated SNUSP''' commands, plus a minor custom feature : ''debugInput''. ''debugInput'' is a pattern to setup a predefined string for (I/O) input. That is, just before reading I/O input operation, if this string is not empty yet, a char is ''popped/taken'' from the string, instead of actually reading from I/O. The pattern is '''debug['''<''string''>''']debug'''. Similar to the starting point '$', this pattern is searched inside the source code before execution, but from bottom lines first.<br> <br>
The following are some notes.
The following are some notes.


*'''Memory'''
*'''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;
**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 a integer 2-dimensional coordinates tuple (x,y), which acts 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;
**Mem is internally represented as an associative array, with ''cfloat'' as key and ''int'' as value. Externally, the ''keys'' are integer 2-dimensional coordinates tuple (x,y), which act 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'''
*'''Code Pointer'''
**This again is in a 2-dimensional space. The Code pointer CP structure contain the pointer position and moving direction. It also includes function to get the ''command code'' in the SNUSP program source under the pointer position, and to manipulate its own position and direction;
**This again is in a 2-dimensional space. The code pointer CP structure contains the pointer position and moving direction. It also includes functions to get the ''command code'' in the SNUSP program source under the pointer position, and to manipulate its own position and direction;
**If CP go out of the code space, no error is threw. In this implementation, such situation is treated as a sub-routine return (#);
**If CP goes out of the code space, no error is thrown. In this implementation, such a situation is treated as a sub-routine return (#);
*'''Core/Thread/Execution Unit''''
*'''Core/Thread/Execution Unit''''
**This class is which actually execute the command. In fact, ''execute'' is the only non-trivial function (beside 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 with the same ''CPU''. Via the CPU, each Core can accessed the common resources like IO, Memory Space and Code Space(program) ;
**This class is what actually executes the command. In fact, ''execute'' is the only non-trivial function (besides 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 shares the same ''CPU''. Via the CPU, each Core can access common resources like IO, Memory Space and Code Space(program) ;
**Since this implementation supported ''Bloated'' feature, aka thread execution, this class is a result of separating execution unit from ''CPU''.
**Since this implementation supports ''Bloated'' features, aka thread execution, this class is a result of separating execution unit from ''CPU''.
*'''CPU'''
*'''CPU'''
**CPU acts as a resource manager and thread execution scheduler(trivially).
**CPU acts as a resource manager and thread execution scheduler(trivially).
Line 152: Line 152:
private Core[] newcores ;
private Core[] newcores ;


static int rnd(int b) { // return a random number between and include 0 and b
static int rnd(int b) { // return a random number between and including 0 and b
int a = 0 ;
int a = 0 ;
if(a > b) { a = b ; b = 0 ; }
if(a > b) { a = b ; b = 0 ; }