How do I make a port of MicroPython for Casio calculators?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
stijn
Posts: 257
Joined: Thu Apr 24, 2014 9:13 am

Re: How do I make a port of MicroPython for Casio calculators?

Post by stijn » Thu Aug 09, 2018 8:31 am

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?

jickster
Posts: 279
Joined: Thu Sep 07, 2017 8:57 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by jickster » Thu Aug 09, 2018 7:48 pm

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.

jickster
Posts: 279
Joined: Thu Sep 07, 2017 8:57 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by jickster » Fri Aug 10, 2018 6:56 pm

Zezombye wrote:
Thu Aug 09, 2018 4:40 am
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() :/
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.

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.

Zezombye
Posts: 6
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Sat Aug 11, 2018 4:35 am

Seems the pow() function is broken.

The problem comes from this line:

Code: Select all

dec_val *= MICROPY_FLOAT_C_FUN(pow)(10, exp_val);
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.

jickster
Posts: 279
Joined: Thu Sep 07, 2017 8:57 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by jickster » Mon Aug 13, 2018 2:50 pm

Zezombye wrote:
Sat Aug 11, 2018 4:35 am
Seems the pow() function is broken.

The problem comes from this line:

Code: Select all

dec_val *= MICROPY_FLOAT_C_FUN(pow)(10, exp_val);
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.
What happens if you define a dummy pow() inside the .c-file where it's used?

Post Reply