[cmds] Add Kilomacs (Rafael's own version of emacs :P ) editor#2597
[cmds] Add Kilomacs (Rafael's own version of emacs :P ) editor#2597ghaerr merged 1 commit intoghaerr:masterfrom
Conversation
| git pull | ||
| make clean | ||
| make | ||
| mv kilomacs emacs |
There was a problem hiding this comment.
Having a name change after make via mv isn't really a good idea here. Can you either change the Makefile in kilomacs or perform this filename change in ExtApplications?
There was a problem hiding this comment.
I'll change in the Makefile
|
Thanks @rafael2k! |
Yes, this is looking very nice, with multiple editors and a working devkit, all automatically distributed. I saw you added mem.c to kilo to allow for larger files to be edited. Have you learned what a typical max file size is? |
|
I added a help, which can be accessed with Ctrl + [ |
|
I can open stdio.h (5307 bytes), but it fails with a > 10kB file. I think I did something wrong. Lemme check why a 10kB+ file is not opening fine. (23)SBRK 10244 FAIL, OUT OF HEAP SPACE Insufficient memory to load file reading line 256! |
|
One question: strdup is also covered by our "mem.c"? |
|
You can always look at the source in libc/string/strdup.c, it calls malloc. Remember that mem.c allocates small strings less than MALLOC_ARENA_THRESH to the local heap. Kilo could be allocating each line separately, in which case they're all going into the local heap. You'll have to chase that down in kilo.c. Alternatively you could rewrite mem.c to always allocate from the far heap and/or set the threshold to 0 or very small. |
|
I had to fix some bugs, there was some outstanding memory issues that was causing some random crashes. At least the code is small... So when I link the software with owc, even if strdup calls malloc (and both of them are in the libc), the linker will still "prefer" the malloc in the mem.c, correct? No malloc is "escaping" to the default libc implementation, right? ps: playing with arena threshold and even using just the far memory, I already managed to open 20kB files - Things are not that bad! As soon as I understand more about kilo internals I'll set the final memory tunables. ps2: I can set the heap in owc very low right (-Wl,heapsize), since it will not be used, correct? |
Yes, correct. Since the symbol
Right. You'll need to best understand the sizes and frequency of
Yes. In general for this type of mem.c configuration, it can be set to the size of allocations expected in the local heap, or just 256 or 512 if mem.c won't ever allocate from it. |
|
With -Wl,heapsize=0x200 the software does not even open, and I already get: The space allocated for the arena is not in the heap (this one set in OWC cmd line), right? |
Actually there are other library routines that may try to allocate from the local heap, like exec(). This allocation shows 178 bytes. We would have to research the source code to see what it is doing to learn more. These use |
|
Something is really allocating memory from the "default" heap. May be calling sbrk() directly? With 1k heap not even drawcube.lua opens (SBRK 58 FAIL, ...) |
Yes, that's correct. Mem.c uses a single far heap, allocated once using MALLOC_ARENA_SIZE bytes max (allocated from main memory), and the rest using individual fmemalloc calls out of main memory. It is possible you're running out of memory from the _fmalloc() call in mem.c, add a __dprintf to check. The _fmalloc allocator uses only 4 bytes overhead per allocation, while fmemalloc uses 16. Debug statements in mem.c will help, and set the near heap size to 1K or 4K and the program should be good. |
I thought you're talking about kilomacs. If you're talking about Lua, that could be far more complicated, I have no idea how it is allocating memory. You have to understand the memory allocation mechanism(s) the program is using in order to code mem.c properly. Set the default near heap to 60k and proceed. That should allow you to find out how large a file kilomacs can edit. |
|
It is kilomacs. I disabled a "open recent files" feature. Lets see. ps: I'm using drawcube.lua just as a test text file for kilomacs! |
I get it now, sorry. Set the local heap to 60k, and then add debug statements to mem.c. That will allow you to use a max local heap and also see which malloc allocations are being routed through the two arenas it supports. If you display the size values and use __dprintf to display to the debug console rather than direct console, you will be able to get a good idea of how many and how big each allocation is. |
|
trying to open a big file, I get an error from SBRK too I need to debug who is calling sbrk(). |
Yes, perhaps kilo itself doesn't call malloc but uses sbrk for the entire size of the file? If so, then you'll need to rewrite that. |
sbrk should work if the local heap is small, say 4k. This is because initially the heap is unused, and sbrk extends the "top" of it. So you might try running with a smaller initial heap, and let kilo use sbrk to extend it. If sbrk is used for allocation, then your mem.c won't do much good, as only internal C library routines would be calling it. Look for explicit calls to malloc in kilo.c to find out. |
|
Uff, I think I forgot to define ELKS for mem.c |
|
All good, sorry the noise... |
What is the approximate max size of file that can be edited with kilomacs now? |
|
With stability, about 20kB (a bit more, but not much more), which is much more than the default kilo, which can not even open stdio.h with its 5kB. |


After spending countless hours trying to make jove run perfectly... I decided to just adapt kilo to use emacs key bindings. I improved memory handling too, so I can edit drawcube.lua comfortably in ELKS, without memory exhaustion.
It adopts the default "emacs" naming, like "elvis". Let me know if this is ok.