diff --git a/include/types.hpp b/include/types.hpp index f6c99f6..3af1975 100644 --- a/include/types.hpp +++ b/include/types.hpp @@ -8,6 +8,7 @@ #include // for clangd +#include "error_handling.hpp" #include "utils.hpp" namespace info::type { @@ -49,6 +50,11 @@ public: } bool HasTypeclass(utils::IdType graph_id) { + error_handling::DebugPrint(name_); + error_handling::DebugPrint(requirement_graph_ids_.size()); + for (auto& requirement_graph_id : requirement_graph_ids_) { + error_handling::DebugPrint(requirement_graph_id); + } return requirement_graph_ids_.count(graph_id) != 0; } diff --git a/include/utils.hpp b/include/utils.hpp index b2c9802..cfa30f4 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -69,21 +69,21 @@ inline bool IsBuiltinFunction(const std::string& name) { // optimize ?? builtin_functions.insert("+="); builtin_functions.insert("-="); builtin_functions.insert("*="); - builtin_functions.insert("//="); - builtin_functions.insert("%="); + builtin_functions.insert("div"); + builtin_functions.insert("mod"); builtin_functions.insert("/="); - builtin_functions.insert("+"); - builtin_functions.insert("-"); - builtin_functions.insert("*"); - builtin_functions.insert("//"); - builtin_functions.insert("%"); - builtin_functions.insert("/"); + // builtin_functions.insert("+"); + // builtin_functions.insert("-"); + // builtin_functions.insert("*"); + // builtin_functions.insert("/"); builtin_functions.insert("&&"); builtin_functions.insert("||"); builtin_functions.insert("size"); builtin_functions.insert("random"); builtin_functions.insert("print"); builtin_functions.insert("scan"); + builtin_functions.insert("zero"); + builtin_functions.insert("one"); return builtin_functions.count(name) != 0; } diff --git a/src/build_visitor.cpp b/src/build_visitor.cpp index 6982618..ca0a941 100644 --- a/src/build_visitor.cpp +++ b/src/build_visitor.cpp @@ -902,7 +902,7 @@ void BuildVisitor::VisitBinaryOperatorExpression(FunctionCallExpression* node) { FunctionCallExpression* argument_node = std::get>(node->arguments[i]).get(); if (argument_node->is_binary_operator_expression && argument_node->precedence.has_value() - && argument_node->precedence.value() >= node->precedence.value()) { + && argument_node->precedence.value() == node->precedence.value()) { error_handling::HandleParsingError("Operators can't be chained (left argument)", node->base.start_position, node->base.end_position); } } diff --git a/tests/.test_code.lang.kate-swp b/tests/.test_code.lang.kate-swp deleted file mode 100644 index c343296..0000000 Binary files a/tests/.test_code.lang.kate-swp and /dev/null differ diff --git a/tests/stdlib.lang b/tests/stdlib.lang new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_code.lang b/tests/test_code.lang index 7f574d3..eac5aea 100644 --- a/tests/test_code.lang +++ b/tests/test_code.lang @@ -1,7 +1,7 @@ -basic (Float : #Ord) -basic (Int : #Ord) +basic (Float : #Ord #Div) +basic (Int : #Ord #IDiv) basic (String : #Ord) -basic (Char : #Ord) +basic (Char : #Ord #Enum) basic (Bool : #Ord) basic Unit @@ -33,7 +33,70 @@ def ( || ) : x y = | false -> false ) -// Eq typeclass +// + +typeclass Move = + & var ( <- ) : Move -> Unit // TODO + +typeclass Copy = + & var ( = ) : Copy -> Unit + +// + +typeclass (Sum : #Copy) = + & var ( += ) : Sum -> Unit + & var ( -= ) : Sum -> Unit + & var ( + ) : Sum -> Sum + & var ( - ) : Sum -> Sum + & zero : -> Sum + +namespace var Sum { + def ( + ) : x = { + var ans = self + ; ans += x + return ans + } + + def ( - ) : x = { + var ans = self + ; ans -= x + return ans + } +} + +typeclass (Mult : #Sum) = + & var ( *= ) : Mult -> Unit + & var ( * ) : Mult -> Mult + +namespace var Mult { + def ( * ) : x = { + var ans = self + ; ans *= x + return ans + } +} + +typeclass (IDiv : #Mult) = + & var div : IDiv -> Unit + & var mod : IDiv -> Unit + +namespace var IDiv { + def mod : x = self -. x * self.div: x +} + +typeclass (Div : #Mult) = + & var ( /= ) : Div -> Unit + & var ( / ) : Div -> Div + +namespace var Div { + def ( / ) : x = { + var ans = self + ; ans /= x + return ans + } +} + +// typeclass Eq = & var ( == ) : Eq -> Bool @@ -82,8 +145,8 @@ typeclass Show = typeclass Read = & var read : String -> Read -typeclass Debug = - & debug : -> String +typeclass DebugShow = + & debug_show : -> String // @@ -141,7 +204,7 @@ def func : s = { } exec main { - for i in (,0 ,1 ,2 ,3) do func: "abacaba" + for i in 0--9 do func: "abacaba" ; print: ({ if true then bring scan: else { ; print: "aaa" } bring "nothing"