3 ms·
That's why I did my own implementation using pointers. var lorem = text_create "Hello" var foo = array_create array_push $foo $lorem `var`, `array_push` and
by alganet 4y ago
That's why I did my own implementation using pointers.
var lorem = text_create "Hello"
var foo = array_create
array_push $foo $lorem
`var`, `array_push` and `array_create` are shell functions working together. They create pointers and return just integers. You don't even have to quote the variable.
The code above should create the following variables:
_123="Hello"
_124=1
_124_0=_123
foo=_124
lorem=_123
This way, I can even implement more complex data structures.
The numbers start from zero and the program will stop if the global variable counter overflows. My current implementation also has a primitive GC (ARC-based), which could be used to avoid that (but I didn't, yet).
Despite all of this runtime processing and jerry rigging, I have some evidence that it could be faster than typical shell scripts. One single subshell or path lookup is often more expensive than these fake pointer arrays. These strucutres have zero subshells and run on PATH='', just with builtins. The subshell only becomes faster if the volume of data is larger than a few kilobytes (when the cost of forking and exec'in is worth the payoff).
I know this is far from ideal. I should try to put these ideas in a new interpreter, not hack them on existing ones (JS calls them polyfills, maybe I should do that). If I did another interpreter though, it would end up like the fish shell (nice, fast, doesn't compile the kernel and no one uses it).
Maybe I should probably stick to bash, ksh and zsh that offers the most complete set of features. Sounds like "best viewed in internet explorer" though.
- jrumbut 4y agoThat's an impressive level of devotion to portable bash arrays.