bootstrap.image.primitives: make more primitives properties be declared here

This commit merges the input/output-classes and flush/foldable
declarations from stack-checker.known-words to this vocab. This should
make adding primitives a little simpler (#1134).
locals-and-roots
Björn Lindqvist 2016-03-30 18:59:10 +02:00
parent 1b71efb748
commit 80f30119c0
5 changed files with 668 additions and 515 deletions

View File

@ -2,7 +2,17 @@ USING: assocs help.markup help.syntax quotations strings words ;
IN: bootstrap.image.primitives IN: bootstrap.image.primitives
HELP: all-primitives HELP: all-primitives
{ $description "A constant " { $link assoc } " containing all primitives. Keys are vocab names and values are sequences of tuples declaring words. The format of the tuples are { name effect vm-func }. If 'vm-func' is a " { $link string } " then the primitive will call a function implemented in C++ code. If 'vm-func' is " { $link f } " then it is a sub-primitive and implemented in one of the files in 'basis/bootstrap/assembler/'." } ; { $description "A constant " { $link assoc } " containing all primitives. Keys are vocab names and values are sequences of tuples declaring words. The format of the tuples are { name effect vm-func inputs outputs extra-props }:"
{ $list
{ "name: Name of the primitive." }
{ "effect: The primitives stack effect." }
{ "vm-func: If it is a " { $link string } " then the primitive will call a function implemented in C++ code. If 'vm-func' is " { $link f } " then it is a sub-primitive and implemented in one of the files in 'basis/bootstrap/assembler/'." }
{ "inputs: The primitives \"input-classes\", if any." }
{ "outputs: The primitives \"output-classes\", if any." }
{ "extra-word: An " { $link word } " that is run with the created word as argument to add extra properties to it. Usually, it would be " { $link make-foldable } " or " { $link make-flushable } " to make the word foldable or flushable respectively." }
}
}
"See " { $link "word-props" } " for documentation of what all word properties do." ;
HELP: primitive-quot HELP: primitive-quot
{ $values { "word" word } { "vm-func" $maybe { string } } { "quot" quotation } } { $values { "word" word } { "vm-func" $maybe { string } } { "quot" quotation } }
@ -11,6 +21,6 @@ HELP: primitive-quot
ARTICLE: "bootstrap.image.primitives" "Bootstrap primitives" ARTICLE: "bootstrap.image.primitives" "Bootstrap primitives"
"This vocab contains utilities for declaring primitives to be added to the bootstrap image. It is used by " { $vocab-link "bootstrap.primitives" } "This vocab contains utilities for declaring primitives to be added to the bootstrap image. It is used by " { $vocab-link "bootstrap.primitives" }
$nl $nl
{ $link all-primitives } " is an assoc where all primitives are declared." ; { $link all-primitives } " is an assoc where all primitives are declared. See that constant for a description of the format." ;
ABOUT: "bootstrap.image.primitives" ABOUT: "bootstrap.image.primitives"

View File

@ -1,4 +1,5 @@
USING: bootstrap.image.primitives kernel.private tools.test words ; USING: bootstrap.image.primitives kernel.private sequences tools.test
vocabs words ;
IN: bootstrap.image.primitives.tests IN: bootstrap.image.primitives.tests
{ {
@ -11,3 +12,7 @@ IN: bootstrap.image.primitives.tests
} [ } [
gensym "hello" primitive-quot gensym "hello" primitive-quot
] unit-test ] unit-test
{ t } [
all-words [ primitive? ] filter [ foldable? ] filter [ flushable? ] all?
] unit-test

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,6 @@ HELP: check-declaration
{ $values { "declaration" sequence } } { $values { "declaration" sequence } }
{ $description "Checks that a declaration sequence as inputted to a " { $link declare } " word is well-formed." } ; { $description "Checks that a declaration sequence as inputted to a " { $link declare } " word is well-formed." } ;
HELP: define-primitive
{ $values { "word" word } { "inputs" sequence } { "outputs" sequence } }
{ $description "Marks the word as a primitive whose input and output types must be the given ones." } ;
HELP: infer-call HELP: infer-call
{ $description "Performs inferencing for the " { $link call } " word." } ; { $description "Performs inferencing for the " { $link call } " word." } ;
@ -30,7 +26,7 @@ HELP: infer-special
{ $description "Performs inferencing of a word with the \"special\" property set." } ; { $description "Performs inferencing of a word with the \"special\" property set." } ;
ARTICLE: "stack-checker.known-words" "Hard-coded stack effects for primitive words" ARTICLE: "stack-checker.known-words" "Extra properties for special words"
"This vocab declares primitive and shuffle words." ; "This vocab adds properties for words that are handled specially by the compiler. Such as " { $link curry } " and " { $link dip } "." ;
ABOUT: "stack-checker.known-words" ABOUT: "stack-checker.known-words"

View File

@ -1,30 +1,14 @@
! Copyright (C) 2004, 2011 Slava Pestov, Daniel Ehrenberg. ! Copyright (C) 2004, 2011 Slava Pestov, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: fry accessors alien alien.accessors alien.private arrays USING: accessors alien arrays assocs classes classes.tuple.private
byte-arrays classes continuations.private effects generic combinators combinators.private combinators.short-circuit effects fry
hashtables hashtables.private io io.backend io.files generic.single.private kernel kernel.private locals locals.backend
io.files.private io.streams.c kernel kernel.private math locals.types macros math namespaces quotations.private sequences
math.private math.parser.private memory memory.private sequences.private stack-checker.alien stack-checker.backend
namespaces namespaces.private parser quotations stack-checker.branches stack-checker.dependencies stack-checker.errors
quotations.private sbufs sbufs.private sequences stack-checker.row-polymorphism stack-checker.state
sequences.private slots.private strings strings.private system stack-checker.transforms stack-checker.values stack-checker.visitor
threads.private classes.tuple classes.tuple.private vectors words ;
vectors.private words words.private definitions assocs summary
compiler.units system.private combinators tools.memory.private
combinators.short-circuit locals locals.backend locals.types
combinators.private stack-checker.values generic.single
generic.single.private alien.libraries tools.dispatch.private
macros tools.profiler.sampling.private classes.algebra
stack-checker.alien
stack-checker.state
stack-checker.errors
stack-checker.visitor
stack-checker.backend
stack-checker.branches
stack-checker.transforms
stack-checker.dependencies
stack-checker.recursive-state
stack-checker.row-polymorphism ;
QUALIFIED-WITH: generic.single.private gsp QUALIFIED-WITH: generic.single.private gsp
IN: stack-checker.known-words IN: stack-checker.known-words
@ -178,8 +162,6 @@ M: object infer-call* \ call bad-macro-input ;
\ <tuple-boa> [ infer-<tuple-boa> ] "special" set-word-prop \ <tuple-boa> [ infer-<tuple-boa> ] "special" set-word-prop
\ <tuple-boa> t "flushable" set-word-prop
: infer-effect-unsafe ( word -- ) : infer-effect-unsafe ( word -- )
pop-literal nip pop-literal nip
add-effect-input add-effect-input
@ -272,255 +254,3 @@ M: object infer-call* \ call bad-macro-input ;
! More words not to compile ! More words not to compile
\ clear t "no-compile" set-word-prop \ clear t "no-compile" set-word-prop
: define-primitive ( word inputs outputs -- )
[ "input-classes" set-word-prop ]
[ "default-output-classes" set-word-prop ]
bi-curry* bi ;
: define-primitives ( seq -- )
[ first3 define-primitive ] each ;
: make-flushable-primitives ( flushables -- )
dup define-primitives [ first make-flushable ] each ;
: make-foldable-primitives ( flushables -- )
dup define-primitives [ first make-foldable ] each ;
! ! Stack effects for all primitives
! Alien getters
{
{ alien-cell { c-ptr integer } { pinned-c-ptr } }
{ alien-double { c-ptr integer } { float } }
{ alien-float { c-ptr integer } { float } }
{ alien-signed-1 { c-ptr integer } { fixnum } }
{ alien-signed-2 { c-ptr integer } { fixnum } }
{ alien-signed-4 { c-ptr integer } { integer } }
{ alien-signed-8 { c-ptr integer } { integer } }
{ alien-signed-cell { c-ptr integer } { integer } }
{ alien-unsigned-1 { c-ptr integer } { fixnum } }
{ alien-unsigned-2 { c-ptr integer } { fixnum } }
{ alien-unsigned-4 { c-ptr integer } { integer } }
{ alien-unsigned-8 { c-ptr integer } { integer } }
{ alien-unsigned-cell { c-ptr integer } { integer } }
} make-flushable-primitives
! Alien setters
{
{ set-alien-cell { c-ptr c-ptr integer } { } }
{ set-alien-double { float c-ptr integer } { } }
{ set-alien-float { float c-ptr integer } { } }
{ set-alien-signed-1 { integer c-ptr integer } { } }
{ set-alien-signed-2 { integer c-ptr integer } { } }
{ set-alien-signed-4 { integer c-ptr integer } { } }
{ set-alien-signed-8 { integer c-ptr integer } { } }
{ set-alien-signed-cell { integer c-ptr integer } { } }
{ set-alien-unsigned-1 { integer c-ptr integer } { } }
{ set-alien-unsigned-2 { integer c-ptr integer } { } }
{ set-alien-unsigned-4 { integer c-ptr integer } { } }
{ set-alien-unsigned-8 { integer c-ptr integer } { } }
{ set-alien-unsigned-cell { integer c-ptr integer } { } }
} define-primitives
! Container constructors
{
{ (byte-array) { integer-array-capacity } { byte-array } }
{ <array> { integer-array-capacity object } { array } }
{ <byte-array> { integer-array-capacity } { byte-array } }
{ <string> { integer-array-capacity integer } { string } }
{ <tuple> { array } { tuple } }
} make-flushable-primitives
! Misc flushables
{
{ (callback-room) { } { byte-array } }
{ (clone) { object } { object } }
{ (code-blocks) { } { array } }
{ (code-room) { } { byte-array } }
{ (data-room) { } { byte-array } }
{ (word) { object object object } { word } }
{ <displaced-alien> { integer c-ptr } { c-ptr } }
{ alien-address { alien } { integer } }
{ callstack-bounds { } { alien alien } }
{ callstack-for { c-ptr } { callstack } }
{ callstack>array { callstack } { array } }
{ check-datastack { array integer integer } { object } }
{ context-object { fixnum } { object } }
{ context-object-for { fixnum c-ptr } { object } }
{ current-callback { } { fixnum } }
{ datastack-for { c-ptr } { array } }
{ nano-count { } { integer } }
{ quotation-code { quotation } { integer integer } }
{ retainstack-for { c-ptr } { array } }
{ size { object } { fixnum } }
{ slot { object fixnum } { object } }
{ special-object { fixnum } { object } }
{ string-nth-fast { fixnum string } { fixnum } }
{ word-code { word } { integer integer } }
} make-flushable-primitives
! Misc foldables
{
{ <wrapper> { object } { wrapper } }
{ array>quotation { array } { quotation } }
{ eq? { object object } { object } }
{ tag { object } { fixnum } }
} make-foldable-primitives
! Numeric primitives
{
! bignum
{ bignum* { bignum bignum } { bignum } }
{ bignum+ { bignum bignum } { bignum } }
{ bignum- { bignum bignum } { bignum } }
{ bignum-bit? { bignum integer } { object } }
{ bignum-bitand { bignum bignum } { bignum } }
{ bignum-bitnot { bignum } { bignum } }
{ bignum-bitor { bignum bignum } { bignum } }
{ bignum-bitxor { bignum bignum } { bignum } }
{ bignum-log2 { bignum } { bignum } }
{ bignum-mod { bignum bignum } { integer } }
{ bignum-gcd { bignum bignum } { bignum } }
{ bignum-shift { bignum fixnum } { bignum } }
{ bignum/i { bignum bignum } { bignum } }
{ bignum/mod { bignum bignum } { bignum integer } }
{ bignum< { bignum bignum } { object } }
{ bignum<= { bignum bignum } { object } }
{ bignum= { bignum bignum } { object } }
{ bignum> { bignum bignum } { object } }
{ bignum>= { bignum bignum } { object } }
{ bignum>fixnum { bignum } { fixnum } }
{ bignum>fixnum-strict { bignum } { fixnum } }
! fixnum
{ fixnum* { fixnum fixnum } { integer } }
{ fixnum*fast { fixnum fixnum } { fixnum } }
{ fixnum+ { fixnum fixnum } { integer } }
{ fixnum+fast { fixnum fixnum } { fixnum } }
{ fixnum- { fixnum fixnum } { integer } }
{ fixnum-bitand { fixnum fixnum } { fixnum } }
{ fixnum-bitnot { fixnum } { fixnum } }
{ fixnum-bitor { fixnum fixnum } { fixnum } }
{ fixnum-bitxor { fixnum fixnum } { fixnum } }
{ fixnum-fast { fixnum fixnum } { fixnum } }
{ fixnum-mod { fixnum fixnum } { fixnum } }
{ fixnum-shift { fixnum fixnum } { integer } }
{ fixnum-shift-fast { fixnum fixnum } { fixnum } }
{ fixnum/i { fixnum fixnum } { integer } }
{ fixnum/i-fast { fixnum fixnum } { fixnum } }
{ fixnum/mod { fixnum fixnum } { integer fixnum } }
{ fixnum/mod-fast { fixnum fixnum } { fixnum fixnum } }
{ fixnum< { fixnum fixnum } { object } }
{ fixnum<= { fixnum fixnum } { object } }
{ fixnum> { fixnum fixnum } { object } }
{ fixnum>= { fixnum fixnum } { object } }
{ fixnum>bignum { fixnum } { bignum } }
{ fixnum>float { fixnum } { float } }
! float
{ (format-float) { float byte-array fixnum fixnum byte-array byte-array } { byte-array } }
{ bits>float { integer } { float } }
{ float* { float float } { float } }
{ float+ { float float } { float } }
{ float- { float float } { float } }
{ float-u< { float float } { object } }
{ float-u<= { float float } { object } }
{ float-u> { float float } { object } }
{ float-u>= { float float } { object } }
{ float/f { float float } { float } }
{ float< { float float } { object } }
{ float<= { float float } { object } }
{ float= { float float } { object } }
{ float> { float float } { object } }
{ float>= { float float } { object } }
{ float>bignum { float } { bignum } }
{ float>bits { real } { integer } }
{ float>fixnum { float } { fixnum } }
! double
{ bits>double { integer } { float } }
{ double>bits { real } { integer } }
} make-foldable-primitives
! ! Misc primitives
{
! Contexts
{ (set-context) { object alien } { object } }
{ (set-context-and-delete) { object alien } { } }
{ (sleep) { integer } { } }
{ (start-context) { object quotation } { object } }
{ (start-context-and-delete) { object quotation } { } }
{ set-context-object { object fixnum } { } }
! Dispatch stats
{ dispatch-stats { } { byte-array } }
{ reset-dispatch-stats { } { } }
! FFI
{ (dlopen) { byte-array } { dll } }
{ (dlsym) { byte-array object } { c-ptr } }
{ (dlsym-raw) { byte-array object } { c-ptr } }
{ dlclose { dll } { } }
{ dll-valid? { object } { object } }
! GC
{ compact-gc { } { } }
{ disable-gc-events { } { object } }
{ enable-gc-events { } { } }
{ gc { } { } }
{ minor-gc { } { } }
! Hashing
{ (identity-hashcode) { object } { fixnum } }
{ compute-identity-hashcode { object } { } }
! IO
{ (exists?) { string } { object } }
{ (fopen) { byte-array byte-array } { alien } }
{ fclose { alien } { } }
{ fflush { alien } { } }
{ fgetc { alien } { object } }
{ fputc { object alien } { } }
{ fread-unsafe { integer c-ptr alien } { integer } }
{ fseek { integer integer alien } { } }
{ ftell { alien } { integer } }
{ fwrite { c-ptr integer alien } { } }
! Profiling
{ (clear-samples) { } { } }
{ (get-samples) { } { object } }
{ profiling { object } { } }
! Resizing
{ resize-array { integer array } { array } }
{ resize-byte-array { integer byte-array } { byte-array } }
{ resize-string { integer string } { string } }
! Other primitives
{ (exit) { integer } { } }
{ (save-image) { byte-array byte-array object } { } }
{ <callback> { word integer } { alien } }
{ all-instances { } { array } }
{ become { array array } { } }
{ both-fixnums? { object object } { object } }
{ die { } { } }
{ fpu-state { } { } }
{ free-callback { alien } { } }
{ innermost-frame-executing { callstack } { object } }
{ innermost-frame-scan { callstack } { fixnum } }
{ jit-compile { quotation } { } }
{ leaf-signal-handler { } { } }
{ gsp:lookup-method { object array } { word } }
{ modify-code-heap { array object object } { } }
{ quotation-compiled? { quotation } { object } }
{ set-fpu-state { } { } }
{ set-innermost-frame-quotation { quotation callstack } { } }
{ set-slot { object object fixnum } { } }
{ set-special-object { object fixnum } { } }
{ set-string-nth-fast { fixnum fixnum string } { } }
{ signal-handler { } { } }
{ strip-stack-traces { } { } }
{ unimplemented { } { } }
{ word-optimized? { word } { object } }
} define-primitives