Posted to tcl by mookie at Mon Nov 02 00:34:29 GMT 2026view raw
- Fun for a Sunday.
- - refactored crystal::cast:autoload, The "skip already loaded" mechanism for now it works elementary of course.
- - 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.
- - not vibe coded, not one for that
- Now to play with interp and rebuild the rest of the sky palace.
- >? 2026/11/01 21:29:56 :: 323032362f31312f30312032313a32393a3536
- :: 175.153 ms -- 180~ms :: reading from IO
- :: 155.153 ms -- 180~ms :: reading from IO (remark)
- :: 93.839 ms :: from creation writing/executing bootstrap to IO
- -> crystal.ix
- >? latched :: crystal_memory.so
- >? GHUI :: awake
- >? 00ff ::
- >? 01-- ::
- >? /forest/neoncrystal/crystal/resource/system.soul :: Double Dictionary construct. Fabulous. crystal0x174a96b9e0
- >? ---- :: boot/procedures
- >? ---- :: cast/cast
- >? ---- :: cast/mem
- >? ---- :: cast/procs
- >? ---- :: cast/ghui
- >? ---- :: cast/debug
- >? ---- :: dict/hext
- >? ---- :: math/hex
- >? 00ff ::
- >? 00-- ::
- >? materialising :: procedures
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 04-- ::
- >? 00ff ::
- >? 00-- ::
- >? materialised :: cast
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 00-- ::
- >? materialised :: mem
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 00-- ::
- >? materialised :: procs
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 00-- ::
- >? materialised :: ghui
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 00-- ::
- >? materialising :: debug
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 04-- ::
- >? 00ff ::
- >? 00-- ::
- >? materialising :: hext
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 04-- ::
- >? 00ff ::
- >? 00-- ::
- >? materialising :: hex
- >? 00ff ::
- >? 03-- ::
- >? 00ff ::
- >? 04-- ::
- >? 00ff ::
- >? 02-- ::
- >? 96.852 ms :: booted in
- >? 2026/11/01 22:28:35 :: 323032362f31312f30312032323a32383a3335
- ======
- namespace eval crystal { }
- namespace eval crystal::cast { }
- namespace export {[a-z]*} {
- namespace ensemble create }
- source [dict get $::crystal::vfs b32_load]/cast/debug.ix
- source [dict get $::crystal::vfs b32_load]/cast/mem.ix
- source [dict get $::crystal::vfs b32_load]/cast/ghui.ix
- proc crystal::lidx {input lindex} { switch $lindex { default { return [lindex "$input" $lindex] } } } ;# end proc :: crystal::lidx
- proc crystal::cast {slate _level args} {
- switch [info exist gtx] { 0 { variable vfs_ctx [crystal::lidx $args 0] } } ;# end switch :: info exist b32_vfs
- switch [info exist vfs_ctx] { 1 { variable gtx [crystal::lidx $args 0] } } ;# end switch :: info exist b32_vfs
- crystal::debug 1 $slate ""
- crystal::debug 1 "$_level--" ""
- crystal::debug 0 $vfs_ctx "vfs_ctx"
- ;# args [0] = vfs / ctx - dependent
- ;# args [1] = load_library
- ;# mux2 = module_name
- variable vfs_ctx [crystal::lidx $args 0]
- variable mux [crystal::lidx $args 1]
- proc cortex {vfs_ctx enc} {
- ;# procedure cortex :: currently displays many data streams
- ;# want to see your data in base64? now you can
- crystal::debug 0 "$vfs_ctx" "$enc"
- switch $vfs_ctx {
- default {
- switch $enc {
- 16 { dict get [crystal::memory::query single $vfs_ctx] 16}
- 32 { dict get [crystal::memory::query single $vfs_ctx] 32}
- 64 { dict get [crystal::memory::query single $vfs_ctx] 64}
- } ;# end switch $enc
- }
- } ;# end switch :: $vfs_ctx
- } ;# end proc :: crystal::context
- ;# Switch :: $b32_resource_slate
- ;# control the flow to the resource permission
- ;# case :: 00ff
- ;# cast file_open on $b32_resource (file)
- ;# case :: default
- ;# Fatal - Resource state not defined - exit
- switch $slate {
- 00ff { switch -- $_level { 00 { crystal::cast::read_open ${vfs_ctx}}
- 01 { crystal::cast::soul_create ${vfs_ctx} }
- 02 { crystal::memory::close [dict get $vfs_ctx ctx] }
- 03 { crystal::memory::insert $vfs_ctx }
- 04 { crystal::cortex $vfs_ctx 32 }
- 05 { crystal::cortex $vfs_ctx 16 }
- 06 { crystal::cortex $vfs_ctx 64 }
- 07 { crystal::memory::open $vfs_ctx }
- default { crystal::debug 1 "$_level" "invalid for $slate " ; exit } }
- }
- 0001 { switch -- $_level { 00 { }
- 01 { crystal::ghui::construct }
- 02 { return ${gtx} }
- default { crystal::debug 1 "$_level" "invalid for $slate " ; exit } }
- }
- default { crystal::debug 1 "FATAL" "invalid cast slate" ; exit }
- } ;# end switch :: $base32_action
- } ;# end proc :: crystal::cast
- proc crystal::cast::2Base {enc input} {
- ;# Everything that comes in b32_enc is what to be converted to
- ;# Switch :: $b32_enc
- ;# Switch to determine which encoding is the characters set in
- ;# Case: 16 - encode it to 16
- ;# Case: 32 - encode it to 32
- ;# Case: 64 - encode it to 64
- proc ::16 {input} { return [binary encode hex [encoding convertto utf-8 "${input}"]] } ;# end proc :: crystal::16
- proc ::32 {b32_input} { return ${b32_input} } ;# end proc :: crystal::32
- proc ::64 {input} { return [binary encode base64 [encoding convertto utf-8 "${input}"]] } ;# end proc :: crystal::64
- switch -- $enc {
- 16 { return [::16 ${input}] }
- 32 { return [::32 ${input}] }
- 64 { return [::64 ${input}] }
- } ;# end switch :: $b32_enc
- } ;# end proc :: crystal::cast::2Base
- proc crystal::cast::read_open {resource_file} {
- # Open the file. If this fails, the procedure stops here.
- set open_file [open [dict get ${::crystal::vfs} b32_load]/${resource_file} r]
- try {
- variable stream [read ${open_file}]
- variable b32_read_file ${stream} ;# assuming our file is in base32 for now
- variable b64_read_file [crystal::cast::2Base 64 ${b32_read_file}] ;# encode our crystal to base64
- variable b16_read_file [crystal::cast::2Base 16 ${b32_read_file}] ;# encode our crystal to base16
- } finally { close $open_file } ; # Runs whether reading succeeds or fails.
- dict append 6372797374616c 64 ${b64_read_file}
- dict append 6372797374616c 32 ${b32_read_file}
- dict append 6372797374616c 16 ${b16_read_file}
- return $6372797374616c ;# return crystal with all three based data streams
- } ;# end proc :: crystal::cast::file_open
- proc crystal::cast::soul_create {resource_file} {
- dict set vfs_ctx resource_path [dict get ${::crystal::vfs} b32_resource]/$resource_file
- dict set vfs_ctx resource_file $resource_file
- dict set vfs_ctx ctx [crystal::memory::open ${vfs_ctx}]
- # Check that the file exists and is not empty
- switch -- [file exists [dict get ${vfs_ctx} resource_path]] {
- 0 { crystal::debug 1 "FATAL" "resource should exist :: $resource_path" ; exit }
- 1 { crystal::cast::autoload ${vfs_ctx} }
- } ;# end switch :: switch -glob -- [file size $resource_path]
- return
- } ;# end proc :: crystal::cast::file_open
- proc crystal::cast::autoload {vfs_ctx} {
- switch $vfs_ctx {
- default {
- dict set _autoload ctx [dict get ${vfs_ctx} ctx]
- dict set _autoload module_list [glob -nocomplain -directory [dict get ${::crystal::vfs} b32_load] */*.ix]
- foreach module [dict get $_autoload module_list] {
- ;# get the length to to the load path /forest/neoncrystal/crystal/load
- ;# get this and then split it load/procedures.ix
- variable module [file rootname [string range ${module} [string length [dict get ${::crystal::vfs} b32_load]/] end]]
- lassign [split $module /] load_library module_name
- crystal::debug 0 "----" "start $load_library"
- crystal::debug 0 ${load_library} "load_library"
- crystal::debug 0 ${module_name} "module_name"
- crystal::debug 0 ${load_library}/${module_name}.ix "load_library/module_name.ix"
- crystal::debug 0 "----" "end $load_library"
- } ;# end foreach :: file [dict get $_autoload module_list]
- switch [file exists [dict get ${vfs_ctx} resource_path].idx] {
- 0 {
- foreach module [dict get $_autoload module_list] {
- variable module_library [file tail [file dirname $module]]
- variable module_name [file rootname [file tail $module]]
- dict set _autoload anchor ${module_library}
- dict set _autoload surface ${module_name}
- dict set _autoload deep [crystal::cast 00ff 00 ${module_library}/${module_name}.ix]
- switch -- ${module_name} { "cast" -
- "mem" -
- "procs" -
- "ghui" { crystal::debug 1 "materialised" "${module_name}" ; crystal::cast 00ff 03 ${_autoload} }
- default { crystal::cast 00ff 03 ${_autoload} ; uplevel #0 [crystal::cast 00ff 04 ${_autoload}] }
- } ;#end switch :: $module_name
- } ;# end foreach file
- }
- 1 {
- foreach module [dict get $_autoload module_list] {
- variable module_library [file tail [file dirname $module]]
- variable module_name [file rootname [file tail $module]]
- dict set _autoload anchor ${module_library}
- dict set _autoload surface ${module_name}
- dict set _autoload deep [crystal::cast 00ff 00 ${module_library}/${module_name}.ix]
- switch -- ${module_name} { "cast" -
- "mem" -
- "procs" -
- "ghui" { crystal::debug 1 "materialised" " ${module_name}" ; continue }
- default { uplevel #0 [crystal::cast 00ff 04 ${_autoload}] }
- } ;#end switch :: $module_name
- uplevel #0 [crystal::cast 00ff 04 ${_autoload}]
- } ;# end foreach file
- }
- } ;# end switch :: [file exists [dict get ${vfs_ctx} resource_path].idx]
- }
- } ;# end switch :: $vfs_ctx
- crystal::cast 00ff 02 ${_autoload} ;# close ctx
- } ;# end proc :: crystal::cast::autoload
- =====
- [remark: script above is missing the performance increase]
Add a comment