aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
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-02Small fixesAryadev Chavali
2023-11-02Created a preprocessing unit presult_t and a function to process themAryadev Chavali
Essentially a presult_t contains one of these: 1) A label construction, which stores the label symbol into `label` (PRES_LABEL) 2) An instruction that calls upon a label, storing the instruction in `instruction` and the label name in `label` (PRES_LABEL_ADDRESS) 3) An instruction that uses a relative address offset, storing the instruction in `instruction` and the offset wanted into `relative_address` (PRES_RELATIVE_ADDRESS) 4) An instruction that requires no further processing, storing the instruction into `instruction` (PRES_COMPLETE_INSTRUCTION) In the processing stage, we resolve all calls by iterating one by one and maintaining an absolute instruction address. Pretty nice, lots more machinery involved in parsing now.
2023-11-02Started work on preprocessing jump addressesAryadev Chavali
2023-11-02Added a TODO file for tasksAryadev Chavali
2023-11-01A small program I am currently working on: reverses an allocated buffer of ↵Aryadev Chavali
bytes, returning a new set
2023-11-01Added MALLOC_STACK and SUB to instruction-test exampleAryadev Chavali
2023-11-01Implemented MALLOC_STACK and SUB in the assemblerAryadev Chavali
2023-11-01Implemented OP_MALLOC_STACK and OP_SUB in the runtimeAryadev Chavali
2023-11-01Added instructions for MALLOC_STACK and SUBAryadev Chavali
MALLOC_STACK is a stack based version of MALLOC, SUB does subtraction.
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-01Updated instruction-test example file for new memory management instructionsAryadev Chavali
2023-11-01Implemented stack versions of MGET and MSET in assemblerAryadev Chavali
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-01Added stack based versions of MSET and MGETAryadev Chavali
Essentially they use the stack for their one and only operand. This allows user level control, in particular it allows for loops to work correctly while using these operands.
2023-11-01Implemented OP_MSIZE into lexer/parser of ASMAryadev Chavali
2023-11-01Implemented OP_MSIZE in the VM runtimeAryadev Chavali
2023-11-01Added instruction to get the size of some allocationAryadev Chavali
This will allow for more library level code to be written. For example, say you wanted to write a generic byte level reversal algorithm for dynamically sized allocations. Getting the size of the allocation would be fundamental to this operation.
2023-11-01Implemented lexer and parser for new memory management instructionsAryadev 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-01Added instructions for allocating, setting, getting and deleting heap memoryAryadev Chavali
One may allocate any number of (bytes|hwords|words), set or get some index from allocated memory, and delete heap memory. The idea is that all the relevant datums will be on the stack, so no register usage. This means no instructions should use register space at all (other than POP, which I'm debating about currently). Register space is purely for users.
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-01heap_free_page returns true if page was successfully deletedAryadev Chavali
2023-11-01Heap now maintains a new page per allocationAryadev Chavali
Instead of having each page be an area of memory, where multiple pointers to differing data may lie, we instead have each page being one allocation. This ensures that a deletion algorithm, as provided, would actually work without destroying older pointers which may have been allocated. Great!
2023-11-01VM runtime now maintains a heap internallyAryadev Chavali
Now need to create some instructions which manage the heap
2023-11-01Added an arena allocatorAryadev Chavali
A page is a flexibly allocated structure of bytes, with a count of the number of bytes already allocated (used) and number of bytes available overall (available), with a pointer to the next page, if any. heap_t is a linked list of pages. One may allocate a requested size off the heap which causes one of two things: 1) Either a page already exists with enough space for the requested size, in which case that page's pointer is used as the base for the requested pointer 2) No pages satisfy the requested size, so a new page is allocated which is the new end of the heap.
2023-11-01Updated README LOCAryadev Chavali
2023-11-01Deleted fib.c as fib.asm replaces itAryadev Chavali
2023-11-01Lines of Code heading for READMEAryadev Chavali
2023-11-01Updated README with build instructionsAryadev Chavali
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-01Makefile now has recipes for example assembly programsAryadev Chavali
Dependencies are just ASM_OUT binary and the corresponding assembly program for the bytecode output file. Actually works very well, with changes triggering a recompilation. Also an `exec` recipe is introduced to do the task of compiling an assembly program and executing the corresponding bytecode all at once.
2023-11-01Ignore all out filesAryadev Chavali
2023-11-01Implemented a factorial program in the assemblyAryadev Chavali
Very cool, easy, and reads well
2023-11-01Removed the index printing in fib.asmAryadev Chavali
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-01Add MULT to lexer and parser for assemblerAryadev Chavali
2023-11-01Introduced a new mathematical operator MULTAryadev Chavali
Thankfully multiplication, like addition, is the same under 2s complement as it is for unsigned numbers. So I just need to implement those versions to be fine.
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 where comparators wouldn't be parsed correctlyAryadev Chavali
This is because comparators may apply to signed types, so I need to use the right parsing function.
2023-11-01examples/fib.asm now terminates on a very large boundAryadev Chavali
This is using the comparators and a jump-if
2023-11-01Changed inst bytecode methods for new register systemAryadev Chavali
As registers may be theoretically infinite in number, we should use the largest size possible when referring to them in bytecode (a word).
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-01Set any new data allocated to 0 for clarityAryadev Chavali
This is only new data allocated, so it's a very careful procedure.
2023-11-01Made an example translation of fib.c to the custom assembly (fib.asm)Aryadev Chavali
2023-11-01Makefile now has green colours for binaries and yellow for object filesAryadev Chavali