aboutsummaryrefslogtreecommitdiff
path: root/asm
AgeCommit message (Collapse)Author
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-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-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.
2023-11-29Cleaned up logs in assembler/parserAryadev Chavali
2023-11-29Fixed incorrect free of tokens in error for preprocess_use_blocksAryadev Chavali
Also error now points to the correct place in the file.
2023-11-29Report some stats of the actual program when workingAryadev Chavali
2023-11-29Refactored preprocessor to preprocess_(use|macro)_blocks and process_presultsAryadev Chavali
We have distinct functions for the use blocks and the macro blocks, which each generate wholesale new token streams via `token_copy` so we don't run into weird errors around ownership of the internal strings of each token. Furthermore, process_presults now uses the stream index in each presult to report errors when stuff goes wrong.
2023-11-29Refactored presult_t to include a stream pointerAryadev Chavali
So when a presult_t is constructed it holds an index to where it was constructed in terms of the token stream. This will be useful when implementing an error checker in the preprocessing or result parsing stages.
2023-11-29Added parse errors for %USE callsAryadev Chavali
So %USE <STRING> is the expected call pattern, so there's an error if there isn't a string after %USE. The other two errors are file I/O errors i.e. nonexistent files or errors in parsing the other file. We don't report specifics about the other file, that should be up to the user to check themselves.
2023-11-29Fixed tokenise_string_literalAryadev Chavali
Forgot to increment buffer->used and memcpy call was just incorrect.
2023-11-29Added function to copy tokensAryadev Chavali
This essentially just copies the internal string of the token into a new buffer.
2023-11-29Added TOKEN_PP_USE to lexer with implementationAryadev Chavali
2023-11-11Added string literals in tokeniserAryadev Chavali
Doesn't do much, invalid for most operations.
2023-11-08Added a preprocessing routine in assemblerAryadev Chavali
Preprocessor handles macros and macro blocks by working at the token level, not doing any high level parsing or instruction making. Essentially every macro is recorded in a registry, recording the name and the tokens assigned to it. Then for every caller it just inserts the tokens inline, creating a new stream and freeing the old one. It leaves actual high level parsing to `parse_next` and `process_presults`.
2023-11-08Added log in assembler for reading a certain number of bytesAryadev Chavali
2023-11-08Lexer symbols now recognise macro constants and referencesAryadev Chavali
2023-11-06Current work on preprocessorAryadev Chavali
2023-11-05Current work on preprocessor implementationAryadev Chavali
Lots to refactor and test
2023-11-03Symbols may now include digits in lexerAryadev Chavali
This is mostly so labels get to have digits. This won't affect number tokens as that happens before symbols.
2023-11-03Removed tabs from VERBOSE logs in asm/main.cAryadev Chavali
2023-11-03Fixed bug where labels were off by oneAryadev Chavali
Was used in a previous fix but not necessary anymore
2023-11-03Refactor assembler to use prog_t structureAryadev Chavali
Set the program structure correctly with a header using the parsed global instruction.
2023-11-03Added a start address (equivalent to `main`) to assemblerAryadev Chavali
Creates a jump address to the label delegated by "global" so program starts at that point.
2023-11-02Better logs for assemblerAryadev Chavali
2023-11-02Implemented CALL(_STACK) and RET on the assemblerAryadev Chavali
2023-11-02Made lexer more error prone so parser is lessAryadev Chavali
Lexer now will straight away attempt to eat up any type or later portions of an opcode rather than leaving everything but the root. This means checking for type in the parser is a direct check against the name rather than prefixed with a dot. Checks are a bit more strong to cause more tokens to go straight to symbol rather than getting checked after one routine in at on the parser side.
2023-11-02Made separate tokens for JUMP_ABS and JUMP_STACKAryadev Chavali
Makes more sense, don't need to fiddle around with strings as much in the parser due to this!
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.