Skip to content

Commit

Permalink
Fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
watamario15 committed Jul 5, 2023
1 parent 9004bb9 commit a8a541c
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 298 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
ColumnLimit: 120
18 changes: 6 additions & 12 deletions bf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ enum Brainfuck::result_t Brainfuck::next(unsigned char *output, bool *didOutput)
++memIndex;
if (memIndex == memLen) ++memLen;
} else {
wsprintfW(lastError, L"%u: Instruction '>' used when the memory pointer is 65535.",
progIndex);
wsprintfW(lastError, L"%u: Instruction '>' used when the memory pointer is 65535.", progIndex);
return RESULT_ERR;
}
break;
Expand All @@ -93,16 +92,14 @@ enum Brainfuck::result_t Brainfuck::next(unsigned char *output, bool *didOutput)
if (memory[memIndex] != 0x7F) {
++memory[memIndex];
} else {
wsprintfW(lastError, L"%u: Instruction '+' used when the pointed memory is 127.",
progIndex);
wsprintfW(lastError, L"%u: Instruction '+' used when the pointed memory is 127.", progIndex);
return RESULT_ERR;
}
} else {
if (memory[memIndex] != 0xFF) {
++memory[memIndex];
} else {
wsprintfW(lastError, L"%u: Instruction '+' used when the pointed memory is 255.",
progIndex);
wsprintfW(lastError, L"%u: Instruction '+' used when the pointed memory is 255.", progIndex);
return RESULT_ERR;
}
}
Expand All @@ -116,16 +113,14 @@ enum Brainfuck::result_t Brainfuck::next(unsigned char *output, bool *didOutput)
if (memory[memIndex] != 0x80) {
--memory[memIndex];
} else {
wsprintfW(lastError, L"%u: Instruction '-' used when the pointed memory is -128.",
progIndex);
wsprintfW(lastError, L"%u: Instruction '-' used when the pointed memory is -128.", progIndex);
return RESULT_ERR;
}
} else {
if (memory[memIndex] != 0x00) {
--memory[memIndex];
} else {
wsprintfW(lastError, L"%u: Instruction '-' used when the pointed memory is 0.",
progIndex);
wsprintfW(lastError, L"%u: Instruction '-' used when the pointed memory is 0.", progIndex);
return RESULT_ERR;
}
}
Expand All @@ -143,8 +138,7 @@ enum Brainfuck::result_t Brainfuck::next(unsigned char *output, bool *didOutput)
} else if (noInput == NOINPUT_FF) {
memory[memIndex] = 255;
} else {
wsprintfW(lastError, L"%u: Instruction ',' used when the input stream is empty.",
progIndex);
wsprintfW(lastError, L"%u: Instruction ',' used when the input stream is empty.", progIndex);
return RESULT_ERR;
}
} else {
Expand Down
33 changes: 9 additions & 24 deletions bf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,15 @@ class Brainfuck {

// Initializes the internal state.
Brainfuck()
: program(NULL),
input(NULL),
memLen(1),
wrapInt(true),
signedness(true),
debug(false),
noInput(NOINPUT_ZERO) {
: program(NULL), input(NULL), memLen(1), wrapInt(true), signedness(true), debug(false), noInput(NOINPUT_ZERO) {
reset();
}

// Initializes the internal state and registers a program and an input.
// You must call reset() whenever you want to modify the program and the input.
// Pass a program and an input as dedicated malloc()-ed data and don't free() them. This module
// takes care of it.
// Pass a program and an input as dedicated malloc()-ed data and don't free() them. This module takes care of it.
Brainfuck(unsigned progLen, wchar_t *program, unsigned inLen, void *input)
: program(NULL),
input(NULL),
memLen(1),
wrapInt(true),
signedness(true),
debug(false),
noInput(NOINPUT_ZERO) {
: program(NULL), input(NULL), memLen(1), wrapInt(true), signedness(true), debug(false), noInput(NOINPUT_ZERO) {
reset(progLen, program, inLen, input);
}

Expand All @@ -51,22 +38,20 @@ class Brainfuck {

// Resets the internal state and registers a program and an input.
// You must call reset() whenever you want to modify the program and the input.
// Pass a program and an input as dedicated malloc()-ed data and don't free() them. This module
// takes care of it.
// Pass a program and an input as dedicated malloc()-ed data and don't free() them. This module takes care of it.
void reset(unsigned progLen, wchar_t *program, unsigned inLen, void *input);

// Change implementation-defined behaviors.
// If wrapInt is false, next() throws an exception when overflowed or underflowed.
// If wrapInt is true, signedness doen't have any effect.
// If debug is true, breakpoint instruction ("@") is enabled.
// The default behavior is [zero for no input, wrap around integer, signed integer (no effects in
// this case), no debug].
void setBehavior(enum noinput_t noInput = NOINPUT_ZERO, bool wrapInt = true,
bool signedness = true, bool debug = false);
// The default behavior is [zero for no input, wrap around integer, signed integer (no effects in this case), no
// debug].
void setBehavior(enum noinput_t noInput = NOINPUT_ZERO, bool wrapInt = true, bool signedness = true,
bool debug = false);

// Executes the next code, and writes its output on `output` if any.
// Returns the result of an execution, which is running, breakpoint, finished, and
// error.
// Returns the result of an execution, which is running, breakpoint, finished, and error.
enum result_t next(unsigned char *output, bool *didOutput);

// Returns the memory and writes its size to `size`.
Expand Down
Empty file modified brain.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void History::add() {
}

void History::undo() {
if (canUndo()) {
if (canUndo()) {
DWORD selEnd;
--historyIndex;
SendMessageW(hEditor, EM_GETSEL, (WPARAM)NULL, (LPARAM)&selEnd);
Expand Down
9 changes: 4 additions & 5 deletions main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#include <string>

#include "bf.hpp"
#include "history.hpp"
#include "resource.h"
#include "util.hpp"
#include "history.hpp"

// Workaround for wrong macro definitions in CeGCC.
#ifdef UNDER_CE
Expand Down Expand Up @@ -71,8 +71,8 @@ typedef enum MONITOR_DPI_TYPE {
} MONITOR_DPI_TYPE;

// The function pointer type for GetDpiForMonitor API.
typedef HRESULT(CALLBACK *GetDpiForMonitor_t)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType,
unsigned *dpiX, unsigned *dpiY);
typedef HRESULT(CALLBACK *GetDpiForMonitor_t)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, unsigned *dpiX,
unsigned *dpiY);
#endif

// Making SetWindowLongW and GetWindowLongW compatible for both 32-bit and 64-bit system.
Expand All @@ -91,8 +91,7 @@ typedef HRESULT(CALLBACK *GetDpiForMonitor_t)(HMONITOR hmonitor, MONITOR_DPI_TYP
#endif

#ifndef WS_OVERLAPPEDWINDOW
#define WS_OVERLAPPEDWINDOW \
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
#define WS_OVERLAPPEDWINDOW WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
#endif
#define WM_APP_THREADEND WM_APP

Expand Down
Loading

0 comments on commit a8a541c

Please sign in to comment.