fixes, optional type name added

This commit is contained in:
ProgramSnail 2023-05-23 00:51:51 +03:00
parent d38d75c9d8
commit 0850e6aa6b
14 changed files with 163 additions and 99 deletions

View file

@ -149,7 +149,7 @@ typeclass Show =
& var show : -> String
typeclass Read =
& var read : String -> Read
& read : String -> Read
typeclass (Str : #Show #Read)
@ -179,9 +179,11 @@ typeclass Enum =
//
decl print : String -> Unit
decl scan : -> String
decl random : -> Int // TODO
namespace IO {
decl print : String -> Unit
decl scan : -> String
decl random : -> Int // TODO
}
//
@ -211,19 +213,46 @@ def ( -- ) : begin end = {
})
}
decl func : String -> Int -> Int
def func : s i = {
; print: s
var x = s
; print: (i.show:)
return 5
}
// decl func : String -> Int -> Int
// def func : s i = {
// ; print: s
// var x = s
// ; print: (i.show:)
// return 5
// }
//
// exec main {
// for i in 0--19 do func: "a" (i * 2 +. 3)
// ; print: ({
// if true then bring scan: else { ; print: "aaa" }
// bring "nothing"
// ; print: "aaa"
// })
// }
decl scan_int : -> Int
def scan_int = Int.read: (IO.scan:)
decl print_int : Int -> Unit
def print_int : x = IO.print: (x.show:)
decl scan_anything ('A : #Read) : -> 'A
def scan_anything = 'A.read: (IO.scan:)
decl print_anything ('A : #Show) : 'A -> Unit
def print_anything : x = IO.print: (x.show:)
/*
struct Array 'A = & data : 'A_0
namespace Array {
decl construct : 'A_0 -> Array
def construct: x = $(Array 'A) & data = x
} // TODO: construct decl + default def -> segfault
*/
exec main {
for i in 0--19 do func: "a" (i * 2 +. 3)
; print: ({
if true then bring scan: else { ; print: "aaa" }
bring "nothing"
; print: "aaa"
})
var n = scan_anything Int:
var a = for _ in 0--n do scan_int:
; print_anything Int: n
}