mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
fixes (debugging)
This commit is contained in:
parent
e6a03ef9bf
commit
f2192b5331
6 changed files with 85 additions and 16 deletions
|
|
@ -8,6 +8,7 @@
|
|||
#include <unordered_map>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -902,7 +902,7 @@ void BuildVisitor::VisitBinaryOperatorExpression(FunctionCallExpression* node) {
|
|||
FunctionCallExpression* argument_node = std::get<std::unique_ptr<FunctionCallExpression>>(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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
0
tests/stdlib.lang
Normal file
0
tests/stdlib.lang
Normal file
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue