new accessors
							parent
							
								
									6fe6475cce
								
							
						
					
					
						commit
						6bd16d7f9f
					
				|  | @ -3,7 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| USING: arrays asn1.ldap assocs byte-arrays combinators | USING: arrays asn1.ldap assocs byte-arrays combinators | ||||||
| continuations io io.binary io.streams.string kernel math | continuations io io.binary io.streams.string kernel math | ||||||
| math.parser namespaces pack strings sequences ; | math.parser namespaces pack strings sequences accessors ; | ||||||
| 
 | 
 | ||||||
| IN: asn1 | IN: asn1 | ||||||
| 
 | 
 | ||||||
|  | @ -48,16 +48,12 @@ SYMBOL: elements | ||||||
| 
 | 
 | ||||||
| TUPLE: element syntax id tag tagclass encoding contentlength newobj objtype ; | TUPLE: element syntax id tag tagclass encoding contentlength newobj objtype ; | ||||||
| 
 | 
 | ||||||
| : <element> ( -- element ) element new ; |  | ||||||
| 
 |  | ||||||
| : set-id ( -- boolean ) |  | ||||||
|     read1 dup elements get set-element-id ; |  | ||||||
| 
 | 
 | ||||||
| : get-id ( -- id ) | : get-id ( -- id ) | ||||||
|     elements get element-id ; |     elements get id>> ; | ||||||
| 
 | 
 | ||||||
