Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7178b86
fix(formatter): accessing static members via :: instead of .
SuperFola Nov 28, 2024
d38ed9f
feat(namespace): starting to introduce namespaces, not using them yet
SuperFola Nov 28, 2024
a5b3255
feat(namespaces): importing inside namespace, and skipping over them …
SuperFola Nov 28, 2024
f13d3c5
refactor(node): adding Node::isStringLike
SuperFola Nov 28, 2024
ee1cdb8
feat(name resolution): crude resolution of prefixed, glob and symbol …
SuperFola Nov 30, 2024
af221b1
feat(name resolution): enhancing resolution of fully qualified names,…
SuperFola Dec 1, 2024
5455561
fix(tests): updating tests to use the new context provided on errors …
SuperFola Dec 2, 2024
b1c5713
chore(tests): removing unnecessary import in string-tests
SuperFola Dec 2, 2024
c39d472
feat(tests): adding name resolution tests
SuperFola Dec 2, 2024
0369524
feat(name resolution): enhance tracking variables and fully qualified…
SuperFola Dec 2, 2024
f15a5b4
feat(name resolution): preventing the generation of stacked namespace…
SuperFola Dec 2, 2024
4f45458
feat(name resolution): somewhat better handling of closures and captures
SuperFola Dec 2, 2024
3282cdb
fix: adding necessary includes and deleting copy constructors so that…
SuperFola Dec 3, 2024
db53404
refactor(builtins)!: renamed str:xyz builtins to string:xyz for unifo…
SuperFola Dec 4, 2024
3afab37
refactor(name resolution): moving name resolution pass to its own sub…
SuperFola Dec 4, 2024
03c7e3a
feat(name resolution): improving unbound error messages by suggesting…
SuperFola Dec 4, 2024
da8f49a
feat(name resolution): only allow unprefix names to be fully qualifie…
SuperFola Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ repos:
"--inline-suppr",
"--suppressions-list=cppcheck-suppressions.txt",
"--suppress=unusedStructMember",
"--suppress=checkersReport"
"--suppress=checkersReport",
"--check-level=exhaustive"
]
- repo: https://github.com/compilerla/conventional-pre-commit
rev: 'v3.2.0'
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- new `MAKE_CLOSURE <page addr>` instruction, generated in place of a `LOAD_CONST` when a closure is made
- added `-fdump-ir` to dump the IR entities to a file named `{file}.ark.ir`
- added 11 super instructions and their implementation to the VM
- support for the glob import syntax and symbol import syntax

### Changed
- instructions are on 4 bytes: 1 byte for the instruction, 1 byte of padding, 2 bytes for an immediate argument
Expand Down Expand Up @@ -90,6 +91,7 @@
- the parser can detect ill-formed macros (that are seen as function macros while being value macros)
- adding a `CALL_BUILTIN <builtin> <arg count>` super instruction
- fixed formatting of comments after the last symbol in an import node
- renamed `str:xyz` builtins to `string:xyz` for uniformity with the standard library

### Removed
- removed unused `NodeType::Closure`
Expand Down
4 changes: 2 additions & 2 deletions examples/99bottles.ark
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

(mut n i)
(while (> n 1) {
(print (str:format "{} Bottles of beer on the wall\n{} bottles of beer\nTake one down, pass it around" n n))
(print (string:format "{} Bottles of beer on the wall\n{} bottles of beer\nTake one down, pass it around" n n))
(set n (- n 1))
(print (str:format "{} Bottles of beer on the wall." n)) })
(print (string:format "{} Bottles of beer on the wall." n)) })
6 changes: 3 additions & 3 deletions examples/blockchain.ark
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
(let new (json:fromString request))
(set nodes_transactions (append nodes_transactions new))
(print "New transaction")
(print (str:format "FROM: {}" (json:get new "from")))
(print (str:format "TO: {}" (json:get new "to")))
(print (str:format "AMOUNT: {}" (json:get new "amount")))
(print (string:format "FROM: {}" (json:get new "from")))
(print (string:format "TO: {}" (json:get new "to")))
(print (string:format "AMOUNT: {}" (json:get new "amount")))

# return value
[200 "transaction submission successful" "text/plain"] }))
Expand Down
2 changes: 1 addition & 1 deletion examples/sum_digits.ark
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(import std.String)

