changes for new grammar, fixes

This commit is contained in:
ProgramSnail 2023-06-03 19:01:03 +03:00
parent 91f9affadc
commit 3106a64949
35 changed files with 605 additions and 550 deletions

View file

@ -1,19 +1,19 @@
basic (Float : #Ord #Div #Str)
basic (Int : #Ord #IDiv #Str)
basic (String : #Ord #Str #CharContainer #Copy)
basic (Char : #Ord #Str #Copy)
basic (Bool : #Ord #Str #Copy)
basic (Unit : #Str #Copy)
basic \float[#ord #div #str]
basic \int[#ord #idiv #str]
basic \string[#ord #str #char-container #copy]
basic \char[#ord #str #copy]
basic \bool[#ord #str #copy]
basic \unit[#str #copy]
//
decl not : Bool -> Bool
decl not : \bool -> \bool
def not : x =
(match x with
| true -> false
| false -> true)
decl ( && ) : Bool -> Bool -> Bool
decl ( && ) : \bool -> \bool -> \bool
def ( && ) : x y =
match x with
| true -> (
@ -23,7 +23,7 @@ def ( && ) : x y =
)
| false -> false
decl ( || ) : Bool -> Bool -> Bool
decl ( || ) : \bool -> \bool -> \bool
def ( || ) : x y =
match x with
| true -> true
@ -35,28 +35,28 @@ def ( || ) : x y =
//
typeclass CharContainer =
& var size : -> Int
& var at : Int -> Char
typeclass \char-container =
& var size : -> \int
& var at : \int -> \char
//
typeclass Move = // TODO
& var ( <- ) : Move -> Unit
typeclass \move = // TODO
& var ( <- ) : \move -> \unit
typeclass Copy =
& var ( = ) : Copy -> Unit
typeclass \copy =
& var ( = ) : \copy -> \unit
//
typeclass (Sum : #Copy) =
& var ( += ) : Sum -> Unit
& var ( -= ) : Sum -> Unit
& var ( + ) : Sum -> Sum
& var ( - ) : Sum -> Sum
& zero : -> Sum
typeclass \sum[#copy] =
& var ( += ) : \sum -> \unit
& var ( -= ) : \sum -> \unit
& var ( + ) : \sum -> \sum
& var ( - ) : \sum -> \sum
& zero : -> \sum
namespace var Sum {
namespace var \sum {
def ( + ) : x = {
var ans = self
; ans += x
@ -70,11 +70,11 @@ namespace var Sum {
}
}
typeclass (Mult : #Sum) =
& var ( *= ) : Mult -> Unit
& var ( * ) : Mult -> Mult
typeclass \mult[#sum] =
& var ( *= ) : \mult -> \unit
& var ( * ) : \mult -> \mult
namespace var Mult {
namespace var \mult {
def ( * ) : x = {
var ans = self
; ans *= x
@ -82,19 +82,19 @@ namespace var Mult {
}
}
typeclass (IDiv : #Mult) =
& var div : IDiv -> IDiv
& var mod : IDiv -> IDiv
typeclass \idiv[#mult] =
& var div : \idiv -> \idiv
& var mod : \idiv -> \idiv
namespace var IDiv {
def mod : x = self -. x * self.div: x
namespace var \idiv {
def mod : x = self -. x * self..div: x
}
typeclass (Div : #Mult) =
& var ( /= ) : Div -> Unit
& var ( / ) : Div -> Div
typeclass \div[#mult] =
& var ( /= ) : \div -> \unit
& var ( / ) : \div -> \div
namespace var Div {
namespace var \div {
def ( / ) : x = {
var ans = self
; ans /= x
@ -104,39 +104,39 @@ namespace var Div {
//
typeclass Eq =
& var ( == ) : Eq -> Bool
& var ( != ) : Eq -> Bool
typeclass \eq =
& var ( == ) : \eq -> \bool
& var ( != ) : \eq -> \bool
namespace var Eq {
namespace var \eq {
def ( != ) : x = not: (self == x)
}
//
struct Order =
| EQ
| LT
| GT
struct \order =
| $eq
| $lt
| $gt
typeclass (Ord : #Eq) =
& var compare : Ord -> Order
& var ( < ) : Ord -> Bool
& var ( >= ) : Ord -> Bool
& var ( > ) : Ord -> Bool
& var ( <= ) : Ord -> Bool
typeclass \ord[#eq] =
& var compare : \ord -> \order
& var ( < ) : \ord -> \bool
& var ( >= ) : \ord -> \bool
& var ( > ) : \ord -> \bool
& var ( <= ) : \ord -> \bool
decl min ('A : #Ord) : 'A -> 'A -> 'A
decl min 'a[#ord] : 'a -> 'a -> 'a
def min : x y = if x < y then x else y
decl max ('A : #Ord) : 'A -> 'A -> 'A
decl max 'a[#ord] : 'a -> 'a -> 'a
def max : x y = if x < y then y else x
namespace var Ord {
namespace var \ord {
def compare : x =
if self == x then $EQ
elif self < x then $LT
else $GT
if self == x then $eq
elif self < x then $lt
else $gt
def ( >= ) : x = not: (self < x)
def ( > ) : x = x < self
@ -145,44 +145,45 @@ namespace var Ord {
//
typeclass Show =
& var show : -> String
typeclass \show =
& var show : -> \string
typeclass Read =
& read : String -> Read
typeclass \read =
& read : \string -> \read
typeclass (Str : #Show #Read)
typeclass \str[#show #read]
// typeclass DebugShow = // TODO
// & debug_show : -> String
// typeclass debug-show = // TODO
// & debugdshow : -> \string
//
typeclass Default =
& default : -> Default
typeclass \default =
& default : -> \default
//
typeclass Bounded =
& min_bound : -> Bounded
& max_bound : -> Bounded
& var is_max_bound : -> Bool
& var is_min_bound : -> Bool
typeclass \bounded =
& min-bound : -> \bounded
& max-bound : -> \bounded
& var is-max-bound : -> \bool
& var is-min-bound : -> \bool
//
typeclass Enum =
& var succ : -> (Optional Enum)
& var pred : -> (Optional Enum)
& to_enum : Int -> Enum
& var from_enum : -> Int
typeclass \enum =
& var succ : -> \optional[enum]
& var pred : -> \optional[enum]
& to-enum : \int -> \enum
& var from-enum : -> \int
//
namespace IO {
decl print : String -> Unit
decl scan : -> String
decl random : -> Int // TODO
namespace io {
decl print : \string -> \unit
decl scan : -> \string
}
decl random : -> \int // TODO
//