Brainfuck interpreter update

git-svn-id: svn://kolibrios.org@7557 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2018-11-19 09:04:24 +00:00
parent d4f784b890
commit 6adf85be15

View File

@ -16,11 +16,13 @@ dword buffer = 0;
word bufferSymbol = 0; word bufferSymbol = 0;
dword memory = 0; dword memory = 0;
byte initConsole = 0; byte initConsole = 0;
dword stack = 0;
void consoleInit() void consoleInit()
{ {
IF(!initConsole) IF(!initConsole)
{ {
load_dll(libConsole, #con_init, 0);
con_init stdcall (-1, -1, -1, -1, "BrainF*ck interpreter"); con_init stdcall (-1, -1, -1, -1, "BrainF*ck interpreter");
initConsole = 0xFF; initConsole = 0xFF;
} }
@ -44,6 +46,7 @@ void evalBrainFuckCode(dword code)
//-------- //--------
offsetMemory = memory + countOffset; offsetMemory = memory + countOffset;
countStack = stack;
WHILE(1) WHILE(1)
{ {
@ -56,11 +59,12 @@ void evalBrainFuckCode(dword code)
DSBYTE[offsetMemory]--; DSBYTE[offsetMemory]--;
break; break;
case '[': case '[':
$push code; DSDWORD[countStack] = code;
countStack += 4;
break; break;
case ']': case ']':
IF (DSBYTE[offsetMemory]) code = DSDWORD[ESP]; IF (DSBYTE[offsetMemory]) code = DSDWORD[countStack - 4];
ELSE $pop EAX; ELSE countStack -= 4;
break; break;
case ',': case ',':
consoleInit(); consoleInit();
@ -93,8 +97,7 @@ void main()
buffer = malloc(bufferSize); buffer = malloc(bufferSize);
memory = malloc(memoryBrainfuck); memory = malloc(memoryBrainfuck);
stack = malloc(stackBrainFuck);
load_dll(libConsole, #con_init, 0);
IF(DSBYTE[I_Param]) IF(DSBYTE[I_Param])
{ {
@ -103,17 +106,16 @@ void main()
ELSE ELSE
{ {
consoleInit(); consoleInit();
con_printf stdcall ("BrainF*ck interpreter v1.1\r\n"); con_printf stdcall ("BrainF*ck interpreter v1.01\r\n");
loop() loop()
{ {
con_printf stdcall ("\r\nEnter BrainF*ck code:\r\n"); con_printf stdcall ("\r\nEnter BrainF*ck code:\r\n");
con_printf stdcall ("Output BrainF*ck:\r\n");
con_gets stdcall(buffer, bufferSize); con_gets stdcall(buffer, bufferSize);
evalBrainFuckCode(EAX); evalBrainFuckCode(EAX);
con_printf stdcall ("\r\n"); con_printf stdcall ("\r\nOutput BrainF*ck:\r\n");
} }
} }
IF(initConsole) con_exit stdcall (0);
ExitProcess(); ExitProcess();
IF(initConsole) con_exit stdcall (0);
} }