define-compound

cvs
Slava Pestov 2004-08-19 23:36:28 +00:00
parent 8623011d35
commit 192dd6c5a6
6 changed files with 25 additions and 11 deletions

View File

@ -146,6 +146,7 @@ public class FactorSideKickParser extends SideKickParser
parsed = parsed.next(); parsed = parsed.next();
} }
if(last != null)
last.end = buffer.createPosition(buffer.getLength()); last.end = buffer.createPosition(buffer.getLength());
} //}}} } //}}}

View File

@ -3,6 +3,7 @@
! $Id$ ! $Id$
! !
! Copyright (C) 2003 Slava Pestov. ! Copyright (C) 2003 Slava Pestov.
! Copyright (C) 2004 Chris Double.
! !
! Redistribution and use in source and binary forms, with or without ! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met: ! modification, are permitted provided that the following conditions are met:
@ -101,3 +102,8 @@ USE: stack
: compound>list ( worddef -- list ) : compound>list ( worddef -- list )
worddef>list dup [ skip-docs ] when ; worddef>list dup [ skip-docs ] when ;
: define-compound ( word def -- )
#! Define a compound word at runtime.
>r dup >r [ "vocabulary" get "name" get ] bind r> r>
<compound> define ;

View File

@ -81,7 +81,7 @@ USE: unparser
#! End a word definition. #! End a word definition.
nreverse nreverse
"cross-compiling" get "cross-compiling" get
[ compound, ] [ define ] ifte ; parsing [ compound, ] [ define-compound ] ifte ; parsing
! Vocabularies ! Vocabularies
: DEFER: CREATE drop ; parsing : DEFER: CREATE drop ; parsing

View File

@ -48,6 +48,12 @@ USE: stack
: primitive? ( obj -- ? ) : primitive? ( obj -- ? )
dup word? [ word-primitive 1 = not ] [ drop f ] ifte ; dup word? [ word-primitive 1 = not ] [ drop f ] ifte ;
: define-compound ( word def -- )
#! Define a compound word at runtime.
over set-word
over set-word-parameter
1 swap set-word-primitive ;
! Various features not supported by native Factor. ! Various features not supported by native Factor.
: comment? drop f ; : comment? drop f ;
: worddef>list word-parameter ; : worddef>list word-parameter ;
@ -61,12 +67,3 @@ IN: kernel
: set-word ( word -- ) : set-word ( word -- )
global [ "last-word" set ] bind ; global [ "last-word" set ] bind ;
IN: builtins
: define ( word definition -- )
#! Unlike the Java interpreter primitive define, the
#! definition parameter is a list.
over set-word
over set-word-parameter
1 swap set-word-primitive ;

View File

@ -78,6 +78,7 @@ USE: unparser
"prettyprint" "prettyprint"
"inspector" "inspector"
"vectors" "vectors"
"words"
"unparser" "unparser"
"random" "random"
"math/bitops" "math/bitops"

View File

@ -0,0 +1,9 @@
IN: scratchpad
USE: arithmetic
USE: test
USE: words
[ 4 ] [
"poo" "scratchpad" create [ 2 2 + ] define-compound
"poo" [ "scratchpad" ] search execute
] unit-test