Skip to content

Commit

Permalink
Pass misc tests again
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Jan 14, 2024
1 parent e553253 commit c962df1
Show file tree
Hide file tree
Showing 46 changed files with 868 additions and 894 deletions.
4 changes: 2 additions & 2 deletions lib/codegen/helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand All @@ -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")
Expand Down
66 changes: 33 additions & 33 deletions test/misc.t/abi.smu
Original file line number Diff line number Diff line change
@@ -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}))
16 changes: 8 additions & 8 deletions test/misc.t/array_drop_back.smu
Original file line number Diff line number Diff line change
@@ -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)))
41 changes: 20 additions & 21 deletions test/misc.t/array_push.smu
Original file line number Diff line number Diff line change
@@ -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]
14 changes: 7 additions & 7 deletions test/misc.t/assert.smu
Original file line number Diff line number Diff line change
@@ -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")
116 changes: 63 additions & 53 deletions test/misc.t/boolean_logic.smu
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion test/misc.t/borrow_string_lit.smu
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(ignore (if true "ok" "err"))
ignore(if true: "ok" else: "err")
45 changes: 22 additions & 23 deletions test/misc.t/capture_record_pattern.smu
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit c962df1

Please sign in to comment.