aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-04-15Default constructor for pp_err_tAryadev Chavali
2024-04-15preprocess_* now uses const references to tokensAryadev Chavali
They copy and construct new token vectors and just read the token inputs.
2024-04-15Updated main.cpp for changes to lexerAryadev Chavali
2024-04-15Implemented preprocess_const_blocksAryadev Chavali
Once again quite similar to preprocess_macro_blocks but shorter, easier to use and easier to read. (76 vs 109)
2024-04-15Implement printing of pp_err_tAryadev Chavali
Another great thing for C++: the ability to tell it how to print structures the way I want. In C it's either: 1) Write a function to print the structure out (preferably to a file pointer) 2) Write a function to return a string (allocated on the heap) which represents it Both are not fun to write, whereas it's much easier to write this.
2024-04-15Implement constructors for pp_err_tAryadev Chavali
2024-04-15Implement preprocess_use_blocksAryadev Chavali
While being very similar in style to the C version, it takes 27 lines of code less to implement it due to the niceties of C++ (41 lines vs 68).
2024-04-15Moved read_file to a general base libraryAryadev Chavali
2024-04-15Fix some off by one errors in lexerAryadev Chavali
2024-04-15lexer now produces a vector of heap allocated tokensAryadev Chavali
This removes the problem of possibly expensive copies occurring due to working with tokens produced from the lexer (that C++ just... does): now we hold pointers where the copy operator is a lot easier to use. I want expensive stuff to be done by me and for a reason: I want to be holding the shotgun.
2024-04-15Rewrote preprocesser APIAryadev Chavali
This C++ rewrite allows me to rewrite the actual API of the system. In particular, I'm no longer restricting myself to just using enums then figuring out a way to get proper error logging later down the line (through tracking tokens in the buffer internally, for example). Instead I can now design error structures which hold references to the token they occurred on as well as possible lexical errors (if they're a FILE_LEXICAL_ERROR which occurs due to the ~%USE~ macro). This means it's a lot easier to write error logging now at the top level.
2024-04-14parser -> preprocesser + parserAryadev Chavali
I've decided to split the module parsing into two modules, one for the preprocessing stage which only deals with tokens and the parsing stage which generates bytecode.
2024-04-14enum -> enum class in lexerAryadev Chavali
This makes enum elements scoped which is actually quite useful as I prefer the namespacing that enum's give in C++.
2024-04-14Added static assert to lexer in case of opcode changesAryadev Chavali
2024-04-14asm/main now tokenises and prints the tokens of a given fileAryadev Chavali
With error checking!
2024-04-14Implemented a function to read a file in fullAryadev Chavali
Uses std::optional in case file doesn't exist.
2024-04-14asm/main now prints usageAryadev Chavali
2024-04-14Implemented cstr functions.Aryadev Chavali
2024-04-14Implemented overload for ostream and token as well as constructors for tokenAryadev Chavali
2024-04-14Implemented tokenise_bufferAryadev Chavali
Note that this is basically the same as the previous version, excluding the fact that it uses C++ idioms more and does a bit better in error checking.
2024-04-14Implemented tokenise_literal_stringAryadev Chavali
One thing I've realised is that even methods such as this require error tracking. I won't implement it in the tokenise method as it's not related to consuming the string per se but instead in the main method.
2024-04-14Implemented tokenise_literal_char (tokenise_char_literal)Aryadev Chavali
I made the escape sequence parsing occur here instead of leaving it to the main tokenise_buffer function as I think it's better suited here.
2024-04-14Implemented tokenise_literal_hexAryadev Chavali
Note the overall size of this function in comparison to the C version, as well as its clarity. Of course, it is doing allocations in the background through std::string which requires more profiling if I want to make this super efficientâ„¢ but honestly the assembler just needs to work, whereas the runtime needs to be fast.
2024-04-14Implemented tokenise_literal_number (tokenise_number)Aryadev Chavali
2024-04-14Started implementing lexer in lexer.cppAryadev Chavali
The implementation for tokenise_symbol is already a lot nicer to look at and add to due to string/string_view operator overloading of ==. Furthermore, error handling through pair<> instead of making some custom structure which essentially does the same thing is already making me happy for this rewrite.
2024-04-14Wrote a new lexer API in C++Aryadev Chavali
Essentially a refactor of the C formed lexer into C++ style. I can already see some benefits from doing this, in particular speed of prototyping.
2024-04-14Added C++ dir localsAryadev Chavali
2024-04-14Created custom functions to convert (h)words to and from bytecode formatAryadev Chavali
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-14Merge branch 'master' into asm-rewrite-cppAryadev Chavali
2024-04-14Start writing assembler in C++Aryadev Chavali
Best language to use as it's already compatible with the headers I'm using and can pretty neatly enter the build system while also using the functions I've built for converting to and from bytecode!
2024-04-14Documented lib/darr.hAryadev Chavali
2024-04-14Moved struct definitions lib/inst.h -> lib/prog.hAryadev Chavali
This means if I write the new assembler in another language I only need to FFI this header rather than all the functions as well which may not be as useful.
2024-04-14Documented lib/darr.hAryadev Chavali
2024-04-14Moved struct definitions lib/inst.h -> lib/prog.hAryadev Chavali
This means if I write the new assembler in another language I only need to FFI this header rather than all the functions as well which may not be as useful.
2024-04-14Added todo to rewrite assembler in a different languageAryadev Chavali
2024-04-14Finished todo on importing another fileAryadev Chavali
2024-04-14fix! loops in preprocess_use_blocks iterate to the wrong bound0.0.1Aryadev Chavali
A token_stream being constructed on the spot has different used/available properties to a fully constructed one: a fully constructed token stream uses available to hold the total number of tokens and used as an internal iterator, while one that is still being constructed uses the semantics of a standard darr. Furthermore, some loops didn't divide by ~sizeof(token_t)~ which lead to iteration over bound errors.
2024-04-12Fix problems with running programs due to mismatched endianAryadev Chavali
Basically ensure we're converting to big endian when writing bytecode and converting from big endian when reading bytecode.
2024-04-12Fixing build problems due to endian.hAryadev Chavali
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-09Reworking todos on library linkingAryadev Chavali
2024-04-09Some rewording of spec.orgAryadev Chavali
2024-04-09Added some TODOs to lib/inst.c to enforce endianAryadev Chavali
2024-04-09Mid-work through documenting darr.hAryadev Chavali
2024-04-09Done TODO: Comment coverage > lib > base.hAryadev Chavali
Pretty simple
2024-04-09Fixed code in vm_pop_hword DWORD -> DHWORDAryadev Chavali
Though practically this would work, as the storage for the half word is not limited in any way, nevertheless it isn't syntactically right and it's better to fix now.
2024-04-09Completed TODO: Rigid EndianAryadev Chavali
Just used the endian.h functions to convert host endian to and from big endian.
2024-04-09Added todo to force an endian conventionAryadev Chavali
I've flip flopped a bit on this but I believe the virtual machine bytecode format must have a convention on endianness. This is because of the issue stated in the TODO which may very well happen.
2024-04-08Added better documentation to TODO listAryadev Chavali
2024-04-07Changed limit for examples/factorial.asmAryadev Chavali
Did some analysis and found that 21! takes above 64 bit integers to store hence set the limit to 20 instead.
2023-11-29Use a limit on $I rather than on $B for examples/fib.asmAryadev Chavali