43 Commits

Author SHA1 Message Date
Aryadev Chavali
f4e0be8977 struct Label -> label_t 2024-12-24 23:21:01 +00:00
Aryadev Chavali
9fb9413c45 node_t -> ast_node_t
Clearer to understand the intent of node_t as a direct result of
parsing source code.
2024-12-24 23:18:52 +00:00
Aryadev Chavali
fbf2202cfd Remove asm_write_init and asm_write_exit
Just inline into asm_translate_nodes
2024-12-24 23:15:04 +00:00
Aryadev Chavali
3c39df6c95 Implement SIZE_FMT and vec_append_fmt
SIZE_FMT gets the size of a cstr with the given sprintf formatted
string and arguments using `snprintf`.

vec_append_fmt formats a cstr with the given sprintf arguments then
appends it to the given vector.

This simplifies a little bit of the wordy implementation of the
assembler.
2024-12-24 23:08:52 +00:00
Aryadev Chavali
70cfeac995 Move system calling code to the end 2024-12-24 22:57:28 +00:00
Aryadev Chavali
493b98c524 Change vec_append signature to ensure ptr is constant 2024-12-24 22:54:57 +00:00
Aryadev Chavali
2c1c89c048 Separate out node type as an enumeration. 2024-12-19 08:48:44 +00:00
Aryadev Chavali
b03ef6564a Refactor obc for new vector based assembler and better config parser
Simpler implementation for configuration parsing with default values.
Now using new assembler functions.
2024-12-19 08:46:19 +00:00
Aryadev Chavali
7686c1043c Refactor assembler to use vec_t instead of buffer
Clearer, precise and no double pointers.
2024-12-19 08:45:47 +00:00
Aryadev Chavali
ffc8068a74 Introduce and implement vec_t
A vec_t is a dynamic array, separate to a buffer.  Should make it
easier to distinguish purposes using these two data types.
2024-12-19 08:44:53 +00:00
Aryadev Chavali
2a4d7addae Delete buffer stretchy functions
A buffer should be a strictly sized array representing a file in
memory.  No dynamic size functions.
2024-12-19 08:44:10 +00:00
Aryadev Chavali
22d1f712ae Fix MAX macro 2024-12-19 08:43:38 +00:00
Aryadev Chavali
0a5990a25e Fix README 2024-12-03 14:04:58 +00:00
Aryadev Chavali
69891d03e5 Added proper build instructions 2024-12-03 04:31:51 +00:00
Aryadev Chavali
423f34ba45 Added Make recipes for examples 2024-12-03 04:31:40 +00:00
Aryadev Chavali
b058becb92 Fix errors with clang 2024-12-03 04:30:20 +00:00
Aryadev Chavali
e778f818c2 Update README 2024-12-03 04:30:16 +00:00
Aryadev Chavali
2cbb2e9ffa Implement compiler (obc) 2024-12-03 04:23:22 +00:00
Aryadev Chavali
959b1f8b2c Clean all asm files as well 2024-12-03 04:23:15 +00:00
Aryadev Chavali
87fa534a7a asm_write_{init, exit} when asm_translate_nodes 2024-12-03 04:22:59 +00:00
Aryadev Chavali
4332862fa3 Fix usage and error messages 2024-12-03 04:22:52 +00:00
Aryadev Chavali
16da0e0f2c Add better error correcting code for bad loops in parser 2024-12-03 04:22:42 +00:00
Aryadev Chavali
6ad3e61a2b Fix errors due to no loops 2024-12-03 04:13:40 +00:00
Aryadev Chavali
0f0862245f Build two executables: obi and obc
The names stand for Oreo's Brainfuck Interpreter and Oreo's Brainfuck
Compiler, separate tasks that shouldn't be packaged in one executable.
2024-12-03 03:40:41 +00:00
Aryadev Chavali
a135262cd8 Wrote an assembler (transpiles brainfuck into assembly code)
Provides:
+ Transpilation from brainfuck code into intel style assembly
+ functions to assemble and link code
2024-12-03 03:38:01 +00:00
Aryadev Chavali
14ee1d3f02 Simplify main interpreter
No need to interpret "multiple files in sequence".  Just execute the
one file given.
2024-12-03 03:19:29 +00:00
Aryadev Chavali
d230dbb679 Capture number of loops in PResult during parsing 2024-12-03 03:17:44 +00:00
Aryadev Chavali
7554cc40fd Moved MEMORY_DEFAULT to lib.h 2024-12-03 03:17:44 +00:00
Aryadev Chavali
9fcd22a03b Simplify build system
RELEASE and DEBUG builds have differing build flags, triggered by
setting RELEASE variable.  No longer doing object based compilation
because:
+ gcc is fast enough without it
+ stale code compilation bugs are annoying
+ having one output binary to clean-up is just easier when switching
build-types
2024-12-03 03:17:44 +00:00
Aryadev Chavali
82eec8b529 Implement buffer_t functions to make it stretchy 2024-12-03 03:17:44 +00:00
Aryadev Chavali
c824772fc7 Introduce some nice typedefs in lib.h 2024-12-03 00:21:33 +00:00
Aryadev Chavali
4c179d7453 Add License 2024-12-03 00:11:44 +00:00
Aryadev Chavali
f66b34ec4d Added a README 2024-12-03 00:05:06 +00:00
Aryadev Chavali
9bbfa7d2cd Some general reworking, error handling 2024-12-03 00:04:40 +00:00
Aryadev Chavali
623b3acc1f Added some examples to test the interpreter 2024-12-03 00:02:12 +00:00
Aryadev Chavali
c2a4eb3985 Debug messages
Flag which provides some helpful messages for debugging.
2023-09-02 18:06:22 +01:00
Aryadev Chavali
a4f548f3ee Interpreter COMPLETE!
Really easy implementation considering opcodes are super simple.  I
was right to implement the loop_ref system so at parse time we have
resolved references and don't need to do it at runtime (helps with
compilation I guess as well).
2023-09-02 16:24:55 +01:00
Aryadev Chavali
e5cba43a0e New module for parser functions
Same principle as main->lib (previous commit).
2023-09-02 16:14:49 +01:00
Aryadev Chavali
c9b6b04d19 New module for functions I no longer need to work on
lib.(h|c) basically has structures and functions I no longer want to
stare at in main.c
2023-09-02 16:14:43 +01:00
Aryadev Chavali
f1891b0c2e Better command line usage
Now you can use command line arguments to list a set of input files
for the interpreter to use.

Currently outputs the data parsed per file.
2023-09-02 16:06:09 +01:00
Aryadev Chavali
89b9c0f94d Chunk allocator for file handling
Apparently you can't just `fseek` because it's "not portable" and
"deeply offensive" or whatever, so here's a really dirty chunk based
allocator which uses `fread` to just read chunks of data at a time and
basically runs around this issue.

While it's slower than an fseek solution for general files, this
solution allows pipes and other _weird_ things that count as "files"
to just werk.
2023-09-02 15:52:40 +01:00
Aryadev Chavali
7d369f6fad Better error reporting
Using a buffer structure allows me to pass more information to
callers and a bit more discretion over how data is passed.

Better error reporting via having a file handle and reporting it
Emacs/GCC style.
2023-09-02 15:39:51 +01:00
Aryadev Chavali
2d33640c03 INIT
Simple parser, took like an hour.

Not very smart but at least it's like O(n).
2023-09-02 15:21:56 +01:00