Posted to tcl by mookie at Mon Nov 02 00:34:29 GMT 2026view raw

  1. Fun for a Sunday.
  2. - refactored crystal::cast:autoload, The "skip already loaded" mechanism for now it works elementary of course.
  3. - boot time to load seven procedures upleveling from a tcl module of my experimental "leaning c" library written as a bare-minimal file datastore. I wish I had more time to learn the language.
  4. - not vibe coded, not one for that
  5. Now to play with interp and rebuild the rest of the sky palace.
  6.  
  7. >? 2026/11/01 21:29:56 :: 323032362f31312f30312032313a32393a3536
  8. :: 175.153 ms -- 180~ms :: reading from IO
  9. :: 155.153 ms -- 180~ms :: reading from IO (remark)
  10. :: 93.839 ms :: from creation writing/executing bootstrap to IO
  11.  
  12. -> crystal.ix
  13. >? latched :: crystal_memory.so
  14. >? GHUI :: awake
  15. >? 00ff ::
  16. >? 01-- ::
  17. >? /forest/neoncrystal/crystal/resource/system.soul :: Double Dictionary construct. Fabulous. crystal0x174a96b9e0
  18. >? ---- :: boot/procedures
  19. >? ---- :: cast/cast
  20. >? ---- :: cast/mem
  21. >? ---- :: cast/procs
  22. >? ---- :: cast/ghui
  23. >? ---- :: cast/debug
  24. >? ---- :: dict/hext
  25. >? ---- :: math/hex
  26. >? 00ff ::
  27. >? 00-- ::
  28. >? materialising :: procedures
  29. >? 00ff ::
  30. >? 03-- ::
  31. >? 00ff ::
  32. >? 04-- ::
  33. >? 00ff ::
  34. >? 00-- ::
  35. >? materialised :: cast
  36. >? 00ff ::
  37. >? 03-- ::
  38. >? 00ff ::
  39. >? 00-- ::
  40. >? materialised :: mem
  41. >? 00ff ::
  42. >? 03-- ::
  43. >? 00ff ::
  44. >? 00-- ::
  45. >? materialised :: procs
  46. >? 00ff ::
  47. >? 03-- ::
  48. >? 00ff ::
  49. >? 00-- ::
  50. >? materialised :: ghui
  51. >? 00ff ::
  52. >? 03-- ::
  53. >? 00ff ::
  54. >? 00-- ::
  55. >? materialising :: debug
  56. >? 00ff ::
  57. >? 03-- ::
  58. >? 00ff ::
  59. >? 04-- ::
  60. >? 00ff ::
  61. >? 00-- ::
  62. >? materialising :: hext
  63. >? 00ff ::
  64. >? 03-- ::
  65. >? 00ff ::
  66. >? 04-- ::
  67. >? 00ff ::
  68. >? 00-- ::
  69. >? materialising :: hex
  70. >? 00ff ::
  71. >? 03-- ::
  72. >? 00ff ::
  73. >? 04-- ::
  74. >? 00ff ::
  75. >? 02-- ::
  76. >? 96.852 ms :: booted in
  77. >? 2026/11/01 22:28:35 :: 323032362f31312f30312032323a32383a3335
  78.  
  79. ======
  80.  
  81. namespace eval crystal { }
  82. namespace eval crystal::cast { }
  83.  
  84. namespace export {[a-z]*} {
  85. namespace ensemble create }
  86.  
  87. source [dict get $::crystal::vfs b32_load]/cast/debug.ix
  88. source [dict get $::crystal::vfs b32_load]/cast/mem.ix
  89. source [dict get $::crystal::vfs b32_load]/cast/ghui.ix
  90.  
  91. proc crystal::lidx {input lindex} { switch $lindex { default { return [lindex "$input" $lindex] } } } ;# end proc :: crystal::lidx
  92.  
  93. proc crystal::cast {slate _level args} {
  94. switch [info exist gtx] { 0 { variable vfs_ctx [crystal::lidx $args 0] } } ;# end switch :: info exist b32_vfs
  95. switch [info exist vfs_ctx] { 1 { variable gtx [crystal::lidx $args 0] } } ;# end switch :: info exist b32_vfs
  96.  
  97. crystal::debug 1 $slate ""
  98. crystal::debug 1 "$_level--" ""
  99. crystal::debug 0 $vfs_ctx "vfs_ctx"
  100.  
  101. ;# args [0] = vfs / ctx - dependent
  102. ;# args [1] = load_library
  103. ;# mux2 = module_name
  104. variable vfs_ctx [crystal::lidx $args 0]
  105. variable mux [crystal::lidx $args 1]
  106.  
  107. proc cortex {vfs_ctx enc} {
  108. ;# procedure cortex :: currently displays many data streams
  109. ;# want to see your data in base64? now you can
  110. crystal::debug 0 "$vfs_ctx" "$enc"
  111. switch $vfs_ctx {
  112. default {
  113. switch $enc {
  114. 16 { dict get [crystal::memory::query single $vfs_ctx] 16}
  115. 32 { dict get [crystal::memory::query single $vfs_ctx] 32}
  116. 64 { dict get [crystal::memory::query single $vfs_ctx] 64}
  117. } ;# end switch $enc
  118. }
  119. } ;# end switch :: $vfs_ctx
  120. } ;# end proc :: crystal::context
  121.  
  122. ;# Switch :: $b32_resource_slate
  123. ;# control the flow to the resource permission
  124. ;# case :: 00ff
  125. ;# cast file_open on $b32_resource (file)
  126. ;# case :: default
  127. ;# Fatal - Resource state not defined - exit
  128. switch $slate {
  129. 00ff { switch -- $_level { 00 { crystal::cast::read_open ${vfs_ctx}}
  130. 01 { crystal::cast::soul_create ${vfs_ctx} }
  131. 02 { crystal::memory::close [dict get $vfs_ctx ctx] }
  132. 03 { crystal::memory::insert $vfs_ctx }
  133. 04 { crystal::cortex $vfs_ctx 32 }
  134. 05 { crystal::cortex $vfs_ctx 16 }
  135. 06 { crystal::cortex $vfs_ctx 64 }
  136. 07 { crystal::memory::open $vfs_ctx }
  137. default { crystal::debug 1 "$_level" "invalid for $slate " ; exit } }
  138. }
  139. 0001 { switch -- $_level { 00 { }
  140. 01 { crystal::ghui::construct }
  141. 02 { return ${gtx} }
  142. default { crystal::debug 1 "$_level" "invalid for $slate " ; exit } }
  143. }
  144. default { crystal::debug 1 "FATAL" "invalid cast slate" ; exit }
  145. } ;# end switch :: $base32_action
  146. } ;# end proc :: crystal::cast
  147.  
  148. proc crystal::cast::2Base {enc input} {
  149. ;# Everything that comes in b32_enc is what to be converted to
  150. ;# Switch :: $b32_enc
  151. ;# Switch to determine which encoding is the characters set in
  152. ;# Case: 16 - encode it to 16
  153. ;# Case: 32 - encode it to 32
  154. ;# Case: 64 - encode it to 64
  155. proc ::16 {input} { return [binary encode hex [encoding convertto utf-8 "${input}"]] } ;# end proc :: crystal::16
  156. proc ::32 {b32_input} { return ${b32_input} } ;# end proc :: crystal::32
  157. proc ::64 {input} { return [binary encode base64 [encoding convertto utf-8 "${input}"]] } ;# end proc :: crystal::64
  158. switch -- $enc {
  159. 16 { return [::16 ${input}] }
  160. 32 { return [::32 ${input}] }
  161. 64 { return [::64 ${input}] }
  162. } ;# end switch :: $b32_enc
  163. } ;# end proc :: crystal::cast::2Base
  164.  
  165. proc crystal::cast::read_open {resource_file} {
  166. # Open the file. If this fails, the procedure stops here.
  167. set open_file [open [dict get ${::crystal::vfs} b32_load]/${resource_file} r]
  168. try {
  169. variable stream [read ${open_file}]
  170. variable b32_read_file ${stream} ;# assuming our file is in base32 for now
  171. variable b64_read_file [crystal::cast::2Base 64 ${b32_read_file}] ;# encode our crystal to base64
  172. variable b16_read_file [crystal::cast::2Base 16 ${b32_read_file}] ;# encode our crystal to base16
  173. } finally { close $open_file } ; # Runs whether reading succeeds or fails.
  174. dict append 6372797374616c 64 ${b64_read_file}
  175. dict append 6372797374616c 32 ${b32_read_file}
  176. dict append 6372797374616c 16 ${b16_read_file}
  177. return $6372797374616c ;# return crystal with all three based data streams
  178. } ;# end proc :: crystal::cast::file_open
  179.  
  180. proc crystal::cast::soul_create {resource_file} {
  181. dict set vfs_ctx resource_path [dict get ${::crystal::vfs} b32_resource]/$resource_file
  182. dict set vfs_ctx resource_file $resource_file
  183. dict set vfs_ctx ctx [crystal::memory::open ${vfs_ctx}]
  184.  
  185. # Check that the file exists and is not empty
  186. switch -- [file exists [dict get ${vfs_ctx} resource_path]] {
  187. 0 { crystal::debug 1 "FATAL" "resource should exist :: $resource_path" ; exit }
  188. 1 { crystal::cast::autoload ${vfs_ctx} }
  189. } ;# end switch :: switch -glob -- [file size $resource_path]
  190. return
  191. } ;# end proc :: crystal::cast::file_open
  192.  
  193. proc crystal::cast::autoload {vfs_ctx} {
  194. switch $vfs_ctx {
  195. default {
  196. dict set _autoload ctx [dict get ${vfs_ctx} ctx]
  197. dict set _autoload module_list [glob -nocomplain -directory [dict get ${::crystal::vfs} b32_load] */*.ix]
  198.  
  199. foreach module [dict get $_autoload module_list] {
  200. ;# get the length to to the load path /forest/neoncrystal/crystal/load
  201. ;# get this and then split it load/procedures.ix
  202. variable module [file rootname [string range ${module} [string length [dict get ${::crystal::vfs} b32_load]/] end]]
  203. lassign [split $module /] load_library module_name
  204. crystal::debug 0 "----" "start $load_library"
  205. crystal::debug 0 ${load_library} "load_library"
  206. crystal::debug 0 ${module_name} "module_name"
  207. crystal::debug 0 ${load_library}/${module_name}.ix "load_library/module_name.ix"
  208. crystal::debug 0 "----" "end $load_library"
  209. } ;# end foreach :: file [dict get $_autoload module_list]
  210.  
  211. switch [file exists [dict get ${vfs_ctx} resource_path].idx] {
  212. 0 {
  213. foreach module [dict get $_autoload module_list] {
  214. variable module_library [file tail [file dirname $module]]
  215. variable module_name [file rootname [file tail $module]]
  216.  
  217. dict set _autoload anchor ${module_library}
  218. dict set _autoload surface ${module_name}
  219. dict set _autoload deep [crystal::cast 00ff 00 ${module_library}/${module_name}.ix]
  220.  
  221. switch -- ${module_name} { "cast" -
  222. "mem" -
  223. "procs" -
  224. "ghui" { crystal::debug 1 "materialised" "${module_name}" ; crystal::cast 00ff 03 ${_autoload} }
  225. default { crystal::cast 00ff 03 ${_autoload} ; uplevel #0 [crystal::cast 00ff 04 ${_autoload}] }
  226. } ;#end switch :: $module_name
  227. } ;# end foreach file
  228. }
  229. 1 {
  230. foreach module [dict get $_autoload module_list] {
  231. variable module_library [file tail [file dirname $module]]
  232. variable module_name [file rootname [file tail $module]]
  233.  
  234. dict set _autoload anchor ${module_library}
  235. dict set _autoload surface ${module_name}
  236. dict set _autoload deep [crystal::cast 00ff 00 ${module_library}/${module_name}.ix]
  237.  
  238. switch -- ${module_name} { "cast" -
  239. "mem" -
  240. "procs" -
  241. "ghui" { crystal::debug 1 "materialised" " ${module_name}" ; continue }
  242. default { uplevel #0 [crystal::cast 00ff 04 ${_autoload}] }
  243. } ;#end switch :: $module_name
  244. uplevel #0 [crystal::cast 00ff 04 ${_autoload}]
  245. } ;# end foreach file
  246. }
  247. } ;# end switch :: [file exists [dict get ${vfs_ctx} resource_path].idx]
  248. }
  249. } ;# end switch :: $vfs_ctx
  250. crystal::cast 00ff 02 ${_autoload} ;# close ctx
  251. } ;# end proc :: crystal::cast::autoload
  252.  
  253. =====
  254.  
  255. [remark: script above is missing the performance increase]

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week