From: Erik Charlebois Date: Sun, 22 May 2011 07:37:56 +0000 (-0400) Subject: Create a setter for C-GLOBAL words X-Git-Tag: 0.97~4323^2^2~5 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=e28e48beea9410480d3d805f635094e92a520165 Create a setter for C-GLOBAL words --- diff --git a/basis/alien/parser/parser.factor b/basis/alien/parser/parser.factor index 32caee214f..6d0cbb79cc 100755 --- a/basis/alien/parser/parser.factor +++ b/basis/alien/parser/parser.factor @@ -179,5 +179,16 @@ PREDICATE: alien-callback-type-word < typedef-word swap [ name>> current-library get ] dip '[ _ _ address-of 0 _ alien-value ] ; -: define-global ( type word -- ) +: set-global-quot ( type word -- quot ) + swap [ name>> current-library get ] dip + '[ _ _ address-of 0 _ set-alien-value ] ; + +: define-global-getter ( type word -- ) [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ; + +: define-global-setter ( type word -- ) + [ nip name>> "set-" prepend create-in ] + [ set-global-quot ] 2bi (( obj -- )) define-declared ; + +: define-global ( type word -- ) + [ define-global-getter ] [ define-global-setter ] 2bi ; diff --git a/basis/alien/syntax/syntax-docs.factor b/basis/alien/syntax/syntax-docs.factor index 8f60e7e088..4901651ce3 100644 --- a/basis/alien/syntax/syntax-docs.factor +++ b/basis/alien/syntax/syntax-docs.factor @@ -122,7 +122,7 @@ HELP: typedef HELP: C-GLOBAL: { $syntax "C-GLOBAL: type name" } { $values { "type" "a C type" } { "name" "a C global variable name" } } -{ $description "Defines a new word named " { $snippet "name" } " which accesses a global variable in the current library, set with " { $link POSTPONE: LIBRARY: } "." } ; +{ $description "Defines a getter " { $snippet "name" } " and setter " { $snippet "set-name" } " for the global value in the current library, set with " { $link POSTPONE: LIBRARY: } "." } ; ARTICLE: "alien.enums" "Enumeration types" "The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link POSTPONE: ENUM: } " C types, and provides words for converting between enum singletons and integers. It is possible to dispatch off of members of an enum."