build_visitor fixed, going to test it

This commit is contained in:
ProgramSnail 2023-04-25 21:21:36 +03:00
parent 5bf0c1bf48
commit c34523bd4f
23 changed files with 45468 additions and 45273 deletions

View file

@ -1,21 +1,21 @@
decl test_arrays : Unit -> Unit
def test_arrays = {
var arr1 = [1; 2; 3]
const arr2 = []
var arr3 = []
var arr1 = ,1 ,2 ,3
const arr2 = Int._array 32
var arr3 = String._array 11
const arr4 = 'a'..'z'
const n = 100
var @arr5 = @$Int_n
var @arr5 <- Int.@_new_array 10
var @arr6 = @$Int_n
var @arr6_pointer = @arr6
var @arr6 <- String.@_new_array 10
var ~arr6_reference = ~arr6
const elem1 = arr1.1
var elem2 = arr1.1
const ~ref1 = ~arr1.1
var ~ref2 = ~arr1.1
; ~arr1.1 = 123
const elem1 = arr1:0
var elem2 = arr1:2
const ~ref1 = ~arr1:1
var ~ref2 = ~arr1:3
; arr1:1 = 123
; ref1 = arr1.2 // set value
; ref1 = arr1:2 // set value
; ~ref1 = ~ref2 // set reference
}

View file

@ -40,7 +40,7 @@ class Employee =
& salary : Int
| Programmer
& skills : Float
& current_task : Optional Task
& current_task : (Optional Task)
& salary : Int)
@ -56,5 +56,4 @@ class Bag =
& weight_g : Int
& weight_g : Int
| Big)
& other_things : Array Something
& other_things : (Array Something)

View file

@ -6,11 +6,11 @@ namespace Employee {
& name = "John"
& role =
($Manager
& name = "John"
& "John"
& productivity =
($Productivity.High
($Productivity::High
& duration = 10.3
& sleep_on_work = ($Productivity.SleepOnWork.No))
& sleep_on_work = ($Productivity::SleepOnWork::No))
& salary = 123)
}

View file

@ -8,9 +8,9 @@ def flow_control_test = {
return {}
}
while (a > 0) && (!array.is_empty) do {
while (a > 0) && (!array.is_empty ()) do {
; --a
; array.pop
; array->pop
}
while x < 10 do

View file

@ -5,39 +5,40 @@ decl fib : Int -> Int
def fib : n =
match n with
| 0 | 1 -> 1
| _ -> fib (n - 1) + fib n
| 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 * fact (n - 1)
| n ? n > 0 -> n * fact (n - 1)
| _ -> error "n must be positive"
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> Array 'H
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> (Array 'H)
def find_prefix_hashes 'H : 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).clone
; 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
}
alias Hash = AccHash Char
alias Hash = (AccHash Char)
decl find_substring : String -> String -> Array Index
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
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
@ -48,8 +49,7 @@ def find_substring : str substr = {
}
decl is_empty : Unit -> Bool
def is_empty =
return 0
def is_empty = 0
decl do_something : Unit -> Unit
def do_something =

View file

@ -1,7 +1,7 @@
decl test_lambdas : Unit -> Unit
def test_lambdas = {
const lambda1 = \x -> x * x
const lambda2 = \x -> x.hash
const lambda2 = \x -> x.hash ()
const lambda3 = \x y -> x + y
const lambda4 = \x -> {

View file

@ -1,15 +1,15 @@
def fruit_cost : fruit = {
return (match fruit with
| $Banana -> 11
| $Apple | $Orange -> 7)
return (match fruit with
| $Banana -> 11
| $Apple | $Orange -> 7)
}
def amount_to_string : x is_zero_separated = {
const ans = match x with
| 0 ? is_zero_separated -> "Zero"
| 0 | 1 | 2 | 3 | 4 -> "Few"
| x ? (5..9).contains x -> "Several"
| x ? (10..19).contains x -> "Pack"
| _ -> "Lots"
const ans = match x with
| 0 ? is_zero_separated () -> "Zero"
| 0 | 1 | 2 | 3 | 4 -> "Few"
| x ? (5..9).contains x -> "Several"
| x ? (10..19).contains x -> "Pack"
| _ -> "Lots"
return ans
}

View file

@ -3,6 +3,6 @@ struct StructWithRef =
decl test_memory : Unit -> Unit
def test_memory = {
const @unique_ref1 <- @(5)
var @unique_ref2 <- @(Array.of 1 2 3)
const @unique_ref1 <- Int.@_new 5
var @unique_ref2 <- Array.@of 1 2 3
}

View file

@ -6,18 +6,6 @@ partition INTERFACE { // or .interface.lang filename
decl something : Unit -> Unit
}
partition CORE { // or .core.lang filename
decl something : Unit -> Unit
}
partition LIB { // or .lib.lang filename
decl something : Unit -> Unit
}
partition MODULE { // or .module.lang filename
decl something : Unit -> Unit
}
partition EXE { // or .exe.lang filename
partition CODE { // or .core.lang filename
decl something : Unit -> Unit
}

View file

@ -3,8 +3,5 @@ def test_tuples = {
var tuple1 = & "a" & 2 & "hello"
const & t1 & t2 & t3 = f x
; tuple1.0 = "b"
; tuple1:0 = "b"
}

View file

@ -3,6 +3,6 @@ alias T1 = Int
abstract (T2 : #A #B #C)
// Used to pre-compile module for some types
let T2 = Int
let T2 = Float
let T2 = Complex
// let T2 = Int
// let T2 = Float
// let T2 = Complex

View file

@ -3,16 +3,13 @@ def test_variants = {
var variant1 = | 'a' | 2 | "hello"
var | val | err = f x
; val -> "something" // open variant as value in expr
; val -?> "something" // open variant as value in expr
; val -!> "nothing" // open variant as None in expr
match variant1 with
| 'a' -> "something"
| 2 -> "something"
| "hello" -> "something"
| a -> "Something"
| String.of str -> "something"
| Int.of i -> "someting"
| 2 -> "nothing"
| "hello" -> "nothing"
| 11 -> "nothing"
}