mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
bool literals, fixes
This commit is contained in:
parent
b1aff1935d
commit
d31979166e
24 changed files with 179 additions and 46 deletions
|
|
@ -139,6 +139,7 @@ private:
|
|||
void Visit(StringLiteral* node) override;
|
||||
void Visit(CharLiteral* node) override;
|
||||
void Visit(UnitLiteral* node) override;
|
||||
void Visit(BoolLiteral* node) override;
|
||||
|
||||
void Visit(Literal& node) override; // variant
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ inline void PrintPosition(std::ostream& out,
|
|||
std::pair<size_t, size_t> start_position,
|
||||
std::pair<size_t, size_t> end_position) {
|
||||
out << '['
|
||||
<< start_position.first
|
||||
<< start_position.first + 1
|
||||
<< ", "
|
||||
<< start_position.second
|
||||
<< start_position.second + 1
|
||||
<< "] - ["
|
||||
<< end_position.first
|
||||
<< end_position.first + 1
|
||||
<< ", "
|
||||
<< end_position.second
|
||||
<< end_position.second + 1
|
||||
<< ']';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@
|
|||
// for clangd
|
||||
#include "contexts.hpp"
|
||||
#include "global_info.hpp"
|
||||
#include "interpreter_tree.hpp"
|
||||
#include "type_info_contexts.hpp"
|
||||
#include "visitor.hpp"
|
||||
#include "error_handling.hpp"
|
||||
|
||||
namespace interpreter {
|
||||
|
||||
|
|
@ -14,11 +16,20 @@ class ExecuteVisitor : public Visitor {
|
|||
public:
|
||||
explicit ExecuteVisitor(info::GlobalInfo& global_info,
|
||||
info::TypeInfoContextManager& type_info_context_manager,
|
||||
info::ContextManager& context_manager)
|
||||
info::ContextManager& context_manager,
|
||||
interpreter::tokens::PartitionStatement* execution_root)
|
||||
: namespace_visitor_(global_info.CreateVisitor()),
|
||||
type_info_context_manager_(type_info_context_manager),
|
||||
context_manager_(context_manager) {}
|
||||
|
||||
void VisitSourceFile(SourceFile* source_file) override {
|
||||
error_handling::HandleInternalError("VisitSourceFile unavailible", "ExecuteVisitor.VisitSourceFile");
|
||||
};
|
||||
|
||||
void ExecutePartition(interpreter::tokens::PartitionStatement* partition) {
|
||||
Visit(partition);
|
||||
}
|
||||
|
||||
private:
|
||||
// Sources -----------------
|
||||
|
||||
|
|
@ -39,8 +50,7 @@ private:
|
|||
void Visit(TypeDefinitionStatement* node) override;
|
||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
void Visit(TypeclassDefinitionStatement* node) override;
|
||||
void Visit(ExecutableStatement* node) override;
|
||||
void Visit(TestStatement* node) override;
|
||||
void Visit(PartitionStatement* node) override;
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -125,6 +135,7 @@ private:
|
|||
void Visit(StringLiteral* node) override;
|
||||
void Visit(CharLiteral* node) override;
|
||||
void Visit(UnitLiteral* node) override;
|
||||
void Visit(BoolLiteral* node) override;
|
||||
|
||||
private:
|
||||
info::GlobalInfo::NamespaceVisitor namespace_visitor_;
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ private:
|
|||
// // void Visit(StringLiteral* node) override;
|
||||
// // void Visit(CharLiteral* node) override;
|
||||
// // void Visit(UnitLiteral* node) override;
|
||||
// // void Visit(BoolLiteral* node) override;
|
||||
|
||||
private:
|
||||
info::GlobalInfo::NamespaceVisitor namespace_visitor_;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ public:
|
|||
void AddImport(definition::Import&& import_info, const std::optional<std::string>& name = std::nullopt);
|
||||
|
||||
void AddEnterNamespace(const std::string& name,
|
||||
std::optional<utils::IsConstModifier> modifier = std::nullopt);
|
||||
std::optional<utils::IsConstModifier> modifier,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
void EnterNamespace(const std::string& name);
|
||||
|
||||
|
|
|
|||
|
|
@ -108,13 +108,15 @@ struct NumberLiteral;
|
|||
struct StringLiteral;
|
||||
struct CharLiteral;
|
||||
struct UnitLiteral;
|
||||
struct BoolLiteral;
|
||||
|
||||
using Literal = std::variant<
|
||||
std::unique_ptr<FloatNumberLiteral>,
|
||||
std::unique_ptr<NumberLiteral>,
|
||||
std::unique_ptr<StringLiteral>,
|
||||
std::unique_ptr<CharLiteral>,
|
||||
std::unique_ptr<UnitLiteral>>;
|
||||
std::unique_ptr<UnitLiteral>,
|
||||
std::unique_ptr<BoolLiteral>>;
|
||||
|
||||
//
|
||||
struct NameExpression;
|
||||
|
|
@ -703,4 +705,10 @@ struct UnitLiteral {
|
|||
BaseNode base;
|
||||
};
|
||||
|
||||
struct BoolLiteral {
|
||||
BaseNode base;
|
||||
|
||||
bool value;
|
||||
};
|
||||
|
||||
} // namespace interpereter::tokens
|
||||
|
|
|
|||
|
|
@ -110,13 +110,14 @@ private:
|
|||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
// // void Visit(ExtendedName* node) override;
|
||||
// //
|
||||
|
||||
// // void Visit(std::string* node) override; // std::string
|
||||
// //
|
||||
|
||||
// // void Visit(FloatNumberLiteral* node) override;
|
||||
// // void Visit(NumberLiteral* node) override;
|
||||
// // void Visit(StringLiteral* node) override;
|
||||
// // void Visit(CharLiteral* node) override;
|
||||
// // void Visit(BoolLiteral* node) override;
|
||||
|
||||
private:
|
||||
info::GlobalInfo::NamespaceVisitor namespace_visitor_;
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ const std::string NumberLiteral = "number_literal";
|
|||
const std::string StringLiteral = "string_literal";
|
||||
const std::string CharLiteral = "char_literal";
|
||||
const std::string UnitLiteral = "unit_literal";
|
||||
const std::string BoolLiteral = "bool_literal";
|
||||
|
||||
const std::string Literal = "literal";
|
||||
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ private:
|
|||
void Visit(StringLiteral* node) override;
|
||||
void Visit(CharLiteral* node) override;
|
||||
void Visit(UnitLiteral* node) override;
|
||||
void Visit(BoolLiteral* node) override;
|
||||
|
||||
private:
|
||||
std::ostream& out_;
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ private:
|
|||
void Visit(StringLiteral* node) override;
|
||||
void Visit(CharLiteral* node) override;
|
||||
void Visit(UnitLiteral* node) override;
|
||||
void Visit(BoolLiteral* node) override;
|
||||
|
||||
//
|
||||
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ private:
|
|||
void Visit(StringLiteral* node) override;
|
||||
void Visit(CharLiteral* node) override;
|
||||
void Visit(UnitLiteral* node) override;
|
||||
void Visit(BoolLiteral* node) override;
|
||||
|
||||
private:
|
||||
std::ostream& out_;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,37 @@ enum class InternalType {
|
|||
Unit = 5,
|
||||
};
|
||||
|
||||
inline std::optional<InternalType> ToInternalType(const std::string& type) {
|
||||
if (type.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
switch (type[0]) {
|
||||
case 'F':
|
||||
if (type == "Float") { return InternalType::Float; }
|
||||
break;
|
||||
case 'I':
|
||||
if (type == "Int") { return InternalType::Int; }
|
||||
break;
|
||||
case 'S':
|
||||
if (type == "String") { return InternalType::String; }
|
||||
break;
|
||||
case 'C':
|
||||
if (type == "Char") { return InternalType::Char; }
|
||||
break;
|
||||
case 'B':
|
||||
if (type == "Bool") { return InternalType::Bool; }
|
||||
break;
|
||||
case 'U':
|
||||
if (type == "Unit") { return InternalType::Unit; }
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
class TupleType {
|
||||
public:
|
||||
TupleType() = default;
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ protected:
|
|||
virtual void Visit(StringLiteral* node);
|
||||
virtual void Visit(CharLiteral* node);
|
||||
virtual void Visit(UnitLiteral* node);
|
||||
virtual void Visit(BoolLiteral* node);
|
||||
|
||||
virtual void Visit(Literal& node); // variant
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue