From 04c29c0a975148b92c9fd4100a21968da0ee9cc4 Mon Sep 17 00:00:00 2001
From: Maxim Savchenko
Date: Mon, 9 Mar 2009 16:33:20 -0400
Subject: [PATCH 01/44] ECDSA OpenSSL interface
---
basis/openssl/libcrypto/libcrypto.factor | 64 +++++++++++++++++-
extra/ecdsa/authors.txt | 1 +
extra/ecdsa/ecdsa-tests.factor | 30 +++++++++
extra/ecdsa/ecdsa.factor | 86 ++++++++++++++++++++++++
extra/ecdsa/summary.txt | 1 +
5 files changed, 181 insertions(+), 1 deletion(-)
create mode 100644 extra/ecdsa/authors.txt
create mode 100644 extra/ecdsa/ecdsa-tests.factor
create mode 100644 extra/ecdsa/ecdsa.factor
create mode 100644 extra/ecdsa/summary.txt
diff --git a/basis/openssl/libcrypto/libcrypto.factor b/basis/openssl/libcrypto/libcrypto.factor
index 9cbed1f752..1a25b4d019 100644
--- a/basis/openssl/libcrypto/libcrypto.factor
+++ b/basis/openssl/libcrypto/libcrypto.factor
@@ -1,4 +1,4 @@
-! Copyright (C) 2007 Elie CHAFTARI
+! Copyright (C) 2007 Elie CHAFTARI, 2009 Maxim Savchenko
! See http://factorcode.org/license.txt for BSD license.
!
! Tested with OpenSSL 0.9.8a_0 on Mac OS X 10.4.9 PowerPC
@@ -159,3 +159,65 @@ FUNCTION: int RSA_check_key ( void* rsa ) ;
FUNCTION: void RSA_free ( void* rsa ) ;
FUNCTION: int RSA_print_fp ( void* fp, void* x, int offset ) ;
+
+! ===============================================
+! objects.h
+! ===============================================
+
+FUNCTION: int OBJ_sn2nid ( char* s ) ;
+
+! ===============================================
+! bn.h
+! ===============================================
+
+FUNCTION: int BN_num_bits ( void* a ) ;
+
+FUNCTION: void* BN_bin2bn ( void* s, int len, void* ret ) ;
+
+FUNCTION: int BN_bn2bin ( void* a, void* to ) ;
+
+FUNCTION: void BN_clear_free ( void* a ) ;
+
+! ===============================================
+! ec.h
+! ===============================================
+
+CONSTANT: POINT_CONVERSION_COMPRESSED 2
+CONSTANT: POINT_CONVERSION_UNCOMPRESSED 4
+CONSTANT: POINT_CONVERSION_HYBRID 6
+
+FUNCTION: int EC_GROUP_get_degree ( void* group ) ;
+
+FUNCTION: void* EC_POINT_new ( void* group ) ;
+
+FUNCTION: void EC_POINT_clear_free ( void* point ) ;
+
+FUNCTION: int EC_POINT_point2oct ( void* group, void* point, int form, void* buf, int len, void* ctx ) ;
+
+FUNCTION: int EC_POINT_oct2point ( void* group, void* point, void* buf, int len, void* ctx ) ;
+
+FUNCTION: void* EC_KEY_new_by_curve_name ( int nid ) ;
+
+FUNCTION: void EC_KEY_free ( void* r ) ;
+
+FUNCTION: int EC_KEY_set_private_key ( void* key, void* priv_key ) ;
+
+FUNCTION: int EC_KEY_set_public_key ( void* key, void* pub_key ) ;
+
+FUNCTION: int EC_KEY_generate_key ( void* eckey ) ;
+
+FUNCTION: void* EC_KEY_get0_group ( void* key ) ;
+
+FUNCTION: void* EC_KEY_get0_private_key ( void* key ) ;
+
+FUNCTION: void* EC_KEY_get0_public_key ( void* key ) ;
+
+! ===============================================
+! ecdsa.h
+! ===============================================
+
+FUNCTION: int ECDSA_size ( void* eckey ) ;
+
+FUNCTION: int ECDSA_sign ( int type, void* dgst, int dgstlen, void* sig, void* siglen, void* eckey ) ;
+
+FUNCTION: int ECDSA_verify ( int type, void* dgst, int dgstlen, void* sig, int siglen, void* eckey ) ;
diff --git a/extra/ecdsa/authors.txt b/extra/ecdsa/authors.txt
new file mode 100644
index 0000000000..f97e1bfbf9
--- /dev/null
+++ b/extra/ecdsa/authors.txt
@@ -0,0 +1 @@
+Maxim Savchenko
diff --git a/extra/ecdsa/ecdsa-tests.factor b/extra/ecdsa/ecdsa-tests.factor
new file mode 100644
index 0000000000..897ee63a95
--- /dev/null
+++ b/extra/ecdsa/ecdsa-tests.factor
@@ -0,0 +1,30 @@
+! Copyright (C) 2009 Maxim Savchenko
+! See http://factorcode.org/license.txt for BSD license.
+
+USING: namespaces ecdsa tools.test checksums checksums.openssl ;
+IN: ecdsa.tests
+
+SYMBOLS: priv-key pub-key signature ;
+
+: message ( -- msg ) "Hello world!" ;
+
+[ ] ! Generating keys
+[
+ "prime256v1" [ generate-key get-private-key get-public-key ] with-ec
+ pub-key set priv-key set
+] unit-test
+
+[ ] ! Signing message
+[
+ message "sha256" checksum-bytes
+ priv-key get
+ "prime256v1" [ set-private-key ecdsa-sign ] with-ec
+ signature set
+] unit-test
+
+[ t ] ! Verifying signature
+[
+ message "sha256" checksum-bytes
+ signature get pub-key get
+ "prime256v1" [ set-public-key ecdsa-verify ] with-ec
+] unit-test
\ No newline at end of file
diff --git a/extra/ecdsa/ecdsa.factor b/extra/ecdsa/ecdsa.factor
new file mode 100644
index 0000000000..78b528d4ad
--- /dev/null
+++ b/extra/ecdsa/ecdsa.factor
@@ -0,0 +1,86 @@
+! Copyright (C) 2009 Maxim Savchenko
+! See http://factorcode.org/license.txt for BSD license.
+
+USING: kernel accessors sequences sequences.private destructors math namespaces
+ locals openssl openssl.libcrypto byte-arrays bit-arrays.private
+ alien.c-types ;
+
+IN: ecdsa
+
+ ( curve -- key )
+ OBJ_sn2nid dup zero? [ "Unknown curve name" throw ] when
+ EC_KEY_new_by_curve_name dup ssl-error ec-key boa ;
+
+: ec-key-handle ( -- handle )
+ ec-key get dup handle>> [ nip ] [ already-disposed ] if* ;
+
+TUPLE: openssl-bignum < openssl-object ;
+
+M: openssl-bignum free-handle BN_clear_free ;
+
+TUPLE: ec-point < openssl-object ;
+
+M: ec-point free-handle EC_POINT_clear_free ;
+
+PRIVATE>
+
+: with-ec ( curve quot -- )
+ swap [ ec-key rot with-variable ] with-disposal ; inline
+
+: generate-key ( -- )
+ ec-key get handle>> EC_KEY_generate_key ssl-error ;
+
+: set-private-key ( bin -- )
+ ec-key-handle swap
+ dup length f BN_bin2bn dup ssl-error dup openssl-bignum boa
+ [ drop EC_KEY_set_private_key ssl-error ] with-disposal ;
+
+:: set-public-key ( BIN -- )
+ ec-key-handle :> KEY
+ KEY EC_KEY_get0_group :> GROUP
+ GROUP EC_POINT_new dup ssl-error :> POINT
+ POINT ec-point boa
+ [
+ drop
+ GROUP POINT BIN dup length f EC_POINT_oct2point ssl-error
+ KEY POINT EC_KEY_set_public_key ssl-error
+ ] with-disposal ;
+
+: get-private-key ( -- bin/f )
+ ec-key-handle EC_KEY_get0_private_key
+ dup [ dup BN_num_bits bits>bytes tuck BN_bn2bin drop ] when ;
+
+:: get-public-key ( -- bin/f )
+ ec-key-handle :> KEY
+ KEY EC_KEY_get0_public_key dup
+ [| PUB |
+ KEY EC_KEY_get0_group :> GROUP
+ GROUP EC_GROUP_get_degree bits>bytes 1+ :> LEN
+ LEN :> BIN
+ GROUP PUB POINT_CONVERSION_COMPRESSED BIN LEN f
+ EC_POINT_point2oct ssl-error
+ BIN
+ ] when ;
+
+:: ecdsa-sign ( DGST -- sig )
+ ec-key-handle :> KEY
+ KEY ECDSA_size dup ssl-error :> SIG
+ "uint" :> LEN
+ 0 DGST dup length SIG LEN KEY ECDSA_sign ssl-error
+ LEN *uint SIG resize ;
+
+: ecdsa-verify ( dgst sig -- ? )
+ ec-key-handle [ 0 -rot [ dup length ] bi@ ] dip ECDSA_verify 0 > ;
\ No newline at end of file
diff --git a/extra/ecdsa/summary.txt b/extra/ecdsa/summary.txt
new file mode 100644
index 0000000000..8f952c36a5
--- /dev/null
+++ b/extra/ecdsa/summary.txt
@@ -0,0 +1 @@
+Elliptic Curve Digital Signature Algorithm (OpenSSL realisation)
From 5a14faecd6f7352a5556dc3a91e368721d164b22 Mon Sep 17 00:00:00 2001
From: Sam Anklesaria
Date: Mon, 9 Mar 2009 20:13:17 -0500
Subject: [PATCH 02/44] added rendering functions
---
basis/ui/utils/utils.factor | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 basis/ui/utils/utils.factor
diff --git a/basis/ui/utils/utils.factor b/basis/ui/utils/utils.factor
new file mode 100644
index 0000000000..468af45150
--- /dev/null
+++ b/basis/ui/utils/utils.factor
@@ -0,0 +1,6 @@
+USING: accessors sequences namespaces ui.render opengl fry ;
+IN: ui.utils
+SYMBOLS: width height ;
+: store-dim ( gadget -- ) dim>> [ first width set ] [ second height set ] bi ;
+: with-dim ( gadget quot -- ) '[ _ store-dim @ ] with-scope ;
+: with-w/h ( gadget quot -- ) '[ origin get _ with-translation ] with-dim ;
\ No newline at end of file
From 4d453923ae1f7c65d7274b8f2ea83b4f3b160497 Mon Sep 17 00:00:00 2001
From: Sam Anklesaria
Date: Mon, 9 Mar 2009 20:34:56 -0500
Subject: [PATCH 03/44] added simple dialogs for the ui
---
basis/ui/gadgets/alerts/alerts.factor | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 basis/ui/gadgets/alerts/alerts.factor
diff --git a/basis/ui/gadgets/alerts/alerts.factor b/basis/ui/gadgets/alerts/alerts.factor
new file mode 100644
index 0000000000..3a4120b3de
--- /dev/null
+++ b/basis/ui/gadgets/alerts/alerts.factor
@@ -0,0 +1,4 @@
+USING: accessors ui ui.gadgets ui.gadgets.labels ui.gadgets.buttons ui.gadgets.packs locals sequences io.styles ;
+IN: ui.gadgets.alerts
+:: alert ( quot string -- ) { 10 10 } >>gap 1 >>align string
"
+ "Feature comparison:
a | Factor | Java | Lisp |
Coolness | Yes | No | No |
Badass | Yes | No | No |
Enterprise | Yes | Yes | No |
Kosher | Yes | No | Yes |
"
] [ "Feature comparison:\n|a|Factor|Java|Lisp|\n|Coolness|Yes|No|No|\n|Badass|Yes|No|No|\n|Enterprise|Yes|Yes|No|\n|Kosher|Yes|No|Yes|\n" convert-farkup ] unit-test
[
- "Feature comparison:\n
a | Factor | Java | Lisp |
Coolness | Yes | No | No |
Badass | Yes | No | No |
Enterprise | Yes | Yes | No |
Kosher | Yes | No | Yes |
"
+ "Feature comparison:
a | Factor | Java | Lisp |
Coolness | Yes | No | No |
Badass | Yes | No | No |
Enterprise | Yes | Yes | No |
Kosher | Yes | No | Yes |
"
] [ "Feature comparison:\n\n|a|Factor|Java|Lisp|\n|Coolness|Yes|No|No|\n|Badass|Yes|No|No|\n|Enterprise|Yes|Yes|No|\n|Kosher|Yes|No|Yes|\n" convert-farkup ] unit-test
[
@@ -131,33 +131,33 @@ link-no-follow? off
[ "<foo>
" ] [ "" convert-farkup ] unit-test
-[ "asdf\n
" ] [ "asdf\n-lol\n-haha" convert-farkup ] unit-test
+[ "asdf
" ] [ "asdf\n-lol\n-haha" convert-farkup ] unit-test
-[ "asdf\n
" ]
+[ "asdf
" ]
[ "asdf\n\n-lol\n-haha" convert-farkup ] unit-test
[ "
" ] [ "___" convert-farkup ] unit-test
-[ "
\n" ] [ "___\n" convert-farkup ] unit-test
+[ "
" ] [ "___\n" convert-farkup ] unit-test
-[ "before:\n
{ 1 2 3 } 1 tail
" ]
+[ "before:
{ 1 2 3 } 1 tail
" ]
[ "before:\n[factor{{ 1 2 3 } 1 tail}]" convert-farkup ] unit-test
[ "Factor-rific!
" ]
[ "[[Factor]]-rific!" convert-farkup ] unit-test
-[ "[ factor { 1 2 3 }]
" ]
+[ " 1 2 3
" ]
[ "[ factor { 1 2 3 }]" convert-farkup ] unit-test
-[ "paragraph\n
" ]
+[ "paragraph
" ]
[ "paragraph\n___" convert-farkup ] unit-test
-[ "paragraph\n a ___ b
" ]
+[ "paragraph
a b
" ]
[ "paragraph\n a ___ b" convert-farkup ] unit-test
-[ "\n
" ]
+[ "
" ]
[ "\n- a\n___" convert-farkup ] unit-test
-[ "hello_world how are you today?\n
- hello_world how are you today?
" ]
+[ "helloworld how are you today?
- helloworld how are you today?
" ]
[ "hello_world how are you today?\n- hello_world how are you today?" convert-farkup ] unit-test
: check-link-escaping ( string -- link )
@@ -168,3 +168,15 @@ link-no-follow? off
[ "" ] [ "[[]]" check-link-escaping ] unit-test
[ "&blah;" ] [ "[[&blah;]]" check-link-escaping ] unit-test
[ "C++" ] [ "[[C++]]" check-link-escaping ] unit-test
+
+[ "The important thing
" ] [ "=The _important_ thing=" convert-farkup ] unit-test
+[ "emphasized text
" ] [ "[[Foo|*emphasized* text]]" convert-farkup ] unit-test
+[ "" ]
+[ "|*bold*|_italics_|" convert-farkup ] unit-test
+[ "italicsboth
" ] [ "_italics*both" convert-farkup ] unit-test
+[ "italicsboth
" ] [ "_italics*both*" convert-farkup ] unit-test
+[ "italicsboth
" ] [ "_italics*both*_" convert-farkup ] unit-test
+[ "italicsboth
" ] [ "_italics*both_" convert-farkup ] unit-test
+[ "italicsbothafter
" ] [ "_italics*both_after*" convert-farkup ] unit-test
+[ "" ] [ "|foo\\|bar|" convert-farkup ] unit-test
+[ "" ] [ "\\" convert-farkup ] unit-test
diff --git a/basis/farkup/farkup.factor b/basis/farkup/farkup.factor
old mode 100755
new mode 100644
index 4041d92773..23a9023835
--- a/basis/farkup/farkup.factor
+++ b/basis/farkup/farkup.factor
@@ -1,10 +1,9 @@
-! Copyright (C) 2008 Doug Coleman.
+! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays combinators io
-io.streams.string kernel math namespaces peg peg.ebnf
-sequences sequences.deep strings xml.entities xml.syntax
-vectors splitting xmode.code2html urls.encoding xml.data
-xml.writer ;
+USING: sequences kernel splitting lists fry accessors assocs math.order
+math combinators namespaces urls.encoding xml.syntax xmode.code2html
+xml.data arrays strings vectors xml.writer io.streams.string locals
+unicode.categories ;
IN: farkup
SYMBOL: relative-link-prefix
@@ -39,123 +38,174 @@ TUPLE: line-break ;
: simple-link-title ( string -- string' )
dup absolute-url? [ "/" split1-last swap or ] unless ;
-EBNF: parse-farkup
-nl = ("\r\n" | "\r" | "\n") => [[ drop "\n" ]]
-whitespace = " " | "\t" | nl
+! _foo*bar_baz*bing works like foo*barbazbing
+! I could support overlapping, but there's not a good use case for it.
-heading1 = "=" (!("=" | nl).)+ "="
- => [[ second >string heading1 boa ]]
+DEFER: (parse-paragraph)
-heading2 = "==" (!("=" | nl).)+ "=="
- => [[ second >string heading2 boa ]]
+: parse-paragraph ( string -- seq )
+ (parse-paragraph) list>array ;
-heading3 = "===" (!("=" | nl).)+ "==="
- => [[ second >string heading3 boa ]]
+: make-paragraph ( string -- paragraph )
+ parse-paragraph paragraph boa ;
-heading4 = "====" (!("=" | nl).)+ "===="
- => [[ second >string heading4 boa ]]
+: cut-half-slice ( string i -- before after-slice )
+ [ head ] [ 1+ short tail-slice ] 2bi ;
-heading = heading4 | heading3 | heading2 | heading1
+: find-cut ( string quot -- before after delimiter )
+ dupd find
+ [ [ cut-half-slice ] [ f ] if* ] dip ; inline
+: parse-delimiter ( string delimiter class -- paragraph )
+ [ '[ _ = ] find-cut drop ] dip
+ '[ parse-paragraph _ new swap >>child ]
+ [ (parse-paragraph) ] bi* cons ;
+: delimiter-class ( delimiter -- class )
+ H{
+ { CHAR: * strong }
+ { CHAR: _ emphasis }
+ { CHAR: ^ superscript }
+ { CHAR: ~ subscript }
+ { CHAR: % inline-code }
+ } at ;
-strong = "*" (!("*" | nl).)+ "*"
- => [[ second >string strong boa ]]
+: parse-link ( string -- paragraph-list )
+ rest-slice "]]" split1-slice [
+ "|" split1
+ [ "" like dup simple-link-title ] unless*
+ [ "image:" ?head ] dip swap [ image boa ] [ parse-paragraph link boa ] if
+ ] dip [ (parse-paragraph) cons ] when* ;
-emphasis = "_" (!("_" | nl).)+ "_"
- => [[ second >string emphasis boa ]]
+: ?first ( seq -- elt ) 0 swap ?nth ;
-superscript = "^" (!("^" | nl).)+ "^"
- => [[ second >string superscript boa ]]
+: parse-big-link ( before after -- link rest )
+ dup ?first CHAR: [ =
+ [ parse-link ]
+ [ [ CHAR: [ suffix ] [ (parse-paragraph) ] bi* ]
+ if ;
-subscript = "~" (!("~" | nl).)+ "~"
- => [[ second >string subscript boa ]]
+: escape ( before after -- before' after' )
+ [ nil ] [ unclip-slice swap [ suffix ] dip (parse-paragraph) ] if-empty ;
-inline-code = "%" (!("%" | nl).)+ "%"
- => [[ second >string inline-code boa ]]
+: (parse-paragraph) ( string -- list )
+ [ nil ] [
+ [ "*_^~%[\\" member? ] find-cut [
+ {
+ { CHAR: [ [ parse-big-link ] }
+ { CHAR: \\ [ escape ] }
+ [ dup delimiter-class parse-delimiter ]
+ } case cons
+ ] [ drop "" like 1list ] if*
+ ] if-empty ;
-link-content = (!("|"|"]").)+
- => [[ >string ]]
+: ( string -- state ) string-lines ;
+: look ( state i -- char ) swap first ?nth ;
+: done? ( state -- ? ) empty? ;
+: take-line ( state -- state' line ) unclip-slice ;
-image-link = "[[image:" link-content "|" link-content "]]"
- => [[ [ second >string ] [ fourth >string ] bi image boa ]]
- | "[[image:" link-content "]]"
- => [[ second >string f image boa ]]
+: take-lines ( state char -- state' lines )
+ dupd '[ ?first _ = not ] find drop
+ [ cut-slice ] [ f ] if* swap ;
-simple-link = "[[" link-content "]]"
- => [[ second >string dup simple-link-title link boa ]]
+:: (take-until) ( state delimiter accum -- string/f state' )
+ state empty? [ accum "\n" join f ] [
+ state unclip-slice :> first :> rest
+ first delimiter split1 :> after :> before
+ before accum push
+ after [
+ accum "\n" join
+ rest after prefix
+ ] [
+ rest delimiter accum (take-until)
+ ] if
+ ] if ;
-labeled-link = "[[" link-content "|" link-content "]]"
- => [[ [ second >string ] [ fourth >string ] bi link boa ]]
+: take-until ( state delimiter -- string/f state' )
+ V{ } clone (take-until) ;
-link = image-link | labeled-link | simple-link
+: count= ( string -- n )
+ dup [ [ CHAR: = = not ] find drop 0 or ] bi@ min ;
-escaped-char = "\" .
- => [[ second 1string ]]
+: trim= ( string -- string' )
+ [ CHAR: = = ] trim ;
-inline-tag = strong | emphasis | superscript | subscript | inline-code
- | link | escaped-char
+: make-heading ( string class -- heading )
+ [ trim= parse-paragraph ] dip boa ; inline
+: parse-heading ( state -- state' heading )
+ take-line dup count= {
+ { 0 [ make-paragraph ] }
+ { 1 [ heading1 make-heading ] }
+ { 2 [ heading2 make-heading ] }
+ { 3 [ heading3 make-heading ] }
+ { 4 [ heading4 make-heading ] }
+ [ drop heading4 make-heading ]
+ } case ;
+: trim-row ( seq -- seq' )
+ rest
+ dup peek empty? [ but-last ] when ;
-inline-delimiter = '*' | '_' | '^' | '~' | '%' | '\' | '['
+: ?peek ( seq -- elt/f )
+ [ f ] [ peek ] if-empty ;
-cell = (!(inline-delimiter | '|' | nl).)+
- => [[ >string ]]
-
-table-column = (list | cell | inline-tag | inline-delimiter ) '|'
- => [[ first ]]
-table-row = "|" (table-column)+
- => [[ second table-row boa ]]
-table = ((table-row nl => [[ first ]] )+ table-row? | table-row)
- => [[ table boa ]]
+: coalesce ( rows -- rows' )
+ V{ } clone [
+ '[
+ _ dup ?peek ?peek CHAR: \\ =
+ [ [ pop "|" rot 3append ] keep ] when
+ push
+ ] each
+ ] keep ;
-text = (!(nl | code | heading | inline-delimiter | table ).)+
- => [[ >string ]]
+: parse-table ( state -- state' table )
+ CHAR: | take-lines [
+ "|" split
+ trim-row
+ coalesce
+ [ parse-paragraph ] map
+ table-row boa
+ ] map table boa ;
-paragraph-nl-item = nl list
- | nl line
- | nl => [[ line-breaks? get [ drop line-break new ] when ]]
-paragraph-item = (table | code | text | inline-tag | inline-delimiter)+
-paragraph = ((paragraph-item paragraph-nl-item)+ nl+ => [[ first ]]
- | (paragraph-item paragraph-nl-item)+ paragraph-item?
- | paragraph-item)
- => [[ paragraph boa ]]
+: parse-line ( state -- state' item )
+ take-line dup "___" =
+ [ drop line new ] [ make-paragraph ] if ;
+: parse-list ( state char class -- state' list )
+ [
+ take-lines
+ [ rest parse-paragraph list-item boa ] map
+ ] dip boa ; inline
-list-item = (cell | inline-tag | inline-delimiter)*
+: parse-ul ( state -- state' ul )
+ CHAR: - unordered-list parse-list ;
-ordered-list-item = '#' list-item
- => [[ second list-item boa ]]
-ordered-list = ((ordered-list-item nl)+ ordered-list-item? | ordered-list-item)
- => [[ ordered-list boa ]]
+: parse-ol ( state -- state' ul )
+ CHAR: # ordered-list parse-list ;
-unordered-list-item = '-' list-item
- => [[ second list-item boa ]]
-unordered-list = ((unordered-list-item nl)+ unordered-list-item? | unordered-list-item)
- => [[ unordered-list boa ]]
+: parse-code ( state -- state' item )
+ dup 1 look CHAR: [ =
+ [ unclip-slice make-paragraph ] [
+ "{" take-until [ rest ] dip
+ "}]" take-until
+ [ code boa ] dip swap
+ ] if ;
-list = ordered-list | unordered-list
+: parse-item ( state -- state' item )
+ dup 0 look {
+ { CHAR: = [ parse-heading ] }
+ { CHAR: | [ parse-table ] }
+ { CHAR: _ [ parse-line ] }
+ { CHAR: - [ parse-ul ] }
+ { CHAR: # [ parse-ol ] }
+ { CHAR: [ [ parse-code ] }
+ { f [ rest-slice f ] }
+ [ drop take-line make-paragraph ]
+ } case ;
-
-line = '___'
- => [[ drop line new ]]
-
-
-named-code
- = '[' (!('{' | whitespace | '[').)+ '{' (!("}]").)+ "}]"
- => [[ [ second >string ] [ fourth >string ] bi code boa ]]
-
-simple-code
- = "[{" (!("}]").)+ "}]"
- => [[ second >string f swap code boa ]]
-
-code = named-code | simple-code
-
-
-stand-alone
- = (line | code | heading | list | table | paragraph | nl)*
-;EBNF
+: parse-farkup ( string -- farkup )
+ [ dup done? not ] [ parse-item ] produce nip sift ;
CONSTANT: invalid-url "javascript:alert('Invalid URL in farkup');"
@@ -168,19 +218,6 @@ CONSTANT: invalid-url "javascript:alert('Invalid URL in farkup');"
[ relative-link-prefix get prepend "" like url-encode ]
} cond ;
-: write-link ( href text -- xml )
- [ check-url link-no-follow? get "nofollow" and ] dip
- [XML rel=<->><-> XML] ;
-
-: write-image-link ( href text -- xml )
- disable-images? get [
- 2drop
- [XML Images are not allowed XML]
- ] [
- [ check-url ] [ f like ] bi*
- [XML
alt=<->/> XML]
- ] if ;
-
: render-code ( string mode -- xml )
[ string-lines ] dip htmlize-lines
[XML <->
XML] ;
@@ -206,11 +243,27 @@ M: ordered-list (write-farkup) "ol" farkup-inside ;
M: paragraph (write-farkup) "p" farkup-inside ;
M: table (write-farkup) "table" farkup-inside ;
+: write-link ( href text -- xml )
+ [ check-url link-no-follow? get "nofollow" and ] dip
+ [XML rel=<->><-> XML] ;
+
+: write-image-link ( href text -- xml )
+ disable-images? get [
+ 2drop
+ [XML Images are not allowed XML]
+ ] [
+ [ check-url ] [ f like ] bi*
+ [XML
alt=<->/> XML]
+ ] if ;
+
+: open-link ( link -- href text )
+ [ href>> ] [ text>> (write-farkup) ] bi ;
+
M: link (write-farkup)
- [ href>> ] [ text>> ] bi write-link ;
+ open-link write-link ;
M: image (write-farkup)
- [ href>> ] [ text>> ] bi write-image-link ;
+ open-link write-image-link ;
M: code (write-farkup)
[ string>> ] [ mode>> ] bi render-code ;
@@ -228,9 +281,7 @@ M: table-row (write-farkup)
M: string (write-farkup) ;
-M: vector (write-farkup) [ (write-farkup) ] map ;
-
-M: f (write-farkup) ;
+M: array (write-farkup) [ (write-farkup) ] map ;
: farkup>xml ( string -- xml )
parse-farkup (write-farkup) ;
@@ -240,3 +291,4 @@ M: f (write-farkup) ;
: convert-farkup ( string -- string' )
[ write-farkup ] with-string-writer ;
+
From c468ed8962b139f78ab403dccef3dc4ca19717f2 Mon Sep 17 00:00:00 2001
From: Slava Pestov
Date: Mon, 16 Mar 2009 00:44:44 -0500
Subject: [PATCH 19/44] integer/integer partial dispatch ops now use
both-fixnums?
---
.../partial-dispatch-tests.factor | 5 +++
.../partial-dispatch/partial-dispatch.factor | 34 ++++++++++++-------
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/basis/math/partial-dispatch/partial-dispatch-tests.factor b/basis/math/partial-dispatch/partial-dispatch-tests.factor
index bcf7bb77b0..29979b62d3 100644
--- a/basis/math/partial-dispatch/partial-dispatch-tests.factor
+++ b/basis/math/partial-dispatch/partial-dispatch-tests.factor
@@ -26,3 +26,8 @@ tools.test math kernel sequences ;
[ fixnum-bitnot ] [ \ bitnot modular-variant ] unit-test
[ fixnum+fast ] [ \ fixnum+ modular-variant ] unit-test
[ fixnum+fast ] [ \ fixnum+fast modular-variant ] unit-test
+
+[ 3 ] [ 1 2 +-integer-integer ] unit-test
+[ 3 ] [ 1 >bignum 2 +-integer-integer ] unit-test
+[ 3 ] [ 1 2 >bignum +-integer-integer ] unit-test
+[ 3 ] [ 1 >bignum 2 >bignum +-integer-integer ] unit-test
\ No newline at end of file
diff --git a/basis/math/partial-dispatch/partial-dispatch.factor b/basis/math/partial-dispatch/partial-dispatch.factor
index 08cd8fb470..6679e81fcd 100644
--- a/basis/math/partial-dispatch/partial-dispatch.factor
+++ b/basis/math/partial-dispatch/partial-dispatch.factor
@@ -45,31 +45,41 @@ M: word integer-op-input-classes
{ bitnot fixnum-bitnot }
} at swap or ;
+: bignum-fixnum-op-quot ( big-word -- quot )
+ '[ fixnum>bignum _ execute ] ;
+
+: fixnum-bignum-op-quot ( big-word -- quot )
+ '[ [ fixnum>bignum ] dip _ execute ] ;
+
: integer-fixnum-op-quot ( fix-word big-word -- quot )
[
[ over fixnum? ] %
- [ '[ _ execute ] , ]
- [ '[ fixnum>bignum _ execute ] , ] bi*
- \ if ,
+ [ '[ _ execute ] , ] [ bignum-fixnum-op-quot , ] bi* \ if ,
] [ ] make ;
: fixnum-integer-op-quot ( fix-word big-word -- quot )
[
[ dup fixnum? ] %
- [ '[ _ execute ] , ]
- [ '[ [ fixnum>bignum ] dip _ execute ] , ] bi*
- \ if ,
+ [ '[ _ execute ] , ] [ fixnum-bignum-op-quot , ] bi* \ if ,
+ ] [ ] make ;
+
+: integer-bignum-op-quot ( big-word -- quot )
+ [
+ [ over fixnum? ] %
+ [ fixnum-bignum-op-quot , ] [ '[ _ execute ] , ] bi \ if ,
] [ ] make ;
: integer-integer-op-quot ( fix-word big-word -- quot )
[
- [ dup fixnum? ] %
- 2dup integer-fixnum-op-quot ,
+ [ 2dup both-fixnums? ] %
+ [ '[ _ execute ] , ]
[
- [ over fixnum? [ [ fixnum>bignum ] dip ] when ] %
- nip ,
- ] [ ] make ,
- \ if ,
+ [
+ [ dup fixnum? ] %
+ [ bignum-fixnum-op-quot , ]
+ [ integer-bignum-op-quot , ] bi \ if ,
+ ] [ ] make ,
+ ] bi* \ if ,
] [ ] make ;
: integer-op-word ( triple -- word )
From 22cd50ca4f51f3758c87098e1e25a526cbea16cd Mon Sep 17 00:00:00 2001
From: Daniel Ehrenberg
Date: Mon, 16 Mar 2009 01:30:42 -0500
Subject: [PATCH 20/44] Fixing html.components unit test
---
basis/html/components/components-tests.factor | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/basis/html/components/components-tests.factor b/basis/html/components/components-tests.factor
index 0b85455c2e..72ceea20a0 100644
--- a/basis/html/components/components-tests.factor
+++ b/basis/html/components/components-tests.factor
@@ -163,7 +163,7 @@ M: link-test link-href drop "http://www.apple.com/foo&bar" ;
[ ] [ "-foo\n-bar" "farkup" set-value ] unit-test
-[ "" ] [
+[ "" ] [
[ "farkup" T{ farkup } render ] with-string-writer
] unit-test
From 4589aab8a4de759570da429d7ad16ebc3a2468eb Mon Sep 17 00:00:00 2001
From: Slava Pestov
Date: Mon, 16 Mar 2009 03:00:37 -0500
Subject: [PATCH 21/44] Move ui.gadgets.alerts, ui.gadgets.book-extras and
ui.utils to extra
---
{basis => extra}/ui/gadgets/alerts/alerts.factor | 0
{basis => extra}/ui/gadgets/book-extras/book-extras.factor | 0
{basis => extra}/ui/utils/utils.factor | 0
3 files changed, 0 insertions(+), 0 deletions(-)
rename {basis => extra}/ui/gadgets/alerts/alerts.factor (100%)
rename {basis => extra}/ui/gadgets/book-extras/book-extras.factor (100%)
rename {basis => extra}/ui/utils/utils.factor (100%)
diff --git a/basis/ui/gadgets/alerts/alerts.factor b/extra/ui/gadgets/alerts/alerts.factor
similarity index 100%
rename from basis/ui/gadgets/alerts/alerts.factor
rename to extra/ui/gadgets/alerts/alerts.factor
diff --git a/basis/ui/gadgets/book-extras/book-extras.factor b/extra/ui/gadgets/book-extras/book-extras.factor
similarity index 100%
rename from basis/ui/gadgets/book-extras/book-extras.factor
rename to extra/ui/gadgets/book-extras/book-extras.factor
diff --git a/basis/ui/utils/utils.factor b/extra/ui/utils/utils.factor
similarity index 100%
rename from basis/ui/utils/utils.factor
rename to extra/ui/utils/utils.factor
From 56ffaf5cb1a82f2d192f7d24ecca26771d2c4e40 Mon Sep 17 00:00:00 2001
From: Slava Pestov
Date: Mon, 16 Mar 2009 03:01:32 -0500
Subject: [PATCH 22/44] Updating ui.gadgets.alerts, ui.gadgets.book-extras,
ui.utils and drills for new_ui changes
---
extra/drills/drills.factor | 13 +++++++------
extra/ui/gadgets/alerts/alerts.factor | 2 +-
extra/ui/gadgets/book-extras/book-extras.factor | 2 +-
extra/ui/utils/utils.factor | 6 +++---
4 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/extra/drills/drills.factor b/extra/drills/drills.factor
index ee4343b1b8..98da12959b 100644
--- a/extra/drills/drills.factor
+++ b/extra/drills/drills.factor
@@ -1,17 +1,18 @@
USING: accessors arrays cocoa.dialogs combinators continuations
fry grouping io.encodings.utf8 io.files io.styles kernel math
-math.parser models models.filter models.history namespaces random
+math.parser models models.arrow models.history namespaces random
sequences splitting ui ui.gadgets.alerts ui.gadgets.book-extras
ui.gadgets.books ui.gadgets.buttons ui.gadgets.frames
-ui.gadgets.grids ui.gadgets.labels ui.gadgets.tracks ui.gestures ;
+ui.gadgets.grids ui.gadgets.labels ui.gadgets.tracks ui.gestures
+ui.gadgets.corners ;
IN: drills
SYMBOLS: it startLength ;
: big ( gadget -- gadget ) { "sans-serif" plain 30 } >>font ;
-: card ( model quot -- button ) big [ next ] ;
+: card ( model quot -- button ) big [ next ] ;
: op ( quot str -- gadget )