Skip to content

Commit d4e9476

Browse files
committed
CHANGE: storing system/modules as an object!; added support to include delayed modules
1 parent b497811 commit d4e9476

File tree

3 files changed

+91
-36
lines changed

3 files changed

+91
-36
lines changed

make/tools/make-boot.reb

+67-20
Original file line numberDiff line numberDiff line change
@@ -911,27 +911,50 @@ foreach section [boot-base boot-sys boot-mezz] [
911911
set section make block! 200
912912

913913
foreach file first mezz-files [
914-
file: load-file/header file
915-
hdr: take file
914+
code: load-file/header file
915+
hdr: take code
916916
append get section either 'module = select hdr 'type [
917-
compose/deep/only [
918-
import module [
919-
Title: (select hdr 'title)
920-
Name: (select hdr 'name)
921-
Version: (select hdr 'version)
922-
Exports: (select hdr 'exports)
923-
] ( file )
917+
either find hdr/options 'delay [
918+
compose [
919+
sys/load-module/delay (
920+
append
921+
mold/only compose/deep/only [
922+
Rebol [
923+
Version: (any [select hdr 'version 0.0.0])
924+
Title: (select hdr 'title)
925+
Name: (select hdr 'name)
926+
Date: (select hdr 'date)
927+
Author: (select hdr 'author)
928+
Exports: (select hdr 'exports)
929+
Needs: (select hdr 'needs)
930+
]
931+
]
932+
mold/only/flat code
933+
)
934+
]
935+
][
936+
compose/deep/only [
937+
import module [
938+
Title: (select hdr 'title)
939+
Name: (select hdr 'name)
940+
Version: (select hdr 'version)
941+
Date: (select hdr 'date)
942+
Author: (select hdr 'author)
943+
Exports: (select hdr 'exports)
944+
Needs: (select hdr 'needs)
945+
] ( code )
946+
]
924947
]
925-
][ file ]
948+
][ code ]
926949
]
927950
remove-tests get section
928951
mezz-files: next mezz-files
929952
]
930953

931954
boot-protocols: make block! 20
932955
foreach file first mezz-files [
933-
file: load-file/header file
934-
hdr: to block! take file
956+
code: load-file/header file
957+
hdr: to block! take code
935958
either all [
936959
;- if protocol exports some function, import must be used so
937960
;- the functions are available in user's context
@@ -940,17 +963,41 @@ foreach file first mezz-files [
940963
'module = select hdr 'type
941964
][
942965
;- using boot-mezz as this section is binded into lib context
943-
append boot-mezz compose/deep/only [
944-
import module [
945-
Title: (select hdr 'title)
946-
Name: (select hdr 'name)
947-
Version: (select hdr 'version)
948-
Exports: (select hdr 'exports)
949-
] ( file )
966+
append boot-mezz
967+
either find hdr/options 'delay [
968+
compose [
969+
sys/load-module/delay (
970+
append
971+
mold/only compose/deep/only [
972+
Rebol [
973+
Version: (any [select hdr 'version 0.0.0])
974+
Title: (select hdr 'title)
975+
Name: (select hdr 'name)
976+
Date: (select hdr 'date)
977+
Author: (select hdr 'author)
978+
Exports: (select hdr 'exports)
979+
Needs: (select hdr 'needs)
980+
]
981+
]
982+
mold/only/flat code
983+
)
984+
]
985+
][
986+
compose/deep/only [
987+
import module [
988+
Title: (select hdr 'title)
989+
Name: (select hdr 'name)
990+
Version: (select hdr 'version)
991+
Date: (select hdr 'date)
992+
Author: (select hdr 'author)
993+
Exports: (select hdr 'exports)
994+
Needs: (select hdr 'needs)
995+
] ( code )
996+
]
950997
]
951998
][
952999
;- else hidden module is used by default (see sys-start.reb)
953-
append/only append/only boot-protocols hdr file
1000+
append/only append/only boot-protocols hdr code
9541001
]
9551002
]
9561003

src/boot/sysobj.reb

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ state: object [
9090
last-result: none ; used to store last console result
9191
]
9292

93-
modules: []
93+
modules: object []
9494

9595
codecs: object []
9696

@@ -208,10 +208,10 @@ standard: object [
208208
]
209209

210210
header: construct [
211+
version: 0.0.0
211212
title: {Untitled}
212213
name:
213214
type:
214-
version:
215215
date:
216216
file:
217217
author:

src/mezz/sys-load.reb

+22-14
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ load-header: function/with [
132132
set/any [hdr: rest:] transcode/next/error rest none ; get header block
133133
not block? :hdr [return 'no-header] ; header block is incomplete
134134
not attempt [hdr: construct/with :hdr system/standard/header][return 'bad-header]
135+
word? :hdr/options [hdr/options: to block! :hdr/options]
135136
not any [block? :hdr/options none? :hdr/options][return 'bad-header]
136137
not any [binary? :hdr/checksum none? :hdr/checksum][return 'bad-checksum]
138+
not tuple? :hdr/version [hdr/version: none]
137139
find hdr/options 'content [repend hdr ['content data]] ; as of start of header
138140
13 = rest/1 [rest: next rest] ; skip CR
139141
10 = rest/1 [rest: next rest] ; skip LF
@@ -241,7 +243,9 @@ load-boot-exts: function [
241243
not delay [hdr: spec-of mod: make module! load-ext-module ext]
242244
; NOTE: This will error out if the code contains commands but
243245
; no extension dispatcher (call) has been provided.
244-
hdr/name [reduce/into [hdr/name mod if hdr/checksum [copy hdr/checksum]] system/modules]
246+
hdr/name [
247+
repend system/modules [hdr/name mod]
248+
]
245249
]
246250
case [
247251
not module? mod none
@@ -461,9 +465,10 @@ load-module: function [
461465
case/all [
462466
as [cause-error 'script 'bad-refine /as] ; no renaming
463467
; Return none if no module of that name found
464-
not tmp: find/skip system/modules source 3 [return none]
465-
set [mod: modsum:] next tmp none ; get the module
468+
not mod: select system/modules source [return none]
469+
466470
;assert/type [mod [module! block!] modsum [binary! none!]] none
471+
467472
; If no further processing is needed, shortcut return
468473
all [not version not check any [delay module? :mod]] [
469474
return reduce [source if module? :mod [mod]]
@@ -497,12 +502,14 @@ load-module: function [
497502
]
498503
]
499504
module? source [ ; see if the same module is already in the list
500-
if tmp: find/skip next system/modules mod: source 3 [
501-
if as [cause-error 'script 'bad-refine /as] ; already imported
502-
if all [ ; not /version, not /check, same as top module of that name
503-
not version not check same? mod select system/modules pick tmp 0
504-
] [return copy/part back tmp 2]
505-
set [mod: modsum:] tmp
505+
mod: source
506+
foreach [n m] system/modules [
507+
if source = m [
508+
if as [cause-error 'script 'bad-refine /as] ; already imported
509+
set mod: m
510+
hdr: spec-of mod
511+
return reduce [hdr/name mod]
512+
]
506513
]
507514
]
508515
block? source [
@@ -566,15 +573,17 @@ load-module: function [
566573
; See if it's there already, or there is something more recent
567574
all [
568575
override?: not no-lib ; set to false later if existing module is used
569-
set [name0: mod0: sum0:] pos: find/skip system/modules name 3
576+
mod0: select system/modules name
570577
] [
571578
; Get existing module's info
572579
case/all [
573580
module? :mod0 [hdr0: spec-of mod0] ; final header
574-
block? :mod0 [hdr0: first mod0] ; cached preparsed header
581+
block? :mod0 [hdr0: first mod0] ; cached preparsed header
575582
;assert/type [name0 word! hdr0 object! sum0 [binary! none!]] none
576-
not tuple? set/any 'ver0 :hdr0/version [ver0: 0.0.0]
583+
;not tuple? set/any 'ver0 :hdr0/version [ver0: 0.0.0] ;@@ remove?
577584
]
585+
ver0: any [hdr0/version 0.0.0]
586+
sum0: hdr0/checksum
578587
; Compare it to the module we want to load
579588
case [
580589
same? mod mod0 [override?: not any [delay module? mod]] ; here already
@@ -626,9 +635,8 @@ load-module: function [
626635
]
627636

628637
all [not no-lib override?] [
638+
repend system/modules [name mod]
629639
case/all [
630-
pos [pos/2: mod pos/3: modsum] ; replace delayed module
631-
not pos [reduce/into [name mod modsum] system/modules]
632640
all [module? mod not mixin? hdr block? select hdr 'exports] [
633641
resolve/extend/only lib mod hdr/exports ; no-op if empty
634642
]

0 commit comments

Comments
 (0)