diff options
| -rw-r--r-- | example/example_02_nectar/example.ncpp | 9 | ||||
| -rw-r--r-- | include/CompilerKit/AE.h | 2 | ||||
| -rw-r--r-- | include/CompilerKit/AST.h | 1 | ||||
| -rw-r--r-- | src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc | 26 | ||||
| -rw-r--r-- | src/CompilerKit/src/Linkers/DynamicLinker64+MachO.cc | 4 |
5 files changed, 31 insertions, 11 deletions
diff --git a/example/example_02_nectar/example.ncpp b/example/example_02_nectar/example.ncpp index 1a42e0f..d83cff9 100644 --- a/example/example_02_nectar/example.ncpp +++ b/example/example_02_nectar/example.ncpp @@ -1,7 +1,8 @@ const main() { - if (0x10 == 0x10) { - return 0x0; - } + _sleep(0x1); + _putchar(0x0, 'H'); + _putchar(0x0, 'i'); + _putchar(0x0, '!'); - return; + return 0; } diff --git a/include/CompilerKit/AE.h b/include/CompilerKit/AE.h index 945dd83..e96861c 100644 --- a/include/CompilerKit/AE.h +++ b/include/CompilerKit/AE.h @@ -4,7 +4,7 @@ // Official repository: https://github.com/nekernel-org/nectar #ifndef NECTAR_COMPILERKIT_AE_H -#define NECTAR_COMPILERKIT_AE_H_ +#define NECTAR_COMPILERKIT_AE_H #include <CompilerKit/Detail/Config.h> #include <fstream> diff --git a/include/CompilerKit/AST.h b/include/CompilerKit/AST.h index 80dd19a..7529d73 100644 --- a/include/CompilerKit/AST.h +++ b/include/CompilerKit/AST.h @@ -41,6 +41,7 @@ enum struct KeywordKind { kKeywordKindDelete, kKeywordKindAccess, kKeywordKindAccessChecked, + kKeywordKindFunctionAccess, kKeywordKindIf, kKeywordKindVariableAssign, kKeywordKindVariableDec, diff --git a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc index 557d9f2..f2cbc04 100644 --- a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc +++ b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc @@ -565,14 +565,24 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( continue; } case CompilerKit::KeywordKind::kKeywordKindAccess: + case CompilerKit::KeywordKind::kKeywordKindFunctionAccess: case CompilerKit::KeywordKind::kKeywordKindAccessChecked: { CompilerKit::STLString valueOfVar = text.substr(text.find(keyword.first.fKeywordName) + keyword.first.fKeywordName.size()); - auto args = valueOfVar.substr(valueOfVar.find("(") + 1); + CompilerKit::STLString args; - if (!valueOfVar.find("(")) - CompilerKit::Detail::print_error("Malformed function call: " + text, file); + if (valueOfVar.find("{") != CompilerKit::STLString::npos) { + break; + } else if (CompilerKit::KeywordKind::kKeywordKindFunctionAccess == keyword.first.fKeywordKind) { + syntax_tree.fUserValue += (kNasmOutput ? "section .text\nextern " : "extern_segment .code64") + + text.substr(0, text.find(keyword.first.fKeywordName)) + "\n"; + } + + if (CompilerKit::KeywordKind::kKeywordKindFunctionAccess == keyword.first.fKeywordKind) + args = text.substr(text.find(keyword.first.fKeywordName)); + else + args = valueOfVar.substr(valueOfVar.find("(") + 1); auto nameVar = text.substr(0, text.find(keyword.first.fKeywordName)); @@ -584,10 +594,14 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( nameVar.erase(nameVar.find("\t"), 1); } + auto method = text.substr(0, text.find(keyword.first.fKeywordName)); + if (!nectar_get_variable_ref(nameVar).empty()) syntax_tree.fUserValue += "lea r8, " + nectar_get_variable_ref(nameVar) + "\n"; - auto method = valueOfVar.erase(valueOfVar.find("(")); + if (CompilerKit::KeywordKind::kKeywordKindFunctionAccess != keyword.first.fKeywordKind) + method = valueOfVar.erase(valueOfVar.find("(")); + valueOfVar += "\n"; CompilerKit::STLString arg; @@ -634,6 +648,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( } else { // NASM: Generate standard call through computed address auto varRef = nectar_get_variable_ref(nameVar); + if (keyword.first.fKeywordName.ends_with('>')) { // Pointer dereference: load pointer then call through it syntax_tree.fUserValue += "mov rax, " + varRef + "\n"; @@ -644,6 +659,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( syntax_tree.fUserValue += "call [rax + " + method + "]\n"; } } + } else { + syntax_tree.fUserValue += "call " + method + "\n"; } break; @@ -1443,6 +1460,7 @@ NECTAR_MODULE(CompilerNectarAMD64) { kKeywords.emplace_back("delete", CompilerKit::KeywordKind::kKeywordKindDelete); kKeywords.emplace_back(".", CompilerKit::KeywordKind::kKeywordKindAccess); kKeywords.emplace_back("->", CompilerKit::KeywordKind::kKeywordKindAccessChecked); + kKeywords.emplace_back("(", CompilerKit::KeywordKind::kKeywordKindFunctionAccess); kKeywords.emplace_back(";", CompilerKit::KeywordKind::kKeywordKindEndLine); kKeywords.emplace_back("return", CompilerKit::KeywordKind::kKeywordKindReturn); diff --git a/src/CompilerKit/src/Linkers/DynamicLinker64+MachO.cc b/src/CompilerKit/src/Linkers/DynamicLinker64+MachO.cc index f076d3c..0068350 100644 --- a/src/CompilerKit/src/Linkers/DynamicLinker64+MachO.cc +++ b/src/CompilerKit/src/Linkers/DynamicLinker64+MachO.cc @@ -61,7 +61,7 @@ struct SectionInfo { /// @brief Extract clean symbol name from AE record name /// AE format: ".code64$symbolname" or "symbolname.code64" -static CompilerKit::STLString ExtractSymbolName(const CompilerKit::STLString& aeName) { +static CompilerKit::STLString macho_extract_symbol_name(const CompilerKit::STLString& aeName) { CompilerKit::STLString name = aeName; // Remove section prefixes/suffixes @@ -251,7 +251,7 @@ NECTAR_MODULE(DynamicLinker64MachO) { section.size = ae_records[ae_record_index].fSize; // Extract clean symbol name and add to symbol table - CompilerKit::STLString symbolName = ExtractSymbolName(section.name); + CompilerKit::STLString symbolName = macho_extract_symbol_name(section.name); if (!symbolName.empty()) { // Determine section number (1 = __text, 2 = __data) |
