Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sktryo committed Jun 30, 2024
1 parent 5e37374 commit 47ecb20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.10)
project(MicroScript C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)

# ソースファイルのリスト
set(SOURCES
Expand Down
10 changes: 8 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ char *readCodeFromFile(const char *filename) {
exit(1);
}

fread(buffer, 1, fileSize, file);
size_t bytesRead = fread(buffer, 1, fileSize, file);
if (bytesRead != fileSize) {
fclose(file);
free(buffer);
fprintf(stderr, "Error reading file: %s\n", filename);
exit(1);
}
buffer[fileSize] = '\0';

fclose(file);
Expand All @@ -39,7 +45,7 @@ int main(int argc, char *argv[]) {
#endif
char *code = readCodeFromFile(argv[1]); // コマンドライン引数からファイル名を取得し、コードを読み込む
MicroScriptInterpreter interpreter;
initInterpreter(&interpreter, code, 0); // デバッグモードをオフにしてインタプリタを初期化
initInterpreter(&interpreter, code, debug); // デバッグモードをオフにしてインタプリタを初期化
interpret(&interpreter);
free(code); // メモリを解放する
return 0;
Expand Down
14 changes: 10 additions & 4 deletions src/microscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,22 @@ void interpret(MicroScriptInterpreter *interpreter) {
break;
case '_': {
char input[2];
printf("Input a character: ");
fgets(input, sizeof(input), stdin);
interpreter->tape[interpreter->pointer] = (int)input[0];
if (interpreter->debug) {
printf("Input a character: ");
}
if (fgets(input, sizeof(input), stdin) != NULL) {
interpreter->tape[interpreter->pointer] = (int)input[0];
} else {
fprintf(stderr, "Error reading input\n");
exit(1);
}
break;
}
case '|':
printf("%c", (char)interpreter->tape[interpreter->pointer]);
break;
default:
// Ignore other characters
// 他の文字は無視
break;
}

Expand Down

0 comments on commit 47ecb20

Please sign in to comment.