Commit Graph

31 Commits

Author SHA1 Message Date
Aryadev Chavali
3a09beb582 Change license agreement terming to ensure version 2 only. 2024-06-28 16:07:15 +01:00
Aryadev Chavali
a9f81992ab Update copyright notices and top level licenses 2024-06-25 00:48:43 +01:00
Aryadev Chavali
ecadcb5e36 Remove an include and define BYTE_SIZE 2024-06-20 02:24:23 +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
b3de11d1f7 Making better documentation 2024-06-04 02:57:51 +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
8aecb7b681 Fixed problem with detecting little endian
Copied the code from stack overflow without thinking about it.  The
first byte in little endian order should always be LSB so I construct
a more contrived example (0xFFFF0000) which should make it easier to
detect what the first byte is considered on the machine.  If it's 0
then the LSB is the first byte hence little endian, otherwise it's big
endian.

On a greater note: Don't never copy no code from stack overflow, bro.
I went up there at 11 o'clock last night trynna get me some code.
Bro, I copied that shit, woke up, my motherfucking LITTLE_ENDIAN
detection don't work.  Explain, bro.
2024-04-28 22:17:51 +05:30
Aryadev Chavali
08c9726333 Fixed bug with converting (h)word to (h)word in terms of endian
While it helped with understanding to use unions as a safe way to
access the underlying bits, this shift based mechanism actually makes
more sense at a glance, particularly by utilising WORD_NTH_BYTE
2024-04-28 20:57:41 +05:30
Aryadev Chavali
df16aa9b19 Fixed WORD_NTH_HWORD which didn't work correctly before
Thank you testing
2024-04-28 19:09:28 +05:30
Aryadev Chavali
06a883d538 Made lib/base conversion functions const where possible 2024-04-28 17:41:17 +05:30
Aryadev Chavali
cce3259b56 Fixed bugs in base.c
In particular, __LITTLE_ENDIAN__ was not a functioning macro.
Instead, I implemented a version by hand (copied from IBM) that
actually figures out if the machine is little endian or not.

Thank you unit testing!
2024-04-28 17:37:48 +05:30
Aryadev Chavali
b9c94d0725 Changed doxygen comment style in base.h
Remove asterisk from start of each line and add a @brief.
2024-04-25 11:50:51 +05:30
Aryadev Chavali
49b4470424 Defined bounds for signed and unsigned base types 2024-04-25 11:10:50 +05:30
Aryadev Chavali
331784281e Refactor s_word -> long_t 2024-04-25 11:08:17 +05:30
Aryadev Chavali
43d14d05cf Refactor type word -> word_t 2024-04-25 11:07:37 +05:30
Aryadev Chavali
9c0125542e Refactored type hword -> hword_t 2024-04-25 10:59:45 +05:30
Aryadev Chavali
1dfdbb3cd0 Refactor type byte -> byte_t
Simpler to read as a type.  This style will allow me to define signed
versions of the base types as simpler names than what they are
currently.
2024-04-25 10:48:51 +05:30
Aryadev Chavali
122e12e8fd Simplify the OP_POP_* routine by adjusting data_type_t
This simple fix made the routine for OP_POP not require an additional
dispatch step on top of the conditional due to OPCODE_DATA_TYPE,
instead using data_type_t as a map from an opcode's base type to a
specific type.
2024-04-25 01:20:35 +05:30
Aryadev Chavali
3b912495de Created custom functions to convert (h)words to and from bytecode format
Instead of using endian.h that is not portable AND doesn't work with
C++, I'll just write my own using a forced union based type punning
trick.

I've decided to use little endian for the format as well: it seems to
be used by most desktop computers so it should make these functions
faster to run for most CPUs.
2024-04-14 03:54:54 +06:30
Aryadev Chavali
72585772ef Fixing build problems due to endian.h
Have to define _DEFAULT_SOURCE before you can use the endian
conversion functions.  As most standard library headers use
features.h, and _DEFAULT_SOURCE must be defined before features.h is
included, we have to include base.h before other headers.
2024-04-12 17:32:58 +06:30
Aryadev Chavali
84028dab79 Done TODO: Comment coverage > lib > base.h
Pretty simple
2024-04-09 15:15:00 +06:30
Aryadev Chavali
99b0ebdfa6 Small fixes 2023-11-02 20:35:47 +00:00
Aryadev Chavali
5045452d7a Added flag which forces the printing of hexes
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-31 22:30:53 +00:00
Aryadev Chavali
5127202722 Introduced 3 new union members to data_t
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-31 21:41:53 +00:00
Aryadev Chavali
095e62b86f Introduced signed versions of common types
For each type T there is the signed version s_T
2023-10-31 21:23:00 +00:00
Aryadev Chavali
157c79d53c Added a "usage" message and colours for assembler
Prints useful and pretty messages when verbose being at least 1.
2023-10-29 16:59:31 +00:00
Aryadev Chavali
1177a5a45b Auto-fill copyright notice in examples/fib.c 2023-10-29 16:56:19 +00:00
Aryadev Chavali
32dfcc109c Added macro to do safe subtractions on a word
Default C just lets overflows occur for subtraction, so this macro
will default to 0 if the subtraction causes an overflow.
2023-10-28 18:16:50 +01:00
Aryadev Chavali
ac57e32a02 Added lib folder for general stuff, introduced as target to Makefile 2023-10-23 04:25:48 +01:00