Paste: References in literals

Author: j
Mode: factor
Date: Thu, 29 Apr 2010 23:14:53
Plain Text |
diff --git a/basis/literals/literals.factor b/basis/literals/literals.factor
index 42a7ab9..f3c3085 100644
--- a/basis/literals/literals.factor
+++ b/basis/literals/literals.factor
@@ -1,6 +1,7 @@
-! (c) Joe Groff, see license for details
-USING: accessors combinators continuations fry kernel lexer
-math parser quotations sequences vectors words words.alias ;
+! (c)2010 Joe Groff bsd license
+USING: accessors arrays assocs combinators continuations fry kernel lexer
+math namespaces parser quotations sequences vectors words words.alias ;
+FROM: kernel.private => become ;
 IN: literals
 
 <PRIVATE
@@ -19,8 +20,34 @@ IN: literals
 : expand-literals ( seq -- seq' )
     [ [ { } ] dip expand-literal ] map concat ;
 
+SYMBOLS: references reference-placeholders ;
+references [ H{ } clone ] initialize
+reference-placeholders [ H{ } clone ] initialize
+
+TUPLE: reference-placeholder < identity-tuple name ;
+
+: reference-placeholder ( name -- placeholder )
+    reference-placeholders get [ \ reference-placeholder boa ] cache ;
+
+: reference ( name -- reference )
+    references get ?at [ reference-placeholder ] unless ;
+
+: reify-placeholder ( value name -- )
+    [ reference-placeholders get at [ swap [ 1array ] bi@ become ] [ drop ] if* ]
+    [ reference-placeholders get delete-at ] bi ;
+
+: make-reference ( value name -- )
+    [ reify-placeholder ]
+    [ references get set-at ] 2bi ;
+
 PRIVATE>
 
+SYNTAX: >##
+    dup last scan make-reference ;
+
+SYNTAX: ##
+    scan reference suffix! ;
+
 SYNTAX: $ scan-word expand-literal >vector ;
 SYNTAX: $[ parse-quotation with-datastack >vector ;
 SYNTAX: ${ \ } [ expand-literals ] parse-literal ;

New Annotation

Summary:
Author:
Mode:
Body: