Unit test fixes
parent
e2c86aab4d
commit
6814e07f49
|
@ -351,18 +351,12 @@ M: curry '
|
||||||
: emit-words ( -- )
|
: emit-words ( -- )
|
||||||
all-words [ emit-word ] each ;
|
all-words [ emit-word ] each ;
|
||||||
|
|
||||||
: fix-source-files
|
|
||||||
[
|
|
||||||
clone dup source-file-definitions H{ } clone 2array
|
|
||||||
over set-source-file-definitions
|
|
||||||
] assoc-map ;
|
|
||||||
|
|
||||||
: emit-global ( -- )
|
: emit-global ( -- )
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
dictionary source-files
|
dictionary source-files
|
||||||
typemap builtins class<map update-map
|
typemap builtins class<map update-map
|
||||||
} [ dup get swap [ source-files eq? [ fix-source-files ] when ] keep bootstrap-word set ] each
|
} [ dup get swap bootstrap-word set ] each
|
||||||
] H{ } make-assoc
|
] H{ } make-assoc
|
||||||
bootstrap-global set
|
bootstrap-global set
|
||||||
bootstrap-global emit-userenv ;
|
bootstrap-global emit-userenv ;
|
||||||
|
|
|
@ -77,15 +77,6 @@ HELP: compile-failed
|
||||||
{ $values { "word" word } { "error" "an error" } }
|
{ $values { "word" word } { "error" "an error" } }
|
||||||
{ $description "Called when the optimizing compiler fails to compile a word. The word is removed from the set of words pending compilation, and it's un-optimized compiled definition will be used. The error is reported by calling " { $link compile-error } "." } ;
|
{ $description "Called when the optimizing compiler fails to compile a word. The word is removed from the set of words pending compilation, and it's un-optimized compiled definition will be used. The error is reported by calling " { $link compile-error } "." } ;
|
||||||
|
|
||||||
HELP: forget-errors
|
|
||||||
{ $values { "seq" "a sequence of words" } }
|
|
||||||
{ $description "If any of the words in the sequence previously failed to compile, removes the marker indicating such."
|
|
||||||
$nl
|
|
||||||
"The compiler remembers which words failed to compile as an optimization, so that it does not try to infer the stack effect of words which do not have one over and over again." }
|
|
||||||
{ $notes "Usually this word does not need to be called directly; if a word failed to compile because of a stack effect error, fixing the word definition clears the flag automatically. However, if words failed to compile due to external factors which were subsequently rectified, such as an unavailable C library or a missing or broken compiler transform, this flag can be cleared for all words:"
|
|
||||||
{ $code "all-words forget-errors" }
|
|
||||||
"Subsequent invocations of the compiler will consider all words for compilation." } ;
|
|
||||||
|
|
||||||
HELP: compile-batch
|
HELP: compile-batch
|
||||||
{ $values { "seq" "a sequence of words" } }
|
{ $values { "seq" "a sequence of words" } }
|
||||||
{ $description "Compiles a batch of words. Any compile errors are summarized at the end and can be viewed with " { $link :warnings } " and " { $link :errors } "." } ;
|
{ $description "Compiles a batch of words. Any compile errors are summarized at the end and can be viewed with " { $link :warnings } " and " { $link :errors } "." } ;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
! Copyright (C) 2004, 2007 Slava Pestov.
|
! Copyright (C) 2004, 2007 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel namespaces arrays sequences io inference.backend
|
USING: kernel namespaces arrays sequences io inference.backend
|
||||||
generator debugger math.parser prettyprint words continuations
|
generator debugger math.parser prettyprint words words.private
|
||||||
vocabs assocs alien.compiler dlists optimizer definitions ;
|
continuations vocabs assocs alien.compiler dlists optimizer
|
||||||
|
definitions ;
|
||||||
IN: compiler
|
IN: compiler
|
||||||
|
|
||||||
SYMBOL: compiler-hook
|
SYMBOL: compiler-hook
|
||||||
|
@ -45,14 +46,14 @@ SYMBOL: compiler-hook
|
||||||
H{ } clone compiled-xts set
|
H{ } clone compiled-xts set
|
||||||
[ queue-compile ] each
|
[ queue-compile ] each
|
||||||
compile-queue get [ (compile) ] dlist-slurp
|
compile-queue get [ (compile) ] dlist-slurp
|
||||||
compiled-xts get finish-compilation-unit
|
compiled-xts get >alist modify-code-heap
|
||||||
] with-scope ; inline
|
] with-scope ; inline
|
||||||
|
|
||||||
: compile-quot ( quot -- word )
|
: compile-quot ( quot -- word )
|
||||||
[ gensym dup rot define-compound ] with-compilation-unit ;
|
[ define-temp ] with-compilation-unit ;
|
||||||
|
|
||||||
: compile-call ( quot -- )
|
: compile-call ( quot -- )
|
||||||
compile-quot execute ;
|
compile-quot execute ;
|
||||||
|
|
||||||
: compile-all ( -- )
|
: compile-all ( -- )
|
||||||
all-words compile-batch ;
|
all-words compile ;
|
||||||
|
|
|
@ -99,12 +99,6 @@ unit-test
|
||||||
"int" { "int" "int" "int" "int" } "stdcall" alien-indirect
|
"int" { "int" "int" "int" "int" } "stdcall" alien-indirect
|
||||||
data-gc ;
|
data-gc ;
|
||||||
|
|
||||||
! This is a hack -- words are compiled before top-level forms
|
|
||||||
! run.
|
|
||||||
|
|
||||||
DEFER: >> delimiter
|
|
||||||
: << \ >> parse-until >quotation call ; parsing
|
|
||||||
|
|
||||||
<< "f-stdcall" f "stdcall" add-library >>
|
<< "f-stdcall" f "stdcall" add-library >>
|
||||||
|
|
||||||
[ f ] [ "f-stdcall" load-library ] unit-test
|
[ f ] [ "f-stdcall" load-library ] unit-test
|
||||||
|
|
|
@ -7,9 +7,11 @@ M: combination-1 perform-combination 2drop { } [ ] each [ ] ;
|
||||||
|
|
||||||
SYMBOL: generic-1
|
SYMBOL: generic-1
|
||||||
|
|
||||||
generic-1 T{ combination-1 } define-generic
|
[
|
||||||
|
generic-1 T{ combination-1 } define-generic
|
||||||
|
|
||||||
[ ] <method> object \ generic-1 define-method
|
[ ] <method> object \ generic-1 define-method
|
||||||
|
] with-compilation-unit
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
[
|
[
|
||||||
|
|
|
@ -85,6 +85,6 @@ SYMBOL: recompile-hook
|
||||||
H{ } clone changed-words set
|
H{ } clone changed-words set
|
||||||
<definitions> new-definitions set
|
<definitions> new-definitions set
|
||||||
<definitions> old-definitions set
|
<definitions> old-definitions set
|
||||||
call
|
[ changed-words get keys recompile-hook get call ] [ ]
|
||||||
changed-words get keys recompile-hook get call
|
cleanup
|
||||||
] with-scope ; inline
|
] with-scope ; inline
|
||||||
|
|
|
@ -22,7 +22,6 @@ SYMBOL: compiled-xts
|
||||||
: compiling? ( word -- ? )
|
: compiling? ( word -- ? )
|
||||||
{
|
{
|
||||||
{ [ dup compiled-xts get key? ] [ drop t ] }
|
{ [ dup compiled-xts get key? ] [ drop t ] }
|
||||||
{ [ dup word-changed? ] [ drop f ] }
|
|
||||||
{ [ t ] [ compiled? ] }
|
{ [ t ] [ compiled? ] }
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,11 @@ M: debug-combination perform-combination
|
||||||
|
|
||||||
SYMBOL: redefinition-test-generic
|
SYMBOL: redefinition-test-generic
|
||||||
|
|
||||||
redefinition-test-generic T{ debug-combination } define-generic
|
[
|
||||||
|
redefinition-test-generic
|
||||||
|
T{ debug-combination }
|
||||||
|
define-generic
|
||||||
|
] with-compilation-unit
|
||||||
|
|
||||||
TUPLE: redefinition-test-tuple ;
|
TUPLE: redefinition-test-tuple ;
|
||||||
|
|
||||||
|
|
|
@ -139,3 +139,11 @@ HELP: dataflow-with
|
||||||
{ $values { "quot" "a quotation" } { "stack" "a vector" } { "dataflow" "a dataflow node" } }
|
{ $values { "quot" "a quotation" } { "stack" "a vector" } { "dataflow" "a dataflow node" } }
|
||||||
{ $description "Attempts to construct a dataflow graph showing stack flow in the quotation, starting with an initial data stack of values." }
|
{ $description "Attempts to construct a dataflow graph showing stack flow in the quotation, starting with an initial data stack of values." }
|
||||||
{ $errors "Throws an " { $link inference-error } " if stack effect inference fails." } ;
|
{ $errors "Throws an " { $link inference-error } " if stack effect inference fails." } ;
|
||||||
|
|
||||||
|
HELP: forget-errors
|
||||||
|
{ $description "Removes markers indicating which words do not have stack effects."
|
||||||
|
$nl
|
||||||
|
"The stack effect inference code remembers which words failed to infer as an optimization, so that it does not try to infer the stack effect of words which do not have one over and over again." }
|
||||||
|
{ $notes "Usually this word does not need to be called directly; if a word failed to compile because of a stack effect error, fixing the word definition clears the flag automatically. However, if words failed to compile due to external factors which were subsequently rectified, such as an unavailable C library or a missing or broken compiler transform, this flag can be cleared for all words:"
|
||||||
|
{ $code "forget-errors" }
|
||||||
|
"Subsequent invocations of the compiler will consider all words for compilation." } ;
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
IN: inference
|
IN: inference
|
||||||
USING: inference.backend inference.dataflow
|
USING: inference.backend inference.dataflow
|
||||||
inference.known-words inference.transforms inference.errors
|
inference.known-words inference.transforms inference.errors
|
||||||
sequences prettyprint io effects kernel namespaces quotations ;
|
sequences prettyprint io effects kernel namespaces quotations
|
||||||
|
words vocabs ;
|
||||||
|
|
||||||
GENERIC: infer ( quot -- effect )
|
GENERIC: infer ( quot -- effect )
|
||||||
|
|
||||||
|
@ -26,5 +27,5 @@ M: callable dataflow-with
|
||||||
f infer-quot
|
f infer-quot
|
||||||
] with-infer nip ;
|
] with-infer nip ;
|
||||||
|
|
||||||
: forget-errors ( seq -- )
|
: forget-errors ( -- )
|
||||||
[ f "no-effect" set-word-prop ] each ;
|
all-words [ f "no-effect" set-word-prop ] each ;
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
USING: io io.streams.string listener tools.test parser
|
USING: io io.streams.string io.streams.duplex listener
|
||||||
math namespaces continuations vocabs ;
|
tools.test parser math namespaces continuations vocabs kernel ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
|
||||||
: hello "Hi" print ; parsing
|
: hello "Hi" print ; parsing
|
||||||
|
|
||||||
|
: parse-interactive ( string -- quot )
|
||||||
|
<string-reader> stream-read-quot ;
|
||||||
|
|
||||||
[ [ ] ] [
|
[ [ ] ] [
|
||||||
"USE: temporary hello" <string-reader> parse-interactive
|
"USE: temporary hello" parse-interactive
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -17,11 +20,10 @@ IN: temporary
|
||||||
[
|
[
|
||||||
"cont" set
|
"cont" set
|
||||||
[
|
[
|
||||||
"\\ + 1 2 3 4"
|
"\\ + 1 2 3 4" parse-interactive
|
||||||
<string-reader>
|
"cont" get continue-with
|
||||||
parse-interactive "cont" get continue-with
|
|
||||||
] catch
|
] catch
|
||||||
":1" eval
|
"USE: debugger :1" eval
|
||||||
] callcc1
|
] callcc1
|
||||||
] unit-test
|
] unit-test
|
||||||
] with-scope
|
] with-scope
|
||||||
|
@ -31,10 +33,14 @@ IN: temporary
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
"USE: vocabs.loader.test.c" <string-reader>
|
"USE: vocabs.loader.test.c" parse-interactive
|
||||||
parse-interactive
|
|
||||||
] unit-test-fails
|
] unit-test-fails
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
"vocabs.loader.test.c" forget-vocab
|
"vocabs.loader.test.c" forget-vocab
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ ] [
|
||||||
|
"IN: temporary : hello\n\"world\" ;" parse-interactive
|
||||||
|
drop
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -15,7 +15,9 @@ SYMBOL: listener-hook
|
||||||
GENERIC: stream-read-quot ( stream -- quot/f )
|
GENERIC: stream-read-quot ( stream -- quot/f )
|
||||||
|
|
||||||
: read-quot-step ( lines -- quot/f )
|
: read-quot-step ( lines -- quot/f )
|
||||||
[ parse-lines ] catch {
|
[
|
||||||
|
[ parse-lines in get ] with-compilation-unit in set
|
||||||
|
] catch {
|
||||||
{ [ dup delegate unexpected-eof? ] [ 2drop f ] }
|
{ [ dup delegate unexpected-eof? ] [ 2drop f ] }
|
||||||
{ [ dup not ] [ drop ] }
|
{ [ dup not ] [ drop ] }
|
||||||
{ [ t ] [ rethrow ] }
|
{ [ t ] [ rethrow ] }
|
||||||
|
@ -36,10 +38,7 @@ M: line-reader stream-read-quot
|
||||||
M: duplex-stream stream-read-quot
|
M: duplex-stream stream-read-quot
|
||||||
duplex-stream-in stream-read-quot ;
|
duplex-stream-in stream-read-quot ;
|
||||||
|
|
||||||
: read-quot ( -- quot )
|
: read-quot ( -- quot ) stdio get stream-read-quot ;
|
||||||
[
|
|
||||||
stdio get stream-read-quot in get
|
|
||||||
] with-compilation-unit in set ;
|
|
||||||
|
|
||||||
: bye ( -- ) quit-flag on ;
|
: bye ( -- ) quit-flag on ;
|
||||||
|
|
||||||
|
|
|
@ -385,3 +385,11 @@ IN: temporary
|
||||||
natural-sort
|
natural-sort
|
||||||
] unit-test
|
] unit-test
|
||||||
] with-scope
|
] with-scope
|
||||||
|
|
||||||
|
[ ] [
|
||||||
|
"IN: temporary USE: kernel PREDICATE: object foo ( x -- y ) ;" eval
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
"foo?" "temporary" lookup word eq?
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -221,7 +221,7 @@ PREDICATE: unexpected unexpected-eof
|
||||||
: CREATE-CLASS ( -- word )
|
: CREATE-CLASS ( -- word )
|
||||||
scan in get create
|
scan in get create
|
||||||
dup save-class-location
|
dup save-class-location
|
||||||
dup predicate-word save-location ;
|
dup predicate-word dup set-word save-location ;
|
||||||
|
|
||||||
: word-restarts ( possibilities -- restarts )
|
: word-restarts ( possibilities -- restarts )
|
||||||
natural-sort [
|
natural-sort [
|
||||||
|
|
|
@ -113,9 +113,9 @@ unit-test
|
||||||
use [ clone ] change
|
use [ clone ] change
|
||||||
|
|
||||||
[
|
[
|
||||||
parse-lines drop
|
[ parse-fresh drop ] with-compilation-unit
|
||||||
[
|
[
|
||||||
"USE: temporary \\ " swap " see" 3append eval
|
"temporary" lookup see
|
||||||
] string-out "\n" split 1 head*
|
] string-out "\n" split 1 head*
|
||||||
] keep =
|
] keep =
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
|
@ -73,15 +73,15 @@ uses definitions ;
|
||||||
|
|
||||||
M: pathname where pathname-string 1 2array ;
|
M: pathname where pathname-string 1 2array ;
|
||||||
|
|
||||||
: forget-source ( path -- )
|
M: pathname forget
|
||||||
[
|
pathname-string
|
||||||
dup source-file
|
dup source-file
|
||||||
dup unxref-source
|
dup unxref-source
|
||||||
source-file-definitions [ keys forget-all ] each
|
source-file-definitions [ keys forget-all ] each
|
||||||
source-files get delete-at
|
source-files get delete-at ;
|
||||||
] with-compilation-unit ;
|
|
||||||
|
|
||||||
M: pathname forget pathname-string forget-source ;
|
: forget-source ( path -- )
|
||||||
|
[ <pathname> forget ] with-compilation-unit ;
|
||||||
|
|
||||||
: rollback-source-file ( source-file -- )
|
: rollback-source-file ( source-file -- )
|
||||||
dup source-file-definitions new-definitions get [ union ] 2map
|
dup source-file-definitions new-definitions get [ union ] 2map
|
||||||
|
|
|
@ -45,7 +45,7 @@ C: <point> point
|
||||||
100 200 <point> "p" set
|
100 200 <point> "p" set
|
||||||
|
|
||||||
! Use eval to sequence parsing explicitly
|
! Use eval to sequence parsing explicitly
|
||||||
"IN: temporary TUPLE: point x y z ; do-parse-hook" eval
|
"IN: temporary TUPLE: point x y z ;" eval
|
||||||
|
|
||||||
[ 100 ] [ "p" get point-x ] unit-test
|
[ 100 ] [ "p" get point-x ] unit-test
|
||||||
[ 200 ] [ "p" get point-y ] unit-test
|
[ 200 ] [ "p" get point-y ] unit-test
|
||||||
|
@ -53,7 +53,7 @@ C: <point> point
|
||||||
|
|
||||||
300 "p" get "set-point-z" "temporary" lookup execute
|
300 "p" get "set-point-z" "temporary" lookup execute
|
||||||
|
|
||||||
"IN: temporary TUPLE: point z y ; do-parse-hook" eval
|
"IN: temporary TUPLE: point z y ;" eval
|
||||||
|
|
||||||
[ "p" get point-x ] unit-test-fails
|
[ "p" get point-x ] unit-test-fails
|
||||||
[ 200 ] [ "p" get point-y ] unit-test
|
[ 200 ] [ "p" get point-y ] unit-test
|
||||||
|
@ -216,46 +216,37 @@ SYMBOL: not-a-tuple-class
|
||||||
[ not-a-tuple-class construct-boa ] unit-test-fails
|
[ not-a-tuple-class construct-boa ] unit-test-fails
|
||||||
[ not-a-tuple-class construct-empty ] unit-test-fails
|
[ not-a-tuple-class construct-empty ] unit-test-fails
|
||||||
|
|
||||||
! Reshaping bug. It's only an issue when optimizer compiler is
|
TUPLE: erg's-reshape-problem a b c ;
|
||||||
! enabled.
|
|
||||||
parse-hook get [
|
|
||||||
TUPLE: erg's-reshape-problem a b c ;
|
|
||||||
|
|
||||||
C: <erg's-reshape-problem> erg's-reshape-problem
|
C: <erg's-reshape-problem> erg's-reshape-problem
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
"IN: temporary TUPLE: erg's-reshape-problem a b c d ;" eval
|
|
||||||
] unit-test
|
|
||||||
|
|
||||||
|
|
||||||
[ 1 2 ] [
|
|
||||||
! <erg's-reshape-problem> hasn't been recompiled yet, so
|
! <erg's-reshape-problem> hasn't been recompiled yet, so
|
||||||
! we just created a tuple using an obsolete layout
|
! we just created a tuple using an obsolete layout
|
||||||
1 2 3 <erg's-reshape-problem>
|
"IN: temporary USE: namespaces TUPLE: erg's-reshape-problem a b c d ; 1 2 3 <erg's-reshape-problem> \"a\" set" eval
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ 1 2 ] [
|
||||||
! that's ok, but... this shouldn't fail:
|
! that's ok, but... this shouldn't fail:
|
||||||
"IN: temporary TUPLE: erg's-reshape-problem a b d c ;" eval
|
"IN: temporary TUPLE: erg's-reshape-problem a b d c ;" eval
|
||||||
|
|
||||||
|
"a" get
|
||||||
{ erg's-reshape-problem-a erg's-reshape-problem-b }
|
{ erg's-reshape-problem-a erg's-reshape-problem-b }
|
||||||
get-slots
|
get-slots
|
||||||
] unit-test
|
] unit-test
|
||||||
] when
|
|
||||||
|
|
||||||
! We want to make sure constructors are recompiled when
|
! We want to make sure constructors are recompiled when
|
||||||
! tuples are reshaped
|
! tuples are reshaped
|
||||||
: cons-test-1 \ erg's-reshape-problem construct-empty ;
|
: cons-test-1 \ erg's-reshape-problem construct-empty ;
|
||||||
: cons-test-2 \ erg's-reshape-problem construct-boa ;
|
: cons-test-2 \ erg's-reshape-problem construct-boa ;
|
||||||
: cons-test-3
|
: cons-test-3
|
||||||
{ erg's-reshape-problem-a }
|
{ set-erg's-reshape-problem-a }
|
||||||
\ erg's-reshape-problem construct ;
|
\ erg's-reshape-problem construct ;
|
||||||
|
|
||||||
"IN: temporary TUPLE: erg's-reshape-problem a b c d e f ;" eval
|
"IN: temporary TUPLE: erg's-reshape-problem a b c d e f ;" eval
|
||||||
|
|
||||||
[ t ] [
|
[ ] [ 1 2 3 4 5 6 cons-test-2 "a" set ] unit-test
|
||||||
{
|
|
||||||
<erg's-reshape-problem>
|
[ t ] [ cons-test-1 array-capacity "a" get array-capacity = ] unit-test
|
||||||
cons-test-1
|
|
||||||
cons-test-2
|
[ t ] [ 1 cons-test-3 array-capacity "a" get array-capacity = ] unit-test
|
||||||
cons-test-3
|
|
||||||
} [ changed-words get key? ] all?
|
|
||||||
] unit-test
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ IN: temporary
|
||||||
"resource:core/vocabs/loader/test/a/a.factor"
|
"resource:core/vocabs/loader/test/a/a.factor"
|
||||||
source-file source-file-definitions dup USE: prettyprint .
|
source-file source-file-definitions dup USE: prettyprint .
|
||||||
"v-l-t-a-hello" "vocabs.loader.test.a" lookup dup .
|
"v-l-t-a-hello" "vocabs.loader.test.a" lookup dup .
|
||||||
swap key?
|
swap first key?
|
||||||
] unit-test
|
] unit-test
|
||||||
] times
|
] times
|
||||||
|
|
||||||
|
@ -93,7 +93,9 @@ IN: temporary
|
||||||
[ 1 ] [ "count-me" get-global ] unit-test
|
[ 1 ] [ "count-me" get-global ] unit-test
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
|
[
|
||||||
"bob" "vocabs.loader.test.b" create [ ] define-compound
|
"bob" "vocabs.loader.test.b" create [ ] define-compound
|
||||||
|
] with-compilation-unit
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ ] [ "vocabs.loader.test.b" refresh ] unit-test
|
[ ] [ "vocabs.loader.test.b" refresh ] unit-test
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
USING: namespaces parser ;
|
USING: namespaces parser ;
|
||||||
IN: vocabs.loader.test.a
|
IN: vocabs.loader.test.a
|
||||||
|
|
||||||
: COUNT-ME global [ "count-me" inc ] bind ; parsing
|
<< global [ "count-me" inc ] bind >>
|
||||||
|
|
||||||
COUNT-ME
|
|
||||||
|
|
||||||
: v-l-t-a-hello 4 ;
|
: v-l-t-a-hello 4 ;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
USING: namespaces ;
|
USING: namespaces ;
|
||||||
IN: vocabs.loader.test.b
|
IN: vocabs.loader.test.b
|
||||||
|
|
||||||
: COUNT-ME global [ "count-me" inc ] bind ; parsing
|
<< global [ "count-me" inc ] bind >>
|
||||||
COUNT-ME
|
|
||||||
|
|
||||||
: fred bob ;
|
: fred bob ;
|
|
@ -75,12 +75,6 @@ SYMBOL: load-vocab-hook
|
||||||
[ vocab-words at ] curry* map
|
[ vocab-words at ] curry* map
|
||||||
[ ] subset ;
|
[ ] subset ;
|
||||||
|
|
||||||
: forget-vocab ( vocab -- )
|
|
||||||
[
|
|
||||||
dup vocab-words values forget-all
|
|
||||||
vocab-name dictionary get delete-at
|
|
||||||
] with-compilation-unit ;
|
|
||||||
|
|
||||||
: child-vocab? ( prefix name -- ? )
|
: child-vocab? ( prefix name -- ? )
|
||||||
2dup = pick empty? or
|
2dup = pick empty? or
|
||||||
[ 2drop t ] [ swap CHAR: . add head? ] if ;
|
[ 2drop t ] [ swap CHAR: . add head? ] if ;
|
||||||
|
@ -98,4 +92,9 @@ M: vocab-link vocab-name vocab-link-name ;
|
||||||
|
|
||||||
UNION: vocab-spec vocab vocab-link ;
|
UNION: vocab-spec vocab vocab-link ;
|
||||||
|
|
||||||
M: vocab-spec forget vocab-name forget-vocab ;
|
M: vocab-spec forget
|
||||||
|
dup vocab-words values forget-all
|
||||||
|
vocab-name dictionary get delete-at ;
|
||||||
|
|
||||||
|
: forget-vocab ( vocab -- )
|
||||||
|
[ f >vocab-link forget ] with-compilation-unit ;
|
||||||
|
|
|
@ -337,6 +337,15 @@ HELP: define-declared
|
||||||
{ $description "Defines a compound word and declares its stack effect." }
|
{ $description "Defines a compound word and declares its stack effect." }
|
||||||
{ $side-effects "word" } ;
|
{ $side-effects "word" } ;
|
||||||
|
|
||||||
|
HELP: define-temp
|
||||||
|
{ $values { "quot" quotation } { "word" word } }
|
||||||
|
{ $description "Creates an uninterned word that will call " { $snippet "quot" } " when executed." }
|
||||||
|
{ $notes
|
||||||
|
"The following phrases are equivalent:"
|
||||||
|
{ $code "[ 2 2 + . ] call" }
|
||||||
|
{ $code "[ 2 2 + . ] define-temp execute" }
|
||||||
|
} ;
|
||||||
|
|
||||||
HELP: quot-uses
|
HELP: quot-uses
|
||||||
{ $values { "quot" quotation } { "assoc" "an assoc with words as keys" } }
|
{ $values { "quot" quotation } { "assoc" "an assoc with words as keys" } }
|
||||||
{ $description "Outputs a set of words referenced by the quotation and any quotations it contains." } ;
|
{ $description "Outputs a set of words referenced by the quotation and any quotations it contains." } ;
|
||||||
|
|
|
@ -4,8 +4,10 @@ vocabs continuations ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
|
||||||
[ 4 ] [
|
[ 4 ] [
|
||||||
"poo" "scratchpad" create [ 2 2 + ] define-compound
|
[
|
||||||
"poo" "scratchpad" lookup execute
|
"poo" "temporary" create [ 2 2 + ] define-compound
|
||||||
|
] with-compilation-unit
|
||||||
|
"poo" "temporary" lookup execute
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ t vocabs [ words [ word? and ] each ] each ] unit-test
|
[ t ] [ t vocabs [ words [ word? and ] each ] each ] unit-test
|
||||||
|
@ -88,14 +90,23 @@ FORGET: another-forgotten
|
||||||
FORGET: foe
|
FORGET: foe
|
||||||
|
|
||||||
! xref should not retain references to gensyms
|
! xref should not retain references to gensyms
|
||||||
gensym [ * ] define-compound
|
[ ] [
|
||||||
|
[ gensym [ * ] define-compound ] with-compilation-unit
|
||||||
|
] unit-test
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
\ * usage [ word? ] subset [ interned? not ] subset empty?
|
\ * usage [ word? ] subset [ interned? not ] subset empty?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
DEFER: calls-a-gensym
|
DEFER: calls-a-gensym
|
||||||
\ calls-a-gensym gensym dup "x" set 1quotation define-compound
|
[ ] [
|
||||||
|
[
|
||||||
|
\ calls-a-gensym
|
||||||
|
gensym dup "x" set 1quotation
|
||||||
|
define-compound
|
||||||
|
] with-compilation-unit
|
||||||
|
] unit-test
|
||||||
|
|
||||||
[ f ] [ "x" get crossref get at ] unit-test
|
[ f ] [ "x" get crossref get at ] unit-test
|
||||||
|
|
||||||
! more xref buggery
|
! more xref buggery
|
||||||
|
@ -130,10 +141,18 @@ DEFER: x
|
||||||
SYMBOL: quot-uses-a
|
SYMBOL: quot-uses-a
|
||||||
SYMBOL: quot-uses-b
|
SYMBOL: quot-uses-b
|
||||||
|
|
||||||
quot-uses-a [ 2 3 + ] define-compound
|
[ ] [
|
||||||
|
[
|
||||||
|
quot-uses-a [ 2 3 + ] define-compound
|
||||||
|
] with-compilation-unit
|
||||||
|
] unit-test
|
||||||
|
|
||||||
[ { + } ] [ \ quot-uses-a uses ] unit-test
|
[ { + } ] [ \ quot-uses-a uses ] unit-test
|
||||||
|
|
||||||
quot-uses-b 2 [ 3 + ] curry define-compound
|
[ ] [
|
||||||
|
[
|
||||||
|
quot-uses-b 2 [ 3 + ] curry define-compound
|
||||||
|
] with-compilation-unit
|
||||||
|
] unit-test
|
||||||
|
|
||||||
[ { + } ] [ \ quot-uses-b uses ] unit-test
|
[ { + } ] [ \ quot-uses-b uses ] unit-test
|
||||||
|
|
|
@ -102,7 +102,8 @@ PRIVATE>
|
||||||
: intern-symbol ( word -- )
|
: intern-symbol ( word -- )
|
||||||
dup undefined? [ define-symbol ] [ drop ] if ;
|
dup undefined? [ define-symbol ] [ drop ] if ;
|
||||||
|
|
||||||
: define-compound ( word def -- ) [ ] like define ;
|
: define-compound ( word def -- )
|
||||||
|
[ ] like define ;
|
||||||
|
|
||||||
: define-declared ( word def effect -- )
|
: define-declared ( word def effect -- )
|
||||||
pick swap "declared-effect" set-word-prop
|
pick swap "declared-effect" set-word-prop
|
||||||
|
@ -135,6 +136,9 @@ PRIVATE>
|
||||||
: gensym ( -- word )
|
: gensym ( -- word )
|
||||||
"G:" \ gensym counter number>string append f <word> ;
|
"G:" \ gensym counter number>string append f <word> ;
|
||||||
|
|
||||||
|
: define-temp ( quot -- word )
|
||||||
|
gensym dup rot define-compound ;
|
||||||
|
|
||||||
: reveal ( word -- )
|
: reveal ( word -- )
|
||||||
dup word-name over word-vocabulary vocab-words set-at ;
|
dup word-name over word-vocabulary vocab-words set-at ;
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ IN: cocoa.subclassing
|
||||||
: prepare-method ( ret types quot -- type imp )
|
: prepare-method ( ret types quot -- type imp )
|
||||||
>r [ encode-types ] 2keep r> [
|
>r [ encode-types ] 2keep r> [
|
||||||
"cdecl" swap 4array % \ alien-callback ,
|
"cdecl" swap 4array % \ alien-callback ,
|
||||||
] [ ] make compile-quot ;
|
] [ ] make define-temp ;
|
||||||
|
|
||||||
: prepare-methods ( methods -- methods )
|
: prepare-methods ( methods -- methods )
|
||||||
[ first4 prepare-method 3array ] map ;
|
[ first4 prepare-method 3array ] map ;
|
||||||
|
|
Loading…
Reference in New Issue