Skip to content

Commit

Permalink
CHANGE: replaced load/type with load/as
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Feb 8, 2022
1 parent bcb875a commit d19b885
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/mezz/sys-base.reb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ do*: func [
; Currently, load of URL has no special block forms.

; Load the data, first so it will error before change-dir
data: load/header/type value 'unbound ; unbound so DO-NEEDS runs before INTERN
data: load/header/as value 'unbound ; unbound so DO-NEEDS runs before INTERN
; Get the header and advance 'data to the code position
hdr: first+ data ; object or none
; data is a block! here, with the header object in the first position back
Expand Down
32 changes: 16 additions & 16 deletions src/mezz/sys-load.reb
Original file line number Diff line number Diff line change
Expand Up @@ -281,22 +281,22 @@ load: function [
source [file! url! string! binary! block!] {Source or block of sources}
/header {Result includes REBOL header object (preempts /all)}
/all {Load all values (does not evaluate REBOL header)}
/type {Override default file-type; use NONE to always load as code}
ftype [word! none!] "E.g. text, markup, jpeg, unbound, etc."
/as {Override default file-type; use NONE to always load as code}
type [word! none!] "E.g. text, markup, jpeg, unbound, etc."
] [
; WATCH OUT: for ALL and NEXT words! They are local.

; NOTES:
; Note that code/data can be embedded in other datatypes, including
; not just text, but any binary data, including images, etc. The type
; argument can be used to control how the raw source is converted.
; Pass a /type of none or 'unbound if you want embedded code or data.
; Pass a /as of none or 'unbound if you want embedded code or data.
; Scripts are normally bound to the user context, but no binding will
; happen for a module or if the /type is 'unbound. This allows the result
; happen for a module or if the /as is 'unbound. This allows the result
; to be handled properly by DO (keeping it out of user context.)
; Extensions will still be loaded properly if /type is 'unbound.
; Note that IMPORT has its own loader, and does not use LOAD directly.
; /type with anything other than 'extension disables extension loading.
; /as with anything other than 'extension disables extension loading.

assert/type [local none!] ; easiest way to protect against /local hacks

Expand All @@ -305,23 +305,23 @@ load: function [

;-- Load multiple sources?
block? source [
return map-each item source [apply :load [:item header all type ftype]]
return map-each item source [apply :load [:item header all as type]]
]

;-- What type of file? Decode it too:
any [file? source url? source] [
sftype: file-type? source
ftype: case [
lib/all ['unbound = ftype 'extension = sftype] [sftype]
type [ftype]
'else [sftype]
stype: file-type? source
type: case [
lib/all ['unbound = as 'extension = stype] [stype]
as [type]
'else [stype]
]
data: read-decode source ftype
data: read-decode source type
]
none? data [data: source]

;-- Is it not source code? Then return it now:
any [block? data not find [0 extension unbound] any [ftype 0]][ ; due to make-boot issue with #[none]
any [block? data not find [0 extension unbound] any [type 0]][ ; due to make-boot issue with #[none]
return data ; directory, image, txt, markup, etc.
]

Expand All @@ -339,7 +339,7 @@ load: function [

;-- Bind code to user context:
not any [
'unbound = ftype
'unbound = type
'module = select hdr 'type
find select hdr 'options 'unbound
][data: intern data]
Expand Down Expand Up @@ -710,15 +710,15 @@ export [load import]
test: [
[
write %test-emb.reb {123^/[REBOL [title: "embed"] 1 2 3]^/123^/}
[1 2 3] = xload/header/type %test-emb.reb 'unbound
[1 2 3] = xload/header/as %test-emb.reb 'unbound
]
][ ; General function:
[[1 2 3] = xload ["1" "2" "3"]]
[[] = xload " "]
[1 = xload "1"]
[[1] = xload "[1]"]
[[1 2 3] = xload "1 2 3"]
[[1 2 3] = xload/type "1 2 3" none]
[[1 2 3] = xload/as "1 2 3" none]
[[1 2 3] = xload "rebol [] 1 2 3"]
[
d: xload/header "rebol [] 1 2 3"
Expand Down
4 changes: 2 additions & 2 deletions src/mezz/sys-start.reb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ start: func [
start: 'done ; only once
init-schemes ; only once

ver: load/type lib/version 'unbound
ver: load/as lib/version 'unbound
system/product: ver/2
system/version: ver/3
system/platform: ver/4
Expand Down Expand Up @@ -215,7 +215,7 @@ start: func [
change-dir first script-path
either exists? second script-path [
sys/log/info 'REBOL ["Evaluating:" script]
code: load/header/type second script-path 'unbound
code: load/header/as second script-path 'unbound
; update system/script (Make into a function?)
system/script: make system/standard/script [
title: select first code 'title
Expand Down

0 comments on commit d19b885

Please sign in to comment.