Improving Nasal: Difference between revisions

Jump to navigation Jump to search
m
Line 103: Line 103:
** Regarding the last comment: Providing an API to "lock" a symbol/naRef to become immutable would be generally useful, not just for functions - but also for constants (math.pi FT2M etc) and other stuff that may otherwise break consistency - ThorstenR mentioned a couple of times how he's intentionally replicating standard constants in LW/AW just to be on the safe side, because there's no such thing as a "constant" in Nasal. Providing a library function to make naRefs read-only should be straightforward, and could be easily implemented by hooking into the VM to register a callback that yields naRuntimeError() -aka die()- for any such attempts. The method would be scalable to also implement optional typing or min/max/stepping (value ranges), too
** Regarding the last comment: Providing an API to "lock" a symbol/naRef to become immutable would be generally useful, not just for functions - but also for constants (math.pi FT2M etc) and other stuff that may otherwise break consistency - ThorstenR mentioned a couple of times how he's intentionally replicating standard constants in LW/AW just to be on the safe side, because there's no such thing as a "constant" in Nasal. Providing a library function to make naRefs read-only should be straightforward, and could be easily implemented by hooking into the VM to register a callback that yields naRuntimeError() -aka die()- for any such attempts. The method would be scalable to also implement optional typing or min/max/stepping (value ranges), too
** This should be doable, since I do a naRuntimeError(ctx,naGetError(subcontext)) which ''should'' pass errors from a callback (untested).
** This should be doable, since I do a naRuntimeError(ctx,naGetError(subcontext)) which ''should'' pass errors from a callback (untested).
** To implement support for immutable symbols (constants/ private/protected encapsulation), one would really just need to either lock WRITE access or
restrict visibility, which could work analogous to parents, just as embedded protected/private hashes that are honored by the codegen.
* Timing parts of VM: use the callbacks and systime/unix.time to time things. Need hooks into the GC as well. Statistics worth tracking (also look at similar tools like [http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html google perftools]):
* Timing parts of VM: use the callbacks and systime/unix.time to time things. Need hooks into the GC as well. Statistics worth tracking (also look at similar tools like [http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html google perftools]):
** Per function (also handles timers/listeners and other typical FG callbacks):
** Per function (also handles timers/listeners and other typical FG callbacks):

Navigation menu