root/trunk/orca/boot.r

Revision 297, 14.4 kB (checked in by krobillard, 2 years ago)

Orca - Added /return refinement to 'quit.

Line 
1REBOL [
2    Purpose: {ORCA boot-strap script.}
3]
4
5
6natives: [
7    ;native: native [spec [block!]]
8    sizeof: native []
9
10    comment: native [value]
11
12    set: native [
13        word  ; [any-word! none!]
14        value ; [any-type!]
15        ;/any
16    ]
17
18    unset: native [
19        word [word! block!]
20    ]
21
22    value?: native [val]
23    any-word?: native [val]
24
25    get: native [
26        word ; [any-word! none!]
27        ;/any
28    ]
29
30    do: native [
31      "Evaluates a block or any other value."
32      value
33      /args arg
34      ;/next
35    ]
36
37    make: native [
38        "Construct new value"
39        type
40        spec
41    ]
42
43    bind: native [
44        words [block! word!]        ;[block! any-word!]
45        known-word [word! object!]  ;[any-word! object! port!]
46        /copy
47    ]
48
49    in: native [
50        object [object!] ; port!
51        word [word!]     ; any-word!
52    ]
53
54    use: native [
55        words [block! word!]
56        body [block!]
57    ]
58
59    copy: native [
60        value [series! bitset! matrix!]     ; [series! port!]
61        /part
62        range [integer! series!]    ; [number! port! pair!]
63        /deep
64    ]
65
66    change: native [
67        series [series!]    ; port!
68        value               ; [any-type!]
69        /part
70        range [integer! series!]    ; [number! port!]
71        /only
72    ]
73
74    find: native [
75        series [series!]    ; port! bitset!
76        value   ; [any-type!]
77        /match
78        /last
79        /skip size [integer!]
80        ;/part
81        ;range   ; [number! series! port!]
82        ;/case
83    ]
84
85    reduce: native [
86        value
87    ]
88
89    compose: native [
90        value
91        /deep
92        /only
93    ]
94
95    form: native [
96        value
97    ]
98
99    mold: native [
100        value
101        /only
102        ;/all
103        ;/flat
104    ]
105
106    not: native [ value ]
107
108    print: native [ value ]
109    prin: native [ value ]
110
111    clear: native [
112        series [series! none!]    ;port! bitset!
113    ]
114
115    skip: native [
116        series [series!]    ;port!
117        offset [number! logic!]  ; pair!
118    ]
119
120    at: native [
121        series [series!]    ; port!
122        index [number! logic!]  ; pair!
123    ]
124
125    pick: native [
126        series [series! tuple! matrix!]    ; time! object! port! ...
127        index [number! logic!]  ; pair!
128    ]
129
130    poke: native [
131        value
132        index [number! logic!]  ; pair!
133        data
134    ]
135
136    select: native [
137        series [series!] ; port!
138        value
139        ;/part
140        ;range [number! series!]  ; port!
141        ;/only
142        ;/case
143        ;/skip
144        ;size [integer!]
145    ]
146
147    first:  native [ value ]
148    second: native [ value ]
149    third:  native [ value ]
150
151    last: native [ value [series! tuple!] ]  ;port!
152
153    reverse: native [
154        value [series! tuple! pair!]
155        /part
156        range [integer! series!]
157    ]
158
159    parse: native [
160        input [series!]
161        rules [block! string! none!]
162        /all
163        /case
164    ]
165
166    type?: native [value /word]
167    length?: native [value [series! tuple!]]  ; port! bitset! struct!
168    any-string?: native [value]
169    any-block?: native [value]
170
171    ;series?: native [ value ]
172    ;integer?: native [ value ]
173    ;tag?: native [ value ]
174
175    binary?:
176    bitset?:
177    block?:
178    char?:
179    datatype?:
180    decimal?:
181    error?:
182    file?:
183    function?:
184    getword?:
185    hash?:
186    integer?:
187    issue?:
188    list?:
189    litpath?:
190    litword?:
191    logic?:
192    native?:
193    none?:
194    number?:
195    object?:
196    op?:
197    pair?:
198    paren?:
199    path?:
200    refinement?:
201    series?:
202    setpath?:
203    setword?:
204    string?:
205    tag?:
206    time?:
207    tuple?:
208    unset?:
209    word?: native [value]
210
211    to: native [
212        type
213        value
214    ]
215
216    disarm: native [ error [error!] ]
217    try:   native [ block [block!] ]
218    catch: native [
219        block [block!]
220        /name word [word!]  ;[word! block!]
221    ]
222    throw: native [ value /name word [word!] ]
223
224    does: native [ value ]
225
226    func: native [
227        ;[catch]
228        spec [block!]
229        body [block!]
230    ]
231
232    if: native [
233        condition
234        then-block [block!]
235        ;/else
236        ;else-block [block!]
237    ]
238
239    unless: native [
240        condition
241        then-block [block!]
242    ]
243
244    either: native [
245        condition
246        then-block [block!]
247        else-block [block!]
248    ]
249
250    any: native [
251        block [block!]
252    ]
253
254    all: native [
255        block [block!]
256    ]
257
258    loop: native [
259        count [integer!]
260        block [block!]
261    ]
262
263    repeat: native [
264        'word [word!]
265        value [integer! series!]
266        block [block!]
267    ]
268
269    foreach: native [
270        'word [word! block!]    ; get-word!
271        data [series!]
272        body [block!]
273    ]
274
275    remove-each: native [
276        'word [word! block!]
277        data [series!]
278        body [block!]
279    ]
280   
281    while: native [
282        cond [block!]
283        body [block!]
284    ]
285
286    until: native [
287        cond [block!]
288    ]
289
290    break: native [
291        /return
292        value   ;[any-type!]
293    ]
294
295    return: native [
296        value   ;[any-type!]
297    ]
298
299    exit: native []
300
301    back: native [
302        series [series!]    ; [series! port!]
303    ]
304
305    next: native [
306        series [series!]    ; [series! port!]
307    ]
308
309    head: native [
310        series [series!]    ; [series! port!]
311    ]
312
313    tail: native [
314        series [series!]    ; [series! port!]
315    ]
316
317    index?: native [
318        series [series!]    ; [series! port!]
319    ]
320
321    head?: native [
322        series [series!]    ; port!
323    ]
324
325    tail?: native [
326        series [series!]    ; [series! port! bitset!]
327    ]
328
329    insert: native [
330        series [series!]    ;[series! port! bitset!]
331        value  ;[any-type!]
332        /part
333        range  [integer! series!] ;[number! series! port! pair!]
334        /only
335        ;/dup
336        ;count [integer!] ;[number! pair!]
337    ]
338
339    remove: native [
340        series [series! none!]    ; [series! port! bitset! none!]
341        /part
342        range [integer! series! pair!] ; [number! series! port! pair!]
343    ]
344
345    lowercase: native [
346        string [string! file!]  ; any-string!
347        /part range [integer!]  ; any-string!
348    ]
349
350    uppercase: native [
351        string [string! file!]  ; any-string!
352        /part range [integer!]  ; any-string!
353    ]
354
355    load: native [
356        source [file! string!]  ; url! any-block! binary!
357    ]
358
359
360    open:  native [ what ]
361    close: native [ port [port!] ]
362
363    read: native [
364        source [file! port!]  ; block! object! url!
365        /binary
366        /lines
367        /skip length [number!]
368        /part size [number!]
369        ; many more...
370    ]
371
372    write: native [
373        dest [file! port! object! block!] ; url!
374        value
375        /binary
376        /append
377        ;/lines
378        ; many more...
379    ]
380
381    rename: native [
382        old [file!]             ; url!
383        new [file! string!]     ; url!
384    ]
385
386    delete: native [
387        what [file!]    ; url!
388    ]
389
390    exists?: native [
391        target [file!]  ; url!
392    ]
393
394    size?: native [
395        target [file!]  ; url!
396    ]
397
398    dir?: native [
399        target [file!]  ; url!
400    ]
401
402    modified?: native [
403        target [file!]  ; url!
404    ]
405
406    getenv: native [name [string!]]
407
408    change-dir: native [value]
409    what-dir: native []
410    make-dir: native [path [file!]]     ; url!
411
412    clean-path: native [path [file!]]   ; url!
413
414    recycle: native [/off /on]
415
416    halt: native []
417    quit: native [/return code]
418
419    protect: native [
420        value [word! block!]
421    ]
422
423    now: native [
424        ;/year
425        ;/month
426        ;/day
427        /time
428        ;/zone
429        ;/date
430        ;/weekday
431        ;/precise
432    ]
433
434    trim: native [
435        string [string! series!]  ; [series! port!]
436        /auto
437        /head
438        /tail
439        ;/all
440        ;/lines
441        ;/with
442        ;pattern [char! string!]
443    ]
444
445    ;to-hex: native [
446    ;    value [integer!]
447    ;]   
448    ;sizeof: native []
449    ;memory: native []
450    dump: native [val]
451
452    same?: native [v1 v2]
453    equal?: native [v1 v2]
454    strict-equal?: native [v1 v2]
455    greater-or-equal?: native [v1 v2]
456    greater?: native [v1 v2]
457    lesser-or-equal?: native [v1 v2]
458    lesser?: native [v1 v2]
459
460    odd?: native [number [number! char!]]  ; date! time!
461    even?: native [number [number! char!]]  ; date! time!
462    abs: native [number [number! pair!]] ; date! time!
463    complement: native [value [logic! integer! bitset!]] ;number! char! tuple!
464    negate: native [number [number! pair! bitset! vec3!]] ; time!
465
466    sine: native [value [number!] /radians]
467    cosine: native [value [number!] /radians]
468    arcsine: native [value [number!] /radians]
469    arccosine: native [value [number!] /radians]
470    tangent: native [value [number!] /radians]
471    arctangent: native [value [number!] /radians]
472    square-root: native [value [number!]]
473
474    random: native [value /seed /only]
475    power: native [x [number!] y [number!]]
476    remainder: native [
477        x [number!]   ; pair! char! time! tuple!
478        y [number!]   ; pair! char! time! tuple!
479    ]
480
481
482    ; config compress
483
484    compress: native [data [string! binary!]] ; any-string!
485    decompress: native [data [binary!]]
486
487
488    ; config glmath
489
490    dot:   native [a [vec3!] b [vec3!]]
491    cross: native [a [vec3!] b [vec3!]]
492    normalize: native [vec [vec3!]]
493]
494
495
496boot: [
497    context: func [blk [block!]] [make object! blk]
498
499    probe: func [ value ][ print mold :value :value ]
500
501    source: func ['word] [
502        prin rejoin [word ": "]
503        either function? get word [
504            print mold get word
505        ][
506            either native? get word
507                [print mold get word]
508                [print "is not a function"]
509        ]
510    ]
511
512    function: func [
513        spec [block!]
514        vars [block!]
515        body [block!]
516    ][
517        func head insert insert tail copy spec /local vars body
518    ]
519
520    true: yes: on:  make logic! 1
521    false: no: off: make logic! 0
522
523    newline: #"^/"
524
525    empty?: :tail?
526    q: :quit
527
528    orca: true
529
530    system: context [
531        version: 0.0.23
532        os: none
533        error: context [
534          msg: type: id: near: none
535        ]
536        error-types: [ 'syntax 'script 'math 'access 'internal ]
537        words: none
538        script-proto: context [
539            args:
540            path:
541            parent:
542            header: none
543        ]
544        script: none
545
546        ;console: context [
547        ;  history: []
548        ;  prompt: {>> }
549        ;]
550    ]
551
552    protect 'system
553    protect 'datatypes
554
555    to-binary: func [value][to binary! :value]
556    to-bitset: func [value][to bitset! :value]
557    to-block: func [value][to block! :value]
558    to-char: func [value][to char! :value]
559    ;to-date: func [value][to date! :value]
560    to-decimal: func [value][to decimal! :value]
561    to-file: func [value][to file! :value]
562    to-get-word: func [value][to get-word! :value]
563    ;to-hash: func [value][to hash! :value]
564    to-integer: func [value][to integer! :value]
565    to-issue: func [value][to issue! :value]
566    ;to-list: func [value][to list! :value]
567    to-lit-path: func [value][to lit-path! :value]
568    to-lit-word: func [value][to lit-word! :value]
569    to-logic: func [value][to logic! :value]
570    ;to-pair: func [value][to pair! :value]
571    to-paren: func [value][to paren! :value]
572    to-path: func [value][to path! :value]
573    to-refinement: func [value][to refinement! :value]
574    to-set-path: func [value][to set-path! :value]
575    to-set-word: func [value][to set-word! :value]
576    to-string: func [value][to string! :value]
577    to-tag: func [value][to tag! :value]
578    to-time: func [value][to time! :value]
579    to-tuple: func [value][to tuple! :value]
580    ;to-url: func [value][to url! :value]
581    to-word: func [value][to word! :value]
582
583    charset: func [str [string! block!]] [make bitset! str]
584
585    append: func [
586        series [series!]    ; [series! port!]
587        value
588        /only
589    ][
590        head either only
591            [insert/only tail series :value]
592            [insert tail series :value]
593    ]
594
595    rejoin: func [
596        block [block!]
597    ][
598        if empty? block: reduce block [return block]
599        append either series? first block
600            [copy first block]
601            [form first block]
602        next block
603    ]
604
605    replace: func [
606        series [series!]
607        pattern
608        with
609        /all
610        /local orig len
611    ][
612      orig: series
613      if (any-string? series) and any [not any-string? :pattern tag? :pattern][
614          pattern: form :pattern
615      ]
616      len: either any [any-string? series any-block? :pattern]
617          [length? :pattern]
618          [1]
619      while [series: find series :pattern][
620          series: change/part series :with len
621          if not all [break]
622      ]
623      orig
624    ]
625
626    forall: func [
627        [throw]
628        'word [word!]
629        body [block!]
630    ][
631        while [not tail? get word] [
632          do body
633          set word next get word
634        ]
635    ]
636
637    switch: func [
638        [throw]
639        value
640        options [block!]
641        /default else
642    ][
643        either value: select options value
644            [do value]
645            [either default [do else][none]]
646    ]
647
648    forever: func [
649        [throw]
650        body [block!]
651    ][
652        while [1] body
653    ]
654
655    forskip: func [
656        [throw]
657        'iter [word!]
658        mod   [integer!]
659        body  [block!]
660    ][
661        while [not tail? get iter] [
662            do body
663            set iter skip get iter mod
664        ]
665    ]
666
667    join: func [a b] [
668        a: either series? a [copy a][form a]
669        head insert tail a reduce :b
670    ]
671
672    reform: func [value] [
673        form reduce value
674    ]
675
676    repend: func [
677        series [series!]  ; port!
678        value
679        /only
680    ][
681        head either only
682            [insert/only tail series reduce :value]
683            [insert tail series reduce :value]
684    ]
685
686    save: func [
687        file [file!]
688        data
689    ][
690        write file mold/only data
691    ]
692
693    dirize: func [path [file! string!] /local end]
694    [
695        end: last path
696        either all [
697            end <> #"/"
698            end <> #"\"
699        ][ append path #"/" ][ path ]
700    ]
701
702    time-block: func [blk /local a b] [a: now/time do blk b: now/time b - a]
703]
704
705
706do %config.r
707if find config 'rebol [append boot load %rebol_compat.r]
708
709if find config 'os_call [
710    append natives [
711        call: native [
712            command [string! block!]
713            ;/input
714            ;in [string! file! none!]    ; [any-string! port! file! url! none!]
715            /output
716            out [string! file! none!]    ; [string! port! file! url! none!]
717            /wait
718            ;/console
719            ;/shell
720            ;/info
721        ]
722    ]
723]
724
725;eof
Note: See TracBrowser for help on using the browser.