From 4044cd293a66877d3c6c41cf7cf61d2aba60fc87 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 00:09:08 -0800 Subject: [PATCH] TYPEDEF-IF: and USE-IF: words; ptrdiff_t C type moved to alien.c-types and special-cased for win64 --- core/alien/c-types/c-types.factor | 3 +++ core/alien/syntax/syntax-docs.factor | 10 ++++++++-- core/alien/syntax/syntax.factor | 3 +++ core/syntax/syntax-docs.factor | 6 ++++++ core/syntax/syntax.factor | 1 + extra/opengl/gl/gl.factor | 2 -- extra/opengl/gl/unix/unix.factor | 2 +- 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/alien/c-types/c-types.factor b/core/alien/c-types/c-types.factor index b665300bee..6d9c2cec14 100755 --- a/core/alien/c-types/c-types.factor +++ b/core/alien/c-types/c-types.factor @@ -358,4 +358,7 @@ M: long-long-type box-return ( type -- ) "ushort*" define-primitive-type [ string>u16-alien ] "ushort*" c-type set-c-type-prep + + win64? "longlong" "long" ? "ptrdiff_t" typedef + ] with-compilation-unit diff --git a/core/alien/syntax/syntax-docs.factor b/core/alien/syntax/syntax-docs.factor index d87b67eb59..00ee6345dc 100755 --- a/core/alien/syntax/syntax-docs.factor +++ b/core/alien/syntax/syntax-docs.factor @@ -49,8 +49,14 @@ $nl HELP: TYPEDEF: { $syntax "TYPEDEF: old new" } -{ $values { "old" "a C type" } { "new" "a C type" } } -{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } "." } +{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } } +{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } " if ." } +{ $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; + +HELP: TYPEDEF-IF: +{ $syntax "TYPEDEF-IF: word old new" } +{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } } +{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } " if " { $snippet "word" } " evaluates to a true value." } { $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; HELP: C-STRUCT: diff --git a/core/alien/syntax/syntax.factor b/core/alien/syntax/syntax.factor index bc3bc911ef..b81a91efcb 100755 --- a/core/alien/syntax/syntax.factor +++ b/core/alien/syntax/syntax.factor @@ -46,6 +46,9 @@ PRIVATE> : TYPEDEF: scan scan typedef ; parsing +: TYPEDEF-IF: + scan-word execute scan scan rot [ typedef ] [ 2drop ] if ; parsing + : C-STRUCT: scan in get parse-definition diff --git a/core/syntax/syntax-docs.factor b/core/syntax/syntax-docs.factor index 9cf9647e41..f4efc3b6bb 100755 --- a/core/syntax/syntax-docs.factor +++ b/core/syntax/syntax-docs.factor @@ -363,6 +363,12 @@ HELP: USE: { $description "Adds a new vocabulary at the front of the search path. Subsequent word lookups by the parser will search this vocabulary first." } { $errors "Throws an error if the vocabulary does not exist." } ; +HELP: USE-IF: +{ $syntax "USE-IF: word vocabulary" } +{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "vocabulary" "a vocabulary name" } } +{ $description "Adds " { $snippet "vocabulary" } " at the front of the search path if " { $snippet "word" } " evaluates to a true value." } +{ $errors "Throws an error if the vocabulary does not exist." } ; + HELP: USING: { $syntax "USING: vocabularies... ;" } { $values { "vocabularies" "a list of vocabulary names" } } diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index b0a7ea19bd..cd97aea9eb 100755 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -46,6 +46,7 @@ IN: bootstrap.syntax ] define-syntax "USE:" [ scan use+ ] define-syntax + "USE-IF:" [ scan-word execute scan swap [ use+ ] [ drop ] if ] define-syntax "USING:" [ ";" parse-tokens add-use ] define-syntax diff --git a/extra/opengl/gl/gl.factor b/extra/opengl/gl/gl.factor index c7ce176aca..4a9d9c84d5 100644 --- a/extra/opengl/gl/gl.factor +++ b/extra/opengl/gl/gl.factor @@ -1469,8 +1469,6 @@ GL-FUNCTION: void glWindowPos3sv ( GLshort* p ) ; : GL_SRC2_ALPHA GL_SOURCE2_ALPHA ; inline : GL_SRC2_RGB GL_SOURCE2_RGB ; inline -TYPEDEF: long ptrdiff_t - TYPEDEF: ptrdiff_t GLsizeiptr TYPEDEF: ptrdiff_t GLintptr diff --git a/extra/opengl/gl/unix/unix.factor b/extra/opengl/gl/unix/unix.factor index 08141ad81d..16cd38f92f 100644 --- a/extra/opengl/gl/unix/unix.factor +++ b/extra/opengl/gl/unix/unix.factor @@ -2,4 +2,4 @@ USING: alien.syntax kernel syntax words ; IN: opengl.gl.unix -: GL-FUNCTION: \ FUNCTION: word-def call ; parsing +: GL-FUNCTION: POSTPONE: FUNCTION: ; parsing