/red-system/runtime/utils.reds

http://github.com/dockimbel/Red · Redscript · 83 lines · 77 code · 6 blank · 0 comment · 4 complexity · 3d9f4cb0c280f7fcd492c28e8ba683f6 MD5 · raw file

  1. Red/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. newline: "^/"
  12. lf: #"^/" ;-- Line-feed
  13. cr: #"^M"
  14. tab: #"^-"
  15. space: #" "
  16. slash: #"/"
  17. ;-------------------------------------------
  18. ;-- Print in console a single byte as an ASCII character
  19. ;-------------------------------------------
  20. prin-byte: func [
  21. c [byte!] ;-- ASCII value to print
  22. return: [byte!]
  23. /local char
  24. ][
  25. char: " "
  26. char/1: c
  27. prin char
  28. c
  29. ]
  30. ;-------------------------------------------
  31. ;-- Low-level polymorphic print function
  32. ;-- (not intended to be called directly)
  33. ;-------------------------------------------
  34. _print: func [
  35. count [integer!] ;-- typed values count
  36. list [typed-value!] ;-- pointer on first typed value
  37. spaced? [logic!] ;-- if TRUE, insert a space between items
  38. ][
  39. until [
  40. if list/type = type-logic! [
  41. prin either as-logic list/value ["true"]["false"]
  42. ]
  43. if list/type = type-integer! [
  44. prin-int list/value
  45. ]
  46. if list/type = type-byte! [
  47. prin-byte as-byte list/value
  48. ]
  49. if list/type = type-c-string! [
  50. prin as-c-string list/value
  51. ]
  52. if list/type > 4 [
  53. prin-hex list/value
  54. ]
  55. list: list + 1
  56. count: count - 1
  57. if all [spaced? count <> 0][prin " "]
  58. zero? count
  59. ]
  60. ]
  61. ;-------------------------------------------
  62. ;-- Polymorphic print in console
  63. ;-- (inserts a space character between each item)
  64. ;-------------------------------------------
  65. print-wide: func [
  66. [typed] count [integer!] list [typed-value!]
  67. ][
  68. _print count list yes
  69. ]
  70. ;-------------------------------------------
  71. ;-- Polymorphic print in console
  72. ;-------------------------------------------
  73. print: func [
  74. [typed] count [integer!] list [typed-value!]
  75. ][
  76. _print count list no
  77. ]