mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
fixes, optional type name added
This commit is contained in:
parent
d38d75c9d8
commit
0850e6aa6b
14 changed files with 163 additions and 99 deletions
|
|
@ -17,7 +17,7 @@ struct (Complex : #Value) =
|
|||
|
||||
struct Task =
|
||||
& name : String
|
||||
& duration : Float
|
||||
& duration : Float!
|
||||
|
||||
class Employee =
|
||||
& name : String
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue