summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-01-13 03:33:51 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-01-13 03:33:51 +0100
commit0d7337aef0eb32f49b25ea7ce7b12af727121381 (patch)
tree2eeedcbb0efcea8be14ec46813c82e4c5836e5f6
parentef7f9bead82e73ff3efd4577a20e5170b017a859 (diff)
chore: nectar: Frontend improvements and syntax updates.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--doc/specs/NECTAR_LANG.md4
-rw-r--r--include/CompilerKit/AST.h3
-rw-r--r--include/LibNectar/iterator.nhh6
-rw-r--r--include/LibNectarCore/__abi.h2
-rw-r--r--include/LibNectarCore/base_process.h8
-rw-r--r--src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc59
-rw-r--r--test/test_samples/iostream.ncpp6
7 files changed, 42 insertions, 46 deletions
diff --git a/doc/specs/NECTAR_LANG.md b/doc/specs/NECTAR_LANG.md
index c1eae55..2dddfd4 100644
--- a/doc/specs/NECTAR_LANG.md
+++ b/doc/specs/NECTAR_LANG.md
@@ -21,7 +21,7 @@
- `.` Checked pointer access.
- `->` UnChecked pointer access.
- `struct` Plain Old Data data Structure, implement Trees, Heaps, etc..
-- `import` import module.
-- `export` export module.
+- `let` Pointer/Reference variable declaration.
+- `const` const `let` declaration.
diff --git a/include/CompilerKit/AST.h b/include/CompilerKit/AST.h
index 6a31597..6136721 100644
--- a/include/CompilerKit/AST.h
+++ b/include/CompilerKit/AST.h
@@ -30,9 +30,6 @@ enum struct KeywordKind {
kKeywordKindFunctionEnd,
kKeywordKindVariable,
kKeywordKindType,
- kKeywordKindTypePtr,
- kKeywordKindImport,
- kKeywordKindExport,
kKeywordKindExpressionBegin,
kKeywordKindExpressionEnd,
kKeywordKindArgSeparator,
diff --git a/include/LibNectar/iterator.nhh b/include/LibNectar/iterator.nhh
index 2f4e34e..5b760ed 100644
--- a/include/LibNectar/iterator.nhh
+++ b/include/LibNectar/iterator.nhh
@@ -24,10 +24,4 @@ struct iterator_traits
}
};
-type <struct It>
-typedef It::pointer iterator_pointer;
-
-type <struct It>
-typedef It::reference iterator_reference;
-
#endif // NECTAR_LIBNECTAR_ITERATOR_NHH \ No newline at end of file
diff --git a/include/LibNectarCore/__abi.h b/include/LibNectarCore/__abi.h
index 802bd1c..a35639d 100644
--- a/include/LibNectarCore/__abi.h
+++ b/include/LibNectarCore/__abi.h
@@ -11,7 +11,7 @@
__init_decl()
-static constexpr int32_t __unreachable_code = 34;
+ static constexpr int32_t __unreachable_code = 34;
inline void __compilerkit_unreachable(void) {
signal(__unreachable_code);
diff --git a/include/LibNectarCore/base_process.h b/include/LibNectarCore/base_process.h
index 15d601b..f6fd539 100644
--- a/include/LibNectarCore/base_process.h
+++ b/include/LibNectarCore/base_process.h
@@ -10,10 +10,10 @@
__init_decl()
-/// @brief CRT exit, with exit code (!!! exits all threads. !!!)
-/// @param code the exit code.
-/// @return the return > 0 for non successful.
-extern int exit_(int code);
+ /// @brief CRT exit, with exit code (!!! exits all threads. !!!)
+ /// @param code the exit code.
+ /// @return the return > 0 for non successful.
+ extern int exit_(int code);
/// @brief CRT signal handler.
/// @param code the signal code.
diff --git a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
index 3284094..56ae555 100644
--- a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
+++ b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
@@ -225,15 +225,17 @@ class CompilerFrontendNectarAMD64 final CK_COMPILER_FRONTEND {
public:
/// \brief Parse NECTAR namespaces and objects.
/// \param CompilerKit::SyntaxLeafList::SyntaxLeaf the leaf to build upon.
- CompilerKit::SyntaxLeafList::SyntaxLeaf CompileClasses(CompilerKit::STLString& text,
- const CompilerKit::STLString& file,
- CompilerKit::SyntaxLeafList::SyntaxLeaf&);
+ CompilerKit::SyntaxLeafList::SyntaxLeaf CompileLayout(CompilerKit::STLString& text,
+ const CompilerKit::STLString& file,
+ CompilerKit::SyntaxLeafList::SyntaxLeaf&);
};
/// @internal compiler variables
static CompilerFrontendNectarAMD64* kFrontend = nullptr;
+static std::vector<CompilerKit::STLString> kCurrentImportDirs{};
+
static std::vector<CompilerKit::STLString> kRegisterList = {
"rbx", "rsi", "r10", "r11", "r12", "r13", "r14", "r15", "xmm12", "xmm13", "xmm14", "xmm15",
};
@@ -566,11 +568,15 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
valueOfVar = text.substr(text.find("-=") + 2);
} else if (keyword.first.fKeywordKind ==
CompilerKit::KeywordKind::kKeywordKindVariableAssign) {
- valueOfVar = text.substr(text.find("=") + 1);
+ valueOfVar = text.substr(text.find(":=") + 2);
} else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
break;
}
+ if (valueOfVar.empty()) {
+ CompilerKit::Detail::print_error("Undefined Right-Value for variable", file);
+ }
+
while (valueOfVar.find(";") != CompilerKit::STLString::npos &&
keyword.first.fKeywordKind != CompilerKit::KeywordKind::kKeywordKindEndInstr) {
valueOfVar.erase(valueOfVar.find(";"));
@@ -585,7 +591,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
varName.erase(varName.find("-="));
} else if (keyword.first.fKeywordKind ==
CompilerKit::KeywordKind::kKeywordKindVariableAssign) {
- varName.erase(varName.find("="));
+ varName.erase(varName.find(":="));
} else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
varName.erase(varName.find(";"));
}
@@ -619,9 +625,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
}
if (keyword.second > 0 && kKeywords[keyword.second - 1].fKeywordKind ==
- CompilerKit::KeywordKind::kKeywordKindType ||
- kKeywords[keyword.second - 1].fKeywordKind ==
- CompilerKit::KeywordKind::kKeywordKindTypePtr) {
+ CompilerKit::KeywordKind::kKeywordKindType) {
syntax_tree.fUserValue += "\n";
continue;
}
@@ -686,10 +690,6 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
break;
}
- case CompilerKit::KeywordKind::kKeywordKindImport:
- case CompilerKit::KeywordKind::kKeywordKindExport: {
- break;
- }
case CompilerKit::KeywordKind::kKeywordKindReturn: {
try {
auto pos = text.find("return");
@@ -733,12 +733,12 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
}
}
- return this->CompileClasses(text, file, syntax_tree);
+ return this->CompileLayout(text, file, syntax_tree);
}
-/// \brief Parse NECTAR namespaces and objects.
+/// \brief Parse NECTAR objects.
/// \param CompilerKit::SyntaxLeafList::SyntaxLeaf the leaf to build upon.
-CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::CompileClasses(
+CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::CompileLayout(
CompilerKit::STLString& text, const CompilerKit::STLString& file,
CompilerKit::SyntaxLeafList::SyntaxLeaf& syntax_tree) {
// Handle class entry
@@ -910,7 +910,10 @@ static CompilerKit::STLString nectar_mangle_name(const CompilerKit::STLString& i
if (inClass) {
mangled += "M_" + identifierCopy;
} else {
- mangled += "F_" + identifierCopy;
+ if (identifierCopy != "main")
+ mangled += "F_" + identifierCopy;
+ else
+ return identifierCopy;
}
// Add argument types if provided
@@ -1216,31 +1219,26 @@ class AssemblyNectarInterfaceAMD64 final CK_ASSEMBLY_INTERFACE {
NECTAR_MODULE(CompilerNectarAMD64) {
bool skip = false;
- kKeywords.emplace_back("if", CompilerKit::KeywordKind::kKeywordKindIf);
- kKeywords.emplace_back("else", CompilerKit::KeywordKind::kKeywordKindElse);
- kKeywords.emplace_back("else if", CompilerKit::KeywordKind::kKeywordKindElseIf);
kKeywords.emplace_back("struct", CompilerKit::KeywordKind::kKeywordKindClass);
- kKeywords.emplace_back("typedef", CompilerKit::KeywordKind::kKeywordKindTypedef);
- kKeywords.emplace_back("import", CompilerKit::KeywordKind::kKeywordKindImport);
- kKeywords.emplace_back("export", CompilerKit::KeywordKind::kKeywordKindExport);
kKeywords.emplace_back("{", CompilerKit::KeywordKind::kKeywordKindBodyStart);
kKeywords.emplace_back("}", CompilerKit::KeywordKind::kKeywordKindBodyEnd);
kKeywords.emplace_back("let", CompilerKit::KeywordKind::kKeywordKindType);
kKeywords.emplace_back("(", CompilerKit::KeywordKind::kKeywordKindFunctionStart);
kKeywords.emplace_back(")", CompilerKit::KeywordKind::kKeywordKindFunctionEnd);
- kKeywords.emplace_back("=", CompilerKit::KeywordKind::kKeywordKindVariableAssign);
+ kKeywords.emplace_back(":=", CompilerKit::KeywordKind::kKeywordKindVariableAssign);
kKeywords.emplace_back("+=", CompilerKit::KeywordKind::kKeywordKindVariableInc);
kKeywords.emplace_back("-=", CompilerKit::KeywordKind::kKeywordKindVariableDec);
kKeywords.emplace_back("const", CompilerKit::KeywordKind::kKeywordKindConstant);
- kKeywords.emplace_back("*", CompilerKit::KeywordKind::kKeywordKindPtr);
kKeywords.emplace_back("->", CompilerKit::KeywordKind::kKeywordKindPtrAccess);
kKeywords.emplace_back(".", CompilerKit::KeywordKind::kKeywordKindAccess);
kKeywords.emplace_back(",", CompilerKit::KeywordKind::kKeywordKindArgSeparator);
kKeywords.emplace_back(";", CompilerKit::KeywordKind::kKeywordKindEndInstr);
+
kKeywords.emplace_back("return", CompilerKit::KeywordKind::kKeywordKindReturn);
- kKeywords.emplace_back("/*", CompilerKit::KeywordKind::kKeywordKindCommentMultiLineStart);
- kKeywords.emplace_back("*/", CompilerKit::KeywordKind::kKeywordKindCommentMultiLineEnd);
- kKeywords.emplace_back("//", CompilerKit::KeywordKind::kKeywordKindCommentInline);
+
+ kKeywords.emplace_back("if", CompilerKit::KeywordKind::kKeywordKindIf);
+ kKeywords.emplace_back("else", CompilerKit::KeywordKind::kKeywordKindElse);
+
kKeywords.emplace_back("==", CompilerKit::KeywordKind::kKeywordKindEq);
kKeywords.emplace_back("!=", CompilerKit::KeywordKind::kKeywordKindNotEq);
kKeywords.emplace_back(">=", CompilerKit::KeywordKind::kKeywordKindGreaterEq);
@@ -1281,6 +1279,13 @@ NECTAR_MODULE(CompilerNectarAMD64) {
return NECTAR_SUCCESS;
}
+ if (strcmp(argv[index], "-nec-import-dir") == 0) {
+ kCurrentImportDirs.push_back(argv[index + 1]);
+ skip = true;
+
+ continue;
+ }
+
if (strcmp(argv[index], "-nec-max-err") == 0) {
try {
kErrorLimit = std::strtol(argv[index + 1], nullptr, 10);
diff --git a/test/test_samples/iostream.ncpp b/test/test_samples/iostream.ncpp
index 6ba52ac..a432896 100644
--- a/test/test_samples/iostream.ncpp
+++ b/test/test_samples/iostream.ncpp
@@ -1,9 +1,9 @@
-#include "../../include/LibNectar/iostream.nhh"
let main()
{
- let io = iostream{};
- let first_number = io.read_once();
+ let io := iostream{};
+ let first_number := io.read_once();
+ first_number -= io.read_once();
return first_number;
} \ No newline at end of file