Paste: namespaces2
Author: | erg |
Mode: | factor |
Date: | Fri, 4 Mar 2016 02:50:48 |
Plain Text |
USING: accessors arrays assocs hashtables kernel kernel.private
math sequences vectors ;
IN: namespaces2
<PRIVATE
TUPLE: global-hashtable
{ boxes hashtable read-only } ;
TUPLE: global-box value ;
: (box-at)
boxes>> [ drop f global-box boa ] cache ; foldable
: box-at
(box-at) { global-box } declare ; inline
M: global-hashtable at*
boxes>> at* [
{ global-box } declare value>> t
] [ drop f f ] if ; inline
M: global-hashtable set-at
box-at value<< ; inline
M: global-hashtable delete-at
box-at f swap value<< ; inline
: (get-namestack)
CONTEXT-OBJ-NAMESTACK context-object { vector } declare ; inline
: (set-namestack)
CONTEXT-OBJ-NAMESTACK set-context-object ; inline
: >n (get-namestack) push ;
: ndrop (get-namestack) pop* ;
PRIVATE>
: global
OBJ-GLOBAL special-object { global-hashtable } declare ; foldable
: namespace (get-namestack) last ; inline
: get-namestack (get-namestack) clone ;
: set-namestack >vector (set-namestack) ;
: init-namespaces global 1array set-namestack ;
: get-global global box-at value>> ; inline
: set-global global set-at ; inline
: change-global
[ [ get-global ] keep ] dip dip set-global ; inline
: counter [ 0 or 1 + dup ] change-global ; inline
: initialize [ unless* ] curry change-global ; inline
ERROR: get-failed variable hashtable ;
ERROR: set-failed obj variable hashtable ;
ERROR: change-failed variable hashtable ;
: ensure-get-at 2dup last key? [ get-failed ] unless ;
: ensure-set-at 2dup key? [ set-failed ] unless ;
: ensure-change's-get-at 2dup last key? [ change-failed ] unless ;
: get (get-namestack) ensure-get-at assoc-stack ; inline
: change's-get (get-namestack) ensure-change's-get-at assoc-stack ; inline
: set namespace ensure-set-at set-at ;
: change [ [ change's-get ] keep ] dip dip set ; inline
: on t swap set ; inline
: off f swap set ; inline
: toggle [ not ] change ; inline
: +@ [ 0 or + ] change ; inline
: inc 1 swap +@ ; inline
: dec -1 swap +@ ; inline
: with-variables swap >n call ndrop ; inline
: with-scope 5 <hashtable> swap with-variables ; inline
: with-variable [ associate ] dip with-variables ; inline
: with-global [ global ] dip with-variables ; inline
/*
erg@erglinux:~/factor/basis/compiler$ find . -type f -print0 | xargs -0 sed -i 's/namespaces/namespaces2/g'
erg@erglinux:~/factor/basis/compiler$ find . -type f -print0 | xargs -0 sed -i 's/namespaces2/namespaces/g'
disable-optimizer
f2
erg@erglinux:~/factor/basis/compiler$ find . -type f -print0 | xargs -0 sed -i 's/insn-classes get/insn-classes get-global/g'
*/
New Annotation