mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
type_check_visitor fixes, array access and function call syntax change
This commit is contained in:
parent
f7080ba856
commit
c1dec6a0d1
16 changed files with 426 additions and 311 deletions
|
|
@ -5,24 +5,24 @@ decl fib : Int -> Int
|
|||
def fib : n =
|
||||
match n with
|
||||
| 0 | 1 -> 1
|
||||
| n ? n > 1 -> fib (n - 1) + fib n
|
||||
| _ -> error "n must be positive"
|
||||
| n ? n > 1 -> fib: (n - 1) + fib: n
|
||||
| _ -> error: "n must be positive"
|
||||
|
||||
decl fact : Int -> Int
|
||||
def fact : n =
|
||||
match n with
|
||||
| 0 -> 1
|
||||
| n ? n > 0 -> n * fact (n - 1)
|
||||
| _ -> error "n must be positive"
|
||||
| n ? n > 0 -> n * fact: (n - 1)
|
||||
| _ -> error: "n must be positive"
|
||||
|
||||
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> (Array 'H)
|
||||
def find_prefix_hashes : str = {
|
||||
var hashes = (Array 'H).new (str.size () + 1)
|
||||
var hashes = (Array 'H).new: (str.size: + 1)
|
||||
|
||||
; hashes:0 = 'H.of str:0
|
||||
for i in 1..hashes.size () do {
|
||||
; hashes:i = hashes:(i - 1)
|
||||
; hashes:i.append str:i
|
||||
; hashes`0 = 'H.of: str`0
|
||||
for i in 1..hashes.size: do {
|
||||
; hashes`i = hashes`(i - 1)
|
||||
; hashes`i.append: str`i
|
||||
}
|
||||
|
||||
return hashes
|
||||
|
|
@ -32,16 +32,16 @@ alias Hash = (AccHash Char)
|
|||
|
||||
decl find_substring : String -> String -> (Array Index)
|
||||
def find_substring : str substr = {
|
||||
var result = (Array Index).empty ()
|
||||
var result = (Array Index).empty:
|
||||
|
||||
const str_hashes = find_prefix_hashes Hash str
|
||||
const substr_hash = Hash.of substr
|
||||
const str_hashes = find_prefix_hashes Hash: str
|
||||
const substr_hash = Hash.of: substr
|
||||
|
||||
for i in 0..(str_hashes.size () - substr.size ()) do {
|
||||
const part_hash = Hash.diff str_hashes(i + substr->size ()) str_hashes:i
|
||||
for i in 0..(str_hashes.size: - substr.size:) do {
|
||||
const part_hash = Hash.diff: str_hashes`(i + substr->size:) str_hashes`i
|
||||
|
||||
if part_hash == substr_hash then {
|
||||
; result.push i
|
||||
; result.push: i
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,10 +53,10 @@ def is_empty = 0
|
|||
|
||||
decl do_something : Unit -> Unit
|
||||
def do_something =
|
||||
IO.print "Hello World!"
|
||||
IO.print: "Hello World!"
|
||||
|
||||
decl mul : Int -> Int -> Int
|
||||
def mul : x y = x * y
|
||||
|
||||
decl mul_10 : Int -> Int
|
||||
def mul_10 = mul 10
|
||||
def mul_10 = mul: 10
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue