461 Commits

Author SHA1 Message Date
Aryadev Chavali
30bed795fd New TODO on reworking the entire virtual machine
Some checks failed
C/C++ CI / build (push) Has been cancelled
C/C++ CI / test (push) Has been cancelled
I've had a revelation: the virtual machine shouldn't cater to any
specific dynamic or trend.  What I need the VM to do is provide a
basis where very useful features such as arithmetic of arbitrary sized
integers, basic control flow, memory management and file I/O are a bit
nicer than doing it myself in C.  Past that it can be as barebones as
necessary.

Previous development was done in tandem with the assembler, which
influenced how I designed the system.  I will no longer do this.  Here
I describe the creation of more generic opcodes and instructions.
These complicate the virtual machined data model but they are also
extensible, can be generalised to a wider array of use cases and can
be optimised by the virtual machine.

Instead, the assembler can use these generic instructions and make
porcelains over them to provide a nicer environment.  Take the new
PUSH opcode: since it can take an arbitrary payload of bytes and push
them all onto the stack, the assembler can provide porcelains for
shorts, half words and words as well as more interesting macros.
2024-07-10 19:37:02 +01:00
Aryadev Chavali
a408ccacb9 MSET pops n before data to set 2024-07-07 19:39:38 +01:00
Aryadev Chavali
a7f14c8f58 Remove indent in MESSAGE 2024-07-07 19:39:03 +01:00
Aryadev Chavali
7a5eee932a Moved logging macros to base.h and use them everywhere
The macros used in the testing library are actually useful everywhere
so may as well use them.
2024-07-07 03:16:42 +01:00
Aryadev Chavali
74c5746bff Reworked SPEC a ton 2024-07-07 03:04:19 +01:00
Aryadev Chavali
edf90780af Remove JUMP_STACK and CALL_STACK
Any program that generates addresses at runtime can be easily
expressed through fixed address jumps and calls.  No need for them.
2024-07-07 03:01:41 +01:00
Aryadev Chavali
ebdb1a948d Removed m*_stack_* opcodes, make them default behaviour
Memory operations used operands to encode positional/size arguments,
with stack variants in case the user wanted to programmatically do so.
In most large scale cases I don't see the non-stack variants being
used; many cases require using the stack for additions and
subtractions to create values such as indexes or sizes.  Therefore,
it's better to be stack-first.

One counter point is inline optimisation of code at runtime: if an
compile-time-known object is pushed then immediately used in an
operation, we can instead encode the value directly into an operand
based instruction which will speed up execution time because it's
slower to pop the value off the stack than have it available as part
of the instruction.
2024-07-07 03:01:06 +01:00
Aryadev Chavali
2b1e7a49d2 Added a clang-format file to the root
Copy of my personal Dotfiles but this helps in case anyone else wants
to contribute.
2024-06-28 16:21:58 +01:00
Aryadev Chavali
6014620baa Changed fill-column to 80, so more space for comments. 2024-06-28 16:11:01 +01:00
Aryadev Chavali
3a09beb582 Change license agreement terming to ensure version 2 only. 2024-06-28 16:07:15 +01:00
Aryadev Chavali
8b2192a0b6 Add a todo to rework the heap 2024-06-28 00:27:53 +01:00
Aryadev Chavali
4c0c00183b Add compile command value in dir-locals.el 2024-06-28 00:27:32 +01:00
Aryadev Chavali
a9f81992ab Update copyright notices and top level licenses 2024-06-25 00:48:43 +01:00
Aryadev Chavali
62b9b230c5 Update README 2024-06-25 00:41:43 +01:00
Aryadev Chavali
a24196f236 Fix up some TODOs 2024-06-24 17:03:19 +01:00
Aryadev Chavali
3cd2dbc2ac Registers are now fixed size
todo.org contains an explanation for this
2024-06-24 15:14:11 +01:00
Aryadev Chavali
4ad3d46996 LE ordering in data oriented instructions, make more macros
Little Endian ordering is now ensured for stack based and register
based operations e.g.  PUSH now pushes datums in LE ordering onto the
stack, POP pops data on the stack, converting from LE ordering to host
ordering.

More functions in the runtime are now macro defined, so there's less
code while still maintaining the lookup table.

--------------------------------------------------------------------------------

What LE ordering means for actual source code is that I utilise the
convert_*_to_* functions for PUSH and POP.  All other data oriented
instructions are completely internal to the system and any data
storage must be in Little Endian.  So MOV, PUSH-REGISTER and DUP can
all directly memcpy the data around the system without needing to
consider endian at all.

Macros were a necessity after I felt the redefinition of push for 4
different data types was too much.  Most functions are essentially
copies for each datatype.  Lisp macros would make this so easy :(
2024-06-24 14:29:05 +01:00
Aryadev Chavali
8984c97d33 Clean up runtime source code a little bit 2024-06-20 02:28:15 +01:00
Aryadev Chavali
ecadcb5e36 Remove an include and define BYTE_SIZE 2024-06-20 02:24:23 +01:00
Aryadev Chavali
05235497dc Propagate addition of short based instructions to runtime
Lots of busy work
2024-06-19 21:48:13 +01:00
Aryadev Chavali
1ae28bdb3b Propagating short addition to data types into instructions
(De)Serialising routines now can deal with shorts.
2024-06-19 21:36:39 +01:00
Aryadev Chavali
f2addcef0a Introducing short to data_t and handlers for converting endian 2024-06-19 20:31:16 +01:00
Aryadev Chavali
213d4afcfd long -> sword, int -> shword, char -> sbyte 2024-06-19 20:31:16 +01:00
Aryadev Chavali
bdc6e15ae9 Updated includes, README and TODO 2024-06-19 20:01:20 +01:00
Aryadev Chavali
e3aabff845 Disable -Werror 2024-06-19 19:14:01 +01:00
Aryadev Chavali
92bbf1f9a3 Fix errors in GitHub workflows version of GCC 2024-06-19 19:11:32 +01:00
Aryadev Chavali
c142578254 GitHub workflow now generates release builds 2024-06-19 19:09:12 +01:00
Aryadev Chavali
11f79a84a3 Clean errors in compilation when VERBOSE > 0 2024-06-19 19:07:50 +01:00
Aryadev Chavali
002b21b649 Fix some errors in pedantic mode for testing.h 2024-06-18 23:57:09 +01:00
Aryadev Chavali
4e513dbf01 Fix stupid issues in prog_write_bytecode
In particular, not writing the full words for the program header and
incrementing bytes prematurely.
2024-06-18 23:49:42 +01:00
Aryadev Chavali
99fb0a0e2e Moved OP_HALT to the beginning (stable ABI)
OP_HALT = 1 now.  This commit also adjusts the error checking in
inst_read_bytecode.

The main reasoning behind this is when other platforms or applications
target the AVM: whenever a new opcode may be added, the actual binary
for OP_HALT changes (as a result of how C enums work).

Say your application targets commit alpha of AVM.  OP_HALT is, say,
98.  In commit beta, AVM is updated with a new opcode so OP_HALT is
changed to 99 (due to the new opcode being placed before OP_HALT).  If
your application builds a binary for AVM version alpha and AVM version
beta is used instead, OP_HALT will be interpreted as another
instruction, which can lead to undefined behaviour.

This can be hard to debug, so here I've made the decision to try and
not place new opcodes in between old ones; new ones will always be
placed *before* NUMBER_OF_OPCODES.
2024-06-18 23:49:42 +01:00
Aryadev Chavali
d0ab1644cb Modified Makefile for less colours and a release build option 2024-06-18 23:49:42 +01:00
Aryadev Chavali
66153afbde Some light header pruning 2024-06-17 23:11:30 +01:00
Aryadev Chavali
a60108ae1d Made heap a vector of pages
Instead of using a linked list, which is incredibly fragmented, a
vector keeps all pointers together.  Keeps all our stuff together and
in theory we should have less cache misses when deleting pages.

It does introduce the issue of fragmenting, where if we allocate and
then delete many times a lot of the heap vector will be empty so
traversal will be over a ton of useless stuff.
2024-06-17 23:11:20 +01:00
Aryadev Chavali
b3de11d1f7 Making better documentation 2024-06-04 02:57:51 +01:00
Aryadev Chavali
95a8747c7f Cleaned up .dir-locals.el 2024-06-01 01:14:17 +01:00
Aryadev Chavali
d65da8eb0d char8_t -> char_t 2024-05-05 20:26:07 +05:30
Aryadev Chavali
91af3e14ef Clean up code 2024-05-05 20:20:25 +05:30
Aryadev Chavali
b77cc5639c Now base.c and inst.c are used to make a shared library
Instead of targeting the needed object files, users just need to link
with the shared library.
2024-05-05 20:20:25 +05:30
Aryadev Chavali
7a3e6d180f Use eglot for project
I rely on eglot being enabled for this to work
2024-05-05 20:20:25 +05:30
Aryadev Chavali
a40eaf29b8 OP_HALT is its own opcode, fixed some other minor bugs 2024-05-01 22:36:34 +05:30
Aryadev Chavali
fcc6bce6f9 Added header file for all INST_ macros that I deleted
This can be a possible method of native compilation, albeit requiring
the source code of the project.  Until I explore that this thing will
stay.
2024-04-29 01:42:08 +05:30
Aryadev Chavali
a83653f45d Added vm/struct.h and vm/main.c to documenting TODO 2024-04-29 01:38:51 +05:30
Aryadev Chavali
f64f456dff Finished documenting lib/heap.h 2024-04-29 01:38:43 +05:30
Aryadev Chavali
8ba25b2bf2 Use memset instead of setting properties manually
Does the same thing but it's a bit clearer that I'm not setting
anything.
2024-04-29 01:37:47 +05:30
Aryadev Chavali
e9d5aafde4 Trying to get github tests to work 2024-04-29 01:16:07 +05:30
Aryadev Chavali
ba573fd230 Quick fix to make compilation with VERBOSE=2 work 2024-04-29 01:11:33 +05:30
Aryadev Chavali
d88e297921 Added test to github workflows 2024-04-29 01:10:02 +05:30
Aryadev Chavali
05c3342e27 Added test for darr_append_bytes 2024-04-29 01:07:15 +05:30
Aryadev Chavali
3e64d7855a Changed darr_at to return a pointer 2024-04-29 01:06:58 +05:30