# OpenAIcVM **OpenAIcVM** is an advanced C-based Virtual Machine (VM) with a fully featured, nested operating system (OS) shell. This project was created as a demonstration of the capabilities of modern AI-assisted coding—showing how iterative, detailed prompts can lead to the development of a complex, modular software system from scratch. ## Disclaimer Much to my embarressment, my bio is no longer true. Sadly, not all of this code was created by humans. It was created on earth, but this ungodly, unhuman creation was created by the gross, monolithic amalgamation algothm with a hat that tries to pretend to be smart and that is known as ChatGPT-03-mini-high. I feel this disclaimer is warranted so I can in good contious still have my bio stay the same as it currently is which is (incase I ever change it in the future): "All code made on earth, by humans" ## Overview OpenAIcVM supports a custom instruction set that includes arithmetic operations, branching, stack management, function calls/returns, and transitions into an interactive nested OS shell. The OS shell simulates a simple file system, supports commands such as `ls`, `mkdir`, `touch`, `cd`, `edit`, `cat`, `cp`, and even includes a "save" command to persist the current state. Additional features include: - **Autosave on termination:** The VM automatically saves the OS state (into a custom `.osstate` file stored in a `states` directory) when receiving termination signals (e.g., Control‑C). - **Reload capability:** Start the VM with a `--reload ` option to load a previously saved state. - **Control‑L support:** Typing Control‑L (or its equivalent input) clears the OS shell screen. ## Purpose The main purpose of OpenAIcVM is to test and showcase the capabilities of a coding AI - ChatGPT o3-mini-high. In this project: - Detailed, iterative prompts were used to guide the design and implementation. - New features and improvements were added progressively, illustrating how an AI can respond to and incorporate feedback. - The project highlights modular design principles, robust error handling, and advanced functionality using only standard C (C11). ## Conversation Summary and Analysis Throughout our conversation, the user guided the project with a series of detailed prompts: - **Initial VM design:** Requests for a modular VM with a custom instruction set. - **Nested OS Shell:** Enhancements included creating an interactive shell with simulated file system operations. - **Feature Extensions:** Additional commands were added (such as file copying, text editing, and autosave on termination), and improvements were made (e.g., handling Control‑L for screen clearing). - **State Persistence:** The VM was enhanced to support saving and reloading its state via a custom file format. - **Meta Discussion:** Finally, the user requested a README to explain the project purpose and reflect on the iterative process. This process illustrates the potential of AI-assisted programming. While internal conversation details and prompts remain confidential, the evolution of OpenAIcVM—from a simple virtual machine to a feature-rich system—is a testament to the dynamic interaction between user guidance and AI-generated code. ## Build and Run Instructions To compile the project: ```bash make ``` To run the VM: ```bash ./vm [--reload ] ``` ## Project Structure ``` project/ ├── include/ │ ├── opcodes.h // Definition of the custom instruction set. │ ├── os.h // Interface for the nested OS shell and state management. │ └── vm.h // VM structure and function prototypes. └── src/ ├── main.c // Main entry point, signal handling, and program loop. ├── os.c // Implementation of the nested OS shell and file system. └── vm.c // Implementation of the virtual machine. ``` ## Prompts used: - Start Prompt (1): ```txt You are an advanced AI with chain-of-thought reasoning. Your task is to create a more advanced, fully-fledged C-based Virtual Machine from scratch. Do not hallucinate or invent libraries/functions that don’t exist in standard C. Ensure error-free code that strictly follows the C11 (or newer) standard and compiles cleanly under a typical C compiler (gcc/clang) with -Wall -Wextra flags. Provide only the source code, with inline explanations and build instructions. Do not create a README. Requirements Modular Project Structure Create a top-level project/ directory. Inside project/, have include/ for headers and src/ for .c files. Provide separate .h and .c files with robust inline comments. Advanced Virtual Machine Design Implement a custom instruction set that is more extensive than simple LOAD/PRINT/HALT. Include arithmetic instructions (e.g., ADD, SUB, MUL, DIV), branching (e.g., JMP, JMPZ), stack operations (PUSH, POP), and function calls/returns if you wish. Manage registers and memory safely; avoid undefined behavior. Make sure the VM is capable of interpreting bytecode that you define. Provide a well-commented example bytecode program demonstrating these new instructions. Nested OS / Shell Demonstrate a more feature-rich nested OS or shell that can be entered via an instruction (e.g., OP_CALL_OS). Implement at least one or two advanced capabilities in the nested OS (for example, a mini file system simulation in memory, or a small command set that manipulates virtual memory). Keep it simple but functional—no need for actual disk I/O, but show how it could be extended. Safety & No Extraneous Dependencies Write safe, portable C code. No external libraries beyond the C standard library. Use checks and error messages for invalid registers, memory bounds, or unexpected instruction opcodes. Inline Documentation & Build/Run Instructions No README—instead, provide a concise set of instructions in your final answer (e.g., compile with gcc -std=c11 -Wall -Wextra -o vm src/*.c). Explain the purpose of each file, instruction set design, and how to run the example program within the final answer. Show that it is genuinely capable of running the advanced instructions and the nested OS. Deliverables Present all source code for the project in your final response (i.e., contents of each file in include/ and src/). Include a single example bytecode program that demonstrates: Arithmetic, branching, stack usage, function calls (if implemented), or any other advanced instructions you have added. A transition into and out of the nested OS/shell. Indicate how to compile (exact command) and run the resulting VM. Make sure your final output is self-contained and error-free. Do not hallucinate. Only standard C code, minimal shell commands, and inline documentation. No README. ``` - secondary Follow Up Prompt (2): ```txt This is the program it created: (ins)klein@kernelpanic:~/codeWS/C/OpenAIcVM$ ./vm Register 0: 30 Register 2: 5 Register 0: 60 Entering Nested OS Shell. Type 'exit' to return to VM. nested-os> help Available commands: help, exit, echo nested-os> echo lol lol nested-os> exit Exiting Nested OS Shell. Error: Stack underflow in OP_RET. I would like more options like basic gnu utilities, make it a bit more advanced, do not use actual gnu utilities but like make all of this from scratch in your own mind. Additionally fix the stack underflow error, possible add more registers and memory and such to accomodate this. It should literally be an OS that you emulate from scratch but it should be able to actually do something beyond those 3 options, for instance make files, make directories, move them, remove them, have a very simple shell, accept system calls like up arrows and stuff. ``` - third follow up prompt (3): ```txt This is the new output: (ins)klein@kernelpanic:~/codeWS/C/OpenAIcVM$ ./vm Register 0: 30 Register 2: 5 Register 0: 60 Entering Nested OS Shell. Type 'exit' to return to VM. nested-os> help Available commands: help - Show this help message. exit - Exit the nested OS shell. ls - List directory contents. mkdir - Create a new directory. rmdir - Remove an empty directory. touch - Create a new file. rm - Remove a file. cd - Change directory (.. for parent, / for root). pwd - Print working directory. history - Show command history. echo - Print text. cat - Show file contents (dummy content). nested-os> ls Contents of /: nested-os> pwd Unknown command. Type 'help' for available commands. nested-os> pwd / nested-os> touch test nested-os> ls Contents of /: FILE test nested-os> cat test Contents of test: [This is a dummy file.] nested-os> . Please only give me the files you change but keep reference to all of the files youve made. I would like the following iprovements: 1) imporove cat to actually show the contents of a file, 2) add a cp command, 3) add a text editor. All of this should be your own creation and your own code. Make the operating system more interactive, more realistic, have a real shell that you make up. ``` - Fourth follow up prompt (4): ```txt With that new os.c I now get: (ins)klein@kernelpanic:~/codeWS/C/OpenAIcVM$ make gcc -std=c11 -Wall -Wextra -Iinclude -o vm src/*.c /usr/bin/ld: /tmp/ccTEcE5I.o: in function run_os': vm.c:(.text+0xb45): multiple definition of run_os'; /tmp/ccvPItXb.o:os.c:(.text+0xa3f): first defined here /usr/bin/ld: /tmp/ccTC61kR.o: in function main': main.c:(.text+0x16): undefined reference to init_vm' /usr/bin/ld: main.c:(.text+0x1d5): undefined reference to load_program' /usr/bin/ld: main.c:(.text+0x1ef): undefined reference to run_vm' collect2: error: ld returned 1 exit status make: *** [Makefile:11: vm] Error 1 also make sure that the main.c handles control Cs or Ds to properly kill itself and clean itself. ``` - Fifth follow up prompt - Ending Prompt (5): ```txt Okay thats perfect it compiles. I have one last request for the shell. I would like to add support for control L to clear the inside screen (ie trap it), and add 1 more command and add the supporting functionality to "save" the operating system and the state that the user left it in. Like add a flag to the vm like --reload . Make a custom file type for this save like entirely your own idea. Additionally change the control C functionality to autosave as well and by default it should save and make a directory called states where it should save the custom os file type that you make. ``` ## LICENSE Fucking chatgpt wrote this entire program except for the readme. Fuck OpenAI but this model is pretty impressive. Do whatever the fuck you want with this code. There is no need for a license agreement bc this isn't mine by nature. As god is my witness I am sure this repo will somehow indept my soul to OpenAI and I am sure they will come to collect. Propriatary software - especially that not made by a human is fucking stupid. You heard it here first. ## Some Beautiful ASCII text to express my love of OpenAI ```txt ______ _ ____ _____ | ____| | | / __ \ /\ |_ _| | |__ _ _ ___| | __ | | | |_ __ ___ _ __ / \ | | | __| | | |/ __| |/ / | | | | '_ \ / _ \ '_ \ / /\ \ | | | | | |_| | (__| < | |__| | |_) | __/ | | |/ ____ \ _| |_ |_| \__,_|\___|_|\_\ \____/| .__/ \___|_| |_/_/ \_\_____| | | |_| ``` ```txt ____ _____ _ _____ _ _ _ / __ \ /\ |_ _| (_) | __ \ (_) | | | | | | |_ __ ___ _ __ / \ | | _ ___ | |__) |___ ___ _ __ ___ _ __ ___ _| |__ | | ___ | | | | '_ \ / _ \ '_ \ / /\ \ | | | / __| | _ // _ \/ __| '_ \ / _ \| '_ \/ __| | '_ \| |/ _ \ | |__| | |_) | __/ | | |/ ____ \ _| |_ | \__ \ | | \ \ __/\__ \ |_) | (_) | | | \__ \ | |_) | | __/ \____/| .__/ \___|_| |_/_/ \_\_____| |_|___/ |_| _\_\___||___/ .__/ \___/|_| |_|___/_|_.__/|_|\___| | ____| | | | | | | __ \ | | | | | | / _| (_) | | |__ _|_| _ __ | |_| |__ ___ | | | | ___ __ _| |_| |__ |_|_ | |_ _| |_ ___ | __/ _ \| '__| | __| '_ \ / _ \ | | | |/ _ \/ _` | __| '_ \ / _ \| _| | | __/ __| | | | (_) | | | |_| | | | __/ | |__| | __/ (_| | |_| | | | | (_) | | | | |_\__ \ |_| \___/|_|__ \__|_| |_|\___| |_____/ \___|\__,_|\__|_| |_| \___/|_| |_|\__|___/ \ \ / / | (_) | | | | | | | | \ \ /\ / /| |__ _ ___| |_| | ___ | |__ | | _____ _____ _ __ \ \/ \/ / | '_ \| / __| __| |/ _ \ | '_ \| |/ _ \ \ /\ / / _ \ '__| \ /\ / | | | | \__ \ |_| | __/ | |_) | | (_) \ V V / __/ | \/ \/ |_| |_|_|___/\__|_|\___| |_.__/|_|\___/ \_/\_/ \___|_| ``` ```txt _____ _ _ _____ ______ _ / ____| /\ | | | |_ _| | ____| | | | (___ __ _ _ __ ___ / \ | | |_ _ __ ___ __ _ _ __ | | ___ __ _ | |__ _ __ __ _ _ _ __| | \___ \ / _` | '_ ` _ \ / /\ \ | | __| '_ ` _ \ / _` | '_ \ | | / __| / _` | | __| '__/ _` | | | |/ _` | ____) | (_| | | | | | | / ____ \| | |_| | | | | | (_| | | | | _| |_\__ \ | (_| | | | | | | (_| | |_| | (_| | |_____/ \__,_|_| |_| |_| /_/ \_\_|\__|_| |_| |_|\__,_|_| |_| |_____|___/ \__,_| |_| |_| \__,_|\__,_|\__,_| ``` ```txt _ /\ | | / \ ___ ___ _ __ ___ _ __ _ _| |_ ___ _ __ ___ __ _ _ __ _ __ _____ _____ _ __ / /\ \ / __/ _ \| '_ ` _ \| '_ \| | | | __/ _ \ '__| / __/ _` | '_ \ | '_ \ / _ \ \ / / _ \ '__| / ____ \ | (_| (_) | | | | | | |_) | |_| | || __/ | | (_| (_| | | | | | | | | __/\ V / __/ | /_/ \_\ \___\___/|_| |_| |_| .__/ \__,_|\__\___|_| \___\__,_|_| |_| |_| |_|\___| \_/ \___|_| | | _ _ _ |_| _ _ _ | | | | | | | | | | | | | | | |__ ___ | |__ ___| | __| | __ _ ___ ___ ___ _ _ _ __ | |_ __ _| |__ | | ___ | '_ \ / _ \ | '_ \ / _ \ |/ _` | / _` |/ __/ __/ _ \| | | | '_ \| __/ _` | '_ \| |/ _ \ | |_) | __/ | | | | __/ | (_| | | (_| | (_| (_| (_) | |_| | | | | || (_| | |_) | | __/_ |_.__/ \___| |_| |_|\___|_|\__,_| \__,_|\___\___\___/ \__,_|_| |_|\__\__,_|_.__/|_|\___( ) _ _ __ _ _ _ |/ | | | | / _| (_) | | | | |_| |__ ___ _ __ ___| |_ ___ _ __ ___ _| |_ _ __ ___ _ _ ___| |_ | __| '_ \ / _ \ '__/ _ \ _/ _ \| '__/ _ \ | | __| | '_ ` _ \| | | / __| __| | |_| | | | __/ | | __/ || (_) | | | __/ | | |_ | | | | | | |_| \__ \ |_ \__|_| |_|\___|_| \___|_| \___/|_| \___| |_|\__| |_| |_| |_|\__,_|___/\__| | | _ __ _____ _____ _ __ _ __ ___ __ _| | _____ | '_ \ / _ \ \ / / _ \ '__| | '_ ` _ \ / _` | |/ / _ \ | | | | __/\ V / __/ | | | | | | | (_| | < __/ _ _ _ _ |_| |_|\___| \_/ \___|_| |_| |_| |_|\__,_|_|\_\___| | | | | (_) (_) _ __ ___ __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_ __| | ___ ___ _ ___ _ ___ _ __ ___ | '_ ` _ \ / _` | '_ \ / _` |/ _` |/ _ \ '_ ` _ \ / _ \ '_ \| __| / _` |/ _ \/ __| / __| |/ _ \| '_ \/ __| | | | | | | (_| | | | | (_| | (_| | __/ | | | | | __/ | | | |_ | (_| | __/ (__| \__ \ | (_) | | | \__ \ |_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__| \__,_|\___|\___|_|___/_|\___/|_| |_|___/ __/ | |___/ ```