Compare commits
3
Commits
c6ea42bc5d
...
9271b9fe01
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9271b9fe01 | ||
|
|
6c12b199e8 | ||
|
|
17fddc1cf4 |
@@ -79,6 +79,7 @@ Function::Function(Lambda lambda)
|
|||||||
|
|
||||||
void Formatter<blaze::ASTNode*>::format(Builder& builder, blaze::ASTNode* value) const
|
void Formatter<blaze::ASTNode*>::format(Builder& builder, blaze::ASTNode* value) const
|
||||||
{
|
{
|
||||||
|
// TODO: Call into Printer::dumpImp(), instead of doing it manually
|
||||||
if (is<blaze::String>(value)) {
|
if (is<blaze::String>(value)) {
|
||||||
return Formatter<std::string>::format(builder, static_cast<blaze::String*>(value)->data());
|
return Formatter<std::string>::format(builder, static_cast<blaze::String*>(value)->data());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ class GlobalEnvironment final : public Environment {
|
|||||||
public:
|
public:
|
||||||
GlobalEnvironment()
|
GlobalEnvironment()
|
||||||
{
|
{
|
||||||
|
// TODO: Add more native functions
|
||||||
|
// TODO: Move the functions to their own file
|
||||||
auto add = [](std::span<ASTNode*> nodes) -> ASTNode* {
|
auto add = [](std::span<ASTNode*> nodes) -> ASTNode* {
|
||||||
int64_t result = 0;
|
int64_t result = 0;
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -42,7 +42,7 @@ ASTNode* Eval::evalAst(ASTNode* ast, Environment* env)
|
|||||||
if (is<Symbol>(ast)) {
|
if (is<Symbol>(ast)) {
|
||||||
auto result = env->lookup(static_cast<Symbol*>(ast)->symbol());
|
auto result = env->lookup(static_cast<Symbol*>(ast)->symbol());
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Error::the().addError(format("'{}' not found", ast));
|
Error::the().addError(format("symbol’s function definition is void: {}", ast));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -79,6 +79,7 @@ ASTNode* Eval::apply(List* evaluated_list)
|
|||||||
auto nodes = evaluated_list->nodes();
|
auto nodes = evaluated_list->nodes();
|
||||||
|
|
||||||
if (!is<Function>(nodes[0])) {
|
if (!is<Function>(nodes[0])) {
|
||||||
|
Error::the().addError(format("invalid function: {}", nodes[0]));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-12
@@ -4,10 +4,12 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lexer.h"
|
#include <iterator> // std::next
|
||||||
|
|
||||||
#include "ruc/format/print.h"
|
#include "ruc/format/print.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "lexer.h"
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
@@ -53,9 +55,9 @@ void Printer::dumpImpl(ASTNode* node)
|
|||||||
print("(");
|
print("(");
|
||||||
m_firstNode = false;
|
m_firstNode = false;
|
||||||
m_previousNodeIsList = true;
|
m_previousNodeIsList = true;
|
||||||
List* list = static_cast<List*>(node);
|
auto nodes = static_cast<List*>(node)->nodes();
|
||||||
for (size_t i = 0; i < list->nodes().size(); ++i) {
|
for (size_t i = 0; i < nodes.size(); ++i) {
|
||||||
dumpImpl(list->nodes()[i]);
|
dumpImpl(nodes[i]);
|
||||||
m_previousNodeIsList = false;
|
m_previousNodeIsList = false;
|
||||||
}
|
}
|
||||||
print(")");
|
print(")");
|
||||||
@@ -65,9 +67,9 @@ void Printer::dumpImpl(ASTNode* node)
|
|||||||
print("[");
|
print("[");
|
||||||
m_firstNode = false;
|
m_firstNode = false;
|
||||||
m_previousNodeIsList = true;
|
m_previousNodeIsList = true;
|
||||||
Vector* vector = static_cast<Vector*>(node);
|
auto nodes = static_cast<Vector*>(node)->nodes();
|
||||||
for (size_t i = 0; i < vector->nodes().size(); ++i) {
|
for (size_t i = 0; i < nodes.size(); ++i) {
|
||||||
dumpImpl(vector->nodes()[i]);
|
dumpImpl(nodes[i]);
|
||||||
m_previousNodeIsList = false;
|
m_previousNodeIsList = false;
|
||||||
}
|
}
|
||||||
print("]");
|
print("]");
|
||||||
@@ -77,15 +79,20 @@ void Printer::dumpImpl(ASTNode* node)
|
|||||||
print("{{");
|
print("{{");
|
||||||
m_firstNode = false;
|
m_firstNode = false;
|
||||||
m_previousNodeIsList = true;
|
m_previousNodeIsList = true;
|
||||||
HashMap* hash_map = static_cast<HashMap*>(node);
|
auto elements = static_cast<HashMap*>(node)->elements();
|
||||||
for (auto element : hash_map->elements()) {
|
for (auto it = elements.begin(); it != elements.end(); ++it) {
|
||||||
print("{} ", element.first.front() == 0x7f ? ":" + element.first.substr(1) : element.first); // 127
|
print("{} ", it->first.front() == 0x7f ? ":" + it->first.substr(1) : it->first); // 127
|
||||||
dumpImpl(element.second);
|
dumpImpl(it->second);
|
||||||
m_previousNodeIsList = false;
|
|
||||||
|
if (it != elements.end() && std::next(it) != elements.end()) {
|
||||||
|
print(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
m_previousNodeIsList = false;
|
||||||
print("}}");
|
print("}}");
|
||||||
}
|
}
|
||||||
else if (is<String>(node)) {
|
else if (is<String>(node)) {
|
||||||
|
// TODO: Implement string readably printing
|
||||||
printSpacing();
|
printSpacing();
|
||||||
print("{}", static_cast<String*>(node)->data());
|
print("{}", static_cast<String*>(node)->data());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ void Reader::read()
|
|||||||
|
|
||||||
m_node = readImpl();
|
m_node = readImpl();
|
||||||
|
|
||||||
|
// TODO: Move these to the appropriate functions
|
||||||
// Error checking
|
// Error checking
|
||||||
|
|
||||||
if (m_invalid_syntax) {
|
if (m_invalid_syntax) {
|
||||||
|
|||||||
Reference in New Issue
Block a user