summaryrefslogtreecommitdiff
path: root/src/rbc.c
diff options
context:
space:
mode:
authorczjstmax <jstmaxlol@disroot.org>2025-12-19 23:32:31 +0100
committerczjstmax <jstmaxlol@disroot.org>2025-12-19 23:32:31 +0100
commit1c11d915a68e60bd191d43e348d56b9eab71b107 (patch)
tree0b79d8ce3f47bc7ead2143e6f6e10e3f7df9075e /src/rbc.c
parentfe0479de0c0305eafb1d3aa1456850af9e3b4fca (diff)
Created `src` dir for code, added Makefile
Diffstat (limited to 'src/rbc.c')
-rw-r--r--src/rbc.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/rbc.c b/src/rbc.c
new file mode 100644
index 0000000..5316cda
--- /dev/null
+++ b/src/rbc.c
@@ -0,0 +1,118 @@
+#ifndef CRBC
+#define CRBC
+/*================================================================================================*
+ * CReborn - The first "official" C implementation of the Reborn programming language
+ * based on the Reborn Standard (reborn-lang.github.io/documents/standard)
+ *
+ * The name CReborn (C/Reborn, CREBORN or whatever) has been chosen because
+ * this implementation works by using C as its IR, or in much simpler terms,
+ * this compiler works by compiling Reborn code to C, and then using the GNU C
+ * Compiler (GNU Compiler Collection, gcc) to compile the output C program to
+ * an executable. This decision was made to both simplify the development and also
+ * to be able to focus more on the frontend of the compiler instead of focusing on
+ * optimization and platform-specific instructions.
+ *================================================================================================*
+ *#* STYLE GUIDELINES FOR CODE CONTRIBUTORS (AND MAINTAINERS):
+ * - Use camelCase for variables.
+ * - Use PascalCase for functions.
+ * - 4 spaces indentation (not tabs but spaces.)
+ * - Don't exceed 100 characters on a single line unless you *really* must, it's mostly
+ * for readability since we think that it is better for code to extend vertically, rather
+ * than horizontally. (Also given some developers might use 3:2 or other less-wide formats.)
+ *================================================================================================*
+ *#* NOTES FOR VIM USERS
+ * - For Vim users that don't know how to set a limit to the coloumn size, you just:
+ * :set textwidth=100
+ * :set formatoptions+=t
+ * You can also obviously also set this in your .vimrc.
+ *
+ * - For Vim users that want to (a)llow the local .exrc for commodity, you can just do:
+ * :set exrc secure
+ * and reopen any file in the repo, then you will be asked to (a)llow, meaning to trust this
+ * repo's .exrc, after (a)llowing it you will already have the 4 spaces indentation, the 100
+ * characters limit (textwidth limit) and the format options set automatically. This only applies
+ * when editing files from this repo, but if you want them in your global .vimrc or neovim config
+ * you can also copy them, again, from the local .exrc file.
+ *
+ * - Note: If you use vim/nvim and you loaded (allowed) the .exrc from this repo you can also use
+ * these commands that will automatically compile for either release / normal mode testing or for
+ * debugging mode.
+ *
+ * :Cn / :Compn - Compiles with 'Normal compile'
+ * :Cd / :Compd - Compiles with 'Debug compile'
+ *
+ *#* COMPILE COMMANDS
+ * Normal compile = 'cc rbc.c -o crbc -O2 -Wall -Wextra -pedantic'
+ * Debug compile = 'cc rbc.c -o crbc -g -O0 -Wall -Wextra -pedantic -fsanitize=address,undefined'
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// git@github.com:jstmaxlol/kat
+#include "headers/kat.h"
+
+// CReborn headers (CReborn APIs)
+#include "headers/codegen.h"
+#include "headers/abstract.h"
+#include "headers/freeast.h"
+
+// ASTs in abstract.h
+//
+
+// Functions (fwd. declars. and externs)
+//
+// headers/abstract.h
+// headers/freeast.h
+// headers/codegen.h
+//
+// local / helpers
+static inline int Eval(int x);
+
+// main
+int main(int argc, char **argv) {
+ printf(":> Checking for arguments...\n");
+ if (argc >= 2) {
+ for (int i = 1; i < argc; i++) {
+ printf("argv[%d] = %s\n", i, argv[i]);
+ }
+ } else {
+ printf(":> No arguments were found. (%d)\n\n", argc-1);
+ }
+
+ const char *ident_buff = "number";
+ const char *type_buff = "int";
+
+ int value_buff = 2;
+
+ if (argc == 3) {
+ if (strlen(argv[1]) >= 1)
+ ident_buff = argv[1];
+ //if (strlen(argv[2]) >= 1)
+ // type_buff = argv[2];
+ if (strlen(argv[2]) >= 1)
+ value_buff = atoi(argv[2]);
+ }
+
+ Expr *e = ExprIntLiteral(value_buff);
+ Decl *decl = DeclareVariable(ident_buff, type_buff, e);
+
+ if (decl->kind == DECL_VAR) {
+ DeclVar *v = decl->as;
+ printf("v->ident=%s, v->type=%s\nlet %s: %s = %d;", v->ident, v->type, v->ident, v->type, value_buff);
+ }
+
+ FreeExpr(e);
+ FreeDecl(decl);
+
+ return 0;
+}
+
+// Functions (definitions)
+//
+static inline int Eval(int x) {
+ return x;
+}
+
+#endif