From f2192b5331f7d60aca6715a5c78e283b9009dadf Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Sun, 21 May 2023 17:00:59 +0300 Subject: [PATCH] fixes (debugging) --- include/types.hpp | 6 +++ include/utils.hpp | 16 +++---- src/build_visitor.cpp | 2 +- tests/.test_code.lang.kate-swp | Bin 1119 -> 0 bytes tests/stdlib.lang | 0 tests/test_code.lang | 77 ++++++++++++++++++++++++++++++--- 6 files changed, 85 insertions(+), 16 deletions(-) delete mode 100644 tests/.test_code.lang.kate-swp create mode 100644 tests/stdlib.lang 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 c343296ea1a070343445724337fe4bfc9d2c3338..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1119 zcmcJO%SyvQ6ow};ZF;|?5m&;X)}@G5a4Q%=#En6^j#8x%q+mr{^@a2ay7LL#>9dFn z&p$)*55=tmA?KU_N<|mhe4^9mY^Kkq`9vS=?JK3?#rX1g`S$v?+<5==fAY=g z$9I^HMH$JX&gD6TA;;G`F$ykxC`Y)KW0Wf~O4lU42HMxiezpTwYYwdmpIz%Sw89ny zgx-cBC(v@NhN}RY2}BKvOLzC%vaCY&lhoC{IoXpS-V50W&&X@w2{{1Yk}KexTm@(3 z5d284t#BPIjTZGaz^CLU*va1l-%)RaoqQee6ZJ0Gsjml?{)^#(`$V|+h=|rDB3Xxs zTG~XE+9INpCJQl*osdmq&R|Sq4x7fN^f!&&lTBj}WYd^4h`yxvZm35qJODd`iNP}H zVld!!BHUvlq78^h77_n_s6~<3o(A(`x#~phUX6&=42js>DiMoaA!6?XPVdj(KqtQh CU22Q~ 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"