PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/red-system/runtime/utils.reds

http://github.com/dockimbel/Red
Unknown | 83 lines | 77 code | 6 blank | 0 comment | 0 complexity | 3d9f4cb0c280f7fcd492c28e8ba683f6 MD5 | raw file
 1Red/System [
 2	Title:   "Red/System runtime OS-independent runtime functions"
 3	Author:  "Nenad Rakocevic"
 4	File: 	 %utils.reds
 5	Rights:  "Copyright (C) 2011 Nenad Rakocevic. All rights reserved."
 6	License: {
 7		Distributed under the Boost Software License, Version 1.0.
 8		See https://github.com/dockimbel/Red/blob/master/red-system/runtime/BSL-License.txt
 9	}
10]
11
12newline: "^/"							
13
14lf:  	 #"^/"								;-- Line-feed
15cr:  	 #"^M"
16tab: 	 #"^-"
17space:	 #" "
18slash:	 #"/"
19
20;-------------------------------------------
21;-- Print in console a single byte as an ASCII character
22;-------------------------------------------
23prin-byte: func [
24	c 		[byte!]							;-- ASCII value to print
25	return: [byte!]
26	/local char
27][
28	char: " "
29	char/1: c
30	prin char
31	c
32]
33
34;-------------------------------------------
35;-- Low-level polymorphic print function 
36;-- (not intended to be called directly)
37;-------------------------------------------
38_print: func [
39	count	[integer!]						;-- typed values count
40	list	[typed-value!]					;-- pointer on first typed value
41	spaced?	[logic!]						;-- if TRUE, insert a space between items
42][
43	until [
44		if list/type = type-logic! [
45			prin either as-logic list/value ["true"]["false"]
46		]
47		if list/type = type-integer! [
48			prin-int list/value
49		]
50		if list/type = type-byte! [
51			prin-byte as-byte list/value
52		]
53		if list/type = type-c-string! [
54			prin as-c-string list/value
55		]
56		if list/type > 4 [
57			prin-hex list/value
58		]
59		list: list + 1
60		count: count - 1
61		if all [spaced? count <> 0][prin " "]
62		zero? count
63	]
64]
65
66;-------------------------------------------
67;-- Polymorphic print in console
68;-- (inserts a space character between each item)
69;-------------------------------------------
70print-wide: func [
71	[typed]	count [integer!] list [typed-value!]
72][
73	_print count list yes
74]
75
76;-------------------------------------------
77;-- Polymorphic print in console
78;-------------------------------------------
79print: func [
80	[typed]	count [integer!] list [typed-value!]
81][
82	_print count list no
83]