How do I make a port of MicroPython for Casio calculators?
Re: How do I make a port of MicroPython for Casio calculators?
Build the unix or windows port and debug that step by step to see what gets executed. If mp_execute_bytecode doesn't get reached the problem should be in lexing, parsing or compiling. Hard to tell what. Could be a mismatch of options in mpconfigport, or something non-standard with the way the platform implements doubles. You could try other float implementations as well?
Re: How do I make a port of MicroPython for Casio calculators?
Zezombye wrote:I can't put breakpoints so I did the "manual" method with good old print().
Anyway, I put print statements everywhere (beginning of mp_execute_bytecode, before for loop, beginning of for loop, beginning of switch...): when I type an integer, all print statements are executed, however when I type a double it crashes before it even prints anything.
So I guess the crash occurs before the execution of mp_execute_bytecode() :/
I remember now there was a second macro that needed to be enabled when I was playing around with this issue.
I’ll reply again once I get to my desk as I’m mobile right now.
Re: How do I make a port of MicroPython for Casio calculators?
Interesting that it crashes before printing ANYTHING i.e. it's not printing the error message that an exception is throwing out; we know that exceptions work for you from the "name not defined" screenshot you gave us.Zezombye wrote: ↑Thu Aug 09, 2018 4:40 amI can't put breakpoints so I did the "manual" method with good old print().
Anyway, I put print statements everywhere (beginning of mp_execute_bytecode, before for loop, beginning of for loop, beginning of switch...): when I type an integer, all print statements are executed, however when I type a double it crashes before it even prints anything.
So I guess the crash occurs before the execution of mp_execute_bytecode() :/
The function that parses floats is mp_parse_num_decimal().
Put print statements in there, specifically before and after any "new" statements i.e. mp_obj_new_float()
My guess is that you didn't initialize the heap correctly.
Re: How do I make a port of MicroPython for Casio calculators?
Seems the pow() function is broken.
The problem comes from this line:
For input 1.0, dec_val is 10.0000000, exp_val is -1, and the result of pow(10, exp_val) is... -0.0000.
This seemingly happens for all inputs of pow().
Weirdly, if I remove my print() statements, it crashes again.
Something else is happening to the value, because after the calculation dec_val is -0.00000 but it prints some weird value like -4.316e-269.
I'll investigate, this is not a bug in micropython but with the libc I am using.
The problem comes from this line:
Code: Select all
dec_val *= MICROPY_FLOAT_C_FUN(pow)(10, exp_val);
This seemingly happens for all inputs of pow().
Weirdly, if I remove my print() statements, it crashes again.
Something else is happening to the value, because after the calculation dec_val is -0.00000 but it prints some weird value like -4.316e-269.
I'll investigate, this is not a bug in micropython but with the libc I am using.
Re: How do I make a port of MicroPython for Casio calculators?
What happens if you define a dummy pow() inside the .c-file where it's used?Zezombye wrote: ↑Sat Aug 11, 2018 4:35 amSeems the pow() function is broken.
The problem comes from this line:For input 1.0, dec_val is 10.0000000, exp_val is -1, and the result of pow(10, exp_val) is... -0.0000.Code: Select all
dec_val *= MICROPY_FLOAT_C_FUN(pow)(10, exp_val);
This seemingly happens for all inputs of pow().
Weirdly, if I remove my print() statements, it crashes again.
Something else is happening to the value, because after the calculation dec_val is -0.00000 but it prints some weird value like -4.316e-269.
I'll investigate, this is not a bug in micropython but with the libc I am using.
Re: How do I make a port of MicroPython for Casio calculators?
It just uses this function instead of the default one, why?
Anyway, I still haven't resolved this issue, but I do know it has absolutely nothing to do with MPy. Even a small program written from scratch has this error.
Why I'm posting is because I'm running into a memory error. I tried to get the available memory to MPy, but the script doesn't work because there is not enough available memory:
Summing gc.mem_free() and gc.mem_alloc() gives me 2064 bytes:
As 2064 is very close to a power of 2, I think there is a hardcoded limit somewhere. I don't think there is a coincidence because 2 kb is quite low, I was expecting at least 5 kb (especially since there is 48 kb of heap total, there should be plenty of room, and MPy's website states that 16 kb is enough). However, I looked in the config files and gc.c and I didn't find anything.
Is there an hardcoded limit, or should I look to free memory?
Anyway, I still haven't resolved this issue, but I do know it has absolutely nothing to do with MPy. Even a small program written from scratch has this error.
Why I'm posting is because I'm running into a memory error. I tried to get the available memory to MPy, but the script doesn't work because there is not enough available memory:
Code: Select all
def mem():
try:
l=[0]
while True:
try:
l=l+l[l[0]:]
except:
if l[0]<len(l)-1:
l[0]=len(l)-1
else:
print("+",4*len(l))
l[0]=4*len(l)+mem()
break
except:
return 0
return l[0]
As 2064 is very close to a power of 2, I think there is a hardcoded limit somewhere. I don't think there is a coincidence because 2 kb is quite low, I was expecting at least 5 kb (especially since there is 48 kb of heap total, there should be plenty of room, and MPy's website states that 16 kb is enough). However, I looked in the config files and gc.c and I didn't find anything.
Is there an hardcoded limit, or should I look to free memory?
Re: How do I make a port of MicroPython for Casio calculators?
Zezombye wrote: ↑Thu Aug 30, 2018 9:12 pmIt just uses this function instead of the default one, why?
Anyway, I still haven't resolved this issue, but I do know it has absolutely nothing to do with MPy. Even a small program written from scratch has this error.
Why I'm posting is because I'm running into a memory error. I tried to get the available memory to MPy, but the script doesn't work because there is not enough available memory:Summing gc.mem_free() and gc.mem_alloc() gives me 2064 bytes:Code: Select all
def mem(): try: l=[0] while True: try: l=l+l[l[0]:] except: if l[0]<len(l)-1: l[0]=len(l)-1 else: print("+",4*len(l)) l[0]=4*len(l)+mem() break except: return 0 return l[0]
As 2064 is very close to a power of 2, I think there is a hardcoded limit somewhere. I don't think there is a coincidence because 2 kb is quite low, I was expecting at least 5 kb (especially since there is 48 kb of heap total, there should be plenty of room, and MPy's website states that 16 kb is enough). However, I looked in the config files and gc.c and I didn't find anything.
Is there an hardcoded limit, or should I look to free memory?
You can use `gc` inside a script.
Code: Select all
num_free_bytes = gc.mem_free()
Code: Select all
if (self->len >= self->alloc) {
self->items = m_renew(mp_obj_t, self->items, self->alloc, self->alloc * 2);
Re: How do I make a port of MicroPython for Casio calculators?
So part of it is a bug in micropython (because it is doubling the size of lists, consuming even more memory, when there is no memory left)?
Also, is there a way to make errors display the character? I just did a beginner error (using = instead of ==), but MPy doesn't show me exactly where it happened:
I would like an output similar to this:
Also, is there a way to make errors display the character? I just did a beginner error (using = instead of ==), but MPy doesn't show me exactly where it happened:
I would like an output similar to this:
Re: How do I make a port of MicroPython for Casio calculators?
Calling it a bug may be too harsh. At the very least, doubling is not a good idea for super memory-constrained systems.