From: Christian Neukirchen Date: 2006-04-27T06:09:01+09:00 Subject: Re: Rake task dependeny vs. method call Joel VanderWerf writes: > Trans wrote: >> Just for fun I put together this simple demonstration. > > This _is_ kind of fun. Your demo suggests that maybe rake and dependency > injection can be unified somehow.... For example, using my favorite DI toy: Funnily, it's exactly the way I've implemented my experimental Rake clone in Forth. Enjoy: #! /usr/bin/env gforth \ Fake - Forth Make \ A cheap clone of (proto-)Rake. \ \ Copyright (C) 2006 Christian Neukirchen \ Licensed under the same terms as Rake. (MIT-style) \ Missing: - incremental task building \ - file tasks \ \ For file tasks, one would need to make the trigger big enough to \ keep a file name and the mtime. This is left as an exercise for the \ reader. \ A version of sh that is compilable. (Rather useless without \ variable interpolation.) :noname sh ; :noname 35 parse postpone sliteral postpone 2dup postpone type postpone cr \ Display command postpone system ; \ Run command interpret/compile: sh$ \ Late binding : $ ( name -- ) parse-word postpone sliteral postpone evaluate ; immediate variable last-trigger \ The address of the last defined trigger. : new-trigger ( -- ) \ Allocate, zero and store a new trigger. here cell allot last-trigger ! 0 last-trigger @ ! ; : trigger ( -- a ) \ Compile the address of the current trigger. last-trigger @ postpone literal ; immediate : trigger! ( a -- ) \ Set the retrieved trigger. 1 swap ! ; : triggered? ( a -- ? ) \ Task run? @ 0= ; : task: ( name -- ) \ Define a new task new-trigger : postpone trigger postpone triggered? postpone IF postpone trigger postpone trigger! ; immediate : ;task ( -- ) \ End of task postpone THEN postpone ; ; immediate : run-tasks ( -- ) argc @ 2 > IF argc @ 2 DO i arg evaluate \ Call all tasks. LOOP ELSE ." fake: No task given." cr THEN ; : load-fakefile ( -- ) TRY s" Fakefile" included RECOVER ." fake: No Fakefile found." cr bye ENDTRY ; load-fakefile run-tasks bye An example fakefile: task: bla $ quux ." hey, bla!" cr ;task task: quux $ bla ." hey, quux!" cr ;task task: a $ b sh$ echo a ;task task: b $ a $ c $ d sh$ echo b ;task task: c $ b $ a sh$ echo c ;task task: d $ b sh$ echo d ;task Example run: #580<5|>lilith:~/mess/2006/09$ ./fake.f a echo c c echo d d echo b b echo a a -- Christian Neukirchen http://chneukirchen.org