From 26131f2b1c0bc27157ebf8553fbc089dbdcf69bc Mon Sep 17 00:00:00 2001 From: Scott Olsen Date: Sun, 10 May 2020 22:53:35 -0400 Subject: [PATCH] Add remaining implements declarations --- core/Double.carp | 1 + core/SDL.carp | 6 ++++++ core/StaticArray.carp | 1 + core/Vector.carp | 7 +++++++ test-for-errors/no_matching_instance.carp | 4 +++- test-for-errors/trick_resolution.carp | 4 ++-- .../no_matching_instance.carp.output.expected | 2 +- test/reload.carp | 3 ++- 8 files changed, 23 insertions(+), 5 deletions(-) diff --git a/core/Double.carp b/core/Double.carp index 0711ed44..2f7b671e 100644 --- a/core/Double.carp +++ b/core/Double.carp @@ -2,6 +2,7 @@ (defmodule Double (def pi 3.141592653589793) + (implements pi Double.pi) (def e 2.718281828459045) (register MAX Double "CARP_DBL_MAX") (register = (Fn [Double Double] Bool)) diff --git a/core/SDL.carp b/core/SDL.carp index b087c357..10cea1bb 100644 --- a/core/SDL.carp +++ b/core/SDL.carp @@ -76,6 +76,8 @@ (set! events (Array.push-back events e))) events)) + (implements = SDL.Event.=) + (implements copy SDL.Event.copy) ) ;; Rendering @@ -117,10 +119,14 @@ (defn = [a b] (Int.= (enum-to-int (the SDL_Keycode a)) (enum-to-int (the SDL_Keycode b)))) + (implements = SDL.Keycode.=) (register copy (Fn [(Ref SDL_Keycode)] SDL_Keycode)) + (implements copy SDL.Keycode.copy) (register str (Fn [SDL_Keycode] String)) + (implements str SDL.Keycode.str) (defn prn [x] (SDL.Keycode.str x)) + (implements prn SDL.Keycode.prn) (register return SDL_Keycode "SDLK_RETURN") (register space SDL_Keycode "SDLK_SPACE") diff --git a/core/StaticArray.carp b/core/StaticArray.carp index 2efacabe..aacbb6b2 100644 --- a/core/StaticArray.carp +++ b/core/StaticArray.carp @@ -47,6 +47,7 @@ (set! eq false) (break)))) eq))) + (implements = StaticArray.=) (doc empty? "checks whether the array `a` is empty.") (defn empty? [a] diff --git a/core/Vector.carp b/core/Vector.carp index bddc48fe..880f9ca1 100644 --- a/core/Vector.carp +++ b/core/Vector.carp @@ -14,9 +14,11 @@ (defn zero [] (init (zero) (zero))) + (implements zero Vector2.zero) (defn random [] (init (random-0-1) (random-0-1))) + (implements random Vector2.random) (defn add [a b] (zip + a b)) @@ -34,6 +36,7 @@ (defn = [a b] (vreduce (fn [i v] (and i v)) true &(zip = a b))) + (implements = Vector2.=) (doc vapprox "Check whether the vectors a and b are approximately equal.") (defn vapprox [a b] @@ -116,12 +119,15 @@ (defn zero [] (init (zero) (zero) (zero))) + (implements zero Vector3.zero) (defn random [] (init (random-0-1) (random-0-1) (random-0-1))) + (implements random Vector3.random) (defn = [a b] (vreduce (fn [i v] (and i v)) true &(zip = a b))) + (implements = Vector3.=) (doc vapprox "Check whether the vectors a and b are approximately equal.") (defn vapprox [a b] @@ -231,6 +237,7 @@ (defn = [a b] (and (Int.= @(n a) @(n b)) (Array.= (v a) (v b)))) + (implements = VectorN.=) (defn add [a b] (zip + a b)) diff --git a/test-for-errors/no_matching_instance.carp b/test-for-errors/no_matching_instance.carp index 732af4c8..4f1e60ad 100644 --- a/test-for-errors/no_matching_instance.carp +++ b/test-for-errors/no_matching_instance.carp @@ -4,7 +4,9 @@ (definterface some-interface (Fn [a] Bool)) ;; A module implements it, accepting Int:s -(defmodule A (defn some-interface [x] (Int.= x 1))) +(defmodule A + (defn some-interface [x] (Int.= x 1)) + (implements some-interface A.some-interface)) ;; The function 'f' uses the interface, should still have a generic type though. (defn f [x] (some-interface x)) diff --git a/test-for-errors/trick_resolution.carp b/test-for-errors/trick_resolution.carp index 9dfeb887..771d2e10 100644 --- a/test-for-errors/trick_resolution.carp +++ b/test-for-errors/trick_resolution.carp @@ -2,7 +2,7 @@ ;; This shouldn't resolve! (definterface blurgh (Fn [a] Bool)) -(defmodule A (defn blurgh [x] (Int.= x 1))) -(defmodule B (defn blurgh [x] (Float.= x 1.0f))) +(defmodule A (defn blurgh [x] (Int.= x 1)) (implements blurgh A.blurgh)) +(defmodule B (defn blurgh [x] (Float.= x 1.0f)) (implements blurgh B.blurgh)) (defn f [x] (blurgh x)) (defn g [] (f "hello")) diff --git a/test/output/test-for-errors/no_matching_instance.carp.output.expected b/test/output/test-for-errors/no_matching_instance.carp.output.expected index 6e6854b7..33d8892e 100644 --- a/test/output/test-for-errors/no_matching_instance.carp.output.expected +++ b/test/output/test-for-errors/no_matching_instance.carp.output.expected @@ -1,3 +1,3 @@ -no_matching_instance.carp:10:14 Can't find matching lookup for symbol 'some-interface' of type (λ [Float] Bool) +no_matching_instance.carp:12:14 Can't find matching lookup for symbol 'some-interface' of type (λ [Float] Bool) None of the possibilities have the correct signature: A.some-interface : (λ [Int] Bool) diff --git a/test/reload.carp b/test/reload.carp index 7a23fd73..4a609620 100644 --- a/test/reload.carp +++ b/test/reload.carp @@ -9,7 +9,8 @@ (defmodule Foo (defn = [a b] - (= (Foo.x a) (Foo.x b)))) + (= (Foo.x a) (Foo.x b))) + (implements = Foo.=)) ;;(deftype (Foo t) [x t]) ;; <- this was the bug, simulate a reload of deftype