<commit_before>REBOL [
	Title:   "Red/System source program loader"
	Author:  "<NAME>"
	File: 	 %loader.r
	Tabs:	 4
	Rights:  "Copyright (C) 2011-2012 <NAME>. All rights reserved."
	License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
]

loader: make-profilable context [
	verbose: 	  0
	include-list: make hash! 20
	ssp-stack: 	  make block! 5
	defs:		  make block! 100

	hex-chars: 	  charset "0123456789ABCDEF"
	ws-chars: 	  charset " ^M^-"
	ws-all:		  union ws-chars charset "^/"
	hex-delim: 	  charset "[]()/"
	non-cbracket: complement charset "}^/"

	current-script: none
	line: none

	throw-error: func [err [string! block!]][
		print [
			"*** Loading Error:"
			either word? err [
				join uppercase/part mold err 1 " error"
			][reform err]
			"^/*** in file:" mold current-script
			"^/*** at line:" line
		]
		compiler/quit-on-error
	]

	count-slash: func [file /local cnt][
		cnt: 0
		parse file [some [slash (cnt: cnt + 1) | skip]]
		cnt
	]

	pop-encap-path: func [cnt [integer!]][
		path: tail encap-fs/base
		loop cnt + 1 [path: find/reverse path slash]
		clear next path
	]

	init: does [
		clear include-list
		clear defs
		insert defs <no-match>					;-- required to avoid empty rule (causes infinite loop)
	]
	
	relative-path?: func [file [file!]][
		not find "/~" first file
	]

	included?: func [file [file!]][
		if encap? [file: join encap-fs/base file]
		
		attempt [file: get-modes file 'full-path]
		either find include-list file [true][
			append include-list file
			false
		]
	]

	push-system-path: func [file [file!] /local path][
		append ssp-stack system/script/path
		if relative-path? file [file: get-modes file 'full-path]
		path: split-path file
		system/script/path: path/1
		path/2
	]
	
	pop-system-path: does [
		system/script/path: take/last ssp-stack
	]
	
	check-macro-parameters: func [args [paren!]][
		unless parse args [some word!][
			throw-error ["only words can be used as macro parameters:" mold args]<commit_msg>FIX Issue#548 Update Loader: INCLUDED? doesn't work properly with encapped Re<commit_after>REBOL [
	Title:   "Red/System source program loader"
	Author:  "<NAME>"
	File: 	 %loader.r
	Tabs:	 4
	Rights:  "Copyright (C) 2011-2012 <NAME>. All rights reserved."
	License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
]

loader: make-profilable context [
	verbose: 	  0
	include-list: make hash! 20
	ssp-stack: 	  make block! 5
	defs:		  make block! 100

	hex-chars: 	  charset "0123456789ABCDEF"
	ws-chars: 	  charset " ^M^-"
	ws-all:		  union ws-chars charset "^/"
	hex-delim: 	  charset "[]()/"
	non-cbracket: complement charset "}^/"

	current-script: none
	line: none

	throw-error: func [err [string! block!]][
		print [
			"*** Loading Error:"
			either word? err [
				join uppercase/part mold err 1 " error"
			][reform err]
			"^/*** in file:" mold current-script
			"^/*** at line:" line
		]
		compiler/quit-on-error
	]

	count-slash: func [file /local cnt][
		cnt: 0
		parse file [some [slash (cnt: cnt + 1) | skip]]
		cnt
	]

	pop-encap-path: func [cnt [integer!]][
		path: tail encap-fs/base
		loop cnt + 1 [path: find/reverse path slash]
		clear next path
	]

	init: does [
		clear include-list
		clear defs
		insert defs <no-match>					;-- required to avoid empty rule (causes infinite loop)
	]
	
	relative-path?: func [file [file!]][
		not find "/~" first file
	]

	included?: func [file [file!]][
		attempt [file: get-modes file 'full-path]
		either find include-list file [true][
			append include-list file
			false
		]
	]

	push-system-path: func [file [file!] /local path][
		append ssp-stack system/script/path
		if relative-path? file [file: get-modes file 'full-path]
		path: split-path file
		system/script/path: path/1
		path/2
	]
	
	pop-system-path: does [
		system/script/path: take/last ssp-stack
	]
	
	check-macro-parameters: func [args [paren!]][
		unless parse args [some word!][
			throw-error ["only words can be used as macro parameters:" mold args]
{'fraction_non_alphanumeric': 0.1426069552164123, 'fraction_numerical': 0.0177633224918689, 'mean_word_length': 3.1131687242798356, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5858539', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1444, 'n_words': 433}