mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-17 08:27:45 +03:00
Add remaining implements declarations
This commit is contained in:
parent
f13a2fdd9d
commit
26131f2b1c
@ -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))
|
||||
|
@ -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")
|
||||
|
@ -47,6 +47,7 @@
|
||||
(set! eq false)
|
||||
(break))))
|
||||
eq)))
|
||||
(implements = StaticArray.=)
|
||||
|
||||
(doc empty? "checks whether the array `a` is empty.")
|
||||
(defn empty? [a]
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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"))
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user