<commit_before>REBOL [
	Title:   "Red/System compiler wrapper"
	Author:  "<NAME>"
	File: 	 %rsc.r
	Rights:  "Copyright (C) 2011 <NAME>. All rights reserved."
	License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
	Usage:   {
		do/args %rsc.r "[-vvvv] [-f PE|ELF] %path/source.reds"
	}
]

unless value? 'system-dialect [
	do %compiler.r
]

unless exists? %builds/ [make-dir %builds/]

verbosity: 0
opts: make system-dialect/options-class [link?: yes]

;-- Load preconfigured compilation targets --
targets: load %config.r
if exists? %custom-targets.r [
	insert targets load %custom-targets.r
]

unless system/script/args [
	print "Missing command-line arguments!"
	halt
]

process-target: func [v][
	value: attempt [to word! trim v]
	either find targets value [
		opts: make opts targets/:value
		opts/config-name: value
	][
		print ["*** Command-line Error: unknown target" v]
		halt
	]
]

unless parse system/script/args [
	any [
		#"-" [
			some [#"v" (verbosity: verbosity + 1)] (opts/verbosity: verbosity)
			| #"t" copy v to #" " (process-target v)
			| #"f" copy fmt to #" " (opts/format: to-word trim fmt)		; to be removed
			| #"r" (opts/runtime?: no)
			| "-" [
				"no-runtime" (opts/runtime?: no)
				| "target" copy v to #" " (process-target v)
				| "verbose" copy v to #" " (opts/verbosity: to integer! trim verbosity)
			]
		]
	]
	file: to end
][
	print "Invalid command line"
	halt
]

unless all [
	file? file: attempt [load file]
	exists? file	
][
	print ["Can't access file" mold file]
	halt
]

print [
	newline
	"-= Red/System Compiler =-" newline
	"Compiling" file "..."
]

if error? set/any 'err try [
	result: system-dialect/compile/options file opts
][
	err: disarm err
	foreach w [arg1 arg2 arg3][
		set w either unset? get/any in err w [none][
			get/any in err w
		]
	]
	print [
		"*** Compiler Internal Error:" 
		system/error/(err/type)/type #":"
		reduce system/error/(err/type)/(err/id) newline
		"*** Where:" mold/flat err/where newline
		"*** Near: " mold/flat err/near newline
	]
	halt
]

print ["^/...compilation time:" tab round result/1/second * 1000 "ms"]
if result/2 [
	print [
		"...linking time:" tab tab round result/2/second * 1000 "ms^/"
		"...output file size:" tab result/3 "bytes"
	]
]


<commit_msg>FEAT: try to infer target, if not passed explicitly<commit_after>REBOL [
	Title:   "Red/System compiler wrapper"
	Author:  "<NAME>"
	File: 	 %rsc.r
	Rights:  "Copyright (C) 2011 <NAME>. All rights reserved."
	License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
	Usage:   {
		do/args %rsc.r "[-vvvv] [-f PE|ELF] %path/source.reds"
	}
]

unless value? 'system-dialect [
	do %compiler.r
]

unless exists? %builds/ [make-dir %builds/]

verbosity: 0
opts: make system-dialect/options-class [link?: yes]

;-- Load preconfigured compilation targets --
targets: load %config.r
if exists? %custom-targets.r [
	insert targets load %custom-targets.r
]

unless system/script/args [
	print "Missing command-line arguments!"
	halt
]

process-target: func [v][
	value: attempt [to word! trim v]
	either find targets value [
		opts: make opts targets/:value
		opts/config-name: value
	][
		print ["*** Command-line Error: unknown target" v]
		halt
	]
]

unless parse system/script/args [
	any [
		#"-" [
			some [#"v" (verbosity: verbosity + 1)] (opts/verbosity: verbosity)
			| #"t" copy v to #" " (process-target v)
			| #"f" copy fmt to #" " (opts/format: to-word trim fmt)		; to be removed
			| #"r" (opts/runtime?: no)
			| "-" [
				"no-runtime" (opts/runtime?: no)
				| "target" copy v to #" " (process-target v)
				| "verbose" copy v to #" " (opts/verbosity: to integer! trim verbosity)
			]
		]
	]
	file: to end
][
	print "Invalid command line"
	halt
]

unless opts/config-name [
	; If desired target was not set explicitly, try to infer it from the
	; REBOL host version.
	process-target any [
		select [
			3 "MSDOS"
			4 "Linux"
			5 "Darwin"
		] system/version/4
		"MSDOS"
	]
]

unless all [
	file? file: attempt [load file]
	exists? file	
][
	print ["Can't access file" mold file]
	halt
]

print [
	newline
	"-= Red/System Compiler =-" newline
	"Compiling" file "..."
]

if error? set/any 'err try [
	result: system-dialect/compile/options file opts
][
	err: disarm err
	foreach w [arg1 arg2 arg3][
		set w either unset? get/any in err w [none][
			get/any in err w
		]
	]
	print [
		"*** Compiler Internal Error:" 
		system/error/(err/type)/type #":"
		reduce system/error/(err/type)/(err/id) newline
		"*** Where:" mold/flat err/where newline
		"*** Near: " mold/flat err/near newline
	]
	halt
]

print ["^/...compilation time:" tab round result/1/second * 1000 "ms"]
if result/2 [
	print [
		"...linking time:" tab tab round result/2/second * 1000 "ms^/"
		"...output file size:" tab result/3 "bytes"
	]
]



{'fraction_non_alphanumeric': 0.1601246105919003, 'fraction_numerical': 0.010384215991692628, 'mean_word_length': 3.1660899653979238, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, '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': '6152953', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1769, 'n_words': 523}