ffi, libs: working on syntax fixes.

locals-and-roots
Doug Coleman 2016-06-06 17:00:20 -07:00
parent 3283261710
commit d54ac497c6
18 changed files with 81 additions and 99 deletions

View File

@ -8,6 +8,6 @@ HELP: run-apple-script
{ $notes "Currently, return values are unsupported." } ;
HELP: APPLESCRIPT:
{ $syntax "APPLESCRIPT: word ...applescript... ;APPLESCRIPT" }
{ $syntax "APPLESCRIPT: word ...applescript... APPLESCRIPT;" }
{ $values { "word" "a new word to define" } { "...applescript..." "AppleScript source text" } }
{ $description "Defines a word that when called will run the provided uncompiled AppleScript. The word has stack effect " { $snippet "( -- )" } " due to return values being currently unsupported." } ;

View File

@ -11,6 +11,6 @@ in: cocoa.apple-script
<NSString> send\ initWithSource: send\ autorelease
f send\ executeAndReturnError: drop ;
SYNTAX: APPLESCRIPT:
scan-new-word ";APPLESCRIPT" parse-multiline-string
SYNTAX: \ APPLESCRIPT:
scan-new-word "APPLESCRIPT;" parse-multiline-string
[ run-apple-script ] curry ( -- ) define-declared ;

View File

@ -13,13 +13,13 @@ symbol: sent-messages
sent-messages (remember-send) ;
SYNTAX: -> scan-token dup remember-send suffix! \ send suffix! ;
SYNTAX: send\ scan-token dup remember-send suffix! \ send suffix! ;
SYNTAX: \ send\ scan-token dup remember-send suffix! \ send suffix! ;
SYNTAX: SEL:
SYNTAX: \ SEL:
scan-token
[ remember-send ]
[ <selector> suffix! \ cocoa.messages:selector suffix! ] bi ;
SYNTAX: sel\
SYNTAX: \ sel\
scan-token
[ remember-send ]
[ <selector> suffix! \ cocoa.messages:selector suffix! ] bi ;
@ -29,8 +29,8 @@ symbol: super-sent-messages
: remember-super-send ( selector -- )
super-sent-messages (remember-send) ;
SYNTAX: SUPER-> scan-token dup remember-super-send suffix! \ super-send suffix! ;
SYNTAX: super-send\ scan-token dup remember-super-send suffix! \ super-send suffix! ;
SYNTAX: \ SUPER-> scan-token dup remember-super-send suffix! \ super-send suffix! ;
SYNTAX: \ super-send\ scan-token dup remember-super-send suffix! \ super-send suffix! ;
symbol: frameworks
@ -38,11 +38,9 @@ frameworks [ V{ } clone ] initialize
[ frameworks get [ load-framework ] each ] "cocoa" add-startup-hook
SYNTAX: FRAMEWORK: scan-token [ load-framework ] [ frameworks get push ] bi ;
SYNTAX: framework: scan-token [ load-framework ] [ frameworks get push ] bi ;
SYNTAX: \ framework: scan-token [ load-framework ] [ frameworks get push ] bi ;
SYNTAX: IMPORT: scan-token [ ] import-objc-class ;
SYNTAX: import: scan-token [ ] import-objc-class ;
SYNTAX: \ import: scan-token [ ] import-objc-class ;
"Importing Cocoa classes..." print

View File

@ -71,10 +71,10 @@ in: cocoa.subclassing
TUPLE: cocoa-protocol name ;
C: <cocoa-protocol> cocoa-protocol ;
SYNTAX: COCOA-PROTOCOL:
SYNTAX: \ COCOA-PROTOCOL:
scan-token <cocoa-protocol> suffix! ;
SYNTAX: CLASS:
SYNTAX: \ CLASS:
scan-token
"<" expect
scan-token
@ -99,7 +99,7 @@ SYNTAX: CLASS:
[ [ make-local ] map ] H{ } make
(parse-lambda) <lambda> ?rewrite-closures first ;
SYNTAX: METHOD:
SYNTAX: \ METHOD:
scan-c-type
parse-selector
parse-method-body [ swap ] 2dip 4array ";" expect

View File

@ -96,7 +96,7 @@ FUNCTION: CFStringRef CFCopyTypeIDDescription ( CFTypeID type_id ) ;
: CFType>description ( cf -- description )
CFGetTypeID [ CFCopyTypeIDDescription &CFRelease CF>string ] with-destructors ;
SYNTAX: CFSTRING:
SYNTAX: \ CFSTRING:
scan-new-word scan-object ";" expect
[ drop ] [ '[ _ [ _ <CFString> ] initialize-alien ] ] 2bi
( -- alien ) define-declared ;

View File

@ -53,18 +53,17 @@ M: gir-not-found summary
PRIVATE>
SYNTAX: GIR: scan-token define-gir-vocab ;
SYNTAX: gir: scan-token define-gir-vocab ;
SYNTAX: \ gir: scan-token define-gir-vocab ;
SYNTAX: IMPLEMENT-STRUCTS:
SYNTAX: \ IMPLEMENT-STRUCTS:
";" parse-tokens
implement-structs [ swap append! ] change-global ;
SYNTAX: FOREIGN-ATOMIC-TYPE:
SYNTAX: \ FOREIGN-ATOMIC-TYPE:
scan-token scan-object ";" expect swap register-atomic-type ;
SYNTAX: FOREIGN-ENUM-TYPE:
SYNTAX: \ FOREIGN-ENUM-TYPE:
scan-token scan-object ";" expect swap register-enum-type ;
SYNTAX: FOREIGN-RECORD-TYPE:
SYNTAX: \ FOREIGN-RECORD-TYPE:
scan-token scan-object ";" expect swap register-record-type ;

View File

@ -9,7 +9,7 @@ FROM: mongodb.tuple.persistent => assoc>tuple ;
in: mongodb.tuple
SYNTAX: MDBTUPLE:
SYNTAX: \ MDBTUPLE:
parse-tuple-definition
mdb-check-slots
define-tuple-class ;

View File

@ -4,5 +4,5 @@ USING: classes.parser classes.singleton classes.union kernel lexer
sequences ;
in: opencl.syntax
SYNTAX: SINGLETONS-UNION:
SYNTAX: \ SINGLETONS-UNION:
scan-new-class ";" parse-tokens [ create-class-in [ define-singleton-class ] keep ] map define-union-class ;

View File

@ -47,7 +47,7 @@ reset-gl-function-number-counter
names return function-effect
define-declared ;
SYNTAX: GL-FUNCTION:
SYNTAX: \ GL-FUNCTION:
gl-function-calling-convention
scan-function-name
"{" expect "}" parse-tokens over suffix

View File

@ -61,12 +61,12 @@ symbol: current-context
PRIVATE>
SYNTAX: PY-FROM: [
SYNTAX: \ PY-FROM: [
current-context get f add-function
] scan-definitions ; inline
SYNTAX: PY-QUALIFIED-FROM: [
SYNTAX: \ PY-QUALIFIED-FROM: [
current-context get t add-function
] scan-definitions ; inline
SYNTAX: PY-METHODS: [ add-method ] scan-definitions ; inline
SYNTAX: \ PY-METHODS: [ add-method ] scan-definitions ; inline

View File

@ -82,7 +82,7 @@ ERROR: no-com-interface interface ;
PRIVATE>
SYNTAX: COM-INTERFACE:
SYNTAX: \ COM-INTERFACE:
CREATE-C-TYPE
void* over typedef
scan-object find-com-interface-definition
@ -92,8 +92,7 @@ SYNTAX: COM-INTERFACE:
dup save-com-interface-definition
define-words-for-com-interface ;
SYNTAX: GUID: scan-object string>guid suffix! ;
SYNTAX: guid: scan-object string>guid suffix! ;
SYNTAX: \ guid: scan-object string>guid suffix! ;
use: vocabs.loader

View File

@ -3,7 +3,7 @@
USING: alien.syntax alien.parser words x11.io sequences kernel ;
in: x11.syntax
SYNTAX: X-FUNCTION:
SYNTAX: \ X-FUNCTION:
(FUNCTION:) make-function
[ \ awaken-event-loop suffix ] dip
define-declared ;

View File

@ -24,7 +24,7 @@ NAMEs. DEFINES ${NAME}s.
WHERE
: (NAME) ( str -- ) drop ; inline
SYNTAX: !NAME (parse-annotation) \ (NAME) suffix! ;
SYNTAX: \ !NAME (parse-annotation) \ (NAME) suffix! ;
: NAMEs ( -- usages )
\ (NAME) (non-annotation-usage) ;

View File

@ -26,4 +26,4 @@ in: dice
'[ _ _ random-roll ]
] if* ;
SYNTAX: ROLL: scan-token roll-quot append! ;
SYNTAX: \ roll: scan-token roll-quot append! ;

View File

@ -3,23 +3,23 @@
USING: help.syntax help.markup math math.functions prettyprint locals sequences ;
in: infix
HELP: [infix
{ $syntax "[infix ... infix]" }
HELP: infix[[
{ $syntax "infix[[ ... ]]" }
{ $description "Parses the infix code inside the brackets, converts it to stack code and executes it." }
{ $examples
{ $example
"USING: infix prettyprint ;"
"in: scratchpad"
"[infix 8+2*3 infix] ."
"infix[[ 8+2*3 ]] ."
"14"
} $nl
{ $link postpone\ [infix } " isn't that useful by itself, as it can only access literal numbers and no variables. It is designed to be used together with locals; for example with " { $link postpone\ :: } " :"
{ $link \ infix[[ } " isn't that useful by itself, as it can only access literal numbers and no variables. It is designed to be used together with locals; for example with " { $link postpone\ :: } " :"
{ $example
"USING: infix locals math.functions prettyprint ;"
"in: scratchpad"
":: quadratic-equation ( a b c -- z- z+ )"
" [infix (-b-sqrt(b*b-4*a*c)) / (2*a) infix]"
" [infix (-b+sqrt(b*b-4*a*c)) / (2*a) infix] ;"
" infix[[ (-b-sqrt(b*b-4*a*c)) / (2*a) ]]"
" infix[[ (-b+sqrt(b*b-4*a*c)) / (2*a) ]] ;"
"1 0 -1 quadratic-equation . ."
"1.0\n-1.0"
}
@ -28,8 +28,8 @@ HELP: [infix
ARTICLE: "infix" "Infix notation"
"The " { $vocab-link "infix" } " vocabulary implements support for infix notation in Factor source code."
{ $subsections
postpone\ [infix
postpone\ INFIX::
\ infix[[
\ INFIX::
}
"The usual infix math operators are supported:"
{ $list
@ -43,7 +43,7 @@ ARTICLE: "infix" "Infix notation"
"The standard precedence rules apply: Grouping with parentheses before " { $snippet "*" } ", " { $snippet "/" } "and " { $snippet "%" } " before " { $snippet "+" } " and " { $snippet "-" } "."
{ $example
"use: infix"
"[infix 5-40/10*2 infix] ."
"infix[[ 5-40/10*2 ]] ."
"-3"
}
$nl
@ -55,34 +55,34 @@ $nl
{ $example
"USING: infix locals math.functions ;"
":: binary_entropy ( p -- h )"
" [infix -(p*log(p) + (1-p)*log(1-p)) / log(2) infix] ;"
"[infix binary_entropy( sqrt(0.25) ) infix] ."
" infix[[ -(p*log(p) + (1-p)*log(1-p)) / log(2) ]] ;"
"infix[[ binary_entropy( sqrt(0.25) ) ]] ."
"1.0"
}
$nl
"You can access " { $vocab-link "sequences" } " inside infix expressions with the familiar " { $snippet "seq[index]" } " notation."
{ $example
"USING: arrays locals infix ;"
"let[ { 1 2 3 4 } :> myarr [infix myarr[4/2]*3 infix] ] ."
"let[ { 1 2 3 4 } :> myarr infix[[ myarr[4/2]*3 ]] ] ."
"9"
}
$nl
"You can create sub-" { $vocab-link "sequences" } " inside infix expressions using " { $snippet "seq[from:to]" } " notation."
{ $example
"USING: arrays locals infix ;"
"let[ \"foobar\" :> s [infix s[0:3] infix] ] ."
"let[ \"foobar\" :> s infix[[ s[0:3] ]] ] ."
"\"foo\""
}
$nl
"Additionally, you can step through " { $vocab-link "sequences" } " with " { $snippet "seq[from:to:step]" } " notation."
{ $example
"USING: arrays locals infix ;"
"let[ \"reverse\" :> s [infix s[::-1] infix] ] ."
"let[ \"reverse\" :> s infix[[ s[::-1] ]] ] ."
"\"esrever\""
}
{ $example
"USING: arrays locals infix ;"
"let[ \"0123456789\" :> s [infix s[::2] infix] ] ."
"let[ \"0123456789\" :> s infix[[ s[::2] ]] ] ."
"\"02468\""
}
;

View File

@ -4,19 +4,19 @@ USING: infix infix.private kernel locals math math.functions
tools.test ;
in: infix.tests
{ 0 } [ [infix 0 infix] ] unit-test
{ 0.5 } [ [infix 3.0/6 infix] ] unit-test
{ 1+2/3 } [ [infix 5/3 infix] ] unit-test
{ 3 } [ [infix 2*7%3+1 infix] ] unit-test
{ 1419857 } [ [infix 17**5 infix] ] unit-test
{ 1 } [ [infix 2-
{ 0 } [ infix[[ 0 ]] ] unit-test
{ 0.5 } [ infix[[ 3.0/6 ]] ] unit-test
{ 1+2/3 } [ infix[[ 5/3 ]] ] unit-test
{ 3 } [ infix[[ 2*7%3+1 ]] ] unit-test
{ 1419857 } [ infix[[ 17**5 ]] ] unit-test
{ 1 } [ infix[[ 2-
1
-5*
0 infix] ] unit-test
0 ]] ] unit-test
{ 0.0 } [ [infix sin(0) infix] ] unit-test
{ 10 } [ [infix lcm(2,5) infix] ] unit-test
{ 1.0 } [ [infix +cos(-0*+3) infix] ] unit-test
{ 0.0 } [ infix[[ sin(0) ]] ] unit-test
{ 10 } [ infix[[ lcm(2,5) ]] ] unit-test
{ 1.0 } [ infix[[ +cos(-0*+3) ]] ] unit-test
{ f } [ 2 \ gcd check-word ] unit-test ! multiple return values
{ f } [ 1 \ drop check-word ] unit-test ! no return value
@ -24,32 +24,32 @@ in: infix.tests
: qux ( -- x ) 2 ;
{ t } [ 0 \ qux check-word ] unit-test
{ 8 } [ [infix qux()*3+2 infix] ] unit-test
{ 8 } [ infix[[ qux()*3+2 ]] ] unit-test
: foobar ( x -- y ) 1 + ;
{ t } [ 1 \ foobar check-word ] unit-test
{ 4 } [ [infix foobar(3*5%12) infix] ] unit-test
{ 4 } [ infix[[ foobar(3*5%12) ]] ] unit-test
: stupid_function ( x x x x x -- y ) + + + + ;
{ t } [ 5 \ stupid_function check-word ] unit-test
{ 10 } [ [infix stupid_function (0, 1, 2, 3, 4) infix] ] unit-test
{ 10 } [ infix[[ stupid_function (0, 1, 2, 3, 4) ]] ] unit-test
{ -1 } [ let[ 1 :> a [infix -a infix] ] ] unit-test
{ -1 } [ let[ 1 :> a infix[[ -a ]] ] ] unit-test
{ char: f } [ let[ "foo" :> s [infix s[0] infix] ] ] unit-test
{ char: r } [ let[ "bar" :> s [infix s[-1] infix] ] ] unit-test
{ "foo" } [ let[ "foobar" :> s [infix s[0:3] infix] ] ] unit-test
{ "foo" } [ let[ "foobar" :> s [infix s[:3] infix] ] ] unit-test
{ "bar" } [ let[ "foobar" :> s [infix s[-3:] infix] ] ] unit-test
{ "boof" } [ let[ "foobar" :> s [infix s[-3::-1] infix] ] ] unit-test
{ "foobar" } [ let[ "foobar" :> s [infix s[:] infix] ] ] unit-test
{ "foa" } [ let[ "foobar" :> s [infix s[::2] infix] ] ] unit-test
{ "bar" } [ let[ "foobar" :> s [infix s[-3:100] infix] ] ] unit-test
{ "foobar" } [ let[ "foobar" :> s [infix s[-100:100] infix] ] ] unit-test
{ "olh" } [ let[ "hello" :> s [infix s[4::-2] infix] ] ] unit-test
{ "rb" } [ let[ "foobar" :> s [infix s[:1:-2] infix] ] ] unit-test
{ "foa" } [ let[ "foobar" :> s [infix s[:-1:2] infix] ] ] unit-test
{ "rbo" } [ let[ "foobar" :> s [infix s[::-2] infix] ] ] unit-test
{ "rbo" } [ let[ "foobar" :> s [infix s[:0:-2] infix] ] ] unit-test
{ "rb" } [ let[ "foobar" :> s [infix s[:-5:-2] infix] ] ] unit-test
{ char: f } [ let[ "foo" :> s infix[[ s[0] ]] ] ] unit-test
{ char: r } [ let[ "bar" :> s infix[[ s[-1] ]] ] ] unit-test
{ "foo" } [ let[ "foobar" :> s infix[[ s[0:3] ]] ] ] unit-test
{ "foo" } [ let[ "foobar" :> s infix[[ s[:3] ]] ] ] unit-test
{ "bar" } [ let[ "foobar" :> s infix[[ s[-3:] ]] ] ] unit-test
{ "boof" } [ let[ "foobar" :> s infix[[ s[-3::-1] ]] ] ] unit-test
{ "foobar" } [ let[ "foobar" :> s infix[[ s[:] ]] ] ] unit-test
{ "foa" } [ let[ "foobar" :> s infix[[ s[::2] ]] ] ] unit-test
{ "bar" } [ let[ "foobar" :> s infix[[ s[-3:100] ]] ] ] unit-test
{ "foobar" } [ let[ "foobar" :> s infix[[ s[-100:100] ]] ] ] unit-test
{ "olh" } [ let[ "hello" :> s infix[[ s[4::-2] ]] ] ] unit-test
{ "rb" } [ let[ "foobar" :> s infix[[ s[:1:-2] ]] ] ] unit-test
{ "foa" } [ let[ "foobar" :> s infix[[ s[:-1:2] ]] ] ] unit-test
{ "rbo" } [ let[ "foobar" :> s infix[[ s[::-2] ]] ] ] unit-test
{ "rbo" } [ let[ "foobar" :> s infix[[ s[:0:-2] ]] ] ] unit-test
{ "rb" } [ let[ "foobar" :> s infix[[ s[:-5:-2] ]] ] ] unit-test
INFIX:: foo ( x y -- z ) x**2-abs(y) ;

View File

@ -117,8 +117,8 @@ M: ast-function infix-codegen
PRIVATE>
SYNTAX: [infix
"infix]" parse-infix-quotation suffix! \ call suffix! ;
SYNTAX: \ infix[[
"]]" parse-infix-quotation suffix! \ call suffix! ;
<PRIVATE
@ -130,4 +130,4 @@ SYNTAX: [infix
PRIVATE>
SYNTAX: INFIX:: (INFIX::) define-declared ;
SYNTAX: \ INFIX:: (INFIX::) define-declared ;

View File

@ -8,30 +8,16 @@
[ dup <vocab-link> . flush vocab>literals ] map-zip
"resource:collections" vocabs-from
{
{ "specialized-arrays" "specialized-vectors"
} diff
[ dup <vocab-link> . flush vocab>literals ] map-zip
"resource:ffi" vocabs-from
{ "x11.syntax" "windows.com.syntax" "python.syntax" "opengl.gl.extensions"
"opencl.syntax" "mongodb.tuple" "cuda.syntax" "core-foundation.strings"
"cocoa.subclassing" "cocoa" "cocoa.apple-script" "gobject-introspection" } diff
{ } diff
[ dup <vocab-link> . flush vocab>literals ] map-zip
"resource:libs" vocabs-from
{ "annotations" "brainfuck" "dice" "infix" "logging"
"metar" "money" "poker" "qw" "roles" "roman" "slides"
"svg" "urls" "xkcd" "calendar.holidays"
"calendar.holidays.canada" "calendar.holidays.us"
"colors.constants" "colors.hex" "gml.macros"
"gml.parser" "gml.runtime" "html.templates.chloe.syntax"
"infix.tokenizer" "irc.messages.base"
"math.complex" "math.rectangles" "math.blas.matrices"
"math.blas.vectors" "math.derivatives.syntax"
"math.vectors.simd" "math.vectors.simd.cords" "peg.pl0"
"peg.javascript.parser" "peg.javascript.tokenizer"
"unicode.categories" "units.reduction" "xml.errors"
"xml.syntax" "xmode.loader.syntax" "yaml.conversion"
{
} diff
[ dup <vocab-link> . flush vocab>literals ] map-zip