(let to-base (fun (n base) {
(let o (str:ord n))
(let o (string:ord n))

(let v
(if (and (>= o 48) (<= o 57))
Expand Down
10 changes: 5 additions & 5 deletions include/Ark/Builtins/Builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ namespace Ark::internal::Builtins

namespace String
{
Value format(std::vector<Value>& n, VM* vm); // str:format, multiple arguments
Value findSubStr(std::vector<Value>& n, VM* vm); // str:find, 2 arguments
Value removeAtStr(std::vector<Value>& n, VM* vm); // str:removeAt, 2 arguments
Value ord(std::vector<Value>& n, VM* vm); // str:ord, 1 arguments
Value chr(std::vector<Value>& n, VM* vm); // str:chr, 1 arguments
Value format(std::vector<Value>& n, VM* vm); // string:format, multiple arguments
Value findSubStr(std::vector<Value>& n, VM* vm); // string:find, 2 arguments
Value removeAtStr(std::vector<Value>& n, VM* vm); // string:removeAt, 2 arguments
Value ord(std::vector<Value>& n, VM* vm); // string:ord, 1 arguments
Value chr(std::vector<Value>& n, VM* vm); // string:chr, 1 arguments
}

namespace Mathematics
Expand Down
24 changes: 9 additions & 15 deletions include/Ark/Compiler/AST/Import.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef COMPILER_AST_IMPORT_HPP
#define COMPILER_AST_IMPORT_HPP
#ifndef ARK_COMPILER_AST_IMPORT_HPP
#define ARK_COMPILER_AST_IMPORT_HPP

#include <vector>
#include <string>
Expand Down Expand Up @@ -31,13 +31,18 @@ namespace Ark::internal
std::vector<std::string> package;

/**
* @brief Import with prefix (the package) or not
* @brief Import with prefix (import package)
*
*/
bool with_prefix = true;

/**
* @brief List of symbols to import, can be empty if none provided
* @brief Import as glob (import package:*)
*/
bool is_glob = false;

/**
* @brief List of symbols to import, can be empty if none provided. (import package :a :b)
*
*/
std::vector<std::string> symbols;
Expand Down Expand Up @@ -68,17 +73,6 @@ namespace Ark::internal
});
}

/**
* @brief Check if we should import everything, given something like `(import foo.bar.egg:*)`
*
* @return true if all symbols of the file should be imported in the importer scope
* @return false otherwise
*/
[[nodiscard]] bool isGlob() const
{
return !with_prefix && symbols.empty();
}

/**
* @brief Check if we should import everything with a prefix, given a `(import foo.bar.egg)`
*
Expand Down
33 changes: 33 additions & 0 deletions include/Ark/Compiler/AST/Namespace.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef ARK_COMPILER_AST_NAMESPACE_HPP
#define ARK_COMPILER_AST_NAMESPACE_HPP

#include <string>
#include <vector>
#include <memory>

namespace Ark::internal
{
class Node;

struct Namespace
{
std::string name;
bool is_glob; // (import package:*)
bool with_prefix; // (import package)
std::vector<std::string> symbols; // (import package :a :b)
std::shared_ptr<Node> ast;
};

inline bool operator==(const Namespace& A, const Namespace& B)
{
return A.name == B.name && A.is_glob == B.is_glob &&
A.with_prefix == B.with_prefix;
}

inline bool operator<([[maybe_unused]] const Namespace&, [[maybe_unused]] const Namespace&)
{
return true;
}
}

#endif // ARK_COMPILER_AST_NAMESPACE_HPP
25 changes: 24 additions & 1 deletion include/Ark/Compiler/AST/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string>
#include <vector>

#include <Ark/Compiler/AST/Namespace.hpp>
#include <Ark/Compiler/Common.hpp>
#include <Ark/Platform.hpp>

Expand All @@ -29,7 +30,7 @@ namespace Ark::internal
class ARK_API Node
{
public:
using Value = std::variant<double, std::string, Keyword, std::vector<Node>>;
using Value = std::variant<double, std::string, Keyword, std::vector<Node>, Namespace>;

Node() = default;

Expand All @@ -39,6 +40,7 @@ namespace Ark::internal
explicit Node(double value);
explicit Node(long value);
explicit Node(Keyword value);
explicit Node(Namespace namespace_);

/**
* @brief Return the string held by the value (if the node type allows it)
Expand All @@ -61,6 +63,20 @@ namespace Ark::internal
*/
[[nodiscard]] Keyword keyword() const noexcept;

/**
* @brief Return the namespace held by the value (if the node type allows it)
*
* @return Namespace&
*/
[[nodiscard]] Namespace& arkNamespace() noexcept;

/**
* @brief Return the namespace held by the value (if the node type allows it)
*
* @return const Namespace&
*/
[[nodiscard]] const Namespace& constArkNamespace() const noexcept;

/**
* @brief Every node has a list as well as a value so we can push_back on all node no matter their type
*
Expand Down Expand Up @@ -96,6 +112,13 @@ namespace Ark::internal
*/
[[nodiscard]] bool isListLike() const noexcept;

/**
* @brief Check if the node is a string like node
* @return true if the node is either a symbol, a string or a spread
* @return false
*/
[[nodiscard]] bool isStringLike() const noexcept;

/**
* @brief Copy a node to the current one, while keeping the filename and position in the file
*
Expand Down
6 changes: 4 additions & 2 deletions include/Ark/Compiler/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Common.hpp
* @author Alexandre Plateau (lexplt.dev@gmail.com)
* @brief Common code for the compiler
* @version 0.4
* @version 0.5
* @date 2021-10-02
*
* @copyright Copyright (c) 2021-2024
Expand Down Expand Up @@ -36,11 +36,12 @@ namespace Ark::internal
Spread,
Field,
Macro,
Namespace,
Unused
};

/// Node types as string, in the same order as the enum NodeType
constexpr std::array<std::string_view, 10> nodeTypes = {
constexpr std::array<std::string_view, 11> nodeTypes = {
"Symbol",
"Capture",
"Keyword",
Expand All @@ -50,6 +51,7 @@ namespace Ark::internal
"Spread",
"Field",
"Macro",
"Namespace",
"Unused"
};

Expand Down
3 changes: 2 additions & 1 deletion include/Ark/Compiler/Macros/Processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ namespace Ark::internal
*
* @param node node on which to operate
* @param depth
* @param is_processing_namespace
*/
void processNode(Node& node, unsigned depth);
void processNode(Node& node, unsigned depth, bool is_processing_namespace = false);

/**
* @brief Apply a macro on a given node
Expand Down
Loading
Loading