diff --git a/.gitignore b/.gitignore index 999acfa..ee3825f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ .vscode/ build/ test.x -out.asm \ No newline at end of file +out.asm +out.o +out \ No newline at end of file diff --git a/documentation/Basics.md b/documentation/Basics.md index 50f958a..fc383d4 100644 --- a/documentation/Basics.md +++ b/documentation/Basics.md @@ -2,14 +2,15 @@ A short and relatively detailed list of all the basics of XILANG. Also yes, the name is supposed to be all caps *always* just like older FORTRAN. -## Extremly Basic Functions +## Extremely Basic Functions * `ret` then a value (can be a numeral or a string) will return that value +* `exit` then a value (can ONLY be a numeral) will exit with that return value * `func` then a name (ex: `func main() {};`) allows you to define a new function * `import` and a filename (either in `""` or `<>` depending on if it is a local file in the dir or a file from the include path, similar to C) allows you to import the functions from another file (ex: `import Example.xh`) -* `print` then a value will allow to print a character or string to the screen (you can also print any other type of varible) +* `print` then a value will allow to print a character or string to the screen (you can also print any other type of variable) -## Defining Varibles +## Defining Variables you define something by doing the type of var you want to define then a name then an = and the value of it (ex: `float Example = 1.0;`) @@ -38,4 +39,4 @@ func main() { ret 0; } ``` -This small prgram will print `Hello World!` and return 0. \ No newline at end of file +This small program will print `Hello World!` and return 0. \ No newline at end of file diff --git a/examples/return.s b/examples/exit.s similarity index 90% rename from examples/return.s rename to examples/exit.s index 78e02c4..ec8b1e4 100644 --- a/examples/return.s +++ b/examples/exit.s @@ -1,7 +1,7 @@ ;This is a comment global _start -start: +_start: mov rax, 60 mov rsi, 0 syscall \ No newline at end of file diff --git a/examples/return.x b/examples/exit.x similarity index 75% rename from examples/return.x rename to examples/exit.x index 10a0f13..3400e18 100644 --- a/examples/return.x +++ b/examples/exit.x @@ -1,5 +1,5 @@ !This is a Comment func main() { - ret 0; + exit 0; }; diff --git a/src/main.cxx b/src/main.cxx index a366317..3e5f72a 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -4,6 +4,8 @@ #include #include +//#include "./tokesizer.hxx" + #define version "RD-00002" #define EXIT_FAILURE 1 @@ -12,7 +14,7 @@ const char *output_filename = "out.asm"; enum class TokenType { - ret, + exit, int_lit, semicolon, comment @@ -38,8 +40,8 @@ std::vector Tokenize(const std::string& str) { } i--; - if (buffer == "ret") { // return func checkor - Tokens.push_back({.type = TokenType::ret}); + if (buffer == "exit") { // return func checkor + Tokens.push_back({.type = TokenType::exit}); buffer.clear(); continue; } @@ -53,11 +55,9 @@ std::vector Tokenize(const std::string& str) { i--; Tokens.push_back({.type = TokenType::int_lit, .value = buffer}); buffer.clear(); - } - else if (c == ';') { // legit only checks for a semicolon + } else if (c == ';') { // legit only checks for a semicolon Tokens.push_back({.type = TokenType::semicolon}); - } - else if (std::isspace(c)) { + } else if (std::isspace(c)) { continue; } } @@ -67,10 +67,10 @@ std::vector Tokenize(const std::string& str) { std::string Tokens_To_Asm(const std::vector& Tokens) { std::stringstream output; - output << "global _start\nstart:\n"; + output << "global _start\n_start:\n"; for (int i = 0; i < Tokens.size(); i++) { const Token& Token = Tokens.at(i); - if (Token.type == TokenType::ret) { + if (Token.type == TokenType::exit) { if (i + 1 < Tokens.size() && Tokens.at(i+1).type == TokenType::int_lit) { if (i + 2 < Tokens.size() && Tokens.at(i+2).type == TokenType::semicolon) { output << " mov rax, 60\n"; @@ -104,5 +104,8 @@ int main(int argC, char *argV[]) { file << Tokens_To_Asm(Tokens); } + system("nasm -felf64 out.asm"); + system("ld -o out out.o"); + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/src/tokesizer.hxx b/src/tokesizer.hxx new file mode 100644 index 0000000..7a33084 --- /dev/null +++ b/src/tokesizer.hxx @@ -0,0 +1,11 @@ +#pragma once + +class Tokenizer { + public: + inline Tokenizer(const std::string& src) { + + } + + private: + const std::string m_src; +}; \ No newline at end of file