PageRenderTime 29ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/make-boot.r

https://github.com/WoodyLin/r3
R | 1195 lines | 972 code | 199 blank | 24 comment | 45 complexity | fc5aea562172d6d49d3baefc6238d689 MD5 | raw file
Possible License(s): Apache-2.0
  1. REBOL [
  2. System: "REBOL [R3] Language Interpreter and Run-time Environment"
  3. Title: "Make primary boot files"
  4. Rights: {
  5. Copyright 2012 REBOL Technologies
  6. REBOL is a trademark of REBOL Technologies
  7. }
  8. License: {
  9. Licensed under the Apache License, Version 2.0
  10. See: http://www.apache.org/licenses/LICENSE-2.0
  11. }
  12. Author: "Carl Sassenrath"
  13. Version: 2.100.0
  14. Needs: 2.100.100
  15. Purpose: {
  16. A lot of the REBOL system is built by REBOL, and this program
  17. does most of the serious work. It generates most of the C include
  18. files required to compile REBOL.
  19. }
  20. ]
  21. print "--- Make Boot : System Embedded Script ---"
  22. do %form-header.r
  23. ; Set platform TARGET
  24. do %systems.r
  25. target: config-system/define ; default
  26. ; Include graphics for these systems:
  27. graphics-targets: [
  28. TO_WIN32
  29. ]
  30. has-graphics: false ;not not find graphics-targets target
  31. opts: system/options/args
  32. if all [block? opts opts/1 = ">"] [opts: none] ; cw editor
  33. if block? opts [
  34. if find opts "no-gfx" [
  35. has-graphics: false
  36. opts: next opts
  37. ]
  38. if not tail? opts [
  39. opts: load first opts
  40. unless tuple? opts [print "Invalid version arg." wait 2 quit]
  41. target: config-system/platform opts
  42. ]
  43. ]
  44. write-if: func [file data] [
  45. if data <> attempt [read file][
  46. print ["UPDATE:" file]
  47. write file data
  48. ]
  49. ]
  50. ;-- SETUP --------------------------------------------------------------
  51. change-dir %../boot/
  52. ;dir: %../core/temp/ ; temporary definition
  53. inc: %../include/
  54. src: %../core/
  55. version: load %version.r
  56. either tuple? opts [
  57. version/4: opts/2
  58. version/5: opts/3
  59. ][
  60. version/4: system/version/4
  61. version/5: system/version/5
  62. ]
  63. ;-- Title string put into boot.h file checksum:
  64. Title:
  65. {REBOL
  66. Copyright 2012 REBOL Technologies
  67. REBOL is a trademark of REBOL Technologies
  68. Licensed under the Apache License, Version 2.0
  69. }
  70. sections: [
  71. boot-types
  72. boot-words
  73. boot-root
  74. boot-task
  75. boot-strings
  76. boot-booters
  77. boot-actions
  78. boot-natives
  79. boot-ops
  80. boot-typespecs
  81. boot-errors
  82. boot-sysobj
  83. boot-base
  84. boot-sys
  85. boot-mezz
  86. boot-protocols
  87. ; boot-script
  88. ]
  89. include-protocols: false ; include protocols in build
  90. system/options/args: [">"]
  91. ;-- Error handler:
  92. error: func [msg arg] [print ["*** Make-boot error:" msg arg] halt]
  93. ;-- Args passed: platform, product
  94. if none? args: system/options/args [error "No platform specified." ""]
  95. if args/1 = ">" [args: ["Win32" "VIEW-PRO"]] ; for debugging only
  96. platform: to-word args/1
  97. product: to-word args/2
  98. platform-data: context [type: 'windows]
  99. build: context [features: [help-strings]]
  100. ;-- Fetch platform specifications:
  101. ;init-build-objects/platform platform
  102. ;platform-data: platforms/:platform
  103. ;build: platform-data/builds/:product
  104. ;-- UTILITIES ----------------------------------------------------------
  105. up-word: func [w] [
  106. w: uppercase form w
  107. foreach [f t] [
  108. #"-" #"_"
  109. ][replace/all w f t]
  110. w
  111. ]
  112. ;-- Emit Function
  113. out: make string! 100000
  114. emit: func [data] [repend out data]
  115. to-c-name: func [word] [
  116. word: form word
  117. foreach [f t] [
  118. #"-" #"_"
  119. #"." #"_"
  120. #"?" #"q"
  121. #"!" #"x"
  122. #"~" ""
  123. #"*" "_p"
  124. #"+" "_add"
  125. #"|" "or_bar"
  126. ][replace/all word f t]
  127. word
  128. ]
  129. emit-enum: func [word] [emit [tab to-c-name word "," newline]]
  130. emit-line: func [prefix word cmt /var /define /code /decl /up1 /local str][
  131. str: to-c-name word
  132. if word = 0 [prefix: ""]
  133. if not any [code decl] [
  134. either var [uppercase/part str 1] [uppercase str]
  135. ]
  136. if up1 [uppercase/part str 1]
  137. str: any [
  138. if define [rejoin [prefix str]]
  139. if code [rejoin [" " prefix str cmt]]
  140. if decl [rejoin [prefix str cmt]]
  141. rejoin [" " prefix str ","]
  142. ]
  143. if any [code decl] [cmt: none]
  144. if cmt [
  145. len: 31 - length? str
  146. loop to-integer len / 4 [append str tab]
  147. any [
  148. if define [repend str cmt]
  149. if cmt [repend str ["// " cmt]]
  150. ]
  151. ]
  152. append str newline
  153. append out str
  154. ]
  155. emit-head: func [title [string!] file [file!]] [
  156. clear out
  157. emit form-header/gen title file %make-boot.r
  158. ]
  159. emit-end: func [/easy] [
  160. if not easy [remove find/last out #","]
  161. append out {^};^/}
  162. ]
  163. binary-to-c: either system/version/4 = 3 [
  164. ; Windows format:
  165. func [comp-data /local out] [
  166. out: make string! 4 * (length? comp-data)
  167. forall comp-data [
  168. out: insert out reduce [to-integer first comp-data ", "]
  169. if zero? ((index? comp-data) // 10) [out: insert out "^/^-"]
  170. ]
  171. ; remove/part out either (pick out -1) = #" " [-2][-4]
  172. head out
  173. ]
  174. ][
  175. ; Other formats (Linux, OpenBSD, etc.):
  176. func [comp-data /local out] [
  177. out: make string! 4 * (length? comp-data)
  178. forall comp-data [
  179. data: copy/part comp-data 16
  180. comp-data: skip comp-data 15
  181. data: enbase/base data 16
  182. forall data [
  183. insert data "\x"
  184. data: skip data 3
  185. ]
  186. data: tail data
  187. insert data {"^/}
  188. append out {"}
  189. append out head data
  190. ]
  191. head out
  192. ]
  193. ]
  194. remove-tests: func [d] [
  195. while [d: find d #test][remove/part d 2]
  196. ]
  197. ;----------------------------------------------------------------------------
  198. ;
  199. ; Evaltypes.h - Evaluation Dispatch Maps
  200. ;
  201. ;----------------------------------------------------------------------------
  202. boot-types: load %types.r
  203. type-record: [type evalclass typeclass moldtype formtype haspath maker typesets]
  204. emit-head "Evaluation Maps" %evaltypes.h
  205. emit {
  206. /***********************************************************************
  207. **
  208. */ const REBINT Eval_Type_Map[REB_MAX] =
  209. /*
  210. ** Specifies the evaluation method used for each datatype.
  211. **
  212. ***********************************************************************/
  213. ^{
  214. }
  215. foreach :type-record boot-types [
  216. emit-line "ET_" evalclass type
  217. ]
  218. emit-end
  219. emit {
  220. /***********************************************************************
  221. **
  222. */ const REBDOF Func_Dispatch[] =
  223. /*
  224. ** The function evaluation dispatchers.
  225. **
  226. ***********************************************************************/
  227. ^{
  228. }
  229. foreach :type-record boot-types [
  230. if find [function operator] evalclass [
  231. emit-line/var "Do_" type none
  232. ]
  233. ]
  234. emit-end
  235. emit {
  236. /***********************************************************************
  237. **
  238. */ const REBACT Value_Dispatch[REB_MAX] =
  239. /*
  240. ** The ACTION dispatch function for each datatype.
  241. **
  242. ***********************************************************************/
  243. ^{
  244. }
  245. foreach :type-record boot-types [
  246. emit-line/var "T_" typeclass type
  247. ]
  248. emit-end
  249. emit {
  250. /***********************************************************************
  251. **
  252. */ const REBPEF Path_Dispatch[REB_MAX] =
  253. /*
  254. ** The path evaluator function for each datatype.
  255. **
  256. ***********************************************************************/
  257. ^{
  258. }
  259. foreach :type-record boot-types [
  260. emit-line/var "PD_" switch/default haspath [
  261. * [typeclass]
  262. - [0]
  263. ][haspath] type
  264. ]
  265. emit-end
  266. write inc/tmp-evaltypes.h out
  267. ;----------------------------------------------------------------------------
  268. ;
  269. ; Maketypes.h - Dispatchers for Make (used by construct)
  270. ;
  271. ;----------------------------------------------------------------------------
  272. emit-head "Datatype Makers" %maketypes.h
  273. emit newline
  274. types-used: []
  275. foreach :type-record boot-types [
  276. if all [
  277. maker = '*
  278. word? typeclass
  279. not find types-used typeclass
  280. ][
  281. emit-line/up1/decl "extern REBFLG MT_" typeclass "(REBVAL *, REBVAL *, REBCNT);"
  282. append types-used typeclass
  283. ]
  284. ]
  285. emit {
  286. /***********************************************************************
  287. **
  288. */ const MAKE_FUNC Make_Dispatch[REB_MAX] =
  289. /*
  290. ** Specifies the make method used for each datatype.
  291. **
  292. ***********************************************************************/
  293. ^{
  294. }
  295. foreach :type-record boot-types [
  296. either maker = '* [
  297. emit-line/var "MT_" typeclass type
  298. ][
  299. emit-line "" "0" type
  300. ]
  301. ]
  302. emit-end
  303. write inc/tmp-maketypes.h out
  304. ;----------------------------------------------------------------------------
  305. ;
  306. ; Comptypes.h - compare functions
  307. ;
  308. ;----------------------------------------------------------------------------
  309. emit-head "Datatype Comparison Functions" %comptypes.h
  310. emit newline
  311. types-used: []
  312. foreach :type-record boot-types [
  313. if all [
  314. word? typeclass
  315. not find types-used typeclass
  316. ][
  317. emit-line/up1/decl "extern REBINT CT_" typeclass "(REBVAL *, REBVAL *, REBINT);"
  318. append types-used typeclass
  319. ]
  320. ]
  321. emit {
  322. /***********************************************************************
  323. **
  324. */ const REBCTF Compare_Types[REB_MAX] =
  325. /*
  326. ** Type comparision functions.
  327. **
  328. ***********************************************************************/
  329. ^{
  330. }
  331. foreach :type-record boot-types [
  332. emit-line/var "CT_" typeclass type
  333. ]
  334. emit-end
  335. write inc/tmp-comptypes.h out
  336. ;----------------------------------------------------------------------------
  337. ;
  338. ; Moldtypes.h - Dispatchers for Mold and Form
  339. ;
  340. ;----------------------------------------------------------------------------
  341. ;emit-head "Mold Dispatchers"
  342. ;
  343. ;emit {
  344. ;/***********************************************************************
  345. ;**
  346. ;*/ const MOLD_FUNC Mold_Dispatch[REB_MAX] =
  347. ;/*
  348. ;** The MOLD dispatch function for each datatype.
  349. ;**
  350. ;***********************************************************************/
  351. ;^{
  352. ;}
  353. ;
  354. ;foreach :type-record boot-types [
  355. ; f: "Mold_"
  356. ; switch/default moldtype [
  357. ; * [t: typeclass]
  358. ; + [t: type]
  359. ; - [t: 0]
  360. ; ][t: uppercase/part form moldtype 1]
  361. ; emit [tab "case " uppercase join "REB_" type ":" tab "\\" t]
  362. ; emit newline
  363. ; ;emit-line/var f t type
  364. ;]
  365. ;emit-end
  366. ;
  367. ;emit {
  368. ;/***********************************************************************
  369. ;**
  370. ;*/ const MOLD_FUNC Form_Dispatch[REB_MAX] =
  371. ;/*
  372. ;** The FORM dispatch function for each datatype.
  373. ;**
  374. ;***********************************************************************/
  375. ;^{
  376. ;}
  377. ;foreach :type-record boot-types [
  378. ; f: "Mold_"
  379. ; switch/default formtype [
  380. ; * [t: typeclass]
  381. ; f* [t: typeclass f: "Form_"]
  382. ; + [t: type]
  383. ; f+ [t: type f: "Form_"]
  384. ; - [t: 0]
  385. ; ][t: uppercase/part form moldtype 1]
  386. ; emit [tab "case " uppercase join "REB_" type ":" tab "\\" t]
  387. ; emit newline
  388. ; ;emit-line/var f t type
  389. ;]
  390. ;emit-end
  391. ;
  392. ;write inc/tmp-moldtypes.h out
  393. ;----------------------------------------------------------------------------
  394. ;
  395. ; Bootdefs.h - Boot include file
  396. ;
  397. ;----------------------------------------------------------------------------
  398. emit-head "Datatype Definitions" %reb-types.h
  399. emit [
  400. {
  401. /***********************************************************************
  402. **
  403. */ enum REBOL_Types
  404. /*
  405. ** Internal datatype numbers. These change. Do not export.
  406. **
  407. ***********************************************************************/
  408. ^{
  409. }
  410. ]
  411. datatypes: []
  412. n: 0
  413. foreach :type-record boot-types [
  414. append datatypes type
  415. emit-line "REB_" type n
  416. n: n + 1
  417. ]
  418. emit { REB_MAX
  419. ^};
  420. }
  421. emit {
  422. /***********************************************************************
  423. **
  424. ** REBOL Type Check Macros
  425. **
  426. ***********************************************************************/
  427. }
  428. new-types: []
  429. foreach :type-record boot-types [
  430. append new-types to-word join type "!"
  431. str: uppercase form type
  432. replace/all str #"-" #"_"
  433. def: join {#define IS_} [str "(v)"]
  434. len: 31 - length? def
  435. loop to-integer len / 4 [append def tab]
  436. emit [def "(VAL_TYPE(v)==REB_" str ")" newline]
  437. ]
  438. emit {
  439. /***********************************************************************
  440. **
  441. ** REBOL Typeset Defines
  442. **
  443. ***********************************************************************/
  444. }
  445. typeset-sets: []
  446. foreach :type-record boot-types [
  447. typesets: compose [(typesets)]
  448. foreach ts typesets [
  449. spot: any [
  450. select typeset-sets ts
  451. first back insert tail typeset-sets reduce [ts copy []]
  452. ]
  453. append spot type
  454. ]
  455. ]
  456. remove/part typeset-sets 2 ; the - markers
  457. foreach [ts types] typeset-sets [
  458. emit ["#define TS_" up-word ts " ("]
  459. foreach t types [
  460. emit ["((REBU64)1<<REB_" up-word t ")|"]
  461. ]
  462. append remove back tail out ")^/"
  463. ]
  464. write-if inc/reb-types.h out
  465. ;----------------------------------------------------------------------------
  466. ;
  467. ; Extension Related Tables
  468. ;
  469. ;----------------------------------------------------------------------------
  470. ext-types: load %types-ext.r
  471. rxt-record: [type offset size]
  472. ; Generate type table with necessary gaps
  473. rxt-types: []
  474. n: 0
  475. foreach :rxt-record ext-types [
  476. if integer? offset [
  477. insert/dup tail rxt-types 0 offset - n
  478. n: offset
  479. ]
  480. append rxt-types type
  481. n: n + 1
  482. ]
  483. emit-head "Extension Types (Isolators)" %ext-types.h
  484. emit [
  485. {
  486. enum REBOL_Ext_Types
  487. ^{
  488. }
  489. ]
  490. n: 0
  491. foreach :rxt-record ext-types [
  492. either integer? offset [
  493. emit-line "RXT_" rejoin [type " = " offset] n
  494. ][
  495. emit-line "RXT_" type n
  496. ]
  497. n: n + 1
  498. ]
  499. emit { RXT_MAX
  500. ^};
  501. }
  502. write inc/ext-types.h out ; part of Host-Kit distro
  503. emit-head "Extension Type Equates" %tmp-exttypes.h
  504. emit {
  505. /***********************************************************************
  506. **
  507. */ const REBYTE Reb_To_RXT[REB_MAX] =
  508. /*
  509. ***********************************************************************/
  510. ^{
  511. }
  512. foreach :type-record boot-types [
  513. either find ext-types type [
  514. emit-line "RXT_" type type
  515. ][
  516. emit-line "" 0 type
  517. ]
  518. ]
  519. emit-end
  520. emit {
  521. /***********************************************************************
  522. **
  523. */ const REBYTE RXT_To_Reb[RXT_MAX] =
  524. /*
  525. ***********************************************************************/
  526. ^{
  527. }
  528. n: 0
  529. foreach type rxt-types [
  530. either word? type [emit-line "REB_" type n][
  531. emit-line "" 0 n
  532. ]
  533. n: n + 1
  534. ]
  535. emit-end
  536. emit {
  537. /***********************************************************************
  538. **
  539. */ const REBCNT RXT_Eval_Class[RXT_MAX] =
  540. /*
  541. ***********************************************************************/
  542. ^{
  543. }
  544. n: 0
  545. foreach type rxt-types [
  546. either all [
  547. word? type
  548. rec: find ext-types type
  549. ][
  550. emit-line "RXE_" rec/3 rec/1
  551. ][
  552. emit-line "" 0 n
  553. ]
  554. n: n + 1
  555. ]
  556. emit-end
  557. emit {
  558. #define RXT_ALLOWED_TYPES (}
  559. foreach type next rxt-types [
  560. if word? type [
  561. emit replace join "((u64)" uppercase rejoin ["1<<REB_" type ") \^/"] #"-" #"_"
  562. emit "|"
  563. ]
  564. ]
  565. remove back tail out
  566. emit ")^/"
  567. write inc/tmp-exttypes.h out
  568. ;----------------------------------------------------------------------------
  569. ;
  570. ; Bootdefs.h - Boot include file
  571. ;
  572. ;----------------------------------------------------------------------------
  573. emit-head "Boot Definitions" %bootdefs.h
  574. emit [
  575. {
  576. #define REBOL_VER } version/1 {
  577. #define REBOL_REV } version/2 {
  578. #define REBOL_UPD } version/3 {
  579. #define REBOL_SYS } version/4 {
  580. #define REBOL_VAR } version/5 {
  581. }
  582. ]
  583. ;-- Generate Lower-Level String Table ----------------------------------------
  584. emit {
  585. /***********************************************************************
  586. **
  587. ** REBOL Boot Strings
  588. **
  589. ** These are special strings required during boot and other
  590. ** operations. Putting them here hides them from exe hackers.
  591. ** These are all string offsets within a single string.
  592. **
  593. ***********************************************************************/
  594. }
  595. boot-strings: load %strings.r
  596. code: ""
  597. n: 0
  598. foreach str boot-strings [
  599. either set-word? :str [
  600. emit-line/define "#define RS_" to word! str n ;R3
  601. ][
  602. n: n + 1
  603. append code str
  604. append code null
  605. ]
  606. ]
  607. emit ["#define RS_MAX" tab n lf]
  608. emit ["#define RS_SIZE" tab length? out lf]
  609. boot-strings: to-binary code
  610. ;-- Generate Canonical Words (must follow datatypes above!) ------------------
  611. emit {
  612. /***********************************************************************
  613. **
  614. */ enum REBOL_Symbols
  615. /*
  616. ** REBOL static canonical words (symbols) used with the code.
  617. **
  618. ***********************************************************************/
  619. ^{
  620. SYM_NOT_USED = 0,
  621. }
  622. n: 1
  623. foreach :type-record boot-types [
  624. emit-line "SYM_" join type "_type" n
  625. n: n + 1
  626. ]
  627. boot-words: load %words.r
  628. replace boot-words '*port-modes* load %modes.r
  629. foreach word boot-words [
  630. emit-line "SYM_" word reform [n "-" word]
  631. n: n + 1
  632. ]
  633. emit-end
  634. ;-- Generate Action Constants ------------------------------------------------
  635. emit {
  636. /***********************************************************************
  637. **
  638. */ enum REBOL_Actions
  639. /*
  640. ** REBOL datatype action numbers.
  641. **
  642. ***********************************************************************/
  643. ^{
  644. }
  645. boot-actions: load %actions.r
  646. n: 1
  647. emit-line "A_" "type = 0" "Handled by interpreter"
  648. foreach word boot-actions [
  649. if set-word? :word [
  650. emit-line "A_" to word! :word n ;R3
  651. n: n + 1
  652. ]
  653. ]
  654. emit [tab "A_MAX_ACTION" lf "};"]
  655. emit {
  656. #define IS_BINARY_ACT(a) ((a) <= A_XOR)
  657. }
  658. print [n "actions"]
  659. write inc/tmp-bootdefs.h out
  660. ;----------------------------------------------------------------------------
  661. ;
  662. ; Sysobj.h - System Object Selectors
  663. ;
  664. ;----------------------------------------------------------------------------
  665. emit-head "System Object" %sysobj.h
  666. emit newline
  667. at-value: func ['field] [next find boot-sysobj to-set-word field]
  668. boot-sysobj: load %sysobj.r
  669. change at-value version version
  670. when: now
  671. when: when - when/zone
  672. when/zone: 0:00
  673. change at-value build when
  674. plats: load %platforms.r
  675. change/only at-value platform reduce [pick plats version/4 * 2 - 1 pick pick plats version/4 * 2 version/5]
  676. ob: context boot-sysobj
  677. make-obj-defs: func [obj prefix depth /local f] [
  678. uppercase prefix
  679. emit ["enum " prefix "object {" newline]
  680. emit-line prefix "SELF = 0" none
  681. foreach field words-of obj [ ;R3
  682. emit-line prefix field none
  683. ]
  684. emit [tab uppercase join prefix "MAX^/"]
  685. emit "};^/^/"
  686. if depth > 1 [
  687. foreach field words-of obj [ ;R3
  688. f: join prefix [field #"_"]
  689. replace/all f "-" "_"
  690. all [
  691. field <> 'standard
  692. object? get in obj field
  693. make-obj-defs obj/:field f depth - 1
  694. ]
  695. ]
  696. ]
  697. ]
  698. make-obj-defs ob "SYS_" 1
  699. make-obj-defs ob/catalog "CAT_" 4
  700. make-obj-defs ob/contexts "CTX_" 4
  701. make-obj-defs ob/standard "STD_" 4
  702. make-obj-defs ob/state "STATE_" 4
  703. ;make-obj-defs ob/network "NET_" 4
  704. make-obj-defs ob/ports "PORTS_" 4
  705. make-obj-defs ob/options "OPTIONS_" 4
  706. ;make-obj-defs ob/intrinsic "INTRINSIC_" 4
  707. make-obj-defs ob/locale "LOCALE_" 4
  708. make-obj-defs ob/view "VIEW_" 4
  709. write inc/tmp-sysobj.h out
  710. ;----------------------------------------------------------------------------
  711. emit-head "Dialects" %reb-dialect.h
  712. emit {
  713. enum REBOL_dialect_error {
  714. REB_DIALECT_END = 0, // End of dialect block
  715. REB_DIALECT_MISSING, // Requested dialect is missing or not valid
  716. REB_DIALECT_NO_CMD, // Command needed before the arguments
  717. REB_DIALECT_BAD_SPEC, // Dialect spec is not valid
  718. REB_DIALECT_BAD_ARG, // The argument type does not match the dialect
  719. REB_DIALECT_EXTRA_ARG // There are more args than the command needs
  720. };
  721. }
  722. make-obj-defs ob/dialects "DIALECTS_" 4
  723. emit {#define DIALECT_LIT_CMD 0x1000
  724. }
  725. write inc/reb-dialect.h out
  726. ;----------------------------------------------------------------------------
  727. ;
  728. ; Event Types
  729. ;
  730. ;----------------------------------------------------------------------------
  731. emit-head "Event Types" %reb-evtypes.h
  732. emit newline
  733. emit ["enum event_types {" newline]
  734. foreach field ob/view/event-types [
  735. emit-line "EVT_" field none
  736. ]
  737. emit [tab "EVT_MAX^/"]
  738. emit "};^/^/"
  739. emit ["enum event_keys {" newline]
  740. emit-line "EVK_" "NONE" none
  741. foreach field ob/view/event-keys [
  742. emit-line "EVK_" field none
  743. ]
  744. emit [tab "EVK_MAX^/"]
  745. emit "};^/^/"
  746. write inc/reb-evtypes.h out
  747. ;----------------------------------------------------------------------------
  748. ;
  749. ; Error Constants
  750. ;
  751. ;----------------------------------------------------------------------------
  752. ;-- Error Structure ----------------------------------------------------------
  753. emit-head "Error Structure and Constants" %errnums.h
  754. emit {
  755. #ifdef VAL_TYPE
  756. /***********************************************************************
  757. **
  758. */ typedef struct REBOL_Error_Obj
  759. /*
  760. ***********************************************************************/
  761. ^{
  762. }
  763. ; Generate ERROR object and append it to bootdefs.h:
  764. emit-line/code "REBVAL " 'self ";" ;R3
  765. foreach word words-of ob/standard/error [ ;R3
  766. if word = 'near [word: 'nearest] ; prevents C problem
  767. emit-line/code "REBVAL " word ";"
  768. ]
  769. emit {^} ERROR_OBJ;
  770. #endif
  771. }
  772. emit {
  773. /***********************************************************************
  774. **
  775. */ enum REBOL_Errors
  776. /*
  777. ***********************************************************************/
  778. ^{
  779. }
  780. boot-errors: load %errors.r
  781. err-list: make block! 200
  782. errs: false
  783. foreach [cat msgs] boot-errors [
  784. code: second msgs
  785. new1: true
  786. foreach [word val] skip msgs 4 [
  787. err: uppercase form to word! word ;R3
  788. replace/all err "-" "_"
  789. if find err-list err [print ["DUPLICATE Error Constant:" err] errs: true]
  790. append err-list err
  791. either new1 [
  792. emit-line "RE_" reform [err "=" code] reform [code mold val]
  793. new1: false
  794. ][
  795. emit-line "RE_" err reform [code mold val]
  796. ]
  797. code: code + 1
  798. ]
  799. emit-line "RE_" join to word! cat "_max" none ;R3
  800. emit newline
  801. ]
  802. if errs [wait 3 quit]
  803. emit-end
  804. emit {
  805. #define RE_NOTE RE_NO_LOAD
  806. #define RE_USER RE_MESSAGE
  807. }
  808. write inc/tmp-errnums.h out
  809. ;-------------------------------------------------------------------------
  810. emit-head "Port Modes" %port-modes.h
  811. data: load %modes.r
  812. emit {
  813. enum port_modes ^{
  814. }
  815. foreach word data [
  816. emit-enum word
  817. ]
  818. emit-end
  819. write inc/tmp-portmodes.h out
  820. ;----------------------------------------------------------------------------
  821. ;
  822. ; Load Boot Mezzanine Functions - Base, Sys, and Plus
  823. ;
  824. ;----------------------------------------------------------------------------
  825. ;-- Add other MEZZ functions:
  826. mezz-files: load %../mezz/boot-files.r ; base lib, sys, mezz
  827. ;append boot-mezz+ none ?? why was this needed?
  828. foreach section [boot-base boot-sys boot-mezz] [
  829. set section make block! 200
  830. foreach file first mezz-files [
  831. append get section load join %../mezz/ file
  832. ]
  833. remove-tests get section
  834. mezz-files: next mezz-files
  835. ]
  836. boot-protocols: make block! 20
  837. foreach file first mezz-files [
  838. m: load/all join %../mezz/ file ; not REBOL word
  839. append/only append/only boot-protocols m/2 skip m 2
  840. ]
  841. emit-head "Sys Context" %sysctx.h
  842. sctx: construct boot-sys
  843. make-obj-defs sctx "SYS_CTX_" 1
  844. write inc/tmp-sysctx.h out
  845. ;----------------------------------------------------------------------------
  846. ;
  847. ; b-boot.c - Boot data file
  848. ;
  849. ;----------------------------------------------------------------------------
  850. ;-- Build b-boot.c output file -------------------------------------------------
  851. emit-head "Natives and Bootstrap" %b-boot.c
  852. emit {
  853. #include "sys-core.h"
  854. }
  855. externs: make string! 2000
  856. boot-booters: load %booters.r
  857. boot-natives: load %natives.r
  858. if has-graphics [append boot-natives load %graphics.r]
  859. nats: append copy boot-booters boot-natives
  860. n: boot-sys
  861. ;while [n: find n 'native] [
  862. ; if set-word? first back n [
  863. ; print index? n
  864. ; append nats copy/part back n 3
  865. ; ]
  866. ; n: next next n
  867. ;]
  868. nat-count: 0
  869. foreach val nats [
  870. if set-word? val [
  871. emit-line/decl "REBNATIVE(" to word! val ");" ;R3
  872. nat-count: nat-count + 1
  873. ]
  874. ]
  875. print [nat-count "natives"]
  876. emit [newline {const REBFUN Native_Funcs[} nat-count {] = ^{
  877. }]
  878. foreach val nats [
  879. if set-word? val [
  880. emit-line/code "N_" to word! val "," ;R3
  881. ]
  882. ;nat-count: nat-count + 1
  883. ]
  884. emit-end
  885. emit newline
  886. ;-- Embedded REBOL Tests:
  887. ;where: find boot/script 'tests
  888. ;if where [
  889. ; remove where
  890. ; foreach file sort load %../tests/ [
  891. ; test: load join %../tests/ file
  892. ; if test/1 <> 'skip-test [
  893. ; where: insert where test
  894. ; ]
  895. ; ]
  896. ;]
  897. ;-- Build typespecs block (in same order as datatypes table):
  898. boot-typespecs: make block! 100
  899. specs: load %typespec.r
  900. foreach type datatypes [
  901. append/only boot-typespecs select specs type
  902. ]
  903. ;-- Create main code section (compressed):
  904. boot-types: new-types
  905. boot-root: load %root.r
  906. boot-task: load %task.r
  907. boot-ops: load %ops.r
  908. ;boot-script: load %script.r
  909. write %boot-code.r mold reduce sections
  910. data: mold/flat reduce sections
  911. insert data reduce ["; Copyright (C) REBOL Technologies " now newline]
  912. insert tail data make char! 0 ; scanner requires zero termination
  913. comp-data: compress data: to-binary data ;R3
  914. ;append comp-data "ABCD"
  915. encloak/with comp-data thekey: checksum/secure to binary! "REBOL Version 3.0" ;R3
  916. ;cc: decompress decloak/with comp-data thekey print ["decompressed?" cc = data] halt
  917. emit ["const REBYTE Native_Specs[" length? comp-data "] = {^/^-"]
  918. ;-- Convert to C-encoded string:
  919. emit binary-to-c comp-data
  920. emit-end/easy
  921. write src/b-boot.c out
  922. ;-- Output stats:
  923. print [
  924. "Compressed" length? data "to" length? comp-data "bytes:"
  925. to-integer ((length? comp-data) / (length? data) * 100)
  926. "percent of original"
  927. ]
  928. ;-- Create platform string:
  929. ;platform: to-string platform
  930. ;lowercase platform
  931. ;if platform-data/type = 'windows [ ; Why?? Not sure.
  932. ; product: to-string product
  933. ; lowercase product
  934. ; replace/all product "-" ""
  935. ;]
  936. ;;dir: to-file rejoin [%../to- platform "/" product "/temp/"]
  937. ;----------------------------------------------------------------------------
  938. ;
  939. ; Boot.h - Boot header file
  940. ;
  941. ;----------------------------------------------------------------------------
  942. emit-head "Bootstrap Structure and Root Module" %boot.h
  943. emit [
  944. {
  945. #define MAX_NATS } nat-count {
  946. #define NAT_SPEC_SIZE } length? comp-data {
  947. #define CHECK_TITLE } checksum to binary! title {
  948. extern const REBYTE Native_Specs[];
  949. extern const REBFUN Native_Funcs[];
  950. typedef struct REBOL_Boot_Block ^{
  951. }
  952. ]
  953. foreach word sections [
  954. word: form word
  955. remove/part word 5 ; boot_
  956. emit-line/code "REBVAL " word ";"
  957. ]
  958. emit "} BOOT_BLK;"
  959. ;-------------------
  960. emit [
  961. {
  962. //**** ROOT Context (Root Module):
  963. typedef struct REBOL_Root_Context ^{
  964. }
  965. ]
  966. foreach word boot-root [
  967. emit-line/code "REBVAL " word ";"
  968. ]
  969. emit ["} ROOT_CTX;" lf lf]
  970. n: 0
  971. foreach word boot-root [
  972. emit-line/define "#define ROOT_" word join "(&Root_Context->" [lowercase replace/all form word #"-" #"_" ")"]
  973. n: n + 1
  974. ]
  975. emit ["#define ROOT_MAX " n lf]
  976. ;-------------------
  977. emit [
  978. {
  979. //**** Task Context
  980. typedef struct REBOL_Task_Context ^{
  981. }
  982. ]
  983. foreach word boot-task [
  984. emit-line/code "REBVAL " word ";"
  985. ]
  986. emit ["} TASK_CTX;" lf lf]
  987. n: 0
  988. foreach word boot-task [
  989. emit-line/define "#define TASK_" word join "(&Task_Context->" [lowercase replace/all form word #"-" #"_" ")"]
  990. n: n + 1
  991. ]
  992. emit ["#define TASK_MAX " n lf]
  993. write inc/tmp-boot.h out
  994. ;print ask "-DONE-"
  995. ;wait .3
  996. print " "