diff --git a/lib/codegen/helpers.ml b/lib/codegen/helpers.ml index b1ac43eb..0ebcfc0a 100644 --- a/lib/codegen/helpers.ml +++ b/lib/codegen/helpers.ml @@ -284,7 +284,7 @@ struct (* Don't print the string 'assert ' *) let start = lbeg.pos_cnum + 7 in match Hashtbl.find_opt src_tbl lbeg.pos_fname with - | Some (Some str) -> String.sub str start (lend.pos_cnum - start) + | Some (Some str) -> String.sub str start (lend.pos_cnum - start - 1) | Some None -> "file not found" | None -> ( (* Try to open file and read into lexbuf *) @@ -293,7 +293,7 @@ struct let str = In_channel.input_all ic in In_channel.close ic; Hashtbl.add src_tbl lbeg.pos_fname (Some str); - String.sub str start (lend.pos_cnum - start) + String.sub str start (lend.pos_cnum - start - 1) with _ -> Hashtbl.replace src_tbl lbeg.pos_fname None; "file not found") diff --git a/test/misc.t/abi.smu b/test/misc.t/abi.smu index da8acddd..c9f99980 100644 --- a/test/misc.t/abi.smu +++ b/test/misc.t/abi.smu @@ -1,35 +1,35 @@ -(type v2 {:z float :y float}) -(type i2 {:x int :y int}) -(type i1 {:x int}) -(type v1 {:z float}) -(type v3 {:x float :y float :z float}) -(type i3 {:w int :y int :z int}) -(type v4 {:x float :y float :z float :w float}) -(type mixed4 {:x float :y float :z float :k int}) -(type trailv2 {:a int :b int :c float :d float}) -(type f2s {:fx f32 :fy f32}) -(type f3s {:fx f32 :fy f32 :fz f32}) +type v2 = {z : float, y : float} +type i2 = {x : int, y : int} +type i1 = {x : int} +type v1 = {z : float} +type v3 = {x : float, y : float, z : float} +type i3 = {w : int, y : int, z : int} +type v4 = {x : float, y : float, z : float, w : float} +type mixed4 = {x : float, y : float, z : float, k : int} +type trailv2 = {a : int, b : int, c : float, d : float} +type f2s = {fx : f32, fy : f32} +type f3s = {fx : f32, fy : f32, fz : f32} -(external subv2 (fun v2 v2)) -(external subi2 (fun i2 i2)) -(external subv1 (fun v1 v1)) -(external subi1 (fun i1 i1)) -(external subv3 (fun v3 v3)) -(external subi3 (fun i3 i3)) -(external subv4 (fun v4 v4)) -(external submixed4 (fun mixed4 mixed4)) -(external subtrailv2 (fun trailv2 trailv2)) -(external subf2s (fun f2s f2s)) -(external subf3s (fun f3s f3s)) +external subv2 : (v2) -> v2 +external subi2 : (i2) -> i2 +external subv1 : (v1) -> v1 +external subi1 : (i1) -> i1 +external subv3 : (v3) -> v3 +external subi3 : (i3) -> i3 +external subv4 : (v4) -> v4 +external submixed4 : (mixed4) -> mixed4 +external subtrailv2 : (trailv2) -> trailv2 +external subf2s : (f2s) -> f2s +external subf3s : (f3s) -> f3s -(ignore (subv2 {:z 1.0 :y 10.0})) -(ignore (subi2 {:x 1 :y 10 })) -(ignore (subv1 {:z 1.0})) -(ignore (subi1 {:x 1 })) -(ignore (subv3 {:x 1.0 :y 10.0 :z 100.0 })) -(ignore (subi3 {:w 1 :y 10 :z 100 })) -(ignore (subv4 {:x 1.0 :y 10.0 :z 100.0 :w 1000.0})) -(ignore (submixed4 {:x 1.0 :y 10.0 :z 100.0 :k 1 })) -(ignore (subtrailv2 {:a 1 :b 2 :c 1.0 :d 2.0 })) -(ignore (subf2s {:fx 2.0f32 :fy 3.0f32})) -(ignore (subf3s {:fx 2.0f32 :fy 3.0f32 :fz 5.0f32})) +ignore (subv2 ({z = 1.0, y = 10.0})) +ignore (subi2 ({x = 1, y = 10 })) +ignore (subv1 ({z = 1.0})) +ignore (subi1 ({x = 1 })) +ignore (subv3 ({x = 1.0, y = 10.0, z = 100.0 })) +ignore (subi3 ({w = 1, y = 10, z = 100 })) +ignore (subv4 ({x = 1.0, y = 10.0, z = 100.0, w = 1000.0})) +ignore (submixed4 ({x = 1.0, y = 10.0, z = 100.0, k = 1 })) +ignore (subtrailv2 ({a = 1, b = 2, c = 1.0, d = 2.0 })) +ignore (subf2s ({fx = 2.0f32, fy = 3.0f32})) +ignore (subf3s ({fx = 2.0f32, fy = 3.0f32, fz = 5.0f32})) diff --git a/test/misc.t/array_drop_back.smu b/test/misc.t/array_drop_back.smu index bce6c8df..25c0ab4a 100644 --- a/test/misc.t/array_drop_back.smu +++ b/test/misc.t/array_drop_back.smu @@ -1,8 +1,8 @@ -(def nested& [[0 1] [2 3]]) -(print (fmt-str (array/length nested))) -(array/drop-back &nested) -(print (fmt-str (array/length nested))) -(array/drop-back &nested) -(print (fmt-str (array/length nested))) -(array/drop-back &nested) -(print (fmt-str (array/length nested))) +let nested& = [[0, 1], [2, 3]] +print(fmt(Array.length(nested))) +Array.drop_back(&nested) +print(fmt(Array.length(nested))) +Array.drop_back(&nested) +print(fmt(Array.length(nested))) +Array.drop_back(&nested) +print(fmt(Array.length(nested))) diff --git a/test/misc.t/array_push.smu b/test/misc.t/array_push.smu index e93affcf..844c47b5 100644 --- a/test/misc.t/array_push.smu +++ b/test/misc.t/array_push.smu @@ -1,28 +1,27 @@ -(def a& [10 20]) -(def b (copy a)) +let a& = [10, 20] +let b = copy(a) -(array/push &a !30) +Array.push(&a, !30) -(print (fmt-str (array/length a))) -(print (fmt-str (array/length b))) +print(fmt(Array.length(a))) +print(fmt(Array.length(b))) +fun in_fun(): + let a& = [10, 20] + let b = copy(a) -(defn in-fun () - (def a& [10 20]) - (def b (copy a)) + Array.push(&a, !30) - (array/push &a !30) + print(fmt(Array.length(a))) + print(fmt(Array.length(b))) - (print (fmt-str (array/length a))) - (print (fmt-str (array/length b)))) +in_fun() -(in-fun) - -(def nested& [[0 1] [2 3]]) -(def a [4 5]) -(array/push &nested !(copy a)) -(set & nested.[1] !(copy a)) -(set &nested.[1] !(copy a)) -(array/push &nested ![4 5]) -(set &nested.[1] ![4 5]) -(set &nested.[1] ![4 5]) +let nested& = [[0, 1], [2, 3]] +let a = [4, 5] +Array.push(&nested, !copy(a)) +&nested.[1] <- copy(a) +&nested.[1] <- copy(a) +Array.push(&nested, ![4, 5]) +&nested.[1] <- [4, 5] +&nested.[1] <- [4, 5] diff --git a/test/misc.t/assert.smu b/test/misc.t/assert.smu index b44ab857..98d5e8c8 100644 --- a/test/misc.t/assert.smu +++ b/test/misc.t/assert.smu @@ -1,11 +1,11 @@ -(external stdout (raw_ptr u8)) -(external fflush (fun (raw_ptr u8) unit)) +external stdout : raw_ptr(u8) +external fflush : (raw_ptr(u8)) -> unit -(assert true) +assert(true) -(print "hmm") -(fflush stdout) -- flush to see it in testing +print("hmm") +fflush(stdout) -- flush to see it in testing -(assert false) +assert(false) -(print "lol") +print("lol") diff --git a/test/misc.t/boolean_logic.smu b/test/misc.t/boolean_logic.smu index ed8a09a0..d042e399 100644 --- a/test/misc.t/boolean_logic.smu +++ b/test/misc.t/boolean_logic.smu @@ -1,53 +1,63 @@ -(defn true_ () - (print "true") - true) - -(defn false_ () - (print "false") - false) - -(print "test 'and':") - -(if (and (true_) (true_)) - (print "yes") - (print "no")) - -(if (and (true_) (false_)) - (print "yes") - (print "no")) - -(if (and (false_) (true_)) - (print "yes") - (print "no")) - -(if (and (false_) (false_)) - (print "yes") - (print "no")) - -(print "test 'or':") - -(if (or (true_) (true_)) - (print "yes") - (print "no")) - -(if (or (true_) (false_)) - (print "yes") - (print "no")) - -(if (or (false_) (true_)) - (print "yes") - (print "no")) - -(if (or (false_) (false_)) - (print "yes") - (print "no")) - -(print "test 'not':") - -(if (not (true_)) - (print "yes") - (print "no")) - -(if (not (false_)) - (print "yes") - (print "no")) +fun true_(): + print("true") + true + +fun false_(): + print("false") + false + +print("test 'and':") + +if true_() and true_(): + print("yes") +else: + print("no") + +if true_() and false_(): + print("yes") +else: + print("no") + +if false_() and true_(): + print("yes") +else: + print("no") + +if false_() and false_(): + print("yes") +else: + print("no") + +print ("test 'or':") + +if true_() or true_(): + print("yes") +else: + print("no") + +if true_() or false_(): + print("yes") +else: + print("no") + +if false_() or true_(): + print("yes") +else: + print("no") + +if false_() or false_(): + print("yes") +else: + print("no") + +print("test 'not':") + +if not(true_()): + print("yes") +else: + print("no") + +if not(false_()): + print("yes") +else: + print("no") diff --git a/test/misc.t/borrow_string_lit.smu b/test/misc.t/borrow_string_lit.smu index 43b52e89..2d6a2d8c 100644 --- a/test/misc.t/borrow_string_lit.smu +++ b/test/misc.t/borrow_string_lit.smu @@ -1 +1 @@ -(ignore (if true "ok" "err")) +ignore(if true: "ok" else: "err") diff --git a/test/misc.t/capture_record_pattern.smu b/test/misc.t/capture_record_pattern.smu index 84d67bb3..fdd84e48 100644 --- a/test/misc.t/capture_record_pattern.smu +++ b/test/misc.t/capture_record_pattern.smu @@ -1,28 +1,27 @@ -(defn bind (res f) - (match res - ((#some r) (f r)) - (#none #none))) +fun bind(res, f): + match res: + Some(r): f(r) + None: None -(defn use (param thing) - (match param - ({bar foo} (bind (bar thing) - -- (foo) must be captured here - (fn (r) (bind (foo r) - (fn (r) (print (fmt-str r)) (#some (copy r))))))))) +fun use(param, thing): + match param: + (bar, foo): bind(bar(thing), fun r: + bind(foo(r), fun r: + print(fmt(r)) + Some(copy(r)))) -(ignore - (use {(fn (i) (#some (+ i 1))) - (fn (i) (#some (+ i 2)))} - 0)) +ignore(use((fun i: Some(i + 1), + fun i: Some(i + 2)), + 0)) --- This here is just a test to make sure that we can alias normal, --- monomorphized functions -(defn f (i) - (print (fmt-str "printing " i))) +-- This here is just a test to make sure that we can alias normal, monomorphized +-- functions +fun f(i): + print(fmt("printing ", i)) -(defn print-poly (to-print) - (match f - (foo (foo to-print)))) +fun print_poly(to_print): + match f: + foo: foo(to_print) -(print-poly 0) -(print-poly 1.1) +print_poly(0) +print_poly(1.1) diff --git a/test/misc.t/closure_monomorph.smu b/test/misc.t/closure_monomorph.smu index 96b4e697..d09c2ec3 100644 --- a/test/misc.t/closure_monomorph.smu +++ b/test/misc.t/closure_monomorph.smu @@ -1,17 +1,14 @@ -(defn sort (arr& cmp) - (defn partition (arr& lo hi) - (def pivot (copy arr.[hi])) - (def i& (- lo 1)) - (iter-range lo hi - (fn (j) - -- TODO cannot capture (cmp) here - (if (< (cmp arr.[j] pivot) 0) - (do - (set &i !(+ i 1)) - (array/swap-items &arr i j))))) - (def i (+ i 1)) - (array/swap-items &arr i hi) - i) +fun sort(arr&, cmp): + fun partition(arr&, lo, hi): + let pivot = copy(arr.[hi]) + let i& = lo - 1 + iter_range(lo, hi, fun j: + if cmp(arr.[j], pivot) < 0: + &i <- i + 1 + Array.swap_items(&arr, i, j)) + let i = i + 1 + Array.swap_items(&arr, i, hi) + i -- quicksort is a closure, as it closes over partition. partition itself -- is polymorphic. Before this change, quicksort would close over the dummy -- representation of partition and then construct the closure at the call site. @@ -19,45 +16,49 @@ -- Instead, quicksort now closes over the already monomorphized partition. -- Functions in closures are now mention the monomorphized name instead -- of the lexical one - (defn quicksort (arr& lo hi) - (if (or (not (< lo hi)) (< lo 0)) - () - (let ((p (partition &arr lo hi))) - (quicksort &arr lo (- p 1)) - (quicksort &arr (+ p 1) hi)))) + fun quicksort(arr&, lo, hi): + if not(lo < hi) or (lo < 0): () + else: + let p = partition(&arr, lo, hi) + quicksort(&arr, lo, p - 1) + quicksort(&arr, p + 1, hi) - (let ((len (- (array/length arr) 1))) - (quicksort &arr 0 len))) + let len = Array.length(arr) - 1 + quicksort(&arr, 0, len) -(def arr& [9 30 0 50 2030 34]) -(sort &arr (fn (a b ) (- a b))) -(array/iter arr (fn (i) (print (fmt-str i)))) +let arr& = [9, 30, 0, 50, 2030, 34] +sort(&arr, fun(a, b): a - b) +Array.iter(arr, fun i: print(fmt(i))) -- These functions have different call names. Make sure this works as well -(defn sort (arr& cmp) - (defn partition (arr& lo hi) - (def pivot (copy arr.[hi])) - (def i& (- lo 1)) - (iter-range lo hi - (fn (j) - -- TODO cannot capture (cmp) here - (if (< (cmp arr.[j] pivot) 0) - (do - (set &i !(+ i 1)) - (array/swap-items &arr i j))))) - (def i (+ i 1)) - (array/swap-items &arr i hi) - i) - (defn quicksort (arr& lo hi) - (if (or (not (< lo hi)) (< lo 0)) - () - (let ((p (partition &arr lo hi))) - (quicksort &arr lo (- p 1)) - (quicksort &arr (+ p 1) hi)))) +fun sort(arr&, cmp): + fun partition(arr&, lo, hi): + let pivot = copy(arr.[hi]) + let i& = lo - 1 + iter_range(lo, hi, fun j: + if cmp(arr.[j], pivot) < 0: + &i <- i + 1 + Array.swap_items(&arr, i, j)) + let i = i + 1 + Array.swap_items(&arr, i, hi) + i + -- quicksort is a closure, as it closes over partition. partition itself + -- is polymorphic. Before this change, quicksort would close over the dummy + -- representation of partition and then construct the closure at the call site. + -- This doesn't work here because cmp is not available insize quicksort. + -- Instead, quicksort now closes over the already monomorphized partition. + -- Functions in closures are now mention the monomorphized name instead + -- of the lexical one + fun quicksort(arr&, lo, hi): + if not(lo < hi) or (lo < 0): () + else: + let p = partition(&arr, lo, hi) + quicksort(&arr, lo, p - 1) + quicksort(&arr, p + 1, hi) - (let ((len (- (array/length arr) 1))) - (quicksort &arr 0 len))) + let len = Array.length(arr) - 1 + quicksort(&arr, 0, len) -(def arr& [9 30 0 50 2030 34]) -(sort &arr (fn (a b ) (- a b))) -(array/iter arr (fn (i) (print (fmt-str i)))) +let arr& = [9, 30, 0, 50, 2030, 34] +sort(&arr, fun(a, b): a - b) +Array.iter(arr, fun i: print(fmt(i))) diff --git a/test/misc.t/cname_decl.smu b/test/misc.t/cname_decl.smu index bb18975f..67acce95 100644 --- a/test/misc.t/cname_decl.smu +++ b/test/misc.t/cname_decl.smu @@ -1,3 +1,3 @@ -(external printi (fun int unit) "Printi") +external printi : (int) -> unit = "Printi" -(printi 42) +printi(42) diff --git a/test/misc.t/const_fixed_arr.smu b/test/misc.t/const_fixed_arr.smu index f0a6d78f..d75b1b81 100644 --- a/test/misc.t/const_fixed_arr.smu +++ b/test/misc.t/const_fixed_arr.smu @@ -1,5 +1,5 @@ -(def a 17) -(def arr #[1 a 3]) +let a = 17 +let arr = #[1, a, 3] -(print (fmt-str arr.(1))) -(def _ {10 a}) +print(fmt(arr#[1])) +let _ = (10, a) diff --git a/test/misc.t/decr_rc_if.smu b/test/misc.t/decr_rc_if.smu index 7ba3e60a..c0677047 100644 --- a/test/misc.t/decr_rc_if.smu +++ b/test/misc.t/decr_rc_if.smu @@ -1,7 +1,6 @@ -(defn ret-true () true) +fun ret_true(): true -(ignore - (if (ret-true) - (let ((_ [10])) - [10]) - [0])) +(if ret_true(): + let _ = [10] + [10] +else: [0]) -> ignore diff --git a/test/misc.t/elseif.smu b/test/misc.t/elseif.smu index efbce899..bc4a18d1 100644 --- a/test/misc.t/elseif.smu +++ b/test/misc.t/elseif.smu @@ -1,13 +1,12 @@ -(external assert (fun bool unit)) +external assert : (bool) -> unit -(defn test (n) - (cond - ((= n 10) 1) - ((< n 1) 2) - ((< n 10) 3) - (else 4))) +fun test(n): + if n == 10: 1 + else if n < 1: 2 + else if n < 10: 3 + else: 4 -(assert (= (test 10) 1)) -(assert (= (test 0) 2)) -(assert (= (test 1) 3)) -(assert (= (test 11) 4)) +assert(test(10) == 1) +assert(test(0) == 2) +assert(test(1) == 3) +assert(test(11) == 4) diff --git a/test/misc.t/find_fn.smu b/test/misc.t/find_fn.smu index bb45db4f..129bec3a 100644 --- a/test/misc.t/find_fn.smu +++ b/test/misc.t/find_fn.smu @@ -1,6 +1,5 @@ -(def a 1) +let a = 1 -(defn capture () - (+ a 1)) +fun capture(): a + 1 -(def _ {(copy capture)}) +let _ = (copy(capture), 0) diff --git a/test/misc.t/fixed_array_allocs.smu b/test/misc.t/fixed_array_allocs.smu index 8c062239..a57a204c 100644 --- a/test/misc.t/fixed_array_allocs.smu +++ b/test/misc.t/fixed_array_allocs.smu @@ -1,11 +1,11 @@ -(def arr #[#[1 2 3] #[3 4 5]]) +let arr = #[#[1, 2, 3], #[3, 4, 5]] -(defn print-snd (arr) - (print (fmt-str arr.(1)))) +fun print_snd(arr): + print(fmt(arr#[1])) -(print-snd #[1 3 2]) -(print-snd #["hey" "hi"]) -- correctly free -(def arr& #["hey" "hie"]) -- correctly free as mut -(ignore (copy arr)) -(print-snd arr) -(print (fmt-str #[#["oho"]].(0).(0))) +print_snd(#[1, 3, 2]) +print_snd(#["hey", "hi"]) -- correctly free +let arr& = #["hey", "hie"] -- correctly free as mut +ignore(copy(arr)) +print_snd(arr) +print(fmt(#[#["oho"]]#[0]#[0])) diff --git a/test/misc.t/free_array.smu b/test/misc.t/free_array.smu index e0679587..cbe5eed9 100644 --- a/test/misc.t/free_array.smu +++ b/test/misc.t/free_array.smu @@ -1,64 +1,63 @@ -(type foo {:x int}) -(type container {:index int :arr (array int)}) +type foo = {x : int} +type container = {index : int, arr : array(int)} -(def x {:x 1}) +let x = {x = 1} -- These are freed at the end of the program -(def arr ["hey" "young" "world"]) -(def arr [(copy x) {:x 2} {:x 3}]) +let arr = ["hey", "young", "world"] +let arr = [copy(x), {x = 2}, {x = 3}] -- Arr is only alive inside the function and should be freed there -(defn arr_inside () - (def arr& [(copy x) {:x 2} {:x 3}]) +fun arr_inside(): + let arr& = [copy(x), {x = 2}, {x = 3}] -- Make sure we can call realloc - (array/push &arr !{:x 12})) + Array.push(&arr, !{x = 12}) -- Arr is returned and should be freed in its parent scope -(defn make_arr () - (def x {:x 23}) - [x {:x 2} {:x 3}]) +fun make_arr(): + let x = {x = 23} + [x, {x = 2}, {x = 3}] -(defn inner_parent_scope () - (ignore (make_arr))) +fun inner_parent_scope(): + ignore(make_arr()) -- Arr can be propagated out through multiple function calls -(defn nest_fns () - (make_arr)) +fun nest_fns(): make_arr() -(defn make_nested_arr () - (def nested [[0 1] [2 3]]) - nested) +fun make_nested_arr(): + let nested = [[0, 1], [2, 3]] + nested -(defn nest_allocs () - (make_nested_arr)) +fun nest_allocs(): + make_nested_arr() --- Should be freed locally -(defn nest_local () - (ignore [[0 1] [2 3]])) +-- Should be freed locall +fun nest_local(): + ignore([[0, 1], [2, 3]]) -- Records of arrtors -(defn record_of_arrs () - (def arr [1 2]) - {:index 1 :arr}) +fun record_of_arrs(): + let arr = [1, 2] + {index = 1, arr} -- Arrtors of records (of arrtors) -(defn arr_of_records () - [(record_of_arrs) (record_of_arrs)]) +fun arr_of_records(): + [record_of_arrs(), record_of_arrs()] -(def arr (make_arr)) -(arr_inside) -(inner_parent_scope) -(def normal (nest_fns)) +let arr = make_arr() +arr_inside() +inner_parent_scope() +let normal = nest_fns() -(def nested& [[0 1] [2 3]]) -(array/push &nested ![4 5]) -(def nested (make_nested_arr)) -(def nested (nest_allocs)) -(nest_local) +let nested& = [[0, 1], [2, 3]] +Array.push(&nested, ![4, 5]) +let nested = make_nested_arr() +let nested = nest_allocs() +nest_local() -(def rec_of_arr {:index 12 :arr [1 2]}) -(def rec_of_arr (record_of_arrs)) +let rec_of_arr = {index = 12, arr = [1, 2]} +let rec_of_arr = record_of_arrs() -(def arr_of_rec [(record_of_arrs) (record_of_arrs)]) -(def arr_of_rec (arr_of_records)) +let arr_of_rec = [record_of_arrs(), record_of_arrs()] +let arr_of_rec = arr_of_records() 0 diff --git a/test/misc.t/free_cond.smu b/test/misc.t/free_cond.smu index 8b7fbfa3..e1657da4 100644 --- a/test/misc.t/free_cond.smu +++ b/test/misc.t/free_cond.smu @@ -1,8 +1,9 @@ -(defn test () - (def ai [10]) - (def bi [11]) - (if false - [12] - (if false bi (if true ai [10])))) +fun test(): + let ai = [10] + let bi = [11] + if false: [12] + else: if false: bi + else: if true: ai + else: [10] -(ignore (test)) +ignore(test) diff --git a/test/misc.t/free_moved_param.smu b/test/misc.t/free_moved_param.smu index 48d98cb4..5b85ce68 100644 --- a/test/misc.t/free_moved_param.smu +++ b/test/misc.t/free_moved_param.smu @@ -1,5 +1,5 @@ -(defn hm (a!) - (ignore a) - ()) +fun hm(a!): + ignore(a) + () -(hm !["aoeu"]) +hm(!["aoeu"]) diff --git a/test/misc.t/function_array.smu b/test/misc.t/function_array.smu index c838bd1a..97d3298f 100644 --- a/test/misc.t/function_array.smu +++ b/test/misc.t/function_array.smu @@ -1,2 +1,2 @@ -(def arr [(copy print)]) -(ignore arr) +let arr = [copy(print)] +ignore(arr) diff --git a/test/misc.t/function_call_annot.smu b/test/misc.t/function_call_annot.smu index 6f7bb2a3..292580be 100644 --- a/test/misc.t/function_call_annot.smu +++ b/test/misc.t/function_call_annot.smu @@ -1,14 +1,14 @@ -(type a {:field int}) -(type b {:field int}) -(type c (#ctor)) -(type d (#ctor)) +type a = {field : int} +type b = {field : int} +type c = Ctor +type d = Ctor -(defn take-a ([a a]) (ignore a)) -(defn take-b ([b b]) (ignore b)) -(defn take-c ([c c]) (ignore c)) -(defn take-d ([d d]) (ignore d)) +fun take_a(a : a): ignore(a) +fun take_b(b : b): ignore(b) +fun take_c(c : c): ignore(c) +fun take_d(d : d): ignore(d) -(take-a {:field 0}) -(take-b {:field 0}) -(take-c #ctor) -(take-d #ctor) +take_a({field = 0}) +take_b({field = 0}) +take_c(Ctor) +take_d(Ctor) diff --git a/test/misc.t/global_let.smu b/test/misc.t/global_let.smu index 55ec5e5a..b6c57a3c 100644 --- a/test/misc.t/global_let.smu +++ b/test/misc.t/global_let.smu @@ -1,10 +1,12 @@ -(defn ret-none () - (def [a (option (array int))] #none) - a) -(def b !(match (ret-none) ((#some a) a) (#none [1 2]))) -(ignore b) +fun ret_none(): + let a : option(array(int)) = None + a +let b = !match ret_none(): Some(a): a | None: [1, 2] +ignore(b) -(type (r 'a) {:a 'a}) -(defn ret-rec () {:a [10 20 30]}) -(def c (let ((a (ret-rec))) (.a a).[1])) -(ignore c) +type r('a) = {a : 'a} +fun ret_rec(): {a = [10, 20, 30]} +let c = do: + let a = ret_rec() + a.a.[1] +ignore(c) diff --git a/test/misc.t/if_no_else.smu b/test/misc.t/if_no_else.smu index 77275396..41664c3c 100644 --- a/test/misc.t/if_no_else.smu +++ b/test/misc.t/if_no_else.smu @@ -1,2 +1,2 @@ -(if true ()) -(if true 2) +if true: () +if true: 2 diff --git a/test/misc.t/if_ret_param.smu b/test/misc.t/if_ret_param.smu index 6e67d522..2d1808a8 100644 --- a/test/misc.t/if_ret_param.smu +++ b/test/misc.t/if_ret_param.smu @@ -1,16 +1,13 @@ -(def s "/") +let s = "/" -(defn times (limit f) - (defn inner (i) - (if (= i limit) - () - (do - (f s) - (inner (+ i 1))))) - (inner 0)) +fun times(limit, f): + fun inner(i): + if i == limit: () + else: + f(s) + inner(i + 1) + inner(0) -(defn test (value) - (ignore (if true - (copy value) - (fmt-str "/" value)))) -(times 2 test) +fun test(value): + ignore(if true: copy(value) else: fmt("/", value)) +times(2, test) diff --git a/test/misc.t/incr_str_lit_ifs.smu b/test/misc.t/incr_str_lit_ifs.smu index 7d74983b..645c965b 100644 --- a/test/misc.t/incr_str_lit_ifs.smu +++ b/test/misc.t/incr_str_lit_ifs.smu @@ -1,12 +1,11 @@ -(defn ret-non () - (if false - (#some 20) - #none)) +fun ret_non(): + if false: Some(20) + else: None -(defn try () - (match (ret-non) - ((#some j) (print (fmt-str j))) - (#none (print "none")))) +fun try(): + match ret_non(): + Some(j): print(fmt(j)) + None: print("none") -(try) -(try) +try() +try() diff --git a/test/misc.t/m2.smu b/test/misc.t/m2.smu index f9ab3579..cb9faade 100644 --- a/test/misc.t/m2.smu +++ b/test/misc.t/m2.smu @@ -1,40 +1,30 @@ -- (mod/extr-a {:b 10}) -(rec - (defn even? (i) - (match i - (0 true) - (1 false) - (n (odd? (- n 1))))) - (defn odd? (i) - (match i - (0 false) - (1 true) - (n (even? (- n 1)))))) +fun rec even(i): + match i: + 0: true + 1: false + n: odd(n - 1) --- (print (fmt-str (odd? 1))) --- (print (fmt-str (odd? 100))) --- (print (fmt-str (even? 100))) +and odd(i): + match i: + 0: true + 1: true + n: even(n - 1) +fun rec pop(arr&): + print("pop") + Array.drop_back(&arr) + pop_all(&arr) -(rec - (defn pop (arr&) - (print "pop") - (array/drop-back &arr) - (pop-all &arr)) - (defn pop-all (arr&) - (if (= (array/length arr) 0) - () - (pop &arr)))) +and pop_all(arr&): + if Array.length(arr) == 0: () + else: pop(&arr) --- (val arr& (0 1 2 3)) --- (pop-all &arr) --- (print (fmt-str (array/length arr))) +fun test(i): + print("wrong") + copy(i) -(defn test (i) - (print "wrong") - (copy i)) - -(defn test (i) - (print "right") - (copy i)) +fun test(i): + print("right") + copy(i) diff --git a/test/misc.t/mutual_rec.smu b/test/misc.t/mutual_rec.smu index 00d83783..287475e6 100644 --- a/test/misc.t/mutual_rec.smu +++ b/test/misc.t/mutual_rec.smu @@ -1,15 +1,15 @@ -(rec - (defn even? (i) - (match i - (0 true) - (1 false) - (n (odd? (- n 1))))) - (defn odd? (i) - (match i - (0 false) - (1 true) - (n (even? (- n 1)))))) +fun rec even(i): + match i: + 0: true + 1: false + n: odd(n - 1) -(print (fmt-str (odd? 1))) -(print (fmt-str (odd? 100))) -(print (fmt-str (even? 100))) +and odd(i): + match i: + 0: false + 1: true + n: even(n - 1) + +print(fmt(odd(1))) +print(fmt(odd(100))) +print(fmt(even(100))) diff --git a/test/misc.t/partials.smu b/test/misc.t/partials.smu index df59cc15..ec9038b1 100644 --- a/test/misc.t/partials.smu +++ b/test/misc.t/partials.smu @@ -1,20 +1,19 @@ -(type (f 'a) {:a 'a :b 'a :c 'a}) +type f('a) = {a : 'a, b : 'a, c : 'a} -(defn inf () - (def a {:a [10] :b [10] :c [10]}) - (def _ !(if true - (if false a.c a.a) - -- a.a - -- [10] - a.c)) - a.b) +fun inf(): + let a = {a = [10], b = [10], c = [10]} + let _ = !do: + if true: + if false: a.c else: a.a + else: a.c + a.b -(ignore (inf)) +ignore(inf()) -(type (t 'a) {:a& 'a :b 'a}) -(defn set-moved () - (def a& {:a [10] :b [20]}) - (ignore {a.a}) - (set &a.a ![20])) +type t('a) = {a& : 'a, b : 'a} +fun set_moved(): + let a& = {a = [10], b = [20]} + ignore((a.a, 0)) + &a.a <- [20] -(set-moved) +set_moved() diff --git a/test/misc.t/pattern_decls.smu b/test/misc.t/pattern_decls.smu index 82d97e91..6a6d3812 100644 --- a/test/misc.t/pattern_decls.smu +++ b/test/misc.t/pattern_decls.smu @@ -1,17 +1,17 @@ -(defn hmm ({_ {x _}}) - (print x)) +fun hmm((_, (x, _))): print(x) -(hmm {10 {"hello" 20.0}}) +hmm((10, ("hello", 20.0))) -(def {i _} {20 30.0}) -(print (fmt-str i)) +let i, _ = (20, 30.0) +print(fmt(i)) -(let (({f _} {30.0 20})) - (print (fmt-str f))) +do: + let f, _ = (30.0, 20) + print(fmt(f)) --- pattern matched thing is a closure -(defn hmm ({x _}) - (fn :copy x () (x))) +-- pattern matched thing as a closure +fun hmm((x, _)): + fun ()[x]: x() -- this case is strange. The tuple needs to be moved right now -((hmm {(fn () (print "lol")) 10})) +hmm((fun (): print("lol"), 10))() diff --git a/test/misc.t/piping.smu b/test/misc.t/piping.smu index ff15d49c..7e302364 100644 --- a/test/misc.t/piping.smu +++ b/test/misc.t/piping.smu @@ -1,21 +1,14 @@ -(external printi (fun int unit) "Printi") +external printi : (int) -> unit = "Printi" -- pipe into normal function -(-> 1 - (fn (x) (+ x 1)) - printi) +1 -> (fun x: x + 1) -> printi -- pipe into ctor -(-> 1 - #some - (fn (x) - (match x - ((#some a) a) - (#none 0))) - printi) +1 -> Some -> (fun x: match x: + Some(a): a + None: 0) +-> printi --- pipe field accessor -(type foo {:x int}) -(-> {:x 1} - .x - printi) +-- pipe field accessor (this isn't supported anymore, but works naturally with .x) +type foo = {x : int} +{x = 1}.x -> printi diff --git a/test/misc.t/polymorphic_mutual_rec.smu b/test/misc.t/polymorphic_mutual_rec.smu index 1d83cf50..ea3b1d59 100644 --- a/test/misc.t/polymorphic_mutual_rec.smu +++ b/test/misc.t/polymorphic_mutual_rec.smu @@ -1,28 +1,28 @@ -m2/(do - (print (fmt-str (odd? 1))) - (print (fmt-str (odd? 100))) - (print (fmt-str (even? 100))) +M2.do: + print(fmt(odd(1))) + print(fmt(odd(100))) + print(fmt(even(100))) - (def arr& [0 1 2 3]) - (pop &arr) - (def arr& [0 1 2 3]) - (pop-all &arr) - (print (fmt-str (array/length arr)))) + let arr& = [0, 1, 2, 3] + pop(&arr) + let arr& = [0, 1, 2, 3] + pop_all(&arr) + print(fmt(Array.length(arr))) -(rec - (defn pop (arr&) - (print "pop") - (array/drop-back &arr) - (pop-all &arr)) - (defn pop-all (arr&) - (if (= (array/length arr) 0) - () - (pop &arr)))) +fun rec pop(arr&): + print("pop") + Array.drop_back(&arr) + pop_all(&arr) -(def arr& [0 1 2 3]) -(pop &arr) -(def arr& [0 1 2 3]) -(pop-all &arr) -(print (fmt-str (array/length arr))) +and pop_all(arr&): + if Array.length(arr) == 0: () + else: pop(&arr) -(ignore (m2/test 1)) + +let arr& = [0, 1, 2, 3] +pop(&arr) +let arr& = [0, 1, 2, 3] +pop_all(&arr) +print(fmt(Array.length(arr))) + +ignore(M2.test(1)) diff --git a/test/misc.t/rc_ifs.smu b/test/misc.t/rc_ifs.smu index d2527296..b1fe5914 100644 --- a/test/misc.t/rc_ifs.smu +++ b/test/misc.t/rc_ifs.smu @@ -1,42 +1,38 @@ -(defn test (b) - (def [ret (array int)] []) - (defn inner (i) - (def [ai (array int)] []) - (def [bi (array int)] []) - (if (= i b) - ai - (if (= i 30) - bi - (inner (+ i 1))))) - (def io (inner 10)) - (ignore io) - ret) +fun test(b): + let ret : array(int) = [] + fun inner(i): + let ai : array(int) = [] + let bi : array(int) = [] + if i == b: ai + else: + if i == 30: bi + else: inner(i + 1) + let io = inner(10) + ignore(io) + ret - -(def a (test 2)) -(ignore a) +let a = test(2) +ignore(a) -- For these to pass, the moved bindings from other branches need to -- be freed correctly -(defn test (a!) - (def ai [10]) - (def bi [11]) - (def _ !(if false - [12] - (if true - bi - (if true - (do - (ignore {a}) - ai) - [10])))) - ()) +fun test(a!): + let ai = [10] + let bi = [11] + let _ = !(if false: [12] + else: + if true: bi + else: + if true: + ignore((a, 0)) + ai + else: [10]) + () -(ignore (test ![10])) +ignore(test(![10])) -(defn test (a!) - (if true - (ignore {a}) - ())) +fun test(a!): + if true: ignore((a, 0)) + else: () -(test ![10]) +test(![10]) diff --git a/test/misc.t/rc_linear_closed_return.smu b/test/misc.t/rc_linear_closed_return.smu index fc47b0d8..d23e8ded 100644 --- a/test/misc.t/rc_linear_closed_return.smu +++ b/test/misc.t/rc_linear_closed_return.smu @@ -1,12 +1,11 @@ -(defn test () - (def [ret (array int)] []) - (defn inner (i) - (ignore i) - (copy ret)) - (def io (inner 10)) - (ignore io) - ret) +fun test(): + let ret : array(int) = [] + fun inner(i): + ignore(i) + copy(ret) + let io = inner(10) + ignore(io) + ret - -(def a (test)) -(ignore a) +let a = test() +ignore(a) diff --git a/test/misc.t/regression_issue_19.smu b/test/misc.t/regression_issue_19.smu index 643222b8..a5a8a7a1 100644 --- a/test/misc.t/regression_issue_19.smu +++ b/test/misc.t/regression_issue_19.smu @@ -1,13 +1,13 @@ -(type v3 {:x float :y float :z float}) +type v3 = {x : float, y : float, z : float} -(defn v3_add (lhs rhs) - {:x (+. (.x lhs) (.x rhs)) :y (+. (.y lhs) (.y rhs)) :z (+. (.z lhs) (.z rhs))}) +fun v3_add(lhs, rhs): + {x = lhs.x +. rhs.x, y = lhs.y +. rhs.y, z = lhs.z +. rhs.z} -(defn v3_scale (v3 factor) - {:x (*. (.x v3) factor) :y (*. (.y v3) factor) :z (*. (.z v3) factor)}) +fun v3_scale(v3, factor): + {x = v3.x *. factor, y = v3.y *. factor, z = v3.z *. factor} -(defn wrap () - (-> (v3_scale {:x 1.0 :y 10.0 :z 100.0 } 1.5) - (v3_add (v3_scale {:x 1.0 :y 2.0 :z 3.0} 1.5)))) +fun wrap(): + v3_scale({x = 1.0, y = 10.0, z = 100.0}, 1.5) + -> v3_add(v3_scale({x = 1.0, y = 2.0, z = 3.0}, 1.5)) -(ignore (wrap)) +ignore(wrap()) diff --git a/test/misc.t/regression_issue_26.smu b/test/misc.t/regression_issue_26.smu index 60fb0a78..14b5f104 100644 --- a/test/misc.t/regression_issue_26.smu +++ b/test/misc.t/regression_issue_26.smu @@ -1,38 +1,35 @@ -(external printf (fun string/cstr int int int unit)) +external printf : (String.cstr, int, int, int) -> unit -(def limit 3) +let limit = 3 -- this works -(defn nested (a b) - (cond - ((= b limit) (nested (+ a 1) 0)) - ((= a limit) ()) - (else (do - (printf (string/data "%i, %i\n") a b 0) - (nested a (+ b 1)))))) - -(nested 0 0) - -(printf (string/data "\n") 0 0 0) - -(defn nested (a b c) - (cond - ((= b limit) (nested (+ a 1) 0 c)) - ((= c limit) (nested a (+ b 1) 0)) - ((= a limit) ()) - (else (do - (printf (string/data "%i, %i, %i\n") a b c) - (nested a b (+ c 1)))))) - -(nested 0 0 0) - -(defn nested (a b c) - (cond - ((= b limit) (nested (+ a 1) 0 c)) - ((= a limit) ()) - ((= c limit) (nested a (+ b 1) 0)) - (else (do - (printf (string/data "%i, %i, %i\n") a b c) - (nested a b (+ c 1)))))) +fun nested(a, b): + if b == limit: nested(a + 1, 0) + else if a == limit: () + else: + printf(String.data("%i, %i\n"), a, b, 0) + nested(a, b + 1) + +nested(0, 0) + +printf(String.data("\n"), 0, 0, 0) + +fun nested(a, b, c): + if b == limit: nested(a + 1, 0, c) + else if c == limit: nested(a, b + 1, 0) + else if a == limit: () + else: + printf(String.data("%i, %i, %i\n"), a, b, c) + nested(a, b, c + 1) + +nested(0, 0, 0) + +fun nested(a, b, c): + if b == limit: nested(a + 1, 0, c) + else if a == limit: () + else if c == limit: nested(a, b + 1, 0) + else: + printf(String.data("%i, %i, %i\n"), a, b, c) + nested(a, b, c + 1) 0 diff --git a/test/misc.t/regression_issue_30.smu b/test/misc.t/regression_issue_30.smu index 155957c5..b909240b 100644 --- a/test/misc.t/regression_issue_30.smu +++ b/test/misc.t/regression_issue_30.smu @@ -1,19 +1,19 @@ -(type v {:x float :y float :z float}) +type v = {x : float, y : float, z : float} -(external dot (fun v v float)) -(external norm (fun v v)) -(external scale (fun v float v)) -(external maybe (fun unit bool)) +external dot : (v, v) -> float +external norm: (v) -> v +external scale : (v, float) -> v +external maybe: () -> bool -(defn calc_acc (vel) - (def vunit (if (>. (dot vel vel) 0.1) - (norm vel) - {:x 1.0 :y 0.0 :z 0.0})) - (def acc_force 100.0) - (def acc (cond - ((maybe) (scale vunit acc_force)) - ((maybe) (scale vunit - (*. acc_force 3.0))) - (else (scale vunit 0.1)))) - acc) +fun calc_acc(vel): + let vunit = do: + if dot(vel, vel) >. 0.1: + norm(vel) + else: {x = 1.0, y = 0.0, z = 0.0} + let acc_force = 100.0 + let acc = if maybe(): scale(vunit, acc_force) + else if maybe(): scale(vunit, -(acc_force *. 3.0)) + else: scale(vunit, 0.1) + acc -(ignore calc_acc) +ignore(calc_acc) diff --git a/test/misc.t/regression_load_global.smu b/test/misc.t/regression_load_global.smu index 6eb017e0..12a2950e 100644 --- a/test/misc.t/regression_load_global.smu +++ b/test/misc.t/regression_load_global.smu @@ -1,24 +1,22 @@ -(type segment {:start float :width float}) +type segment = {start : float, width : float} -(type bar {:start float :end float :nsegs int :margin float :y float :thick f32}) +type bar = {start : float, end : float, nsegs : int, + margin : float, y : float, thick : f32} -(def height 720) +let height = 720 -(def world {:start 0.0 - :end 1280.0 - :nsegs 10 - :margin 0.1 - :y (*. (float_of_int height) 0.75) - :thick 5.0f32}) +let world = { + start = 0.0, + end = 1280.0, + nsegs = 10, + margin = 0.1, + y = float_of_int(height) *. 0.75, + thick = 5.0f32} -(defn get-seg - "Get segment [i] of [bar]" - (bar) - (ignore bar)) +fun get_seg(bar): ignore(bar) -(defn wrap-seg () - (get-seg world)) +fun wrap_seg(): get_seg(world) -(wrap-seg) +wrap_seg() 0 diff --git a/test/misc.t/return_closure.smu b/test/misc.t/return_closure.smu index 06211973..20038daf 100644 --- a/test/misc.t/return_closure.smu +++ b/test/misc.t/return_closure.smu @@ -1,15 +1,14 @@ -(defn ret-fn (b) - (defn bla (a) (+ a b)) - bla) +fun ret_fn(b): + fun bla(a): a + b + bla -(defn ret-lambda (b) - (fn (a) (+ a b))) +fun ret_lambda(b): + fun a: a + b +let f = ret_fn(13) +let f2 = ret_fn(35) +print(fmt(f(12))) +print(fmt(f2(12))) -(def f (ret-fn 13)) -(def f2 (ret-fn 35)) -(print (fmt-str (f 12))) -(print (fmt-str (f2 12))) - -(def f (ret-lambda 134)) -(print (fmt-str (f 12))) +let f = ret_lambda(134) +print(fmt(f(12))) diff --git a/test/misc.t/return_fn.smu b/test/misc.t/return_fn.smu index 6fd8cbee..c3f56437 100644 --- a/test/misc.t/return_fn.smu +++ b/test/misc.t/return_fn.smu @@ -1,13 +1,12 @@ -(defn ret-fn () - (fn (a) (+ a 12))) +fun ret_fn(): + fun a: a + 12 -(defn ret-named () - (defn named (a) - (+ a 13)) - named) +fun ret_named(): + fun named(a): a + 13 + named -(def f (ret-fn)) -(print (fmt-str (f 12))) +let f = ret_fn() +print(fmt(f(12))) -(def f (ret-named)) -(print (fmt-str (f 12))) +let f = ret_named() +print(fmt(f(12))) diff --git a/test/misc.t/run.t b/test/misc.t/run.t index b9a4c156..625b3d6c 100644 --- a/test/misc.t/run.t +++ b/test/misc.t/run.t @@ -51,10 +51,10 @@ Test elif Test simple typedef $ schmu --dump-llvm stub.o simple_typealias.smu && ./simple_typealias - simple_typealias.smu:2.11-15: warning: Unused binding puts. + simple_typealias.smu:2.10-14: warning: Unused binding puts. - 2 | (external puts (fun foo unit)) - ^^^^ + 2 | external puts : (foo) -> unit + ^^^^ ; ModuleID = 'context' source_filename = "context" @@ -68,55 +68,55 @@ Test simple typedef Allocate vectors on the heap and free them. Check with valgrind whenever something changes here. Also mutable fields and 'realloc' builtin $ schmu --dump-llvm stub.o free_array.smu && valgrind -q --leak-check=yes --show-reachable=yes ./free_array - free_array.smu:7.6-9: warning: Unused binding arr. + free_array.smu:7.5-8: warning: Unused binding arr. - 7 | (def arr ["hey" "young" "world"]) - ^^^ + 7 | let arr = ["hey", "young", "world"] + ^^^ - free_array.smu:8.6-9: warning: Unused binding arr. + free_array.smu:8.5-8: warning: Unused binding arr. - 8 | (def arr [(copy x) {:x 2} {:x 3}]) - ^^^ + 8 | let arr = [copy(x), {x = 2}, {x = 3}] + ^^^ - free_array.smu:48.6-9: warning: Unused binding arr. + free_array.smu:47.5-8: warning: Unused binding arr. - 48 | (def arr (make_arr)) - ^^^ + 47 | let arr = make_arr() + ^^^ - free_array.smu:51.6-12: warning: Unused binding normal. + free_array.smu:50.5-11: warning: Unused binding normal. - 51 | (def normal (nest_fns)) - ^^^^^^ + 50 | let normal = nest_fns() + ^^^^^^ - free_array.smu:55.6-12: warning: Unused binding nested. + free_array.smu:54.5-11: warning: Unused binding nested. - 55 | (def nested (make_nested_arr)) - ^^^^^^ + 54 | let nested = make_nested_arr() + ^^^^^^ - free_array.smu:56.6-12: warning: Unused binding nested. + free_array.smu:55.5-11: warning: Unused binding nested. - 56 | (def nested (nest_allocs)) - ^^^^^^ + 55 | let nested = nest_allocs() + ^^^^^^ - free_array.smu:59.6-16: warning: Unused binding rec_of_arr. + free_array.smu:58.5-15: warning: Unused binding rec_of_arr. - 59 | (def rec_of_arr {:index 12 :arr [1 2]}) - ^^^^^^^^^^ + 58 | let rec_of_arr = {index = 12, arr = [1, 2]} + ^^^^^^^^^^ - free_array.smu:60.6-16: warning: Unused binding rec_of_arr. + free_array.smu:59.5-15: warning: Unused binding rec_of_arr. - 60 | (def rec_of_arr (record_of_arrs)) - ^^^^^^^^^^ + 59 | let rec_of_arr = record_of_arrs() + ^^^^^^^^^^ - free_array.smu:62.6-16: warning: Unused binding arr_of_rec. + free_array.smu:61.5-15: warning: Unused binding arr_of_rec. - 62 | (def arr_of_rec [(record_of_arrs) (record_of_arrs)]) - ^^^^^^^^^^ + 61 | let arr_of_rec = [record_of_arrs(), record_of_arrs()] + ^^^^^^^^^^ - free_array.smu:63.6-16: warning: Unused binding arr_of_rec. + free_array.smu:62.5-15: warning: Unused binding arr_of_rec. - 63 | (def arr_of_rec (arr_of_records)) - ^^^^^^^^^^ + 62 | let arr_of_rec = arr_of_records() + ^^^^^^^^^^ ; ModuleID = 'context' source_filename = "context" @@ -187,7 +187,7 @@ Also mutable fields and 'realloc' builtin %data = bitcast i8* %14 to i64** %15 = getelementptr inbounds i64*, i64** %data, i64 %3 store i64* %value, i64** %15, align 8 - %add = add i64 1, %3 + %add = add i64 %3, 1 store i64 %add, i64* %.pre-phi, align 8 ret void } @@ -242,7 +242,7 @@ Also mutable fields and 'realloc' builtin %18 = bitcast %foo* %17 to i8* %19 = bitcast %foo* %14 to i8* call void @llvm.memcpy.p0i8.p0i8.i64(i8* %18, i8* %19, i64 8, i1 false) - %add = add i64 1, %4 + %add = add i64 %4, 1 store i64 %add, i64* %.pre-phi, align 8 ret void } @@ -1216,25 +1216,25 @@ Test 'and', 'or' and 'not' $ schmu --dump-llvm stub.o unary_minus.smu && ./unary_minus - unary_minus.smu:1.6-7: warning: Unused binding a. + unary_minus.smu:1.5-6: warning: Unused binding a. - 1 | (def a -1.0) - ^ + 1 | let a = -1.0 + ^ - unary_minus.smu:2.6-7: warning: Unused binding a. + unary_minus.smu:2.5-6: warning: Unused binding a. - 2 | (def a -.1.0) - ^ + 2 | let a = -.1.0 + ^ - unary_minus.smu:3.6-7: warning: Unused binding a. + unary_minus.smu:3.5-6: warning: Unused binding a. - 3 | (def a - 1.0) - ^ + 3 | let a = - 1.0 + ^ - unary_minus.smu:4.6-7: warning: Unused binding a. + unary_minus.smu:4.5-6: warning: Unused binding a. - 4 | (def a -. 1.0) - ^ + 4 | let a = -. 1.0 + ^ ; ModuleID = 'context' source_filename = "context" @@ -1255,40 +1255,40 @@ Test 'and', 'or' and 'not' Test unused binding warning $ schmu unused.smu stub.o - unused.smu:2.6-13: warning: Unused binding unused1. + unused.smu:2.5-12: warning: Unused binding unused1. - 2 | (def unused1 0) - ^^^^^^^ + 2 | let unused1 = 0 + ^^^^^^^ - unused.smu:5.6-13: warning: Unused binding unused2. + unused.smu:5.5-12: warning: Unused binding unused2. - 5 | (def unused2 0) - ^^^^^^^ + 5 | let unused2 = 0 + ^^^^^^^ - unused.smu:12.7-18: warning: Unused binding use_unused3. + unused.smu:12.5-16: warning: Unused binding use_unused3. - 12 | (defn use_unused3 () - ^^^^^^^^^^^ + 12 | fun use_unused3(): + ^^^^^^^^^^^ - unused.smu:19.11-18: warning: Unused binding unused4. + unused.smu:17.9-16: warning: Unused binding unused4. - 19 | (def unused4 0) - ^^^^^^^ + 17 | let unused4 = 0 + ^^^^^^^ - unused.smu:23.11-18: warning: Unused binding unused5. + unused.smu:20.9-16: warning: Unused binding unused5. - 23 | (def unused5 0) - ^^^^^^^ + 20 | let unused5 = 0 + ^^^^^^^ - unused.smu:38.13-22: warning: Unused binding usedlater. + unused.smu:33.9-18: warning: Unused binding usedlater. - 38 | (def usedlater 0) - ^^^^^^^^^ + 33 | let usedlater = 0 + ^^^^^^^^^ - unused.smu:52.13-22: warning: Unused binding usedlater. + unused.smu:46.9-18: warning: Unused binding usedlater. - 52 | (def usedlater 0) - ^^^^^^^^^ + 46 | let usedlater = 0 + ^^^^^^^^^ Allow declaring a c function with a different name $ schmu stub.o cname_decl.smu && ./cname_decl @@ -1297,12 +1297,12 @@ Allow declaring a c function with a different name We can have if without else $ schmu if_no_else.smu - if_no_else.smu:2.2-11: error: A conditional without else branch should evaluato to type unit. + if_no_else.smu:2.1-11: error: A conditional without else branch should evaluato to type unit. expecting [unit] but found [int]. - 2 | (if true 2) - ^^^^^^^^^ + 2 | if true: 2 + ^^^^^^^^^^ [1] @@ -1652,14 +1652,14 @@ Ensure global are loadad correctly when passed to functions @schmu_height = constant i64 720 @schmu_world = global %bar zeroinitializer, align 8 - define linkonce_odr void @__g.u_schmu_get-seg_bar.u(%bar* %bar) { + define linkonce_odr void @__g.u_schmu_get_seg_bar.u(%bar* %bar) { entry: ret void } - define void @schmu_wrap-seg() { + define void @schmu_wrap_seg() { entry: - tail call void @__g.u_schmu_get-seg_bar.u(%bar* @schmu_world) + tail call void @__g.u_schmu_get_seg_bar.u(%bar* @schmu_world) ret void } @@ -1671,7 +1671,7 @@ Ensure global are loadad correctly when passed to functions store double 1.000000e-01, double* getelementptr inbounds (%bar, %bar* @schmu_world, i32 0, i32 3), align 8 store double 5.400000e+02, double* getelementptr inbounds (%bar, %bar* @schmu_world, i32 0, i32 4), align 8 store float 5.000000e+00, float* getelementptr inbounds (%bar, %bar* @schmu_world, i32 0, i32 5), align 4 - tail call void @schmu_wrap-seg() + tail call void @schmu_wrap_seg() ret i64 0 } @@ -1733,7 +1733,7 @@ Array push %data = bitcast i8* %14 to i64** %15 = getelementptr inbounds i64*, i64** %data, i64 %3 store i64* %value, i64** %15, align 8 - %add = add i64 1, %3 + %add = add i64 %3, 1 store i64 %add, i64* %.pre-phi, align 8 ret void } @@ -1779,12 +1779,12 @@ Array push %data = bitcast i8* %13 to i64* %14 = getelementptr inbounds i64, i64* %data, i64 %2 store i64 %value, i64* %14, align 8 - %add = add i64 1, %2 + %add = add i64 %2, 1 store i64 %add, i64* %11, align 8 ret void } - define void @schmu_in-fun() { + define void @schmu_in_fun() { entry: %0 = alloca i64*, align 8 %1 = tail call i8* @malloc(i64 32) @@ -1872,7 +1872,7 @@ Array push %5 = load i64*, i64** @schmu_b, align 8 %6 = load i64, i64* %5, align 8 tail call void (i8*, ...) @printf(i8* getelementptr (i8, i8* bitcast ({ i64, i64, [5 x i8] }* @0 to i8*), i64 16), i64 %6) - tail call void @schmu_in-fun() + tail call void @schmu_in_fun() %7 = tail call i8* @malloc(i64 32) %8 = bitcast i8* %7 to i64** store i64** %8, i64*** @schmu_nested, align 8 @@ -2050,14 +2050,14 @@ Decrease ref counts for local variables in if branches source_filename = "context" target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - define i1 @schmu_ret-true() { + define i1 @schmu_ret_true() { entry: ret i1 true } define i64 @main(i64 %arg) { entry: - %0 = tail call i1 @schmu_ret-true() + %0 = tail call i1 @schmu_ret_true() br i1 %0, label %then, label %else then: ; preds = %entry @@ -2304,14 +2304,14 @@ Global lets with expressions @schmu_b = global i64* null, align 8 @schmu_c = global i64 0, align 8 - define void @schmu_ret-none(%option.t_array_int* noalias %0) { + define void @schmu_ret_none(%option.t_array_int* noalias %0) { entry: %1 = bitcast %option.t_array_int* %0 to i8* tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* bitcast (%option.t_array_int* @schmu_a to i8*), i64 16, i1 false) ret void } - define i64 @schmu_ret-rec() { + define i64 @schmu_ret_rec() { entry: %0 = alloca %r_array_int, align 8 %a2 = bitcast %r_array_int* %0 to i64** @@ -2342,7 +2342,7 @@ Global lets with expressions define i64 @main(i64 %arg) { entry: %ret = alloca %option.t_array_int, align 8 - call void @schmu_ret-none(%option.t_array_int* %ret) + call void @schmu_ret_none(%option.t_array_int* %ret) %tag5 = bitcast %option.t_array_int* %ret to i32* %index = load i32, i32* %tag5, align 4 %eq = icmp eq i32 %index, 0 @@ -2372,7 +2372,7 @@ Global lets with expressions %3 = load i64*, i64** %iftmp, align 8 store i64* %3, i64** @schmu_b, align 8 %ret2 = alloca %r_array_int, align 8 - %4 = call i64 @schmu_ret-rec() + %4 = call i64 @schmu_ret_rec() %box = bitcast %r_array_int* %ret2 to i64* store i64 %4, i64* %box, align 8 %5 = inttoptr i64 %4 to i64* @@ -2486,7 +2486,7 @@ Return nonclosure functions ret i64 %add } - define void @schmu_ret-fn(%closure* noalias %0) { + define void @schmu_ret_fn(%closure* noalias %0) { entry: %funptr1 = bitcast %closure* %0 to i8** store i8* bitcast (i64 (i64)* @__fun_schmu0 to i8*), i8** %funptr1, align 8 @@ -2495,7 +2495,7 @@ Return nonclosure functions ret void } - define void @schmu_ret-named(%closure* noalias %0) { + define void @schmu_ret_named(%closure* noalias %0) { entry: %funptr1 = bitcast %closure* %0 to i8** store i8* bitcast (i64 (i64)* @schmu_named to i8*), i8** %funptr1, align 8 @@ -2506,13 +2506,13 @@ Return nonclosure functions define i64 @main(i64 %arg) { entry: - tail call void @schmu_ret-fn(%closure* @schmu_f) + tail call void @schmu_ret_fn(%closure* @schmu_f) %loadtmp = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f, i32 0, i32 0), align 8 %casttmp = bitcast i8* %loadtmp to i64 (i64, i8*)* %loadtmp1 = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f, i32 0, i32 1), align 8 %0 = tail call i64 %casttmp(i64 12, i8* %loadtmp1) tail call void (i8*, ...) @printf(i8* getelementptr (i8, i8* bitcast ({ i64, i64, [5 x i8] }* @0 to i8*), i64 16), i64 %0) - tail call void @schmu_ret-named(%closure* @schmu_f__2) + tail call void @schmu_ret_named(%closure* @schmu_f__2) %loadtmp2 = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f__2, i32 0, i32 0), align 8 %casttmp3 = bitcast i8* %loadtmp2 to i64 (i64, i8*)* %loadtmp4 = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f__2, i32 0, i32 1), align 8 @@ -2587,7 +2587,7 @@ Return closures ret i64 %add } - define void @schmu_ret-fn(%closure* noalias %0, i64 %b) { + define void @schmu_ret_fn(%closure* noalias %0, i64 %b) { entry: %funptr2 = bitcast %closure* %0 to i8** store i8* bitcast (i64 (i64, i8*)* @schmu_bla to i8*), i8** %funptr2, align 8 @@ -2604,7 +2604,7 @@ Return closures ret void } - define void @schmu_ret-lambda(%closure* noalias %0, i64 %b) { + define void @schmu_ret_lambda(%closure* noalias %0, i64 %b) { entry: %funptr2 = bitcast %closure* %0 to i8** store i8* bitcast (i64 (i64, i8*)* @__fun_schmu0 to i8*), i8** %funptr2, align 8 @@ -2640,8 +2640,8 @@ Return closures define i64 @main(i64 %arg) { entry: - tail call void @schmu_ret-fn(%closure* @schmu_f, i64 13) - tail call void @schmu_ret-fn(%closure* @schmu_f2, i64 35) + tail call void @schmu_ret_fn(%closure* @schmu_f, i64 13) + tail call void @schmu_ret_fn(%closure* @schmu_f2, i64 35) %loadtmp = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f, i32 0, i32 0), align 8 %casttmp = bitcast i8* %loadtmp to i64 (i64, i8*)* %loadtmp1 = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f, i32 0, i32 1), align 8 @@ -2652,7 +2652,7 @@ Return closures %loadtmp4 = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f2, i32 0, i32 1), align 8 %1 = tail call i64 %casttmp3(i64 12, i8* %loadtmp4) tail call void (i8*, ...) @printf(i8* getelementptr (i8, i8* bitcast ({ i64, i64, [5 x i8] }* @0 to i8*), i64 16), i64 %1) - tail call void @schmu_ret-lambda(%closure* @schmu_f__2, i64 134) + tail call void @schmu_ret_lambda(%closure* @schmu_f__2, i64 134) %loadtmp5 = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f__2, i32 0, i32 0), align 8 %casttmp6 = bitcast i8* %loadtmp5 to i64 (i64, i8*)* %loadtmp7 = load i8*, i8** getelementptr inbounds (%closure, %closure* @schmu_f__2, i32 0, i32 1), align 8 @@ -2726,22 +2726,22 @@ Take/use not all allocations of a record in tailrec calls target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" %view = type { i8*, i64, i64 } - %parse-result_int = type { i32, %success_int } + %parse_result_int = type { i32, %success_int } %success_int = type { %view, i64 } - %parse-result_view = type { i32, %success_view } + %parse_result_view = type { i32, %success_view } %success_view = type { %view, %view } @schmu_s = global i8* null, align 8 @schmu_inp = global %view zeroinitializer, align 8 @0 = private unnamed_addr constant { i64, i64, [2 x i8] } { i64 1, i64 1, [2 x i8] c" \00" } - declare i1 @prelude_char-equal(i8 %0, i8 %1) + declare i1 @prelude_char_equal(i8 %0, i8 %1) declare i64 @string_len(i8* %0) declare i8 @string_get(i8* %0, i64 %1) - define void @schmu_aux(%parse-result_int* noalias %0, %view* %rem, i64 %cnt) { + define void @schmu_aux(%parse_result_int* noalias %0, %view* %rem, i64 %cnt) { entry: %1 = alloca %view, align 8 %2 = bitcast %view* %1 to i8* @@ -2751,20 +2751,20 @@ Take/use not all allocations of a record in tailrec calls store i1 false, i1* %4, align 1 %5 = alloca i64, align 8 store i64 %cnt, i64* %5, align 8 - %ret = alloca %parse-result_view, align 8 + %ret = alloca %parse_result_view, align 8 br label %rec rec: ; preds = %cont, %entry %6 = phi i1 [ true, %cont ], [ false, %entry ] %7 = phi i64 [ %add, %cont ], [ %cnt, %entry ] - call void @schmu_ch(%parse-result_view* %ret, %view* %1) - %tag8 = bitcast %parse-result_view* %ret to i32* + call void @schmu_ch(%parse_result_view* %ret, %view* %1) + %tag8 = bitcast %parse_result_view* %ret to i32* %index = load i32, i32* %tag8, align 4 %eq = icmp eq i32 %index, 0 br i1 %eq, label %then, label %else then: ; preds = %rec - %data = getelementptr inbounds %parse-result_view, %parse-result_view* %ret, i32 0, i32 1 + %data = getelementptr inbounds %parse_result_view, %parse_result_view* %ret, i32 0, i32 1 %add = add i64 %7, 1 call void @__free_except0_successview(%success_view* %data) br i1 %6, label %call_decr, label %cookie @@ -2787,17 +2787,17 @@ Take/use not all allocations of a record in tailrec calls else: ; preds = %rec %11 = bitcast %view* %1 to i8* - %data1 = getelementptr inbounds %parse-result_view, %parse-result_view* %ret, i32 0, i32 1 - %tag29 = bitcast %parse-result_int* %0 to i32* + %data1 = getelementptr inbounds %parse_result_view, %parse_result_view* %ret, i32 0, i32 1 + %tag29 = bitcast %parse_result_int* %0 to i32* store i32 0, i32* %tag29, align 4 - %data3 = getelementptr inbounds %parse-result_int, %parse-result_int* %0, i32 0, i32 1 + %data3 = getelementptr inbounds %parse_result_int, %parse_result_int* %0, i32 0, i32 1 %rem410 = bitcast %success_int* %data3 to %view* %12 = bitcast %view* %rem410 to i8* call void @llvm.memcpy.p0i8.p0i8.i64(i8* %12, i8* %11, i64 24, i1 false) call void @__copy_view(%view* %rem410) %mtch = getelementptr inbounds %success_int, %success_int* %data3, i32 0, i32 1 store i64 %7, i64* %mtch, align 8 - call void @__free_parse-resultview(%parse-result_view* %ret) + call void @__free_parse_resultview(%parse_result_view* %ret) br i1 %6, label %call_decr5, label %cookie6 call_decr5: ; preds = %else @@ -2812,21 +2812,21 @@ Take/use not all allocations of a record in tailrec calls ret void } - define void @schmu_ch(%parse-result_view* noalias %0, %view* %buf) { + define void @schmu_ch(%parse_result_view* noalias %0, %view* %buf) { entry: %1 = bitcast %view* %buf to i8** %2 = load i8*, i8** %1, align 8 %3 = getelementptr inbounds %view, %view* %buf, i32 0, i32 1 %4 = load i64, i64* %3, align 8 %5 = tail call i8 @string_get(i8* %2, i64 %4) - %6 = tail call i1 @prelude_char-equal(i8 %5, i8 32) + %6 = tail call i1 @prelude_char_equal(i8 %5, i8 32) br i1 %6, label %then, label %else then: ; preds = %entry %7 = bitcast %view* %buf to i8** - %tag8 = bitcast %parse-result_view* %0 to i32* + %tag8 = bitcast %parse_result_view* %0 to i32* store i32 0, i32* %tag8, align 4 - %data = getelementptr inbounds %parse-result_view, %parse-result_view* %0, i32 0, i32 1 + %data = getelementptr inbounds %parse_result_view, %parse_result_view* %0, i32 0, i32 1 %rem9 = bitcast %success_view* %data to %view* %buf110 = bitcast %view* %rem9 to i8** %8 = alloca i8*, align 8 @@ -2841,7 +2841,7 @@ Take/use not all allocations of a record in tailrec calls %sunkaddr = getelementptr inbounds i8, i8* %12, i64 8 %13 = bitcast i8* %sunkaddr to i64* %14 = load i64, i64* %13, align 8 - %add = add i64 1, %14 + %add = add i64 %14, 1 store i64 %add, i64* %start, align 8 %len = getelementptr inbounds %view, %view* %rem9, i32 0, i32 2 %15 = getelementptr inbounds %view, %view* %buf, i32 0, i32 2 @@ -2864,9 +2864,9 @@ Take/use not all allocations of a record in tailrec calls ret void else: ; preds = %entry - %tag512 = bitcast %parse-result_view* %0 to i32* + %tag512 = bitcast %parse_result_view* %0 to i32* store i32 1, i32* %tag512, align 4 - %data6 = getelementptr inbounds %parse-result_view, %parse-result_view* %0, i32 0, i32 1 + %data6 = getelementptr inbounds %parse_result_view, %parse_result_view* %0, i32 0, i32 1 %21 = bitcast %success_view* %data6 to %view* %22 = bitcast %view* %21 to i8* %23 = bitcast %view* %buf to i8* @@ -2876,13 +2876,13 @@ Take/use not all allocations of a record in tailrec calls ret void } - define void @schmu_many-count(%parse-result_int* noalias %0, %view* %buf) { + define void @schmu_many_count(%parse_result_int* noalias %0, %view* %buf) { entry: - tail call void @schmu_aux(%parse-result_int* %0, %view* %buf, i64 0) + tail call void @schmu_aux(%parse_result_int* %0, %view* %buf, i64 0) ret void } - define void @schmu_view-of-string(%view* noalias %0, i8* %str) { + define void @schmu_view_of_string(%view* noalias %0, i8* %str) { entry: %buf1 = bitcast %view* %0 to i8** %1 = alloca i8*, align 8 @@ -2963,15 +2963,15 @@ Take/use not all allocations of a record in tailrec calls ret void } - define linkonce_odr void @__free_parse-resultview(%parse-result_view* %0) { + define linkonce_odr void @__free_parse_resultview(%parse_result_view* %0) { entry: - %tag4 = bitcast %parse-result_view* %0 to i32* + %tag4 = bitcast %parse_result_view* %0 to i32* %index = load i32, i32* %tag4, align 4 %1 = icmp eq i32 %index, 0 br i1 %1, label %match, label %cont match: ; preds = %entry - %data = getelementptr inbounds %parse-result_view, %parse-result_view* %0, i32 0, i32 1 + %data = getelementptr inbounds %parse_result_view, %parse_result_view* %0, i32 0, i32 1 call void @__free_successview(%success_view* %data) br label %cont @@ -2980,7 +2980,7 @@ Take/use not all allocations of a record in tailrec calls br i1 %2, label %match1, label %cont2 match1: ; preds = %cont - %data3 = getelementptr inbounds %parse-result_view, %parse-result_view* %0, i32 0, i32 1 + %data3 = getelementptr inbounds %parse_result_view, %parse_result_view* %0, i32 0, i32 1 %3 = bitcast %success_view* %data3 to %view* call void @__free_view(%view* %3) br label %cont2 @@ -3004,10 +3004,10 @@ Take/use not all allocations of a record in tailrec calls %5 = bitcast i64* %data to i8* %fmt = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %5, i64 %1, i8* getelementptr (i8, i8* bitcast ({ i64, i64, [2 x i8] }* @0 to i8*), i64 16)) store i8* %2, i8** @schmu_s, align 8 - tail call void @schmu_view-of-string(%view* @schmu_inp, i8* %2) - %ret = alloca %parse-result_int, align 8 - call void @schmu_many-count(%parse-result_int* %ret, %view* @schmu_inp) - call void @__free_parse-resulti(%parse-result_int* %ret) + tail call void @schmu_view_of_string(%view* @schmu_inp, i8* %2) + %ret = alloca %parse_result_int, align 8 + call void @schmu_many_count(%parse_result_int* %ret, %view* @schmu_inp) + call void @__free_parse_resulti(%parse_result_int* %ret) call void @__free_view(%view* @schmu_inp) call void @__free_ac(i8** @schmu_s) ret i64 0 @@ -3024,15 +3024,15 @@ Take/use not all allocations of a record in tailrec calls ret void } - define linkonce_odr void @__free_parse-resulti(%parse-result_int* %0) { + define linkonce_odr void @__free_parse_resulti(%parse_result_int* %0) { entry: - %tag4 = bitcast %parse-result_int* %0 to i32* + %tag4 = bitcast %parse_result_int* %0 to i32* %index = load i32, i32* %tag4, align 4 %1 = icmp eq i32 %index, 0 br i1 %1, label %match, label %cont match: ; preds = %entry - %data = getelementptr inbounds %parse-result_int, %parse-result_int* %0, i32 0, i32 1 + %data = getelementptr inbounds %parse_result_int, %parse_result_int* %0, i32 0, i32 1 call void @__free_successi(%success_int* %data) br label %cont @@ -3041,7 +3041,7 @@ Take/use not all allocations of a record in tailrec calls br i1 %2, label %match1, label %cont2 match1: ; preds = %cont - %data3 = getelementptr inbounds %parse-result_int, %parse-result_int* %0, i32 0, i32 1 + %data3 = getelementptr inbounds %parse_result_int, %parse_result_int* %0, i32 0, i32 1 %3 = bitcast %success_int* %data3 to %view* call void @__free_view(%view* %3) br label %cont2 @@ -3240,7 +3240,7 @@ Monomorphization in closures @schmu_arr__2 = global i64* null, align 8 @0 = private unnamed_addr constant { i64, i64, [5 x i8] } { i64 4, i64 4, [5 x i8] c"%li\0A\00" } - declare void @prelude_iter-range(i64 %0, i64 %1, %closure* %2) + declare void @prelude_iter_range(i64 %0, i64 %1, %closure* %2) define linkonce_odr void @__agg.u.u_array_iter_aii.u.u(i64* %arr, %closure* %f) { entry: @@ -3379,10 +3379,10 @@ Monomorphization in closures %env = bitcast { i8*, i8*, i64**, %closure, i64*, i64 }* %clsr___i.u-ag-gg.i-i-g___fun_schmu3_i.u-ai-ii.i-i-i to i8* %envptr = getelementptr inbounds %closure, %closure* %__i.u-ag-gg.i-i-g___fun_schmu3_i.u-ai-ii.i-i-i, i32 0, i32 1 store i8* %env, i8** %envptr, align 8 - call void @prelude_iter-range(i64 %lo, i64 %hi, %closure* %__i.u-ag-gg.i-i-g___fun_schmu3_i.u-ai-ii.i-i-i) + call void @prelude_iter_range(i64 %lo, i64 %hi, %closure* %__i.u-ag-gg.i-i-g___fun_schmu3_i.u-ai-ii.i-i-i) %10 = load i64, i64* %7, align 8 %add = add i64 %10, 1 - call void @__agii.u_array_swap-items_aiii.u(i64** %arr, i64 %add, i64 %hi) + call void @__agii.u_array_swap_items_aiii.u(i64** %arr, i64 %add, i64 %hi) ret i64 %add } @@ -3422,10 +3422,10 @@ Monomorphization in closures %env = bitcast { i8*, i8*, i64**, %closure, i64*, i64 }* %clsr___i.u-ag-gg.i-i-g___fun_schmu0_i.u-ai-ii.i-i-i to i8* %envptr = getelementptr inbounds %closure, %closure* %__i.u-ag-gg.i-i-g___fun_schmu0_i.u-ai-ii.i-i-i, i32 0, i32 1 store i8* %env, i8** %envptr, align 8 - call void @prelude_iter-range(i64 %lo, i64 %hi, %closure* %__i.u-ag-gg.i-i-g___fun_schmu0_i.u-ai-ii.i-i-i) + call void @prelude_iter_range(i64 %lo, i64 %hi, %closure* %__i.u-ag-gg.i-i-g___fun_schmu0_i.u-ai-ii.i-i-i) %10 = load i64, i64* %7, align 8 %add = add i64 %10, 1 - call void @__agii.u_array_swap-items_aiii.u(i64** %arr, i64 %add, i64 %hi) + call void @__agii.u_array_swap_items_aiii.u(i64** %arr, i64 %add, i64 %hi) ret i64 %add } @@ -3529,7 +3529,7 @@ Monomorphization in closures br label %rec } - define linkonce_odr void @__agii.u_array_swap-items_aiii.u(i64** noalias %arr, i64 %i, i64 %j) { + define linkonce_odr void @__agii.u_array_swap_items_aiii.u(i64** noalias %arr, i64 %i, i64 %j) { entry: %eq = icmp eq i64 %i, %j %0 = xor i1 %eq, true @@ -3644,7 +3644,7 @@ Monomorphization in closures %7 = load i64, i64* %i2, align 8 %add = add i64 %7, 1 store i64 %add, i64* %i2, align 8 - tail call void @__agii.u_array_swap-items_aiii.u(i64** %arr1, i64 %add, i64 %j) + tail call void @__agii.u_array_swap_items_aiii.u(i64** %arr1, i64 %add, i64 %j) ret void ifcont: ; preds = %entry @@ -3680,7 +3680,7 @@ Monomorphization in closures %7 = load i64, i64* %i2, align 8 %add = add i64 %7, 1 store i64 %add, i64* %i2, align 8 - tail call void @__agii.u_array_swap-items_aiii.u(i64** %arr1, i64 %add, i64 %j) + tail call void @__agii.u_array_swap_items_aiii.u(i64** %arr1, i64 %add, i64 %j) ret void ifcont: ; preds = %entry @@ -3976,7 +3976,7 @@ Handle partial allocations %f_array_int = type { i64*, i64*, i64* } %t_array_int = type { i64*, i64* } - %tuple_array_int = type { i64* } + %tuple_array_int_int = type { i64*, i64 } define i64* @schmu_inf() { entry: @@ -4030,7 +4030,7 @@ Handle partial allocations ret i64* %14 } - define void @schmu_set-moved() { + define void @schmu_set_moved() { entry: %0 = alloca %t_array_int, align 8 %a12 = bitcast %t_array_int* %0 to i64** @@ -4057,10 +4057,12 @@ Handle partial allocations %data4 = bitcast i8* %6 to i64* store i64 20, i64* %data4, align 8 store i64* %5, i64** %b, align 8 - %7 = alloca %tuple_array_int, align 8 - %"0613" = bitcast %tuple_array_int* %7 to i64** + %7 = alloca %tuple_array_int_int, align 8 + %"0613" = bitcast %tuple_array_int_int* %7 to i64** %8 = load i64*, i64** %a12, align 8 store i64* %8, i64** %"0613", align 8 + %"1" = getelementptr inbounds %tuple_array_int_int, %tuple_array_int_int* %7, i32 0, i32 1 + store i64 0, i64* %"1", align 8 %9 = tail call i8* @malloc(i64 24) %10 = bitcast i8* %9 to i64* %arr7 = alloca i64*, align 8 @@ -4072,7 +4074,7 @@ Handle partial allocations %data10 = bitcast i8* %11 to i64* store i64 20, i64* %data10, align 8 store i64* %10, i64** %a12, align 8 - call void @__free_tup-ai(%tuple_array_int* %7) + call void @__free_tup-ai-i(%tuple_array_int_int* %7) call void @__free_tai(%t_array_int* %0) ret void } @@ -4087,9 +4089,9 @@ Handle partial allocations ret void } - define linkonce_odr void @__free_tup-ai(%tuple_array_int* %0) { + define linkonce_odr void @__free_tup-ai-i(%tuple_array_int_int* %0) { entry: - %1 = bitcast %tuple_array_int* %0 to i64** + %1 = bitcast %tuple_array_int_int* %0 to i64** call void @__free_ai(i64** %1) ret void } @@ -4106,7 +4108,7 @@ Handle partial allocations define i64 @main(i64 %arg) { entry: %0 = tail call i64* @schmu_inf() - tail call void @schmu_set-moved() + tail call void @schmu_set_moved() %1 = alloca i64*, align 8 store i64* %0, i64** %1, align 8 call void @__free_ai(i64** %1) @@ -4124,10 +4126,10 @@ Correct link order for cc flags Check allocs in fixed array $ schmu fixed_array_allocs.smu - fixed_array_allocs.smu:1.6-9: warning: Unused binding arr. + fixed_array_allocs.smu:1.5-8: warning: Unused binding arr. - 1 | (def arr #[#[1 2 3] #[3 4 5]]) - ^^^ + 1 | let arr = #[#[1, 2, 3], #[3, 4, 5]] + ^^^ $ valgrind -q --leak-check=yes --show-reachable=yes ./fixed_array_allocs 3 @@ -4164,25 +4166,25 @@ Const fixed array Using unit values $ schmu unit_values.smu --dump-llvm && valgrind -q --leak-check=yes --show-reachable=yes ./unit_values - unit_values.smu:3.6-7: warning: Unused binding b. + unit_values.smu:3.5-6: warning: Unused binding b. - 3 | (def b (#some a)) - ^ + 3 | let b = Some(a) + ^ - unit_values.smu:8.11-12: warning: Unused binding a. + unit_values.smu:8.8-9: warning: Unused binding a. - 8 | ((#some a) (print "some")) - ^ + 8 | Some(a): print("some") + ^ - unit_values.smu:14.6-7: warning: Unused binding u. + unit_values.smu:14.5-6: warning: Unused binding u. - 14 | (def u t.u) - ^ + 14 | let u = t.u + ^ - unit_values.smu:18.6-8: warning: Unused binding u2. + unit_values.smu:18.5-7: warning: Unused binding u2. - 18 | (def u2 t2.u) - ^^ + 18 | let u2 = t2.u + ^^ ; ModuleID = 'context' source_filename = "context" @@ -4248,7 +4250,7 @@ Using unit values ifcont7: ; preds = %entry, %then2, %else %.pre-phi = phi i64* [ %newcap4, %else ], [ %newcap, %then2 ], [ %1, %entry ] %10 = phi void* [ %9, %else ], [ %6, %then2 ], [ %0, %entry ] - %add = add i64 1, %3 + %add = add i64 %3, 1 store i64 %add, i64* %.pre-phi, align 8 ret void } diff --git a/test/misc.t/simple_typealias.smu b/test/misc.t/simple_typealias.smu index 8ac67064..52a6b93f 100644 --- a/test/misc.t/simple_typealias.smu +++ b/test/misc.t/simple_typealias.smu @@ -1,3 +1,3 @@ -(type foo (raw_ptr u8)) -(external puts (fun foo unit)) +type foo = raw_ptr(u8) +external puts : (foo) -> unit 0 diff --git a/test/misc.t/take_partial_alloc.smu b/test/misc.t/take_partial_alloc.smu index 5b3d2fa7..97b12670 100644 --- a/test/misc.t/take_partial_alloc.smu +++ b/test/misc.t/take_partial_alloc.smu @@ -1,27 +1,28 @@ -(type view {:buf string :start int :len int}) -(type (success 'a) {:rem view :mtch 'a}) -(type (parse-result 'a) ((#ok (success 'a)) (#err view))) +type view = {buf : string, start : int, len : int} +type success('a) = {rem : view, mtch : 'a} +type parse_result('a) = Ok(success('a)) | Err(view) -(defn view-of-string (str) - {:buf (copy str) :start 0 :len (string/len str)}) +fun view_of_string(str): + {buf = copy(str), start = 0, len = String.len(str)} -(defn ch (buf) - (if (char-equal (string/get buf.buf buf.start) ' ') - (#ok {:mtch {@buf :buf (copy buf.buf) :len 1} - :rem {:buf (copy buf.buf) :start (+ 1 buf.start) :len (- buf.len 1)}}) - (#err (copy buf)))) +fun ch(buf): + if char_equal(String.get(buf.buf, buf.start), ' '): + Ok({mtch = {buf with buf = copy(buf.buf), len = 1}, + rem = {buf = copy(buf.buf), start = buf.start + 1, len = buf.len - 1}}) + else: + Err(copy(buf)) -(defn many-count (buf) - (defn aux (rem cnt) - (match (ch rem) - ((#ok r) - -- r.rem is moved out of the result. - -- The mtch part is still alive and needs to be freed - (aux r.rem (+ cnt 1))) - ((#err _) (#ok {:rem (copy rem) :mtch cnt})))) - (aux buf 0)) +fun many_count(buf): + fun aux(rem, cnt): + match ch(rem): + Ok(r): + -- r.rem is moved out of the result. + -- The mtch part is still alive and needs to be freed + aux(r.rem, cnt + 1) + Err(_): Ok({rem = copy(rem), mtch = cnt}) + aux(buf, 0) -(def s (fmt-str " ")) +let s = fmt(" ") -(def inp (view-of-string s)) -(ignore (many-count inp)) +let inp = view_of_string(s) +ignore(many_count(inp)) diff --git a/test/misc.t/take_partial_alloc_reorder.smu b/test/misc.t/take_partial_alloc_reorder.smu index 313f654c..cebc057a 100644 --- a/test/misc.t/take_partial_alloc_reorder.smu +++ b/test/misc.t/take_partial_alloc_reorder.smu @@ -1,28 +1,28 @@ -(type view {:buf string :start int :len int}) -(type (success 'a) {:rem view :mtch 'a}) -(type (parse-result 'a) ((#ok (success 'a)) (#err view))) +type view = {buf : string, start : int, len : int} +type success('a) = {rem : view, mtch : 'a} +type parse_result('a) = Ok(success('a)) | Err(view) -(defn view-of-string (str) - {:buf (copy str) :start 0 :len (string/len str)}) +fun view_of_string(str): + {buf = copy(str), start = 0, len = String.len(str)} -(defn ch (buf) - (if (char-equal (string/get buf.buf buf.start) ' ') - (#ok {:mtch {@buf :buf (copy buf.buf) :len 1} - :rem {:buf (copy buf.buf) :start (+ 1 buf.start) :len (- buf.len 1)}}) - (#err (copy buf)))) +fun ch(buf): + if char_equal(String.get(buf.buf, buf.start), ' '): + Ok({mtch = {buf with buf = copy(buf.buf), len = 1}, + rem = {buf = copy(buf.buf), start = buf.start + 1, len = buf.len - 1}}) + else: + Err(copy(buf)) -(defn many-count (buf) - (defn aux (rem cnt) - (match (ch rem) - ((#err _) (#ok {:rem (copy rem) :mtch cnt})) - ((#ok r) - -- r.rem is moved out of the result. - -- The mtch part is still alive and needs to be freed - (aux r.rem (+ cnt 1))) - )) - (aux buf 0)) +fun many_count(buf): + fun aux(rem, cnt): + match ch(rem): + Err(_): Ok({rem = copy(rem), mtch = cnt}) + Ok(r): + -- r.rem is moved out of the result. + -- The mtch part is still alive and needs to be freed + aux(r.rem, cnt + 1) + aux(buf, 0) -(def s (fmt-str " ")) +let s = fmt(" ") -(def inp (view-of-string s)) -(ignore (many-count inp)) +let inp = view_of_string(s) +ignore(many_count(inp)) diff --git a/test/misc.t/unary_minus.smu b/test/misc.t/unary_minus.smu index 1384b96c..5b2b9522 100644 --- a/test/misc.t/unary_minus.smu +++ b/test/misc.t/unary_minus.smu @@ -1,9 +1,9 @@ -(def a -1.0) -(def a -.1.0) -(def a - 1.0) -(def a -. 1.0) +let a = -1.0 +let a = -.1.0 +let a = - 1.0 +let a = -. 1.0 -(def a - 1) -(def b -1) +let a = - 1 +let b = -1 -(+ a b) +a + b diff --git a/test/misc.t/unit_values.smu b/test/misc.t/unit_values.smu index 1a79d1cf..85a2ddde 100644 --- a/test/misc.t/unit_values.smu +++ b/test/misc.t/unit_values.smu @@ -1,34 +1,34 @@ -- variants -(def a ()) -(def b (#some a)) +let a = () +let b = Some(a) -(defn a () ()) -(def b (#some (a))) -(match b - ((#some a) (print "some")) - (#none (print "none"))) +fun a(): () +let b = Some(a()) +match b: + Some(a): print("some") + None: print("none") -- records -(type thing {:u unit}) -(def t {:u ()}) -(def u t.u) +type thing = {u : unit} +let t = { u = () } +let u = t.u -(defn t () {:u ()}) -(def t2 (t)) -(def u2 t2.u) +fun t(): {u = ()} +let t2 = t() +let u2 = t2.u -(type inrec {:i int :u unit :f float}) -(def t {:i 10 :u () :f 99.9}) -(ignore t.u) -(print (fmt-str t.f)) +type inrec = {i : int, u : unit, f : float} +let t = {i = 10, u = (), f = 99.9} +ignore(t.u) +print(fmt(t.f)) -- arrays -(def arr& [() ()]) -(array/push &arr !()) -(print (fmt-str (array/length arr))) -(ignore {:u arr.[2]}) +let arr& = [(), ()] +Array.push(&arr, !()) +print(fmt(Array.length(arr))) +ignore({u = arr.[2]}) -- fixed arrays -(def arr #[() ()]) -(def u arr.(1)) -(ignore {:u}) +let arr = #[(), ()] +let u = arr#[1] +ignore({u}) diff --git a/test/misc.t/unused.smu b/test/misc.t/unused.smu index 2d075250..1e4f1fae 100644 --- a/test/misc.t/unused.smu +++ b/test/misc.t/unused.smu @@ -1,53 +1,48 @@ -- default unused -(def unused1 0) +let unused1 = 0 -- will be shadowed before usage -(def unused2 0) -(def unused2 0) -(ignore unused2) +let unused2 = 0 +let unused2 = 0 +ignore(unused2) -- use in closure -(def used3 0) +let used3 = 0 -(defn use_unused3 () +fun use_unused3(): -- TODO Should we mark this as used only if the function is used? - (ignore used3)) - -(ignore - (if true - (do - (def unused4 0) - 0) - - (do - (def unused5 0) - 0))) - -(if true - (do - (def used1 0) - (ignore used1)) - (do - (def used2 0) - (ignore used2))) - -(ignore - (if true - -- unused here, should be warned - (do - (def usedlater 0) - 0) - (do - (def usedlater 0) - (ignore usedlater) - 0))) - -(ignore - (if true - (do - (def usedlater 0) - (ignore usedlater) - 0) - (do -- unused here, should be warned - (def usedlater 0) - 0))) + ignore(used3) + +ignore(if true: + let unused4 = 0 + 0 +else: + let unused5 = 0 + 0 +) + +if true: + let used1 = 0 + ignore(used1) +else: + let used2 = 0 + ignore(used2) + +ignore(if true: + -- unused here, should be warned + let usedlater = 0 + 0 +else: + let usedlater = 0 + ignore(usedlater) + 0 +) + +ignore(if true: + let usedlater = 0 + ignore(usedlater) + 0 +else: + let usedlater = 0 + 0 +) diff --git a/test/misc.t/upward_mut.smu b/test/misc.t/upward_mut.smu index 78da3053..82ef50af 100644 --- a/test/misc.t/upward_mut.smu +++ b/test/misc.t/upward_mut.smu @@ -1,23 +1,25 @@ -(type c {:c& int}) +type c = {c& : int} -(defn counter () - (def cnt& 0) - (fn () (set &cnt !(+ cnt 1)) - cnt)) +fun counter(): + let cnt& = 0 + fun (): + &cnt <- cnt + 1 + cnt -(def c (counter)) -(print (fmt-str (c))) -(print (fmt-str (c))) -(print (fmt-str (c))) -(print (fmt-str (c))) +let c = counter() +print(fmt(c())) +print(fmt(c())) +print(fmt(c())) +print(fmt(c())) -(defn counter () - (def cnt& {:c 0}) - (fn () (set &cnt !{:c (+ (.c cnt) 1)}) - cnt)) +fun counter(): + let cnt& = {c = 0} + fun (): + &cnt <- {c = cnt.c + 1} + cnt -(def c (counter)) -(print (fmt-str (.c (c)))) -(print (fmt-str (.c (c)))) -(print (fmt-str (.c (c)))) -(print (fmt-str (.c (c)))) +let c = counter() +print(fmt(c().c)) +print(fmt(c().c)) +print(fmt(c().c)) +print(fmt(c().c))