From 68dcaf3c8909ae09e2197a069f0fb84cfd4a5444 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 13 Jan 2026 04:10:54 +0100 Subject: feat: Nectar specs V1, introduce LibGL. Signed-off-by: Amlal El Mahrouss --- .gitignore | 2 -- doc/specs/NECTAR_LANG.md | 6 ++++ include/CompilerKit/AST.h | 1 - include/LibGL/iostream.nhh | 24 ++++++++++++++++ include/LibGL/iterator.nhh | 32 ++++++++++++++++++++++ include/LibNectar/iostream.nhh | 24 ---------------- include/LibNectar/iterator.nhh | 27 ------------------ .../src/Compilers/NectarCompiler+AMD64.cc | 10 +++---- test/test_samples/iostream.ncpp | 1 + test/test_samples/return_value.ncpp | 4 +-- 10 files changed, 69 insertions(+), 62 deletions(-) create mode 100644 include/LibGL/iostream.nhh create mode 100644 include/LibGL/iterator.nhh delete mode 100644 include/LibNectar/iostream.nhh delete mode 100644 include/LibNectar/iterator.nhh diff --git a/.gitignore b/.gitignore index f0622a6..8bee682 100644 --- a/.gitignore +++ b/.gitignore @@ -240,8 +240,6 @@ nbdist/ ## VSCode .vscode/settings.json -libgl/ - CMakeLists.txt.user CMakeCache.txt CMakeFiles diff --git a/doc/specs/NECTAR_LANG.md b/doc/specs/NECTAR_LANG.md index 2dddfd4..cdb760f 100644 --- a/doc/specs/NECTAR_LANG.md +++ b/doc/specs/NECTAR_LANG.md @@ -24,4 +24,10 @@ - `let` Pointer/Reference variable declaration. - `const` const `let` declaration. +=================================== + +# 2: Concepts + +=================================== +Nectar runs using the Generics Library (GL) -- it contains foundational code to run nectar applications and systems. diff --git a/include/CompilerKit/AST.h b/include/CompilerKit/AST.h index 6136721..b991bd0 100644 --- a/include/CompilerKit/AST.h +++ b/include/CompilerKit/AST.h @@ -29,7 +29,6 @@ enum struct KeywordKind { kKeywordKindFunctionStart, kKeywordKindFunctionEnd, kKeywordKindVariable, - kKeywordKindType, kKeywordKindExpressionBegin, kKeywordKindExpressionEnd, kKeywordKindArgSeparator, diff --git a/include/LibGL/iostream.nhh b/include/LibGL/iostream.nhh new file mode 100644 index 0000000..9e14174 --- /dev/null +++ b/include/LibGL/iostream.nhh @@ -0,0 +1,24 @@ +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (See accompanying +// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) +// Official repository: https://github.com/nekernel-org/nectar + +#ifndef NECTAR_LIBNECTAR_IOSTREAM_NHH +#define NECTAR_LIBNECTAR_IOSTREAM_NHH + +import printf, scanf; + +struct ostream +{ + let write(let data, let size) + { + return nil; + } + + let read(let region, let size) + { + return nil; + } +}; + +#endif // NECTAR_LIBNECTAR_IOSTREAM_NHH \ No newline at end of file diff --git a/include/LibGL/iterator.nhh b/include/LibGL/iterator.nhh new file mode 100644 index 0000000..a038421 --- /dev/null +++ b/include/LibGL/iterator.nhh @@ -0,0 +1,32 @@ +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (See accompanying +// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) +// Official repository: https://github.com/nekernel-org/nectar + +#ifndef NECTAR_LIBNECTAR_ITERATOR_NHH +#define NECTAR_LIBNECTAR_ITERATOR_NHH + +struct iterator_traits +{ + let begin(let it) + { + let end := it._begin; + return end; + } + + let end(let it) + { + let end := it._begin; + end += it._end; + + return end; + } + + let size(let it) + { + let sz := it._size; + return sz; + } +}; + +#endif // NECTAR_LIBNECTAR_ITERATOR_NHH \ No newline at end of file diff --git a/include/LibNectar/iostream.nhh b/include/LibNectar/iostream.nhh deleted file mode 100644 index 9e14174..0000000 --- a/include/LibNectar/iostream.nhh +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (See accompanying -// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) -// Official repository: https://github.com/nekernel-org/nectar - -#ifndef NECTAR_LIBNECTAR_IOSTREAM_NHH -#define NECTAR_LIBNECTAR_IOSTREAM_NHH - -import printf, scanf; - -struct ostream -{ - let write(let data, let size) - { - return nil; - } - - let read(let region, let size) - { - return nil; - } -}; - -#endif // NECTAR_LIBNECTAR_IOSTREAM_NHH \ No newline at end of file diff --git a/include/LibNectar/iterator.nhh b/include/LibNectar/iterator.nhh deleted file mode 100644 index 5b760ed..0000000 --- a/include/LibNectar/iterator.nhh +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (See accompanying -// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) -// Official repository: https://github.com/nekernel-org/nectar - -#ifndef NECTAR_LIBNECTAR_ITERATOR_NHH -#define NECTAR_LIBNECTAR_ITERATOR_NHH - -struct iterator_traits -{ - let begin(let collection) - { - return collection._begin; - } - - let end(let collection) - { - return collection._begin + collection._size; - } - - let size(let collection) - { - return collection._size; - } -}; - -#endif // NECTAR_LIBNECTAR_ITERATOR_NHH \ No newline at end of file diff --git a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc index 56ae555..825c5c2 100644 --- a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc +++ b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc @@ -568,7 +568,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( valueOfVar = text.substr(text.find("-=") + 2); } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableAssign) { - valueOfVar = text.substr(text.find(":=") + 2); + valueOfVar = text.substr(text.find(keyword.first.fKeywordName) + keyword.first.fKeywordName.size()); } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { break; } @@ -591,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(keyword.first.fKeywordName)); } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { varName.erase(varName.find(";")); } @@ -599,7 +599,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( static bool typeFound = false; for (auto& keyword : kKeywords) { - if (keyword.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindType) { + if (keyword.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariable) { if (text.find(keyword.fKeywordName) != CompilerKit::STLString::npos) { if (text[text.find(keyword.fKeywordName)] == ' ') { typeFound = false; @@ -625,7 +625,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( } if (keyword.second > 0 && kKeywords[keyword.second - 1].fKeywordKind == - CompilerKit::KeywordKind::kKeywordKindType) { + CompilerKit::KeywordKind::kKeywordKindVariable) { syntax_tree.fUserValue += "\n"; continue; } @@ -1222,13 +1222,13 @@ NECTAR_MODULE(CompilerNectarAMD64) { kKeywords.emplace_back("struct", CompilerKit::KeywordKind::kKeywordKindClass); 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::kKeywordKindVariableInc); kKeywords.emplace_back("-=", CompilerKit::KeywordKind::kKeywordKindVariableDec); kKeywords.emplace_back("const", CompilerKit::KeywordKind::kKeywordKindConstant); + kKeywords.emplace_back("let", CompilerKit::KeywordKind::kKeywordKindVariable); kKeywords.emplace_back("->", CompilerKit::KeywordKind::kKeywordKindPtrAccess); kKeywords.emplace_back(".", CompilerKit::KeywordKind::kKeywordKindAccess); kKeywords.emplace_back(",", CompilerKit::KeywordKind::kKeywordKindArgSeparator); diff --git a/test/test_samples/iostream.ncpp b/test/test_samples/iostream.ncpp index a432896..9f46fa6 100644 --- a/test/test_samples/iostream.ncpp +++ b/test/test_samples/iostream.ncpp @@ -1,3 +1,4 @@ +#include "../../include/LibGL/iostream.nhh" let main() { diff --git a/test/test_samples/return_value.ncpp b/test/test_samples/return_value.ncpp index 812743a..0144df9 100644 --- a/test/test_samples/return_value.ncpp +++ b/test/test_samples/return_value.ncpp @@ -1,8 +1,6 @@ -#include "../../include/LibNectar/iostream.nhh" let main() { - let six_seven = 67; - + let six_seven := 67; return six_seven; } -- cgit v1.2.3