nakkaya / ferret

Ferret is a free software lisp implementation for real time embedded control systems.

Home Page:https://ferret-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

println stops working for strings above a certain length

esp1 opened this issue · comments

I noticed some strange behavior for println. With a memory pool configured, printing strings above a certain length causes the program to stop functioning properly, I'm guessing because of some kind of memory overflow. It would be reasonable to expect bad behavior if the code/string in question were excessively long, but it does not require a very long string to cause this issue. For example, the program below exhibits this behavior when compiled and run on an Arduino Uno:

(configure-runtime!
  FERRET_MEMORY_POOL_SIZE 512)

(println "123456789012345678901234")

If the string provided to println is shortened by a few characters, or if the memory pool is not configured, the program will function normally.

Currently, strings in Ferret are costly. They are implemented as a sequence of numbers in a container in order to keep them behave like Clojure strings, they are mostly there for debugging purposes. I am still planning on how to implement them properly and portably so they work across multiple architectures.

My plan is to implement string then add a to_string method to the base so things like str can be implemented. As long as you use the Ferret API to go from C,C++ string to Ferret strings and vice versa everything should work when I implement the new string representation.

Also as a note, on atmega328 when you use strings they are always kept in memory even when they are not used. If you need to print a lot of stuff to the user use the F macros. That way strings are kept in flash instead of heap.