aboutsummaryrefslogtreecommitdiff
path: root/vm
AgeCommit message (Collapse)Author
2023-11-02Added memory leak dialog in vm_stopAryadev Chavali
Stack, call stack and heap are evaluated to check for leaks.
2023-11-02Implemented subroutine instructions in runtimeAryadev Chavali
Very easy overall, printing the call stack not so much.
2023-11-02Removed instruction OP_JUMP_REGISTERAryadev Chavali
Not necessary when you can just push the relevant word onto the stack then just do OP_JUMP_STACK.
2023-11-01Implemented OP_MALLOC_STACK and OP_SUB in the runtimeAryadev Chavali
2023-11-01Fixed issue where sometimes vm_print_registers wouldn't work for bytesAryadev Chavali
Happened because we weren't printing all relevant words due to naturally flooring the result of division. Here I ceil the division to ensure we get the maximal number of words necessary.
2023-11-01Added todos to rename the constructive macros in runtime.cAryadev Chavali
2023-11-01Implemented MGET_STACK and MSET_STACK in the runtimeAryadev Chavali
Very easy, they just pop a word then defer to their normal versions. This is probably the best case where a macro works directly so I didn't even need to write a function form for them first. One thing is that then names for the macros are quite bad right now, probably need renaming.
2023-11-01Implemented OP_MSIZE in the VM runtimeAryadev Chavali
2023-11-01Added a print_heap mechanism into vmAryadev Chavali
Pretty simple implementation, nothing massive. In VERBOSE mode, heap is tracked for any allocations/deletions, printing it if so.
2023-11-01Implemented instructions in the runtime for memory managementAryadev Chavali
Pretty simple, required some new types of errors. Obviously there's space for a macro for the differing instruction implementations, but these things need to be tested a bit more before I can do that.
2023-11-01DUP implementation is now part of WORD_ROUTINESAryadev Chavali
As PUSH_REGISTER and MOV have the same signature of taking a word as input, DUP may as well be part of it. This leads to a larger discussion about how signatures of functions matter: I may need to do a cleanup at some point.
2023-11-01VM runtime now maintains a heap internallyAryadev Chavali
Now need to create some instructions which manage the heap
2023-11-01Fix off by one issues in register implementationsAryadev Chavali
word register 0 refers to the first 8 bytes of the dynamic array. Hence the used counter should be at least 8 bytes. This deals with those issues. Also print more useful information in vm_print_registers (how many byte|hword|word registers are currently in use, how many are available).
2023-11-01Implement OP_MULT in runtimeAryadev Chavali
Lucky surprise: OP_PLUS follows the same principle rules as the bitwise operators in that they return the same type as the input. Therefore I can simply use the same macro to implement it and MULT as those. Very nice.
2023-11-01Use vm_stop and vm_load_registersAryadev Chavali
By default I initialise the registers with 8 words, though this may not be necessary for your purposes.
2023-11-01Fixed bug with comparators where all results were flippedAryadev Chavali
This is because: say we have {a, b} where a is on top of the stack. A comparator C applies in the order C(b, a) i.e. b `C` a. The previous version did a `C` b which was wrong.
2023-11-01Added a routine to cleanup resources allocated to the VMAryadev Chavali
This means the stack should be heap allocated, which makes sense as beyond 1KB one should really be using the heap rather than the stack.
2023-11-01VM registers are now a dynamic arrayAryadev Chavali
Stack based machines generally need "variable space". This may be quite via a symbol-to-word association a list, a hashmap, or some other system. Here I decide to go for the simplest: extending the register system to a dynamic/infinite number of them. This means, in practice, that we may use a theoretically infinite number of indexed words, hwords and bytes to act as variable space. This means that the onus is on those who are targeting this virtual machine to create their own association system to create syntactic variables: all the machinery is technically installed within the VM, without the veneer that causes extra cruft.
2023-11-01Clearer VERBOSE messagesAryadev Chavali
2023-11-01Removed OP_EQ signed versions as they're uselessAryadev Chavali
A negative number under 2s complement can never be equal to its positive as the top bit *must* be on. If two numbers are equivalent bit-by-bit then they are equal for both signed and unsigned numbers.
2023-10-31Added new macro for bitwise comparison constructionAryadev Chavali
This pushes a datum of the same type as the operands, which is why it cannot use the comparator macro as that always pushes bytes.
2023-10-31Added flag which forces the printing of hexesAryadev Chavali
Anything other than char (which can just use print.byte to print the hex) and byte (which prints hexes anyway), all other types may be forced to print a hex rather than a number if PRINT_HEX is 1.
2023-10-31Use macros to stop duplication of codeAryadev Chavali
I've made a single macro which defines a function through some common metric, removing code duplication. Not particularly readable per se, but using a macro expansion in your IDE allows one to inspect the code.
2023-10-31Introduced 3 new union members to data_tAryadev Chavali
These new members are just signed versions of the previous members. This makes type punning and usage for signed versions easier than before (no need for memcpy).
2023-10-31Remove duplicated codeAryadev Chavali
2023-10-31Implemented all the comparatorsAryadev Chavali
So much reused code, I definitely need to find a way to make this cleaner.
2023-10-31Use standardised signed version of word type from base.hAryadev Chavali
2023-10-31Moved inst module to libAryadev Chavali
As it has no dependencies on vm specifically, and it's more necessary for any vendors who wish to target the virtual machine, it makes more sense for inst to be a lib module rather than a vm module.
2023-10-31Implemented new types of EQ, forced all comparators to push bytesAryadev Chavali
Just need to call their unsigned versions. All comparators should push bytes as it makes return types uniform.
2023-10-31vm_execute_all: Print every cycle on VERBOSE >= 2, just print final state ↵Aryadev Chavali
otherwise Changed VERBOSE checks to ensure a degree of information.
2023-10-31Created routines for new comparator opcodes (not implemented)Aryadev Chavali
Will cause error if used currently, which is fine.
2023-10-31Introduced new instructions for comparisonAryadev Chavali
Comparing signed and unsigned versions of numbers. Same for EQ as well. Notice the irregular pattern of BYTE, CHAR, INT, HWORD,LONG,WORD as OPCODE_IS_TYPE requires the subcodes to be surrounded by BYTE and WORD.
2023-10-29Added a "usage" message and colours for assemblerAryadev Chavali
Prints useful and pretty messages when verbose being at least 1.
2023-10-29Fixed bug where JUMP_REGISTER couldn't be in bytecode readAryadev Chavali
2023-10-29Fixed bug where reading operand bytecode may stop prematurelyAryadev Chavali
This is due to checking for equality instead of just greater than in darr->used against darr->available.
2023-10-26Fixed bug where printing hword of an instruction prints number not hexAryadev Chavali
This is an easy fix.
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-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-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.