Adding call( -- )

db4
Daniel Ehrenberg 2009-02-08 22:39:22 -06:00
parent b65b88364c
commit af9f5112d4
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,10 @@
! Copyright (C) 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: math tools.test call kernel ;
IN: call.tests
[ 3 ] [ 1 2 [ + ] call( x y -- z ) ] unit-test
[ 1 2 [ + ] call( -- z ) ] must-fail
[ 1 2 [ + ] call( x y -- z a ) ] must-fail
[ 1 2 3 { 4 } ] [ 1 2 3 4 [ datastack nip ] call( x -- y ) ] unit-test
[ [ + ] call( x y -- z ) ] must-infer

24
basis/call/call.factor Normal file
View File

@ -0,0 +1,24 @@
! Copyright (C) 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel macros fry summary sequences generalizations accessors
continuations effects.parser parser ;
IN: call
ERROR: wrong-values values quot length-required ;
M: wrong-values summary
drop "Wrong number of values returned from quotation" ;
<PRIVATE
: firstn-safe ( array quot n -- ... )
3dup nip swap length = [ nip firstn ] [ wrong-values ] if ; inline
PRIVATE>
MACRO: call-effect ( effect -- quot )
[ in>> length ] [ out>> length ] bi
'[ [ _ narray ] dip [ with-datastack ] keep _ firstn-safe ] ;
: call(
")" parse-effect parsed \ call-effect parsed ; parsing