mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-23 23:38:44 +00:00
some fixes for zero argument functions, test_code.lang improvements
This commit is contained in:
parent
79bd30c1ee
commit
3188ba6a54
4 changed files with 104 additions and 3 deletions
|
|
@ -597,7 +597,7 @@ void PrintVisitor::Visit(FunctionType* node) {
|
||||||
out_ << "[FunctionType] (";
|
out_ << "[FunctionType] (";
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
for (auto& type : node->types) {
|
for (auto& type : node->types) {
|
||||||
if (!is_first) {
|
if (!is_first || node->types.size() == 1) {
|
||||||
out_ << " -> ";
|
out_ << " -> ";
|
||||||
}
|
}
|
||||||
is_first = false;
|
is_first = false;
|
||||||
|
|
|
||||||
|
|
@ -849,7 +849,7 @@ void TypedPrintVisitor::Visit(FunctionType* node) {
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
for (auto& type : node->types) {
|
for (auto& type : node->types) {
|
||||||
if (!is_first) {
|
if (!is_first || node->types.size() == 1) {
|
||||||
out_ << " -> ";
|
out_ << " -> ";
|
||||||
}
|
}
|
||||||
is_first = false;
|
is_first = false;
|
||||||
|
|
|
||||||
BIN
tests/.test_code.lang.kate-swp
Normal file
BIN
tests/.test_code.lang.kate-swp
Normal file
Binary file not shown.
|
|
@ -1,5 +1,106 @@
|
||||||
decl print : String -> Unit
|
basic Float
|
||||||
|
basic Int
|
||||||
|
basic String
|
||||||
|
basic Char
|
||||||
|
basic Bool
|
||||||
|
basic Unit
|
||||||
|
|
||||||
|
// bool functions
|
||||||
|
|
||||||
|
decl not : Bool -> Bool
|
||||||
|
def not : x =
|
||||||
|
match x with
|
||||||
|
| true -> false
|
||||||
|
| false -> true
|
||||||
|
|
||||||
|
decl ( && ) : Bool -> Bool -> Bool
|
||||||
|
def ( && ) : x y =
|
||||||
|
match x with
|
||||||
|
| true -> (
|
||||||
|
match y with
|
||||||
|
| true -> true
|
||||||
|
| false -> false
|
||||||
|
)
|
||||||
|
| false -> false
|
||||||
|
|
||||||
|
decl ( || ) : Bool -> Bool -> Bool
|
||||||
|
def ( || ) : x y =
|
||||||
|
match x with
|
||||||
|
| true -> true
|
||||||
|
| false -> (
|
||||||
|
match y with
|
||||||
|
| true -> true
|
||||||
|
| false -> false
|
||||||
|
)
|
||||||
|
|
||||||
|
// Eq typeclass
|
||||||
|
|
||||||
|
typeclass Eq =
|
||||||
|
& ( == ) : Eq -> Bool
|
||||||
|
& ( != ) : Eq -> Bool
|
||||||
|
|
||||||
|
namespace const Eq {
|
||||||
|
def ( != ) : x = not: (self == x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ord typeclass
|
||||||
|
|
||||||
|
struct Order =
|
||||||
|
| EQ
|
||||||
|
| LT
|
||||||
|
| GT
|
||||||
|
|
||||||
|
typeclass (Ord : #Eq) =
|
||||||
|
& compare: Ord -> Order
|
||||||
|
& ( < ) : Ord -> Bool
|
||||||
|
& ( >= ) : Ord -> Bool
|
||||||
|
& ( > ) : Ord -> Bool
|
||||||
|
& ( <= ) : Ord -> Bool
|
||||||
|
& min : Ord -> Ord
|
||||||
|
& max : Ord -> Ord
|
||||||
|
|
||||||
|
namespace var Ord {
|
||||||
|
def compare : x =
|
||||||
|
if self == x then $EQ
|
||||||
|
elif self < x then $LT
|
||||||
|
else $GT
|
||||||
|
|
||||||
|
def ( >= ) : x = not: (self < x)
|
||||||
|
def ( > ) : x = x < self
|
||||||
|
def ( <= ) : x = not: (x < self)
|
||||||
|
def min : x = if self < x then self else x
|
||||||
|
def max : x = if self < x then x else self
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
typeclass Show =
|
||||||
|
& show : -> String
|
||||||
|
|
||||||
|
typeclass Read =
|
||||||
|
& read : String -> Read
|
||||||
|
|
||||||
|
typeclass Debug =
|
||||||
|
& debug : -> String
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
// Enum typeclass
|
||||||
|
|
||||||
|
typeclass Enum =
|
||||||
|
& succ : Enum -> (Optional Enum)
|
||||||
|
& pred : Enum -> (Optional Enum)
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
decl ( -- ) : Int -> Int -> Int_0
|
decl ( -- ) : Int -> Int -> Int_0
|
||||||
|
def ( -- ) : begin end = {
|
||||||
|
var current = begin
|
||||||
|
return (while current < end do {
|
||||||
|
; current += 1
|
||||||
|
return current - 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
decl func : String -> Int
|
decl func : String -> Int
|
||||||
def func : s = {
|
def func : s = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue