aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-10-26Makefile now prints dependencies on successful compilationAryadev Chavali
2023-10-26Moved base functions from inst.c to dedicated fileAryadev Chavali
Doesn't make sense for them to be in the VM module when they have a more general purpose now.
2023-10-26vm/main takes a filename as input to execute bytecodeAryadev Chavali
Also prints a usage for incorrect usage.
2023-10-26Auto fill licensesAryadev Chavali
2023-10-26Unified literal for numbers, main program now tokenisesAryadev Chavali
2023-10-25Started working on a parserAryadev Chavali
No implementations yet
2023-10-25Separated lexer from main file in asmAryadev Chavali
2023-10-24Wrote lexer for assemblyAryadev Chavali
Pretty simple tokeniser, doesn't do a lot and needs to error check better.
2023-10-24Removed assertion in darr_read_fileAryadev Chavali
If an empty file is read, we want to deal with it in later user code rather than just failing immediately.
2023-10-23Starting development on assembly languageAryadev Chavali
2023-10-23Make root directory an include path, set #include's properlyAryadev Chavali
Easier to write includes now just using < with the module name, in comparison to using relative paths.
2023-10-23Reintroduced example fib.c via examples/ folderAryadev Chavali
2023-10-23Added lib folder for general stuff, introduced as target to MakefileAryadev Chavali
2023-10-23Implemented simple example of a for loop in mainAryadev Chavali
2023-10-23src->vm, Makefile is now a bit more abstracted and pretty coloursAryadev Chavali
Changed folder names for sake of clarity (will be introducing a new build target soon), and Makefile can now easily support more targets.
2023-10-23Remove unnecessary log messageAryadev Chavali
2023-10-23Added and implemented OP_JUMP_IF_*Aryadev Chavali
Performs a jump when the (BYTE|HWORD|WORD) at the top of the stack is non zero.
2023-10-23Extracted code that performs a jump into its own routineAryadev Chavali
Checks if the operand given is a well defined program address, then performs the jump.
2023-10-23Fixed bug in vm_mov(byte|hword) where registers aren't set properlyAryadev Chavali
This is because we just OR the bits into the specific byte of the word. This means the previous state may leave artefacts as the OR doesn't clear the bits away. To do so, we apply a bit mask to clear the specified byte(s) of the word, then perform the OR.
2023-10-23Moved macros to extract nth (byte|hword) from a word to base.hAryadev Chavali
2023-10-23Rearrange what is printed in vm_print_allAryadev Chavali
First the program, then the registers then the stack.
2023-10-23Check for and handle errors when interpreting bytecodeAryadev Chavali
Prints an error message, returns a non zero code based on error code (255 - err). In main, I propagate this exit code.
2023-10-23Added an example program fib.cAryadev Chavali
This is simply a program with an embedded set of instructions which indefinitely computes and prints fibonacci numbers, computing them in pairs. Does it completely through the virtual machine rather than just hard C instructions. Also amended the Makefile to compile it. Required moving the main.c object file into the dependencies of $(DIST)/$(OUT). I should track the dependencies for fib.c and main.c as well.
2023-10-23Fixed bugs with ordering of bytes in some operationsAryadev Chavali
Also fixed an overflow error in vm_dup_word, where I underflow the index of vm->stack.data which causes a buffer overflow.
2023-10-23Added and implemented OP_PRINT*Aryadev Chavali
Here is where we may have differing interpretations of what the bits in the data pile may actually mean. This in particular refers to printing the signed or unsigned versions of the bits given. Also, interpreting some byte as a character or just a raw number.
2023-10-23Fixed bug where vm_print_program listing for program was incorrectAryadev Chavali
Only happens when vm_print_program(STDERR), as STDERR occurs before STDOUT on Emacs. So while the lines would print, no instructions would follow. This fixes that by using fp.
2023-10-22Remove get_opcode_data_typeAryadev Chavali
Was only used for OP_PUSH data types anyway, so is essentially useless. Only OP_PUSH has operands after it that directly relate to it: the rest either have a fixed type (a byte for registers, for example) or NIL (because they have no operand).
2023-10-22Coupled some routines together, implemented OP_PLUS_*, -vm_peekAryadev Chavali
Routines that use the stack for their operands i.e. aren't supplied operands directly all have the same signature. We may as well stick them all together in one array and one conditional, just reduces the number of branches. Also looks nicer. Implemented OP_PLUS_*. Pretty simple to implement. Deleted vm_peek as it was only necessary to update the `ret` register.
2023-10-22Added OP_PLUS_*Aryadev Chavali
Takes two operands from the stack then pushes their sum.
2023-10-22Fix bug where negative opcodes lead to invalid bytecode parsingAryadev Chavali
2023-10-22Added runtime errors to virtual machineAryadev Chavali
Every vm routine now returns an err_t, which is an enumeration of possible error states. ERR_OK represents the good state and is 0 so error checking seems very natural in terms of language `if (err) ...`. Errors bubble up the runtime, with any callers forced to check if an error occurred. This does mean that routines that call other routines cannot provide an accurate trace of the subcaller (based on the fact that an error is generated for the current instruction), but this should be a non issue as no instruction should be complex enough to need proper traces.
2023-10-22Added and implemented OP_JUMP_(STACK|REGISTER)Aryadev Chavali
Uses the stack and register, respectively, to jump to an absolute address. The stack based jump pops a word off the stack to perform a jump, while the register based one uses the operand to figure out which register to use.
2023-10-22Removed `ret` registerAryadev Chavali
Wasn't useful or necessary.
2023-10-22Added and implemented OP_JUMP_ABSAryadev Chavali
Jumps to the operand given, interpreted as a word, an absolute address.
2023-10-22Fixed bug in vm_execute_all, if no OP_HALT then program kept goingAryadev Chavali
This adds a bound on vm_execute_all to stop program->ptr from going past program->max.
2023-10-22Implemented vm_* routines for OP_DUP and vm_execute codeAryadev Chavali
2023-10-22Use conversion functions for (h)word to and from bytes instead of bit shiftingAryadev Chavali
Wasn't very secure for endianness, and using these helpers abstracts the details away a bit in case I want to enforce a certain system.
2023-10-22Added NUMBER_OF_OPCODES which aids in compilation errorsAryadev Chavali
If I add a new operand I want the build system to be more helpful in finding the places I need to change to make it work.
2023-10-22Added opcode OP_DUP_*Aryadev Chavali
Duplicates the nth datum off the stack, pushing it to the top. Useful for operations such as MOV which eat the stack.
2023-10-22Cleaned up inst.cAryadev Chavali
Use (H)WORD_SIZE more, added some notes, etc
2023-10-22Functions which convert (h)words to and from bytesAryadev Chavali
Uses memcpy internally, so we don't need to care about endianness.
2023-10-22Simple program which assembles instructions then executes themAryadev Chavali
2023-10-22Fix bug where accessing byte/hword registers > 8 wouldn't workAryadev Chavali
This is because we were checking them as if they were word registers.
2023-10-22Added flag to Makefile to set VERBOSE macro in base.hAryadev Chavali
2023-10-22Made a debug and release configuration via flagsAryadev Chavali
Also split out the check for whether $(DIST) exists by making it its own recipe. Removes the repeated checks in each object compilation.
2023-10-22When VEROBSE flag is set greater than 0, print traces in vm_execute_allAryadev Chavali
For each cycle, print the cycle and any changes. We track changes on the stack by remembering the previous stack pointer. For registers, I remember the previous array of registers and do a byte level compare of the current registers and the remembered ones. Produces pretty log messages and an easy way to track execution.
2023-10-22Changed formats for vm_print_(stack|program)Aryadev Chavali
Easier to read now
2023-10-22Fix bug where FILE is closed when passing to darr_(write|read)Aryadev Chavali
2023-10-22Added flag in base.h, VERBOSEAryadev Chavali
Will be used to provide traces during program execution or assembly.
2023-10-22Added macros for NOOP and HALTAryadev Chavali