start on more methodical test file for runtime, going through all the cases

This commit is contained in:
Paul Chiusano 2019-03-05 14:54:19 -05:00
parent 4ef4f1c064
commit e5bf2f0e13
3 changed files with 127 additions and 1 deletions

View File

@ -0,0 +1,126 @@
-- This file is meant to test all the cases of the runtime.
-- Tests in this file should be as small as possible.
-- LITERALS
ln = 10
li = +10
lf = 10.0
lt = "text"
lb = true
sn = [1,2,3,4,5,6,ln]
-- Make sure we can compile all literals
> (ln, li, lf, lt, lb, sn)
-- LET
c0 =
a = 1000
b = 100
c = 10
d = 1
[a + b + c + d, b + c + d, c + d, d]
-- Make sure we can push values onto the stack and reference them as expected
> c0
-- FUNCTION APPLICATION. There are several cases to check:
-- * Exact application, underapplication, overapplication
-- * Closure formation (used by data types and builtins) vs specialization
-- * Overapplication yielding a request
fn p1 p2 p3 p4 = [p1, p2, p3, p4]
exact =
p1 = 1
p2 = 2
fn p1 p2 3 4
underapply0 =
f = fn 1
f 2 3 4
underapply1 =
f = fn 1 2
f 3 4
underapply2 =
f = fn 1 2 3
f 4
fn2 p1 p2 =
f p3 p4 = [p1, p2] ++ [p3, p4]
f
exact1 =
f = fn2 1 2
f 3 4
overapply1 = fn2 1 2 3 4
overapply2 =
f = fn2 1 2 3
f 4
overapplyN =
id x = x
id id id id id 99
> (exact, underapply0, underapply1, underapply2, exact1, overapply1, overapply2)
> overapplyN
-- Now check exact and underapply cases for constructors
type Woot = Woot Nat Nat Nat Nat
use Woot Woot
exactt = Woot 1 2 3 4
underapply0t =
p1 = 1
f = Woot p1
f 2 3 4
underapply1t =
p2 = 2
f = Woot 1 p2
f 3 4
underapply2t =
f = Woot 1 2 3
f 4
> (exactt, underapply0t, underapply1t, underapply2t)
-- Now check overapply cases for abilities
ability Zing where
zing : Nat -> {Zing} (Nat -> Nat)
zing2 : Nat -> Nat ->{Zing} (Nat -> Nat -> [Nat])
handler z = case z of
{a} -> a
{Zing.zing n -> k} -> handle handler in k (x -> x `drop` n)
{Zing.zing2 n1 n2 -> k} -> handle handler in k (n3 n4 -> [n1, n2, n3, n4])
exacth = handle handler in
f = Zing.zing 3
f 20 + 1
overapplyh = handle handler in
Zing.zing 3 20 + 1
overapplyh2 = handle handler in
Zing.zing2 1 2 3 4
overapplyh3a = handle handler in
Zing.zing2 1 2 3 4 ++ [5]
-- overapplyh3b = handle handler in Zing.zing2 1 2 3 4 ++ [5, Zing.zing 2 8]
-- overapplyh3c = handle handler in Zing.zing2 1 2 3 4 ++ [5, Zing.zing 2 7 + 1]
> (exacth, overapplyh, overapplyh2, overapplyh3a)
--

View File

@ -13,5 +13,4 @@ ex = handle (state 10) in
State.put (5 + 5)
"hello"
-- returns () for some reason!!!
> ex

View File

@ -0,0 +1 @@
"hello"