1. Kink Programming Language
  2. Untitled project
  3. kink

Commits

Taku Miyakawa  committed 06447d0

Moves _internal/EXACT module to TYPED module

  • Participants
  • Parent commits 074709e
  • Branches default

Comments (0)

Files changed (12)

File src/main/java/org/kink_lang/kink/internal/BaseMethods.java

View file
 import org.kink_lang.kink.Fun;
 import org.kink_lang.kink.SetSite;
 import org.kink_lang.kink.ValueList;
-import org.kink_lang.kink.Modules;
 import org.kink_lang.kink.KinkException;
 import org.kink_lang.kink.Define;
 import org.kink_lang.kink.Receiver;
     }
 
 
-    /** GetSite of {@code into}. */
-    private static final GetSite INTO = new GetSite( "into" );
-
-
-    /** GetSite of {@code exactly_typed}. */
-    private static final GetSite EXACTLY_TYPED = new GetSite( "exactly_typed" );
-
-
-    @Define
-    public Value exactly_into( @Receiver Value receiver , Value classVal ) {
-        Value converted = receiver.call( INTO , classVal );
-        Value mod = Modules.find( "_internal/EXACT" );
-        return mod.tailCall( EXACTLY_TYPED , converted , classVal );
-    }
-
-
     @Define
     public Value op_eq( @Receiver Value receiver , Value another ) {
         return Value.value( receiver == another );

File src/main/kink/TYPED.kn

View file
+#! kink
+# vim: et sw=4 sts=4
+
+# Copyright (c) 2013 Miyakawa Taku
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+:exactly_typed = { (:Value :Class)
+    typed(Class Value.into(Class))
+}
+
+:typed = { (:Class :Converted)
+    Converted.child(
+        'can_into?' { \0 == Class }
+        'show' {
+            expand('typed(#{Class.show} #{Converted.show})')
+        }
+    )
+}

File src/main/kink/_internal/EXACT.kn

-#! kink
-# vim: et sw=4 sts=4
-
-# Copyright (c) 2013 Miyakawa Taku
-# 
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-:exactly_typed = { (:Value :Class)
-    _cast(Value.into(Class) Class)
-}
-
-:_cast = { (:Converted :Class)
-    Converted.child(
-        'can_into?' { \0 == Class }
-        'show' {
-            expand('#{Converted.show}.exactly_into(#{Class.show})')
-        }
-    )
-}

File src/test/java/org/kink_lang/kink/internal/BaseMethodsTest.java

View file
 
 
     // }}}1
-    // Tests VALUE.into, can_into?, exactly_into {{{1
-
-
-    /** GetSite of {@code exactly_into}. */
-    private static final GetSite EXACTLY_INTO = new GetSite( "exactly_into" );
-
-
-    /** GetSite of {@code into}. */
-    private static final GetSite INTO = new GetSite( "into" );
-
+    // Tests VALUE.into, can_into? {{{1
 
     /** GetSite of {@code can_into?}. */
     private static final GetSite CAN_INTO_P = new GetSite( "can_into?" );
 
-
-    @Test
-    public void can_create_java_value_with_a_strict_type() {
-        Value typed = Value.value( 42 ).call( EXACTLY_INTO , Value.value( int.class ) );
-        Value notTyped = typed.call( INTO , Value.value( int.class ) );
-        assertThat( notTyped.as( Integer.class , "" ) , is( 42 ) );
-        assertThat( typed.call( CAN_INTO_P , Value.value( int.class ) ).asBool( "" )
-                , is( true ) );
-    }
-
-
-    @Test
-    public void long_to_int_strictly() {
-        Value typed = Value.value( 42L ).call( EXACTLY_INTO , Value.value( int.class ) );
-        Value notTyped = typed.call( INTO , Value.value( int.class ) );
-        assertThat( notTyped.as( Integer.class , "" ) , is( 42 ) );
-        assertThat( typed.call( CAN_INTO_P , Value.value( int.class ) ).asBool( "" )
-                , is( true ) );
-    }
-
-
-    @Test
-    public void decide_whether_convertible_to_java_or_not_for_exactly_typed_value() {
-        Value num = Value.value( 42 ).call( EXACTLY_INTO , Value.value( int.class ) );
-        assertThat( num.call( CAN_INTO_P , Value.value( Integer.class ) ).asBool( "" )
-                , is( false ) );
-        assertThat( num.call( CAN_INTO_P , Value.value( int.class ) ).asBool( "" )
-                , is( true ) );
-        assertThat( num.call( CAN_INTO_P , Value.value( Number.class ) ).asBool( "" )
-                , is( false ) );
-        assertThat( num.call( CAN_INTO_P , Value.value( Object.class ) ).asBool( "" )
-                , is( false ) );
-        assertThat( num.call( CAN_INTO_P , Value.value( String.class ) ).asBool( "" )
-                , is( false ) );
-    }
-
-
-    @Test
-    public void can_create_exactly_typed_java_value() {
-        Value typed = Value.value( 42 ).call( EXACTLY_INTO , Value.value( int.class ) );
-        Value canJava = typed.call( CAN_INTO_P , Value.value( int.class ) );
-        assertThat( canJava.asBool( "" ) , is( true ) );
-        Value orig = typed.call( INTO , Value.value( int.class ) );
-        assertThat( orig.as( Integer.class , "" ) , is( 42 ) );
-    }
-
-
     @Test
     public void base_value_cannot_be_converted_to_any_class() {
         assertThat( Value.base().call( CAN_INTO_P , Value.value( Integer.class ) ).asBool( "" )

File src/test/kink/TYPED_test.kn

View file
+#! kink
+# vim: et sw=4 sts=4
+
+# Copyright (c) 2013 Miyakawa Taku
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+use('TYPED.typed')
+use('TEST.test')
+use('CHECK.check_thrown')
+
+test {
+    use('JAVA.int')
+    use('java.lang.String')
+    use('java.lang.Object')
+    typed(String 'foobar').can_into?(String).check(true)
+    typed(String 'foobar').can_into?(Object).check(false)
+    typed(String 'foobar').can_into?(int).check(false)
+}
+
+test {
+    use('JAVA.int')
+    use('java.lang.String')
+    use('java.lang.Object')
+    typed(Object 'foobar').can_into?(String).check(false)
+    typed(Object 'foobar').can_into?(Object).check(true)
+    typed(Object 'foobar').can_into?(int).check(false)
+}
+
+test {
+    use('java.lang.String')
+    typed(String 'foobar').into(String).check('foobar')
+}
+
+test {
+    use('java.lang.String')
+    typed(String 'foobar').show.check(expand("typed(#{String.show} 'foobar')"))
+}

File src/test/kink/_internal/EXACT_test.kn

-#! kink
-# vim: et sw=4 sts=4
-
-# Copyright (c) 2013 Miyakawa Taku
-# 
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-use('_internal/EXACT.exactly_typed')
-use('TEST.test')
-use('CHECK.check_thrown')
-
-test {
-    use('JAVA.int')
-    use('java.lang.String')
-    use('java.lang.Object')
-    exactly_typed('foobar' String).can_into?(String).check(true)
-    exactly_typed('foobar' String).can_into?(Object).check(false)
-    exactly_typed('foobar' String).can_into?(int).check(false)
-}
-
-test {
-    use('JAVA.int')
-    use('java.lang.String')
-    use('java.lang.Object')
-    exactly_typed('foobar' Object).can_into?(String).check(false)
-    exactly_typed('foobar' Object).can_into?(Object).check(true)
-    exactly_typed('foobar' Object).can_into?(int).check(false)
-}
-
-test {
-    use('java.lang.String')
-    exactly_typed('foobar' String).into(String).check('foobar')
-}
-
-test {
-    use('java.lang.String')
-    exactly_typed('foobar' String).show.check(expand("'foobar'.exactly_into(#{String.show})"))
-}

File src/test/kink/issue/issue_0009_test.kn

-#! kink
-# vim: et sw=4 sts=4
-
-# Copyright (c) 2013 Miyakawa Taku
-# 
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-use('TEST.test')
-use('COMMON_PATTERN.instance_of')
-
-# Tests issue 9
-# http://code.google.com/p/kink-lang/issues/detail?id=9
-test {
-    use('java.math.BigInteger')
-    :Num = 100
-    Num.can_into?(BigInteger).check(true)
-    :Bignum = Num.exactly_into(BigInteger)
-    Bignum.check(instance_of(BigInteger))
-    Bignum.check(BigInteger.valueOf(100))
-}

File src/test/kink/issue/issue_0075_test.kn

View file
 use('JAVA.int')
 use('JAVA.float')
 use('JAVA.double')
-use( 'org.kink_lang.kink.TypeOf' )
-use( 'java.lang.Double' )
-use( 'java.lang.Float' )
-use( 'java.lang.Integer' )
+use('TYPED.typed')
+use('org.kink_lang.kink.TypeOf')
+use('java.lang.Double')
+use('java.lang.Float')
+use('java.lang.Integer')
 
 # Tests issue #75
 # http://code.google.com/p/kink-lang/issues/detail?id=75
 
 test {
     use('JAVA.null')
-    TypeOf.typeOf(3.14.exactly_into(double)).check('double')
-    TypeOf.typeOf(3.14.exactly_into(float)).check('float')
-    TypeOf.typeOf(3.14.exactly_into(Double)).check('java.lang.Double')
-    TypeOf.typeOf(3.14.exactly_into(Float)).check('java.lang.Float')
-    TypeOf.typeOf(null.exactly_into(Double)).check('java.lang.Double')
-    TypeOf.typeOf(null.exactly_into(Float)).check('java.lang.Float')
+    TypeOf.typeOf(typed(double 3.14)).check('double')
+    TypeOf.typeOf(typed(float 3.14)).check('float')
+    TypeOf.typeOf(typed(Double 3.14)).check('java.lang.Double')
+    TypeOf.typeOf(typed(Float 3.14)).check('java.lang.Float')
+    TypeOf.typeOf(typed(Double null)).check('java.lang.Double')
+    TypeOf.typeOf(typed(Float null)).check('java.lang.Float')
 }
 
 test {
-    :Num = 42.exactly_into(int)
+    :Num = typed(int 42)
     Num.can_into?(Integer).check(false)
 }
 

File src/test/kink/issue/issue_0133_test.kn

View file
 
 test {
     use('org.kink_lang.kink.ValueList')
-    ['twift' 'voxxx'].exactly_into(ValueList).check(['twift' 'voxxx'])
+    ['twift' 'voxxx'].into(ValueList).check(['twift' 'voxxx'])
 }

File src/test/kink/issue/issue_0143_test.kn

View file
 use('TEST.test')
 use('COMMON_PATTERN.ne')
 use('JAVA.int')
+use('TYPED.typed')
 
 test {
     use('java.lang.Object')
     :List = [100 200 300 300 200 100]
     :Java_list = AbstractList.new_with(
         'size' { () List.count }
-        'get' { (:Index) List.get(Index).exactly_into(int) }
+        'get' { (:Index) List.get(Index) }
         ['remove' int] { (:Index)
             List.pop(Index)
         }
             Removed?
         }
     )
-    Java_list.remove(300.exactly_into(Object))
+    Java_list.remove(typed(Object 300))
     Java_list.list.check([100 200 200 100])
-    Java_list.remove(0.exactly_into(int))
+    Java_list.remove(typed(int 0))
     Java_list.list.check([200 200 100])
 }

File src/test/kink/spec/cast_operator_test.kn

-#!/usr/bin/env kink
-# vim: et sw=4 sts=4
-
-# Copyright (c) 2013 Miyakawa Taku
-# 
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-# Issue 165: Cast operator
-# http://code.google.com/p/kink-lang/issues/detail?id=165
-
-use('TEST.test')
-
-test {
-    use('JAVA.int')
-    use('java.util.ArrayList')
-    use('java.lang.Object')
-    :Array_list = ArrayList.new
-    eval('Array_list.add(10.exactly_into(int).exactly_into(Object))')
-    eval('Array_list.add(20.exactly_into(int).exactly_into(Object))')
-    eval('Array_list.add(30.exactly_into(int).exactly_into(Object))')
-    eval('Array_list.add(40.exactly_into(int).exactly_into(Object))')
-    eval('Array_list.remove(40.exactly_into(Object))')
-    eval('Array_list.remove(0.exactly_into(int))')
-    Array_list.list.check([20 30])
-}

File src/test/kink/spec/number_operation_test.kn

View file
 use('TEST.test')
 use('TEST.test_group')
 use('SEQ')
+use('TYPED.typed')
 use('JAVA.long')
 use('java.lang.Long')
 use('java.math.BigDecimal')
     SEQ.cross(Nums Nums).loop { ([:X :Y])
         :Operations = ['op_add' 'op_sub' 'op_mul' 'op_div' 'op_intdiv' 'op_rem' 'op_cmp']
         Operations.loop { (:Operation)
-            :Xdecimal = BigDecimal.valueOf(X.exactly_into(long))
-            :Ydecimal = BigDecimal.valueOf(Y.exactly_into(long))
+            :Xdecimal = BigDecimal.valueOf(typed(long X))
+            :Ydecimal = BigDecimal.valueOf(typed(long Y))
             test(expand('(#X).#Operation(#Y)')) {
                 X.var(Operation).call(Y).check(Xdecimal.var(Operation).call(Ydecimal))
             }