From b9de4806082ec4bc0a0ded5d1b17f0ee3d65465a Mon Sep 17 00:00:00 2001 From: hiiamboris Date: Mon, 31 Jan 2022 19:36:27 +0300 Subject: [PATCH 01/16] FEAT: initial l10n module --- compiler.r | 123 ++++++------- environment/console/engine.red | 5 + environment/system.red | 42 +++-- modules/l10n/core.red | 131 +++++++++++++ modules/l10n/l10n.red | 12 ++ modules/l10n/locales.red | 52 ++++++ modules/l10n/locales/LICENSE.md | 3 + modules/l10n/locales/af.red | 211 +++++++++++++++++++++ modules/l10n/locales/af_ZA.red | 10 + modules/l10n/locales/ar.red | 266 +++++++++++++++++++++++++++ modules/l10n/locales/ar_AE.red | 60 ++++++ modules/l10n/locales/ar_EG.red | 14 ++ modules/l10n/locales/ar_SA.red | 10 + modules/l10n/locales/bg.red | 219 ++++++++++++++++++++++ modules/l10n/locales/bg_BG.red | 10 + modules/l10n/locales/cs.red | 221 ++++++++++++++++++++++ modules/l10n/locales/cs_CZ.red | 10 + modules/l10n/locales/de.red | 195 ++++++++++++++++++++ modules/l10n/locales/de_DE.red | 10 + modules/l10n/locales/en.red | 167 +++++++++++++++++ modules/l10n/locales/en_AU.red | 117 ++++++++++++ modules/l10n/locales/en_CA.red | 64 +++++++ modules/l10n/locales/en_GB.red | 44 +++++ modules/l10n/locales/en_US.red | 10 + modules/l10n/locales/es.red | 230 +++++++++++++++++++++++ modules/l10n/locales/es_ES.red | 10 + modules/l10n/locales/es_MX.red | 58 ++++++ modules/l10n/locales/fr.red | 238 ++++++++++++++++++++++++ modules/l10n/locales/fr_CA.red | 118 ++++++++++++ modules/l10n/locales/fr_FR.red | 10 + modules/l10n/locales/he.red | 212 +++++++++++++++++++++ modules/l10n/locales/he_IL.red | 10 + modules/l10n/locales/hi.red | 222 ++++++++++++++++++++++ modules/l10n/locales/hi_IN.red | 10 + modules/l10n/locales/it.red | 207 +++++++++++++++++++++ modules/l10n/locales/it_IT.red | 10 + modules/l10n/locales/ja.red | 218 ++++++++++++++++++++++ modules/l10n/locales/ja_JP.red | 10 + modules/l10n/locales/ko.red | 201 ++++++++++++++++++++ modules/l10n/locales/ko_KR.red | 10 + modules/l10n/locales/pl.red | 207 +++++++++++++++++++++ modules/l10n/locales/pl_PL.red | 10 + modules/l10n/locales/pt.red | 164 +++++++++++++++++ modules/l10n/locales/pt_BR.red | 10 + modules/l10n/locales/red.red | 102 +++++++++++ modules/l10n/locales/root.red | 285 +++++++++++++++++++++++++++++ modules/l10n/locales/ru.red | 198 ++++++++++++++++++++ modules/l10n/locales/ru_BY.red | 14 ++ modules/l10n/locales/ru_RU.red | 10 + modules/l10n/locales/ru_UA.red | 11 ++ modules/l10n/locales/tr.red | 219 ++++++++++++++++++++++ modules/l10n/locales/tr_TR.red | 10 + modules/l10n/locales/zh.red | 216 ++++++++++++++++++++++ modules/l10n/numbering-systems.red | 75 ++++++++ modules/l10n/plural.red | 174 ++++++++++++++++++ utils/extractor.r | 2 +- 56 files changed, 5398 insertions(+), 89 deletions(-) create mode 100644 modules/l10n/core.red create mode 100644 modules/l10n/l10n.red create mode 100644 modules/l10n/locales.red create mode 100644 modules/l10n/locales/LICENSE.md create mode 100644 modules/l10n/locales/af.red create mode 100644 modules/l10n/locales/af_ZA.red create mode 100644 modules/l10n/locales/ar.red create mode 100644 modules/l10n/locales/ar_AE.red create mode 100644 modules/l10n/locales/ar_EG.red create mode 100644 modules/l10n/locales/ar_SA.red create mode 100644 modules/l10n/locales/bg.red create mode 100644 modules/l10n/locales/bg_BG.red create mode 100644 modules/l10n/locales/cs.red create mode 100644 modules/l10n/locales/cs_CZ.red create mode 100644 modules/l10n/locales/de.red create mode 100644 modules/l10n/locales/de_DE.red create mode 100644 modules/l10n/locales/en.red create mode 100644 modules/l10n/locales/en_AU.red create mode 100644 modules/l10n/locales/en_CA.red create mode 100644 modules/l10n/locales/en_GB.red create mode 100644 modules/l10n/locales/en_US.red create mode 100644 modules/l10n/locales/es.red create mode 100644 modules/l10n/locales/es_ES.red create mode 100644 modules/l10n/locales/es_MX.red create mode 100644 modules/l10n/locales/fr.red create mode 100644 modules/l10n/locales/fr_CA.red create mode 100644 modules/l10n/locales/fr_FR.red create mode 100644 modules/l10n/locales/he.red create mode 100644 modules/l10n/locales/he_IL.red create mode 100644 modules/l10n/locales/hi.red create mode 100644 modules/l10n/locales/hi_IN.red create mode 100644 modules/l10n/locales/it.red create mode 100644 modules/l10n/locales/it_IT.red create mode 100644 modules/l10n/locales/ja.red create mode 100644 modules/l10n/locales/ja_JP.red create mode 100644 modules/l10n/locales/ko.red create mode 100644 modules/l10n/locales/ko_KR.red create mode 100644 modules/l10n/locales/pl.red create mode 100644 modules/l10n/locales/pl_PL.red create mode 100644 modules/l10n/locales/pt.red create mode 100644 modules/l10n/locales/pt_BR.red create mode 100644 modules/l10n/locales/red.red create mode 100644 modules/l10n/locales/root.red create mode 100644 modules/l10n/locales/ru.red create mode 100644 modules/l10n/locales/ru_BY.red create mode 100644 modules/l10n/locales/ru_RU.red create mode 100644 modules/l10n/locales/ru_UA.red create mode 100644 modules/l10n/locales/tr.red create mode 100644 modules/l10n/locales/tr_TR.red create mode 100644 modules/l10n/locales/zh.red create mode 100644 modules/l10n/numbering-systems.red create mode 100644 modules/l10n/plural.red diff --git a/compiler.r b/compiler.r index 3014c4840f..95fdfcb4ea 100644 --- a/compiler.r +++ b/compiler.r @@ -6,9 +6,7 @@ REBOL [ Rights: "Copyright (C) 2011-2018 Red Foundation. All rights reserved." License: "BSD-3 - https://github.com/red/red/blob/master/BSD-3-License.txt" ] - do-cache %system/compiler.r - red: context [ verbose: 0 ;-- logs verbosity level job: none ;-- reference the current job object @@ -105,14 +103,61 @@ red: context [ iterators: [loop until while repeat foreach forall forever remove-each] standard-modules: [ - ;-- Name ------ Entry file -------------- OS availability ----- - View %modules/view/view.red [Windows macOS Linux] + ;-- Name ---------- Entry file -------------------- OS availability ----- + View %modules/view/view.red [Windows macOS Linux] + L10N %modules/l10n/l10n.red [Windows macOS Linux] ;-- L10N-Core + Locales + L10N-Core %modules/l10n/core.red [Windows macOS Linux] ;-- all Locales/ in one file + Locales %modules/l10n/locales.red [Windows macOS Linux] + Locales/af %modules/l10n/locales/af.red [Windows macOS Linux] + Locales/af_ZA %modules/l10n/locales/af_ZA.red [Windows macOS Linux] + Locales/ar %modules/l10n/locales/ar.red [Windows macOS Linux] + Locales/ar_AE %modules/l10n/locales/ar_AE.red [Windows macOS Linux] + Locales/ar_EG %modules/l10n/locales/ar_EG.red [Windows macOS Linux] + Locales/ar_SA %modules/l10n/locales/ar_SA.red [Windows macOS Linux] + Locales/bg %modules/l10n/locales/bg.red [Windows macOS Linux] + Locales/bg_BG %modules/l10n/locales/bg_BG.red [Windows macOS Linux] + Locales/cs %modules/l10n/locales/cs.red [Windows macOS Linux] + Locales/cs_CZ %modules/l10n/locales/cs_CZ.red [Windows macOS Linux] + Locales/de %modules/l10n/locales/de.red [Windows macOS Linux] + Locales/de_DE %modules/l10n/locales/de_DE.red [Windows macOS Linux] + Locales/en %modules/l10n/locales/en.red [Windows macOS Linux] + Locales/en_AU %modules/l10n/locales/en_AU.red [Windows macOS Linux] + Locales/en_CA %modules/l10n/locales/en_CA.red [Windows macOS Linux] + Locales/en_GB %modules/l10n/locales/en_GB.red [Windows macOS Linux] + Locales/en_US %modules/l10n/locales/en_US.red [Windows macOS Linux] + Locales/es %modules/l10n/locales/es.red [Windows macOS Linux] + Locales/es_ES %modules/l10n/locales/es_ES.red [Windows macOS Linux] + Locales/es_MX %modules/l10n/locales/es_MX.red [Windows macOS Linux] + Locales/fr %modules/l10n/locales/fr.red [Windows macOS Linux] + Locales/fr_CA %modules/l10n/locales/fr_CA.red [Windows macOS Linux] + Locales/fr_FR %modules/l10n/locales/fr_FR.red [Windows macOS Linux] + Locales/he %modules/l10n/locales/he.red [Windows macOS Linux] + Locales/he_IL %modules/l10n/locales/he_IL.red [Windows macOS Linux] + Locales/hi %modules/l10n/locales/hi.red [Windows macOS Linux] + Locales/hi_IN %modules/l10n/locales/hi_IN.red [Windows macOS Linux] + Locales/it %modules/l10n/locales/it.red [Windows macOS Linux] + Locales/it_IT %modules/l10n/locales/it_IT.red [Windows macOS Linux] + Locales/ja %modules/l10n/locales/ja.red [Windows macOS Linux] + Locales/ja_JP %modules/l10n/locales/ja_JP.red [Windows macOS Linux] + Locales/ko %modules/l10n/locales/ko.red [Windows macOS Linux] + Locales/ko_KR %modules/l10n/locales/ko_KR.red [Windows macOS Linux] + Locales/pl %modules/l10n/locales/pl.red [Windows macOS Linux] + Locales/pl_PL %modules/l10n/locales/pl_PL.red [Windows macOS Linux] + Locales/pt %modules/l10n/locales/pt.red [Windows macOS Linux] + Locales/pt_BR %modules/l10n/locales/pt_BR.red [Windows macOS Linux] + Locales/red %modules/l10n/locales/red.red [Windows macOS Linux] + Locales/root %modules/l10n/locales/root.red [Windows macOS Linux] + Locales/ru %modules/l10n/locales/ru.red [Windows macOS Linux] + Locales/ru_BY %modules/l10n/locales/ru_BY.red [Windows macOS Linux] + Locales/ru_RU %modules/l10n/locales/ru_RU.red [Windows macOS Linux] + Locales/ru_UA %modules/l10n/locales/ru_UA.red [Windows macOS Linux] + Locales/tr %modules/l10n/locales/tr.red [Windows macOS Linux] + Locales/tr_TR %modules/l10n/locales/tr_TR.red [Windows macOS Linux] + Locales/zh %modules/l10n/locales/zh.red [Windows macOS Linux] ] - func-constructors: [ 'func | 'function | 'does | 'has | 'routine | 'make 'function! ] - functions: make hash! [ ;---name--type--arity----------spec----------------------------refs-- make [action! 2 [type [datatype! word!] spec [any-type!]] #[none]] ;-- must be pre-defined @@ -126,9 +171,7 @@ red: context [ ] bind keywords self ] - set-last-none: does [copy [stack/reset none/push-last]] ;-- copy required for R/S line counting injection - --not-implemented--: does [print "Feature not yet implemented!" halt] quit-on-error: does [ @@ -136,7 +179,6 @@ red: context [ if system/options/args [quit/return 1] halt ] - throw-error: func [err [word! string! block!] /near code [block!]][ print [ "*** Compilation Error:" @@ -525,7 +567,6 @@ red: context [ ] blk ] - emit-open-frame: func [name [word!] /with type ctx-name /local symbol][ symbol: either name = 'try-all ['try][name] unless find symbols symbol [add-symbol symbol] @@ -602,7 +643,6 @@ red: context [ [re-throw] [ctx/values: saved system/thrown: 0 exit] ] empty? locals-stack - append body [ default [re-throw] ] @@ -671,7 +711,6 @@ red: context [ ] obj-stk: copy/part fpath (index? find fpath path/1) - 1 obj-stk/1: either find-contexts path/1 ['func-objs]['objects] - either 2 = length? path [ append obj-stk path/1 reduce check @@ -710,12 +749,10 @@ red: context [ name: bs/3 ][ ts: copy [0 0 0] - foreach type spec [ unless block? type [ if type = 'red/cell! [type: 'any-type!] ;-- coming from routines type: either word: in extracts/scalars type [get word][reduce [type]] - foreach word type [ bit: get-RS-type-ID name: word unless bit [throw-error/near ["invalid datatype name:" name] f-spec] @@ -776,7 +813,6 @@ red: context [ either count = index [arg: spec/1 break][count: count + 1] ] ] - emit emit-type-checking/native arg spec emit index emit slot @@ -816,7 +852,6 @@ red: context [ ] blk ] - clean-lf-flag: func [name [word! lit-word! set-word! get-word! refinement!]][ mold/flat to word! name ] @@ -874,7 +909,6 @@ red: context [ declare-variable: func [name [string! word!] /init value /local var set-var][ set-var: to set-word! var: to word! name - unless find declarations set-var [ repend declarations [set-var any [value 0]] ;-- declare variable at root level new-line skip tail declarations -2 yes @@ -1000,7 +1034,6 @@ red: context [ ] ] ] - base: get-obj-base-word path/1 do search ;-- check if path is an absolute object path if all [not found? 1 < length? obj-stack][ @@ -1070,7 +1103,6 @@ red: context [ ] unless found? [return none] ] - fun: append copy fpath either base = obj-stack [ ;-- extract function access path without refinements pick path 1 + (length? fpath) - (length? obj-stack) ][ @@ -1079,12 +1111,10 @@ red: context [ unless function! = attempt [do fun][return none] ;-- not a function call remove fpath ;-- remove 'objects prefix ] - obj: find objects found? origin: find-proto obj last fun name: either origin [select objects origin][obj/2] symbol: decorate-obj-member first find/tail fun fpath name - either find functions symbol [ fpath: next find path last fpath ;-- point to function name reduce [ @@ -1124,7 +1154,6 @@ red: context [ push-locals: func [symbols [block!]][ append/only locals-stack symbols ] - pop-locals: does [ also last locals-stack @@ -1206,7 +1235,6 @@ red: context [ entry ] ] - decode-attributes: func [spec [block!] /local do-error flags][ do-error: [throw-error ["invalid function spec block:" mold pos]] flags: 0 @@ -1289,7 +1317,6 @@ red: context [ entry: find functions alter ] repend functions [new entry/2] - unless local-bound? pc/-1 [ switch/default type: entry/2/1 [ routine! [ @@ -1368,7 +1395,6 @@ red: context [ ][ throw-error ["invalid function spec block:" mold pos] ] - s: copy spec forall s [if any-word? s/1 [s/1: to word! s/1]] @@ -1478,7 +1504,6 @@ red: context [ name: to word! pos/1 if find functions name [return none] ;-- mainly intended for 'make (hardcoded) - switch type: pos/3 [ native! [nat?: yes if find intrinsics name [type: 'intrinsic!]] action! [append actions name] @@ -1606,7 +1631,6 @@ red: context [ declare-variable/init 'r_arg to paren! [as red-value! 0] emit [r_arg: stack/arguments] insert-lf -2 - offset: 0 if type: get-return-type spec [ offset: 1 @@ -1615,7 +1639,6 @@ red: context [ if alter: select-ssa name [name: alter] emit name cnt: 0 - forall spec [ if string? spec/1 [ if tail? remove spec [break] @@ -1665,13 +1688,11 @@ red: context [ if value/time [date: date or 65536] ;-- time? flag date ] - emit-float: func [value [decimal!] /local bin][ bin: IEEE-754/to-binary64 value emit to integer! copy/part bin 4 emit to integer! skip bin 4 ] - emit-fp-special: func [value [issue!]][ switch next value [ #INF [emit to integer! #{7FF00000} emit 0] @@ -1680,7 +1701,6 @@ red: context [ #0- [emit to integer! #{80000000} emit 0] ] ] - comp-literal: func [ /inactive /with val /local value char? special? percent? map? tuple? money? ref? dt-special? name w make-block type idx zone @@ -1696,7 +1716,6 @@ red: context [ value: either with [val][pc/1] ;-- val can be NONE map?: map-value? :value dt-special?: date-special? value - either any [ all [ issue? :value @@ -1876,7 +1895,6 @@ red: context [ /local rule pos self* ][ self*: in ctx 'self - ;-- rebind the new body to the parent object's context entry: bind/copy copy/part next entry 8 ctx @@ -1973,7 +1991,6 @@ red: context [ | skip ] ] - spec: make block! (length? words) / 2 forskip words 2 [append spec to word! words/1] ][ @@ -2018,7 +2035,6 @@ red: context [ ] ] ] - ctx: add-context spec blk-idx: redbin/emit-context/root ctx spec no yes 'object @@ -2047,7 +2063,6 @@ red: context [ none ;-- [idx loc idx2 loc2...] (for events) ] on-set-info: back tail objects - shadow-path: either all [ with find [lit-word! lit-path!] type?/word saved-pc/-2 @@ -2077,7 +2092,6 @@ red: context [ ] if body? [bind body obj] if passive [return []] - unless all [empty? locals-stack not iterator-pending?][ ;-- in a function or iteration block emit compose [ (to set-word! ctx) _context/clone-words get-root (blk-idx) CONTEXT_OBJECT ;-- rebuild context @@ -2095,9 +2109,7 @@ red: context [ emit reduce ['object/transfer ctx2 ctx] insert-lf -3 ] - emit-src-comment/with none rejoin [mold pc/-1 " context " mold spec] - emit-open-frame 'body case [ passive [ ;-- CONSTRUCT support @@ -2357,7 +2369,6 @@ red: context [ append/only output set-last-none emit-close-frame ] - comp-either: does [ emit-open-frame 'either comp-expression/close-path @@ -2372,7 +2383,6 @@ red: context [ comp-loop: has [name set-name mark][ depth: depth + 1 if depth > max-depth [max-depth: depth] - set [name set-name] declare-variable join "i" depth emit-open-frame 'loop @@ -2396,7 +2406,6 @@ red: context [ push-call 'loop comp-sub-block 'loop-body ;-- compile body pop-call - new-line skip tail last output -3 on new-line skip tail last output -7 on depth: depth - 1 @@ -2448,7 +2457,6 @@ red: context [ emit 'natives/coerce-counter* ;-- eventually convert float to integer insert-lf -1 emit-argument-type-check 1 'repeat 'stack/arguments - emit-open-frame 'set emit-push-word name name ;-- push the word emit [ @@ -2456,7 +2464,6 @@ red: context [ word/set ;-- initialize the counter word to 0 ] emit-close-frame - emit [loop integer/get stack/arguments] insert-lf -3 push-call 'repeat @@ -2582,7 +2589,6 @@ red: context [ insert-lf -2 comp-expression/close-path ;-- compile series argument emit-argument-type-check 1 'remove-each [stack/arguments + 1] - either blk [ cond: compose [natives/foreach-next-block (length? blk)] emit compose [block/push get-root (idx)] ;-- block argument @@ -2591,7 +2597,6 @@ red: context [ emit-push-word word word ;-- word argument ] insert-lf -2 - emit-open-frame 'remove-each if blk [ emit 'natives/remove-each-init @@ -2648,9 +2653,7 @@ red: context [ blk: either container-obj? [head insert copy locals [octx [node!]]][locals] emit reduce [to set-word! decorate-func/strict name 'func blk] insert-lf -3 - comp-sub-block/with 'func-body body ;-- compile function's body - ;-- Function's prolog -- pop-locals init: make block! 4 * length? symbols @@ -2854,7 +2857,6 @@ red: context [ set [symbols locals-nb flags] check-spec spec add-function name spec if pos: find spec return-def [register-user-type/store name pos/2] - push-locals symbols ;-- store spec and body blocks ctx: push-context copy symbols @@ -2867,7 +2869,6 @@ red: context [ insert-lf -3 ] pop-locals - repend shadow-funcs [ ;-- register a new shadow context decorate-func/strict name shadow: to-context-spec symbols @@ -2923,7 +2924,6 @@ red: context [ pc: next pc set [spec body] pc - preprocess-strings body ;-- encode strings for Red/System check-spec spec add-function/type name spec 'routine! @@ -2965,7 +2965,6 @@ red: context [ ] emit-exit-function ] - comp-return: does [ check-invalid-exit 'return comp-expression @@ -3357,7 +3356,6 @@ red: context [ if block? defer [emit defer] ] - if obj-field?: all [ obj? word? last path ;-- not allow get-words to pass (#1141) @@ -3791,7 +3789,6 @@ red: context [ ] emit-close-frame ] - comp-word: func [/literal /final /thru /local name local? alter emit-word original new ctx defer][ name: to word! original: pc/1 local?: local-bound? original @@ -3930,7 +3927,6 @@ red: context [ comp-expression/no-infix ;-- fetch first left operand do substitute pc: next pc - forall ops [ paths: length? paths-stack single?: path? pc/1 @@ -4194,14 +4190,12 @@ red: context [ ] cache?: in-cache? file append include-stk script-path - script-path: either all [not booting? relative-path? file][ file: clean-path join any [script-path main-path] file first split-path file ][ none ] - unless any [cache? booting? exists? file][ throw-error ["include file not found:" pc/2] ] @@ -4227,7 +4221,6 @@ red: context [ unless any [only empty? expr-stack][comp-expression] ] ] - comp-directive: has [mark value][ switch pc/1 [ #include [ @@ -4321,7 +4314,6 @@ red: context [ ] exit ] - ] if tail? pc [ pc: any [find/reverse pc current-call back pc] @@ -4427,7 +4419,6 @@ red: context [ pc: any [body pc/1] ;-- dive in nested code comp-block pc: next saved ;-- step over block in source code - convert-to-block mark head insert last output [ stack/reset @@ -4461,7 +4452,6 @@ red: context [ all [not path? obj find-object/by-name obj] ][ ;if prev: find get-obj-base name name [prev/1: none] ;-- unbind word with previous object - insert entry: tail objects copy/part pos 6 entry/1: to word! name ;@@ set-path! case if store [ @@ -4488,7 +4478,6 @@ red: context [ if pos: find/skip objects types/1 6 [ if found? [throw-error ["unsupported multiple object type spec:" mold spec]] if prev: find get-obj-base name name [prev/1: none] ;-- unbind word with previous object - insert entry: tail objects copy/part pos 6 entry/1: to word! name ;@@ set-path! case types/1: 'object! @@ -4546,7 +4535,6 @@ red: context [ func-objs: tail objects depth: max-depth preprocess-types name spec - comp-func-body name spec body copy symbols locals-nb ;-- copy avoids symbols corruption by decoration ] clear pos @@ -4563,7 +4551,6 @@ red: context [ add-symbol name add-global name ] - ;-- Create datatype! datatype and word emit compose [ stack/mark-native ~set @@ -4600,7 +4587,6 @@ red: context [ comp-block script-path: saved ] - pc: code ;-- compile user code user: tail output comp-block @@ -4633,7 +4619,6 @@ red: context [ ] set [user mark main] comp-source code - defs: make block! 10'000 foreach [type cast][ block red-block! @@ -4699,10 +4684,8 @@ red: context [ comp-as-exe: func [code [block!] /local out user mods main defs][ out: copy/deep either job/dev-mode? [[ Red/System [origin: 'Red] - ***-root-size: - with red [ stk-bottom: system/stack/top ;-- reset stk-bottom set by libRedRT to allow GC to mark all pointers on stack root-base: redbin/boot-load system/boot-data yes @@ -4710,7 +4693,6 @@ red: context [ ] ]][[ Red/System [origin: 'Red] - ***-root-size: red/init @@ -4769,7 +4751,6 @@ red: context [ unless empty? sys-global [ process-calls/global sys-global ;-- lazy #call processing ] - change/only find out redbin/index + 3000 + root-slots change/only find last out