Merge branch 'master' of git://factorcode.org/git/factor
commit
89cb818dfb
|
@ -60,6 +60,7 @@ SYNTAX: IMPORT: scan [ ] import-objc-class ;
|
||||||
"NSOpenGLPixelFormat"
|
"NSOpenGLPixelFormat"
|
||||||
"NSOpenGLView"
|
"NSOpenGLView"
|
||||||
"NSOpenPanel"
|
"NSOpenPanel"
|
||||||
|
"NSPanel"
|
||||||
"NSPasteboard"
|
"NSPasteboard"
|
||||||
"NSPropertyListSerialization"
|
"NSPropertyListSerialization"
|
||||||
"NSResponder"
|
"NSResponder"
|
||||||
|
|
|
@ -4,36 +4,37 @@ USING: arrays kernel math cocoa cocoa.messages cocoa.classes
|
||||||
sequences math.bitwise ;
|
sequences math.bitwise ;
|
||||||
IN: cocoa.windows
|
IN: cocoa.windows
|
||||||
|
|
||||||
|
! Window styles
|
||||||
CONSTANT: NSBorderlessWindowMask 0
|
CONSTANT: NSBorderlessWindowMask 0
|
||||||
CONSTANT: NSTitledWindowMask 1
|
CONSTANT: NSTitledWindowMask 1
|
||||||
CONSTANT: NSClosableWindowMask 2
|
CONSTANT: NSClosableWindowMask 2
|
||||||
CONSTANT: NSMiniaturizableWindowMask 4
|
CONSTANT: NSMiniaturizableWindowMask 4
|
||||||
CONSTANT: NSResizableWindowMask 8
|
CONSTANT: NSResizableWindowMask 8
|
||||||
|
|
||||||
|
! Additional panel-only styles
|
||||||
|
CONSTANT: NSUtilityWindowMask 16
|
||||||
|
CONSTANT: NSDocModalWindowMask 64
|
||||||
|
CONSTANT: NSNonactivatingPanelMask 128
|
||||||
|
CONSTANT: NSHUDWindowMask HEX: 1000
|
||||||
|
|
||||||
CONSTANT: NSBackingStoreRetained 0
|
CONSTANT: NSBackingStoreRetained 0
|
||||||
CONSTANT: NSBackingStoreNonretained 1
|
CONSTANT: NSBackingStoreNonretained 1
|
||||||
CONSTANT: NSBackingStoreBuffered 2
|
CONSTANT: NSBackingStoreBuffered 2
|
||||||
|
|
||||||
: standard-window-type ( -- n )
|
: <NSWindow> ( rect style class -- window )
|
||||||
{
|
[ -> alloc ] curry 2dip NSBackingStoreBuffered 1
|
||||||
NSTitledWindowMask
|
|
||||||
NSClosableWindowMask
|
|
||||||
NSMiniaturizableWindowMask
|
|
||||||
NSResizableWindowMask
|
|
||||||
} flags ; inline
|
|
||||||
|
|
||||||
: <NSWindow> ( rect -- window )
|
|
||||||
NSWindow -> alloc swap
|
|
||||||
standard-window-type NSBackingStoreBuffered 1
|
|
||||||
-> initWithContentRect:styleMask:backing:defer: ;
|
-> initWithContentRect:styleMask:backing:defer: ;
|
||||||
|
|
||||||
: <ViewWindow> ( view rect -- window )
|
: class-for-style ( style -- NSWindow/NSPanel )
|
||||||
<NSWindow> [ swap -> setContentView: ] keep
|
HEX: 1ff0 bitand zero? NSWindow NSPanel ? ;
|
||||||
|
|
||||||
|
: <ViewWindow> ( view rect style -- window )
|
||||||
|
dup class-for-style <NSWindow> [ swap -> setContentView: ] keep
|
||||||
dup dup -> contentView -> setInitialFirstResponder:
|
dup dup -> contentView -> setInitialFirstResponder:
|
||||||
dup 1 -> setAcceptsMouseMovedEvents:
|
dup 1 -> setAcceptsMouseMovedEvents:
|
||||||
dup 0 -> setReleasedWhenClosed: ;
|
dup 0 -> setReleasedWhenClosed: ;
|
||||||
|
|
||||||
: window-content-rect ( window -- rect )
|
: window-content-rect ( window -- rect )
|
||||||
[ NSWindow ] dip
|
dup -> class swap
|
||||||
[ -> frame ] [ -> styleMask ] bi
|
[ -> frame ] [ -> styleMask ] bi
|
||||||
-> contentRectForFrameRect:styleMask: ;
|
-> contentRectForFrameRect:styleMask: ;
|
||||||
|
|
|
@ -328,10 +328,3 @@ C: <ro-box> ro-box
|
||||||
TUPLE: empty-tuple ;
|
TUPLE: empty-tuple ;
|
||||||
|
|
||||||
[ ] [ [ empty-tuple boa layout-of ] count-unboxed-allocations drop ] unit-test
|
[ ] [ [ empty-tuple boa layout-of ] count-unboxed-allocations drop ] unit-test
|
||||||
|
|
||||||
! Make sure that initial-quot: doesn't inhibit unboxing
|
|
||||||
TUPLE: initial-quot-tuple { x read-only initial-quot: [ 0 ] } ;
|
|
||||||
|
|
||||||
[ 1 ] [
|
|
||||||
[ initial-quot-tuple new x>> ] count-unboxed-allocations
|
|
||||||
] unit-test
|
|
|
@ -58,8 +58,6 @@ M: object (fake-quotations>) , ;
|
||||||
[ parse-definition* ] dip
|
[ parse-definition* ] dip
|
||||||
parsed ;
|
parsed ;
|
||||||
|
|
||||||
: DEFINE* ( accum -- accum ) \ define-declared* parsed ;
|
|
||||||
|
|
||||||
SYNTAX: `TUPLE:
|
SYNTAX: `TUPLE:
|
||||||
scan-param parsed
|
scan-param parsed
|
||||||
scan {
|
scan {
|
||||||
|
|
|
@ -51,9 +51,6 @@ M: heap heap-size ( heap -- n )
|
||||||
: data-nth ( n heap -- entry )
|
: data-nth ( n heap -- entry )
|
||||||
data>> nth-unsafe ; inline
|
data>> nth-unsafe ; inline
|
||||||
|
|
||||||
: up-value ( n heap -- entry )
|
|
||||||
[ up ] dip data-nth ; inline
|
|
||||||
|
|
||||||
: left-value ( n heap -- entry )
|
: left-value ( n heap -- entry )
|
||||||
[ left ] dip data-nth ; inline
|
[ left ] dip data-nth ; inline
|
||||||
|
|
||||||
|
@ -75,9 +72,6 @@ M: heap heap-size ( heap -- n )
|
||||||
: data-pop* ( heap -- )
|
: data-pop* ( heap -- )
|
||||||
data>> pop* ; inline
|
data>> pop* ; inline
|
||||||
|
|
||||||
: data-peek ( heap -- entry )
|
|
||||||
data>> last ; inline
|
|
||||||
|
|
||||||
: data-first ( heap -- entry )
|
: data-first ( heap -- entry )
|
||||||
data>> first ; inline
|
data>> first ; inline
|
||||||
|
|
||||||
|
@ -130,9 +124,6 @@ DEFER: up-heap
|
||||||
2dup right-bounds-check?
|
2dup right-bounds-check?
|
||||||
[ drop left ] [ (child) ] if ;
|
[ drop left ] [ (child) ] if ;
|
||||||
|
|
||||||
: swap-down ( m heap -- )
|
|
||||||
[ child ] 2keep data-exchange ;
|
|
||||||
|
|
||||||
DEFER: down-heap
|
DEFER: down-heap
|
||||||
|
|
||||||
: (down-heap) ( m heap -- )
|
: (down-heap) ( m heap -- )
|
||||||
|
|
|
@ -55,8 +55,6 @@ PRIVATE>
|
||||||
] check-something
|
] check-something
|
||||||
] [ drop ] if ;
|
] [ drop ] if ;
|
||||||
|
|
||||||
: check-words ( words -- ) [ check-word ] each ;
|
|
||||||
|
|
||||||
: check-article ( article -- )
|
: check-article ( article -- )
|
||||||
[ with-interactive-vocabs ] vocabs-quot set
|
[ with-interactive-vocabs ] vocabs-quot set
|
||||||
>link dup '[
|
>link dup '[
|
||||||
|
|
|
@ -11,17 +11,18 @@ combinators.short-circuit ;
|
||||||
IN: io.servers.connection
|
IN: io.servers.connection
|
||||||
|
|
||||||
TUPLE: threaded-server
|
TUPLE: threaded-server
|
||||||
{ name initial: "server" }
|
name
|
||||||
{ log-level initial: DEBUG }
|
log-level
|
||||||
secure insecure
|
secure
|
||||||
{ secure-config initial-quot: [ <secure-config> ] }
|
insecure
|
||||||
{ sockets initial-quot: [ V{ } clone ] }
|
secure-config
|
||||||
|
sockets
|
||||||
max-connections
|
max-connections
|
||||||
semaphore
|
semaphore
|
||||||
{ timeout initial-quot: [ 1 minutes ] }
|
timeout
|
||||||
encoding
|
encoding
|
||||||
{ handler initial: [ "No handler quotation" throw ] }
|
handler
|
||||||
{ ready initial-quot: [ <flag> ] } ;
|
ready ;
|
||||||
|
|
||||||
: local-server ( port -- addrspec ) "localhost" swap <inet> ;
|
: local-server ( port -- addrspec ) "localhost" swap <inet> ;
|
||||||
|
|
||||||
|
@ -29,6 +30,13 @@ encoding
|
||||||
|
|
||||||
: new-threaded-server ( encoding class -- threaded-server )
|
: new-threaded-server ( encoding class -- threaded-server )
|
||||||
new
|
new
|
||||||
|
"server" >>name
|
||||||
|
DEBUG >>log-level
|
||||||
|
<secure-config> >>secure-config
|
||||||
|
V{ } clone >>sockets
|
||||||
|
1 minutes >>timeout
|
||||||
|
[ "No handler quotation" throw ] >>handler
|
||||||
|
<flag> >>ready
|
||||||
swap >>encoding ;
|
swap >>encoding ;
|
||||||
|
|
||||||
: <threaded-server> ( encoding -- threaded-server )
|
: <threaded-server> ( encoding -- threaded-server )
|
||||||
|
|
|
@ -25,6 +25,7 @@ IN: opengl
|
||||||
{ HEX: 0503 "Stack overflow" }
|
{ HEX: 0503 "Stack overflow" }
|
||||||
{ HEX: 0504 "Stack underflow" }
|
{ HEX: 0504 "Stack underflow" }
|
||||||
{ HEX: 0505 "Out of memory" }
|
{ HEX: 0505 "Out of memory" }
|
||||||
|
{ HEX: 0506 "Invalid framebuffer operation" }
|
||||||
} at "Unknown error" or ;
|
} at "Unknown error" or ;
|
||||||
|
|
||||||
TUPLE: gl-error code string ;
|
TUPLE: gl-error code string ;
|
||||||
|
|
|
@ -61,10 +61,21 @@ PREDICATE: fragment-shader < gl-shader (fragment-shader?) ;
|
||||||
|
|
||||||
! Programs
|
! Programs
|
||||||
|
|
||||||
|
: <mrt-gl-program> ( shaders frag-data-locations -- program )
|
||||||
|
glCreateProgram
|
||||||
|
[
|
||||||
|
[ swap [ glAttachShader ] with each ]
|
||||||
|
[ swap [ first2 swap glBindFragDataLocationEXT ] with each ] bi-curry bi*
|
||||||
|
]
|
||||||
|
[ glLinkProgram ]
|
||||||
|
[ ] tri
|
||||||
|
gl-error ;
|
||||||
|
|
||||||
: <gl-program> ( shaders -- program )
|
: <gl-program> ( shaders -- program )
|
||||||
glCreateProgram swap
|
glCreateProgram
|
||||||
[ dupd glAttachShader ] each
|
[ swap [ glAttachShader ] with each ]
|
||||||
[ glLinkProgram ] keep
|
[ glLinkProgram ]
|
||||||
|
[ ] tri
|
||||||
gl-error ;
|
gl-error ;
|
||||||
|
|
||||||
: (gl-program?) ( object -- ? )
|
: (gl-program?) ( object -- ? )
|
||||||
|
|
|
@ -135,9 +135,6 @@ TUPLE: multi-texture grid display-list loc disposed ;
|
||||||
[ dup image-locs ] dip
|
[ dup image-locs ] dip
|
||||||
'[ [ _ v+ <single-texture> |dispose ] 2map ] 2map ;
|
'[ [ _ v+ <single-texture> |dispose ] 2map ] 2map ;
|
||||||
|
|
||||||
: draw-textured-grid ( grid -- )
|
|
||||||
[ [ [ dim>> ] keep (draw-textured-rect) ] each ] each ;
|
|
||||||
|
|
||||||
: grid-has-alpha? ( grid -- ? )
|
: grid-has-alpha? ( grid -- ? )
|
||||||
first first image>> has-alpha? ;
|
first first image>> has-alpha? ;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ USING: help.markup help.syntax kernel math sequences ;
|
||||||
IN: persistent.vectors
|
IN: persistent.vectors
|
||||||
|
|
||||||
HELP: PV{
|
HELP: PV{
|
||||||
{ $syntax "elements... }" }
|
{ $syntax "PV{ elements... }" }
|
||||||
{ $description "Parses a literal " { $link persistent-vector } "." } ;
|
{ $description "Parses a literal " { $link persistent-vector } "." } ;
|
||||||
|
|
||||||
HELP: >persistent-vector
|
HELP: >persistent-vector
|
||||||
|
|
|
@ -109,10 +109,23 @@ M: cocoa-ui-backend (set-fullscreen) ( world ? -- )
|
||||||
M: cocoa-ui-backend (fullscreen?) ( world -- ? )
|
M: cocoa-ui-backend (fullscreen?) ( world -- ? )
|
||||||
handle>> view>> -> isInFullScreenMode zero? not ;
|
handle>> view>> -> isInFullScreenMode zero? not ;
|
||||||
|
|
||||||
|
CONSTANT: window-control>styleMask
|
||||||
|
H{
|
||||||
|
{ close-button $ NSClosableWindowMask }
|
||||||
|
{ minimize-button $ NSMiniaturizableWindowMask }
|
||||||
|
{ maximize-button 0 }
|
||||||
|
{ resize-handles $ NSResizableWindowMask }
|
||||||
|
{ small-title-bar $[ NSTitledWindowMask NSUtilityWindowMask bitor ] }
|
||||||
|
{ normal-title-bar $ NSTitledWindowMask }
|
||||||
|
}
|
||||||
|
|
||||||
|
: world>styleMask ( world -- n )
|
||||||
|
window-controls>> [ window-control>styleMask at ] map 0 [ bitor ] reduce ;
|
||||||
|
|
||||||
M:: cocoa-ui-backend (open-window) ( world -- )
|
M:: cocoa-ui-backend (open-window) ( world -- )
|
||||||
world [ [ dim>> ] dip <FactorView> ]
|
world [ [ dim>> ] dip <FactorView> ]
|
||||||
with-world-pixel-format :> view
|
with-world-pixel-format :> view
|
||||||
view world world>NSRect <ViewWindow> :> window
|
view world [ world>NSRect ] [ world>styleMask ] bi <ViewWindow> :> window
|
||||||
view -> release
|
view -> release
|
||||||
world view register-window
|
world view register-window
|
||||||
window world window-loc>> auto-position
|
window world window-loc>> auto-position
|
||||||
|
@ -145,7 +158,7 @@ M: cocoa-ui-backend (ungrab-input) ( handle -- )
|
||||||
M: cocoa-ui-backend close-window ( gadget -- )
|
M: cocoa-ui-backend close-window ( gadget -- )
|
||||||
find-world [
|
find-world [
|
||||||
handle>> [
|
handle>> [
|
||||||
window>> f -> performClose:
|
window>> -> close
|
||||||
] when*
|
] when*
|
||||||
] when* ;
|
] when* ;
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,6 @@ TUPLE: gadget-metrics height ascent descent cap-height ;
|
||||||
: max-descent ( seq -- n )
|
: max-descent ( seq -- n )
|
||||||
[ descent>> ] map ?supremum ;
|
[ descent>> ] map ?supremum ;
|
||||||
|
|
||||||
: max-text-height ( seq -- y )
|
|
||||||
[ ascent>> ] filter [ height>> ] map ?supremum ;
|
|
||||||
|
|
||||||
: max-graphics-height ( seq -- y )
|
: max-graphics-height ( seq -- y )
|
||||||
[ ascent>> not ] filter [ height>> ] map ?supremum 0 or ;
|
[ ascent>> not ] filter [ height>> ] map ?supremum 0 or ;
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,7 @@ M: gadget gadget-text-separator
|
||||||
orientation>> vertical = "\n" "" ? ;
|
orientation>> vertical = "\n" "" ? ;
|
||||||
|
|
||||||
: gadget-seq-text ( seq gadget -- )
|
: gadget-seq-text ( seq gadget -- )
|
||||||
gadget-text-separator swap
|
gadget-text-separator '[ _ % ] [ gadget-text* ] interleave ;
|
||||||
[ dup % ] [ gadget-text* ] interleave drop ;
|
|
||||||
|
|
||||||
M: gadget gadget-text*
|
M: gadget gadget-text*
|
||||||
[ children>> ] keep gadget-seq-text ;
|
[ children>> ] keep gadget-seq-text ;
|
||||||
|
|
|
@ -96,10 +96,6 @@ M: pane selected-children
|
||||||
add-incremental
|
add-incremental
|
||||||
] [ next-line ] bi ;
|
] [ next-line ] bi ;
|
||||||
|
|
||||||
: ?pane-nl ( pane -- )
|
|
||||||
[ dup current>> children>> empty? [ pane-nl ] [ drop ] if ]
|
|
||||||
[ pane-nl ] bi ;
|
|
||||||
|
|
||||||
: smash-pane ( pane -- gadget ) [ pane-nl ] [ output>> smash-line ] bi ;
|
: smash-pane ( pane -- gadget ) [ pane-nl ] [ output>> smash-line ] bi ;
|
||||||
|
|
||||||
: pane-write ( seq pane -- )
|
: pane-write ( seq pane -- )
|
||||||
|
|
|
@ -5,10 +5,6 @@ IN: ui.gadgets.sliders
|
||||||
HELP: elevator
|
HELP: elevator
|
||||||
{ $class-description "An elevator is the part of a " { $link slider } " between the up/down arrow buttons, where a " { $link thumb } " may be moved up and down." } ;
|
{ $class-description "An elevator is the part of a " { $link slider } " between the up/down arrow buttons, where a " { $link thumb } " may be moved up and down." } ;
|
||||||
|
|
||||||
HELP: find-elevator
|
|
||||||
{ $values { "gadget" gadget } { "elevator/f" { $maybe elevator } } }
|
|
||||||
{ $description "Finds the first parent of " { $snippet "gadget" } " which is an " { $link elevator } ". Outputs " { $link f } " if the gadget is not contained in an " { $link elevator } "." } ;
|
|
||||||
|
|
||||||
HELP: slider
|
HELP: slider
|
||||||
{ $class-description "A slider is a control for graphically manipulating a " { $link "models-range" } "."
|
{ $class-description "A slider is a control for graphically manipulating a " { $link "models-range" } "."
|
||||||
$nl
|
$nl
|
||||||
|
|
|
@ -23,8 +23,6 @@ TUPLE: slider < track elevator thumb saved line ;
|
||||||
|
|
||||||
TUPLE: elevator < gadget direction ;
|
TUPLE: elevator < gadget direction ;
|
||||||
|
|
||||||
: find-elevator ( gadget -- elevator/f ) [ elevator? ] find-parent ;
|
|
||||||
|
|
||||||
: find-slider ( gadget -- slider/f ) [ slider? ] find-parent ;
|
: find-slider ( gadget -- slider/f ) [ slider? ] find-parent ;
|
||||||
|
|
||||||
CONSTANT: elevator-padding 4
|
CONSTANT: elevator-padding 4
|
||||||
|
|
|
@ -7,16 +7,34 @@ ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
|
||||||
ui.pixel-formats destructors literals strings ;
|
ui.pixel-formats destructors literals strings ;
|
||||||
IN: ui.gadgets.worlds
|
IN: ui.gadgets.worlds
|
||||||
|
|
||||||
|
SYMBOLS:
|
||||||
|
close-button
|
||||||
|
minimize-button
|
||||||
|
maximize-button
|
||||||
|
resize-handles
|
||||||
|
small-title-bar
|
||||||
|
normal-title-bar ;
|
||||||
|
|
||||||
CONSTANT: default-world-pixel-format-attributes
|
CONSTANT: default-world-pixel-format-attributes
|
||||||
{ windowed double-buffered T{ depth-bits { value 16 } } }
|
{ windowed double-buffered T{ depth-bits { value 16 } } }
|
||||||
|
|
||||||
|
CONSTANT: default-world-window-controls
|
||||||
|
{
|
||||||
|
normal-title-bar
|
||||||
|
close-button
|
||||||
|
minimize-button
|
||||||
|
maximize-button
|
||||||
|
resize-handles
|
||||||
|
}
|
||||||
|
|
||||||
TUPLE: world < track
|
TUPLE: world < track
|
||||||
active? focused? grab-input?
|
active? focused? grab-input?
|
||||||
layers
|
layers
|
||||||
title status status-owner
|
title status status-owner
|
||||||
text-handle handle images
|
text-handle handle images
|
||||||
window-loc
|
window-loc
|
||||||
pixel-format-attributes ;
|
pixel-format-attributes
|
||||||
|
window-controls ;
|
||||||
|
|
||||||
TUPLE: world-attributes
|
TUPLE: world-attributes
|
||||||
{ world-class initial: world }
|
{ world-class initial: world }
|
||||||
|
@ -24,7 +42,8 @@ TUPLE: world-attributes
|
||||||
{ title string initial: "Factor Window" }
|
{ title string initial: "Factor Window" }
|
||||||
status
|
status
|
||||||
gadgets
|
gadgets
|
||||||
{ pixel-format-attributes initial: $ default-world-pixel-format-attributes } ;
|
{ pixel-format-attributes initial: $ default-world-pixel-format-attributes }
|
||||||
|
{ window-controls initial: $ default-world-window-controls } ;
|
||||||
|
|
||||||
: <world-attributes> ( -- world-attributes )
|
: <world-attributes> ( -- world-attributes )
|
||||||
world-attributes new ; inline
|
world-attributes new ; inline
|
||||||
|
@ -86,6 +105,7 @@ M: world request-focus-on ( child gadget -- )
|
||||||
[ title>> >>title ]
|
[ title>> >>title ]
|
||||||
[ status>> >>status ]
|
[ status>> >>status ]
|
||||||
[ pixel-format-attributes>> >>pixel-format-attributes ]
|
[ pixel-format-attributes>> >>pixel-format-attributes ]
|
||||||
|
[ window-controls>> >>window-controls ]
|
||||||
[ grab-input?>> >>grab-input? ]
|
[ grab-input?>> >>grab-input? ]
|
||||||
[ gadgets>> [ 1 track-add ] each ]
|
[ gadgets>> [ 1 track-add ] each ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
|
@ -72,9 +72,6 @@ SYMBOL: table
|
||||||
: connect ( class1 class2 -- ) 1 set-table ;
|
: connect ( class1 class2 -- ) 1 set-table ;
|
||||||
: disconnect ( class1 class2 -- ) 0 set-table ;
|
: disconnect ( class1 class2 -- ) 0 set-table ;
|
||||||
|
|
||||||
: break-around ( classes1 classes2 -- )
|
|
||||||
[ disconnect ] [ swap disconnect ] 2bi ;
|
|
||||||
|
|
||||||
: make-grapheme-table ( -- )
|
: make-grapheme-table ( -- )
|
||||||
{ CR } { LF } connect
|
{ CR } { LF } connect
|
||||||
{ Control CR LF } graphemes disconnect
|
{ Control CR LF } graphemes disconnect
|
||||||
|
@ -91,9 +88,6 @@ VALUE: grapheme-table
|
||||||
: grapheme-break? ( class1 class2 -- ? )
|
: grapheme-break? ( class1 class2 -- ? )
|
||||||
grapheme-table nth nth not ;
|
grapheme-table nth nth not ;
|
||||||
|
|
||||||
: chars ( i str n -- str[i] str[i+n] )
|
|
||||||
swap [ dupd + ] dip [ ?nth ] curry bi@ ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: first-grapheme ( str -- i )
|
: first-grapheme ( str -- i )
|
||||||
|
|
|
@ -80,7 +80,6 @@ IN: bootstrap.syntax
|
||||||
">>"
|
">>"
|
||||||
"call-next-method"
|
"call-next-method"
|
||||||
"initial:"
|
"initial:"
|
||||||
"initial-quot:"
|
|
||||||
"read-only"
|
"read-only"
|
||||||
"call("
|
"call("
|
||||||
"execute("
|
"execute("
|
||||||
|
|
|
@ -142,11 +142,3 @@ TUPLE: parsing-corner-case x ;
|
||||||
" x 3 }"
|
" x 3 }"
|
||||||
} "\n" join eval( -- tuple )
|
} "\n" join eval( -- tuple )
|
||||||
] [ error>> unexpected-eof? ] must-fail-with
|
] [ error>> unexpected-eof? ] must-fail-with
|
||||||
|
|
||||||
|
|
||||||
[ ] [
|
|
||||||
<" USE: sequences
|
|
||||||
IN: classes.tuple.tests
|
|
||||||
TUPLE: book { name initial-quot: [ "Lord of the " "Rings" append ] } ;">
|
|
||||||
eval( -- )
|
|
||||||
] unit-test
|
|
||||||
|
|
|
@ -729,50 +729,3 @@ DEFER: redefine-tuple-twice
|
||||||
[ ] [ "IN: classes.tuple.tests TUPLE: redefine-tuple-twice ;" eval( -- ) ] unit-test
|
[ ] [ "IN: classes.tuple.tests TUPLE: redefine-tuple-twice ;" eval( -- ) ] unit-test
|
||||||
|
|
||||||
[ t ] [ \ redefine-tuple-twice symbol? ] unit-test
|
[ t ] [ \ redefine-tuple-twice symbol? ] unit-test
|
||||||
|
|
||||||
TUPLE: lucky-number { n initial-quot: [ 64 random-bits ] } ;
|
|
||||||
SLOT: winner?
|
|
||||||
|
|
||||||
[ t ] [ lucky-number new n>> integer? ] unit-test
|
|
||||||
|
|
||||||
: compiled-lucky-number ( -- tuple ) lucky-number new ;
|
|
||||||
|
|
||||||
[ t ] [ compiled-lucky-number n>> integer? ] unit-test
|
|
||||||
|
|
||||||
! Reshaping initial-quot:
|
|
||||||
lucky-number new dup n>> 2array "luckiest-number" set
|
|
||||||
|
|
||||||
[ t ] [ "luckiest-number" get first2 [ n>> ] dip = ] unit-test
|
|
||||||
|
|
||||||
[ ] [ "USING: accessors random ; IN: classes.tuple.tests TUPLE: lucky-number { n initial-quot: [ 64 random-bits ] } { winner? initial-quot: [ t ] } ;" eval( -- ) ] unit-test
|
|
||||||
|
|
||||||
[ t ] [ "luckiest-number" get first2 [ n>> ] dip = ] unit-test
|
|
||||||
[ t ] [ "luckiest-number" get first winner?>> ] unit-test
|
|
||||||
|
|
||||||
! invalid-quot: together with type declaration
|
|
||||||
TUPLE: decl-initial-quot { x integer initial-quot: [ 1 ] } ;
|
|
||||||
|
|
||||||
[ t ] [ decl-initial-quot new x>> integer? ] unit-test
|
|
||||||
|
|
||||||
: compiled-decl-initial-quot ( -- tuple ) decl-initial-quot new ;
|
|
||||||
|
|
||||||
[ t ] [ compiled-decl-initial-quot x>> integer? ] unit-test
|
|
||||||
|
|
||||||
! invalid-quot: with read-only
|
|
||||||
TUPLE: read-only-initial-quot { x integer read-only initial-quot: [ 1 ] } ;
|
|
||||||
|
|
||||||
[ t ] [ read-only-initial-quot new x>> integer? ] unit-test
|
|
||||||
|
|
||||||
: compiled-read-only-initial-quot ( -- tuple ) read-only-initial-quot new ;
|
|
||||||
|
|
||||||
[ t ] [ compiled-read-only-initial-quot x>> integer? ] unit-test
|
|
||||||
|
|
||||||
! Specifying both initial: and initial-quot: should fail
|
|
||||||
2 [
|
|
||||||
[
|
|
||||||
"IN: classes.tuple.test TUPLE: redundant-decl { x initial: 0 initial-quot: [ 0 ] } ;"
|
|
||||||
eval( -- )
|
|
||||||
]
|
|
||||||
[ error>> duplicate-initial-values? ]
|
|
||||||
must-fail-with
|
|
||||||
] times
|
|
||||||
|
|
|
@ -50,9 +50,6 @@ M: tuple class layout-of 2 slot { word } declare ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: initial-quots? ( class -- ? )
|
|
||||||
all-slots [ initial-quot>> ] any? ;
|
|
||||||
|
|
||||||
: initial-values ( class -- slots )
|
: initial-values ( class -- slots )
|
||||||
all-slots [ initial>> ] map ;
|
all-slots [ initial>> ] map ;
|
||||||
|
|
||||||
|
@ -149,21 +146,12 @@ ERROR: bad-superclass class ;
|
||||||
: define-boa-check ( class -- )
|
: define-boa-check ( class -- )
|
||||||
dup boa-check-quot "boa-check" set-word-prop ;
|
dup boa-check-quot "boa-check" set-word-prop ;
|
||||||
|
|
||||||
: tuple-initial-quots-quot ( class -- quot )
|
|
||||||
all-slots [ initial-quot>> ] filter
|
|
||||||
[
|
|
||||||
[
|
|
||||||
[ initial-quot>> % \ over , ] [ offset>> , ] bi \ set-slot ,
|
|
||||||
] each
|
|
||||||
] [ ] make f like ;
|
|
||||||
|
|
||||||
: tuple-prototype ( class -- prototype )
|
: tuple-prototype ( class -- prototype )
|
||||||
[ initial-values ] [ over [ ] any? ] [ initial-quots? or ] tri
|
[ initial-values ] keep over [ ] any?
|
||||||
[ slots>tuple ] [ 2drop f ] if ;
|
[ slots>tuple ] [ 2drop f ] if ;
|
||||||
|
|
||||||
: define-tuple-prototype ( class -- )
|
: define-tuple-prototype ( class -- )
|
||||||
dup [ tuple-prototype ] [ tuple-initial-quots-quot ] bi 2array
|
dup tuple-prototype "prototype" set-word-prop ;
|
||||||
dup [ ] any? [ drop f ] unless "prototype" set-word-prop ;
|
|
||||||
|
|
||||||
: prepare-slots ( slots superclass -- slots' )
|
: prepare-slots ( slots superclass -- slots' )
|
||||||
[ make-slots ] [ class-size 2 + ] bi* finalize-slots ;
|
[ make-slots ] [ class-size 2 + ] bi* finalize-slots ;
|
||||||
|
@ -185,16 +173,10 @@ ERROR: bad-superclass class ;
|
||||||
: define-tuple-layout ( class -- )
|
: define-tuple-layout ( class -- )
|
||||||
dup make-tuple-layout "layout" set-word-prop ;
|
dup make-tuple-layout "layout" set-word-prop ;
|
||||||
|
|
||||||
: calculate-initial-value ( slot-spec -- value )
|
|
||||||
dup initial>> [ ] [
|
|
||||||
dup initial-quot>>
|
|
||||||
[ call( -- obj ) ] [ drop f ] ?if
|
|
||||||
] ?if ;
|
|
||||||
|
|
||||||
: compute-slot-permutation ( new-slots old-slots -- triples )
|
: compute-slot-permutation ( new-slots old-slots -- triples )
|
||||||
[ [ [ name>> ] map ] bi@ [ index ] curry map ]
|
[ [ [ name>> ] map ] bi@ [ index ] curry map ]
|
||||||
[ drop [ class>> ] map ]
|
[ drop [ class>> ] map ]
|
||||||
[ drop [ calculate-initial-value ] map ]
|
[ drop [ initial>> ] map ]
|
||||||
2tri 3array flip ;
|
2tri 3array flip ;
|
||||||
|
|
||||||
: update-slot ( old-values n class initial -- value )
|
: update-slot ( old-values n class initial -- value )
|
||||||
|
@ -358,11 +340,7 @@ M: tuple tuple-hashcode
|
||||||
M: tuple hashcode* tuple-hashcode ;
|
M: tuple hashcode* tuple-hashcode ;
|
||||||
|
|
||||||
M: tuple-class new
|
M: tuple-class new
|
||||||
dup "prototype" word-prop [
|
dup "prototype" word-prop [ (clone) ] [ tuple-layout <tuple> ] ?if ;
|
||||||
first2 [ (clone) ] dip [ call( obj -- obj ) ] when*
|
|
||||||
] [
|
|
||||||
tuple-layout <tuple>
|
|
||||||
] ?if ;
|
|
||||||
|
|
||||||
M: tuple-class boa
|
M: tuple-class boa
|
||||||
[ "boa-check" word-prop [ call ] when* ]
|
[ "boa-check" word-prop [ call ] when* ]
|
||||||
|
|
|
@ -40,6 +40,4 @@ $nl
|
||||||
HELP: math-generic
|
HELP: math-generic
|
||||||
{ $class-description "The class of generic words using " { $link math-combination } "." } ;
|
{ $class-description "The class of generic words using " { $link math-combination } "." } ;
|
||||||
|
|
||||||
HELP: last/first
|
|
||||||
{ $values { "seq" sequence } { "pair" "a two-element array" } }
|
|
||||||
{ $description "Creates an array holding the first and last element of the sequence." } ;
|
|
||||||
|
|
|
@ -15,8 +15,6 @@ PREDICATE: math-class < class
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: last/first ( seq -- pair ) [ last ] [ first ] bi 2array ;
|
|
||||||
|
|
||||||
: bootstrap-words ( classes -- classes' )
|
: bootstrap-words ( classes -- classes' )
|
||||||
[ bootstrap-word ] map ;
|
[ bootstrap-word ] map ;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ HELP: <lexer-error>
|
||||||
|
|
||||||
HELP: skip
|
HELP: skip
|
||||||
{ $values { "i" "a starting index" } { "seq" sequence } { "?" "a boolean" } { "n" integer } }
|
{ $values { "i" "a starting index" } { "seq" sequence } { "?" "a boolean" } { "n" integer } }
|
||||||
{ $description "Skips to the first space character (if " { $snippet "boolean" } " is " { $link f } ") or the first non-space character (otherwise)." } ;
|
{ $description "Skips to the first space character (if " { $snippet "boolean" } " is " { $link f } ") or the first non-space character (otherwise). Tabulations used as separators instead of spaces will be flagged as an error." } ;
|
||||||
|
|
||||||
HELP: change-lexer-column
|
HELP: change-lexer-column
|
||||||
{ $values { "lexer" lexer } { "quot" { $quotation "( col line -- newcol )" } } }
|
{ $values { "lexer" lexer } { "quot" { $quotation "( col line -- newcol )" } } }
|
||||||
|
|
|
@ -22,9 +22,17 @@ TUPLE: lexer text line line-text line-length column ;
|
||||||
: <lexer> ( text -- lexer )
|
: <lexer> ( text -- lexer )
|
||||||
lexer new-lexer ;
|
lexer new-lexer ;
|
||||||
|
|
||||||
|
ERROR: unexpected want got ;
|
||||||
|
|
||||||
|
PREDICATE: unexpected-tab < unexpected
|
||||||
|
got>> CHAR: \t = ;
|
||||||
|
|
||||||
|
: forbid-tab ( c -- c )
|
||||||
|
[ CHAR: \t eq? [ "[space]" "[tab]" unexpected ] when ] keep ;
|
||||||
|
|
||||||
: skip ( i seq ? -- n )
|
: skip ( i seq ? -- n )
|
||||||
over length
|
over length
|
||||||
[ [ swap CHAR: \s eq? xor ] curry find-from drop ] dip or ;
|
[ [ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop ] dip or ;
|
||||||
|
|
||||||
: change-lexer-column ( lexer quot -- )
|
: change-lexer-column ( lexer quot -- )
|
||||||
[ [ column>> ] [ line-text>> ] bi ] prepose keep
|
[ [ column>> ] [ line-text>> ] bi ] prepose keep
|
||||||
|
@ -65,8 +73,6 @@ M: lexer skip-word ( lexer -- )
|
||||||
|
|
||||||
: scan ( -- str/f ) lexer get parse-token ;
|
: scan ( -- str/f ) lexer get parse-token ;
|
||||||
|
|
||||||
ERROR: unexpected want got ;
|
|
||||||
|
|
||||||
PREDICATE: unexpected-eof < unexpected
|
PREDICATE: unexpected-eof < unexpected
|
||||||
got>> not ;
|
got>> not ;
|
||||||
|
|
||||||
|
|
|
@ -286,3 +286,8 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ;
|
||||||
[ f f ] [
|
[ f f ] [
|
||||||
{ 1 2 3 4 5 6 7 8 } [ H{ { 11 "hi" } } at ] map-find
|
{ 1 2 3 4 5 6 7 8 } [ H{ { 11 "hi" } } at ] map-find
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
USE: make
|
||||||
|
|
||||||
|
[ { "a" 1 "b" 1 "c" } ]
|
||||||
|
[ 1 { "a" "b" "c" } [ [ dup , ] [ , ] interleave drop ] { } make ] unit-test
|
|
@ -510,7 +510,7 @@ PRIVATE>
|
||||||
: interleave ( seq between quot -- )
|
: interleave ( seq between quot -- )
|
||||||
pick empty? [ 3drop ] [
|
pick empty? [ 3drop ] [
|
||||||
[ [ drop first-unsafe ] dip call ]
|
[ [ drop first-unsafe ] dip call ]
|
||||||
[ [ rest-slice ] 2dip [ [ call ] bi@ ] 2curry each ]
|
[ [ rest-slice ] 2dip [ bi* ] 2curry each ]
|
||||||
3bi
|
3bi
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ classes classes.algebra slots.private combinators accessors
|
||||||
words sequences.private assocs alien quotations hashtables ;
|
words sequences.private assocs alien quotations hashtables ;
|
||||||
IN: slots
|
IN: slots
|
||||||
|
|
||||||
TUPLE: slot-spec name offset class initial initial-quot read-only ;
|
TUPLE: slot-spec name offset class initial read-only ;
|
||||||
|
|
||||||
PREDICATE: reader < word "reader" word-prop ;
|
PREDICATE: reader < word "reader" word-prop ;
|
||||||
|
|
||||||
|
@ -190,7 +190,6 @@ ERROR: bad-slot-attribute key ;
|
||||||
dup empty? [
|
dup empty? [
|
||||||
unclip {
|
unclip {
|
||||||
{ initial: [ [ first >>initial ] [ rest ] bi ] }
|
{ initial: [ [ first >>initial ] [ rest ] bi ] }
|
||||||
{ initial-quot: [ [ first >>initial-quot ] [ rest ] bi ] }
|
|
||||||
{ read-only [ [ t >>read-only ] dip ] }
|
{ read-only [ [ t >>read-only ] dip ] }
|
||||||
[ bad-slot-attribute ]
|
[ bad-slot-attribute ]
|
||||||
} case
|
} case
|
||||||
|
@ -198,14 +197,7 @@ ERROR: bad-slot-attribute key ;
|
||||||
|
|
||||||
ERROR: bad-initial-value name ;
|
ERROR: bad-initial-value name ;
|
||||||
|
|
||||||
ERROR: duplicate-initial-values slot ;
|
|
||||||
|
|
||||||
: check-duplicate-initial-values ( slot-spec -- slot-spec )
|
|
||||||
dup [ initial>> ] [ initial-quot>> ] bi and
|
|
||||||
[ duplicate-initial-values ] when ;
|
|
||||||
|
|
||||||
: check-initial-value ( slot-spec -- slot-spec )
|
: check-initial-value ( slot-spec -- slot-spec )
|
||||||
check-duplicate-initial-values
|
|
||||||
dup initial>> [
|
dup initial>> [
|
||||||
[ ] [
|
[ ] [
|
||||||
dup [ initial>> ] [ class>> ] bi instance?
|
dup [ initial>> ] [ class>> ] bi instance?
|
||||||
|
|
|
@ -246,8 +246,6 @@ IN: bootstrap.syntax
|
||||||
|
|
||||||
"initial:" "syntax" lookup define-symbol
|
"initial:" "syntax" lookup define-symbol
|
||||||
|
|
||||||
"initial-quot:" "syntax" lookup define-symbol
|
|
||||||
|
|
||||||
"read-only" "syntax" lookup define-symbol
|
"read-only" "syntax" lookup define-symbol
|
||||||
|
|
||||||
"call(" [ \ call-effect parse-call( ] define-core-syntax
|
"call(" [ \ call-effect parse-call( ] define-core-syntax
|
||||||
|
|
Loading…
Reference in New Issue