| : (set-tag) ( -- ) | : (set-tag) ( -- ) | ||||||
|     elements get element-id 31 bitand |     elements get id>> 31 bitand | ||||||
|     dup elements get set-element-tag |     dup elements get set-element-tag | ||||||
|     31 < [ |     31 < [ | ||||||
|         [ "unsupported tag encoding: #{" %  |         [ "unsupported tag encoding: #{" %  | ||||||
|  | @ -81,14 +77,14 @@ TUPLE: element syntax id tag tagclass encoding contentlength newobj objtype ; | ||||||
|     ] unless elements get set-element-contentlength ; |     ] unless elements get set-element-contentlength ; | ||||||
| 
 | 
 | ||||||
| : set-newobj ( -- ) | : set-newobj ( -- ) | ||||||
|     elements get element-contentlength read |     elements get contentlength>> read | ||||||
|     elements get set-element-newobj ; |     elements get set-element-newobj ; | ||||||
| 
 | 
 | ||||||
| : set-objtype ( syntax -- ) | : set-objtype ( syntax -- ) | ||||||
|     builtin-syntax 2array [ |     builtin-syntax 2array [ | ||||||
|         elements get element-tagclass swap at |         elements get tagclass>> swap at | ||||||
|         elements get element-encoding swap at |         elements get encoding>> swap at | ||||||
|         elements get element-tag |         elements get tag>> | ||||||
|         swap at [  |         swap at [  | ||||||
|             elements get set-element-objtype |             elements get set-element-objtype | ||||||
|         ] when* |         ] when* | ||||||
|  | @ -99,7 +95,7 @@ DEFER: read-ber | ||||||
| SYMBOL: end | SYMBOL: end | ||||||
| 
 | 
 | ||||||
| : (read-array) ( -- ) | : (read-array) ( -- ) | ||||||
|     elements get element-id [ |     elements get id>> [ | ||||||
|         elements get element-syntax read-ber |         elements get element-syntax read-ber | ||||||
|         dup end = [ drop ] [ , (read-array) ] if |         dup end = [ drop ] [ , (read-array) ] if | ||||||
|     ] when ; |     ] when ; | ||||||
|  | @ -115,9 +111,13 @@ SYMBOL: end | ||||||
|         { "array" [ "" or [ read-array ] with-string-reader ] } |         { "array" [ "" or [ read-array ] with-string-reader ] } | ||||||
|     } case ; |     } case ; | ||||||
| 
 | 
 | ||||||
|  | : set-id ( -- boolean ) | ||||||
|  |     read1 dup elements get set-element-id ; | ||||||
|  | 
 | ||||||
| : read-ber ( syntax -- object ) | : read-ber ( syntax -- object ) | ||||||
|     <element> elements set |     element new | ||||||
|     elements get set-element-syntax |         swap >>syntax | ||||||
|  |     elements set | ||||||
|     set-id [ |     set-id [ | ||||||
|         (set-tag) |         (set-tag) | ||||||
|         set-tagclass |         set-tagclass | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| USING: math kernel debugger ; | USING: accessors math kernel debugger ; | ||||||
| IN: benchmark.fib4 | IN: benchmark.fib4 | ||||||
| 
 | 
 | ||||||
| TUPLE: box i ; | TUPLE: box i ; | ||||||
|  | @ -6,15 +6,15 @@ TUPLE: box i ; | ||||||
| C: <box> box | C: <box> box | ||||||
| 
 | 
 | ||||||
| : tuple-fib ( m -- n ) | : tuple-fib ( m -- n ) | ||||||
|     dup box-i 1 <= [ |     dup i>> 1 <= [ | ||||||
|         drop 1 <box> |         drop 1 <box> | ||||||
|     ] [ |     ] [ | ||||||
|         box-i 1- <box> |         i>> 1- <box> | ||||||
|         dup tuple-fib |         dup tuple-fib | ||||||
|         swap |         swap | ||||||
|         box-i 1- <box> |         i>> 1- <box> | ||||||
|         tuple-fib |         tuple-fib | ||||||
|         swap box-i swap box-i + <box> |         swap i>> swap i>> + <box> | ||||||
|     ] if ; |     ] if ; | ||||||
| 
 | 
 | ||||||
| : fib-main ( -- ) T{ box f 34 } tuple-fib T{ box f 9227465 } assert= ; | : fib-main ( -- ) T{ box f 34 } tuple-fib T{ box f 9227465 } assert= ; | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| USING: math kernel ; | USING: math kernel accessors ; | ||||||
| IN: benchmark.typecheck1 | IN: benchmark.typecheck1 | ||||||
| 
 | 
 | ||||||
| TUPLE: hello n ; | TUPLE: hello n ; | ||||||
| 
 | 
 | ||||||
| : foo ( obj -- obj n ) 0 100000000 [ over hello-n + ] times ; | : foo ( obj -- obj n ) 0 100000000 [ over n>> + ] times ; | ||||||
| 
 | 
 | ||||||
| : typecheck-main ( -- ) 0 hello boa foo 2drop ; | : typecheck-main ( -- ) 0 hello boa foo 2drop ; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ USING: arrays combinators kernel lists math math.parser | ||||||
| namespaces parser lexer parser-combinators parser-combinators.simple | namespaces parser lexer parser-combinators parser-combinators.simple | ||||||
| promises quotations sequences combinators.lib strings math.order | promises quotations sequences combinators.lib strings math.order | ||||||
| assocs prettyprint.backend memoize unicode.case unicode.categories | assocs prettyprint.backend memoize unicode.case unicode.categories | ||||||
| combinators.short-circuit ; | combinators.short-circuit accessors ; | ||||||
| USE: io | USE: io | ||||||
| IN: regexp | IN: regexp | ||||||
| 
 | 
 | ||||||
|  | @ -277,7 +277,7 @@ TUPLE: regexp source parser ignore-case? ; | ||||||
| 
 | 
 | ||||||
| : match-head ( string regexp -- end ) | : match-head ( string regexp -- end ) | ||||||
|     do-ignore-case regexp-parser parse dup nil? |     do-ignore-case regexp-parser parse dup nil? | ||||||
|     [ drop f ] [ car parse-result-unparsed slice-from ] if ; |     [ drop f ] [ car parse-result-unparsed from>> ] if ; | ||||||
| 
 | 
 | ||||||
| ! Literal syntax for regexps | ! Literal syntax for regexps | ||||||
| : parse-options ( string -- ? ) | : parse-options ( string -- ? ) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue