jerryscript-project / jerryscript

Ultra-lightweight JavaScript engine for the Internet of Things.
https://jerryscript.net
Apache License 2.0
6.96k stars 673 forks source link

Compile error when using JERRY_NUMBER_TYPE_FLOAT64=0 #5081

Open VayuDev opened 1 year ago

VayuDev commented 1 year ago

I'm trying to build jerryscript for the esp32. Due to the fact that the esp32 has no 64-Bit FPU, doubles are very slow. Sadly the JERRY_NUMBER_TYPE_FLOAT64=0 config option seems to be broken and there are multiple compile errors, even when specifying JERRY_BUILTIN_DATE=0. There seem to be multiple issues, fixing the first one about the semicolon isn't enough and I don't know how to fix the rest.

To reproduce this, just checkout the latest commit, edit jerry-core/config.h and add the following lines:

#define JERRY_BUILTIN_DATE 0
#define JERRY_NUMBER_TYPE_FLOAT64
JerryScript revision

05dbbd134c3b9e2482998f267857dd3722001cd7

Build platform

"Arch Linux" (Linux 6.3.1-arch2-1 x86_64

Build steps
tools/build.py
Build log
In file included from /home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:16:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_sign’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.h:106:41: error: expected ‘)’ before ‘;’ token
  106 | #define ECMA_NUMBER_SIGN_BIT 0x7f800000u;
      |                                         ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:79:20: note: in expansion of macro ‘ECMA_NUMBER_SIGN_BIT’
   79 |   return (binary & ECMA_NUMBER_SIGN_BIT) != 0;
      |                    ^~~~~~~~~~~~~~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:79:10: note: to match this ‘(’
   79 |   return (binary & ECMA_NUMBER_SIGN_BIT) != 0;
      |          ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_biased_exp’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.h:106:41: error: expected ‘)’ before ‘;’ token
  106 | #define ECMA_NUMBER_SIGN_BIT 0x7f800000u;
      |                                         ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:90:33: note: in expansion of macro ‘ECMA_NUMBER_SIGN_BIT’
   90 |   return (uint32_t) ((binary & ~ECMA_NUMBER_SIGN_BIT) >> ECMA_NUMBER_FRACTION_WIDTH);
      |                                 ^~~~~~~~~~~~~~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:90:22: note: to match this ‘(’
   90 |   return (uint32_t) ((binary & ~ECMA_NUMBER_SIGN_BIT) >> ECMA_NUMBER_FRACTION_WIDTH);
      |                      ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_create’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:120:13: error: conversion from ‘uint64_t’ {aka ‘long unsigned int’} to ‘ecma_binary_num_t’ {aka ‘unsigned int’} may change value [-Werror=conversion]
  120 |   binary |= fraction;
      |             ^~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_is_negative’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.h:106:41: error: expected ‘)’ before ‘;’ token
  106 | #define ECMA_NUMBER_SIGN_BIT 0x7f800000u;
      |                                         ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:200:41: note: in expansion of macro ‘ECMA_NUMBER_SIGN_BIT’
  200 |   return (ecma_number_to_binary (num) & ECMA_NUMBER_SIGN_BIT) != 0;
      |                                         ^~~~~~~~~~~~~~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:200:10: note: to match this ‘(’
  200 |   return (ecma_number_to_binary (num) & ECMA_NUMBER_SIGN_BIT) != 0;
      |          ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_is_infinity’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.h:106:41: error: expected ‘)’ before ‘;’ token
  106 | #define ECMA_NUMBER_SIGN_BIT 0x7f800000u;
      |                                         ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:232:42: note: in expansion of macro ‘ECMA_NUMBER_SIGN_BIT’
  232 |   return (ecma_number_to_binary (num) & ~ECMA_NUMBER_SIGN_BIT) == ECMA_NUMBER_BINARY_INF;
      |                                          ^~~~~~~~~~~~~~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:232:10: note: to match this ‘(’
  232 |   return (ecma_number_to_binary (num) & ~ECMA_NUMBER_SIGN_BIT) == ECMA_NUMBER_BINARY_INF;
      |          ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:232:64: error: bitwise comparison always evaluates to false [-Werror=tautological-compare]
  232 |   return (ecma_number_to_binary (num) & ~ECMA_NUMBER_SIGN_BIT) == ECMA_NUMBER_BINARY_INF;
      |                                                                ^~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_get_prev’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:262:10: error: conversion from ‘double’ to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=float-conversion]
  262 |   return __builtin_nextafter (num, -INFINITY);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_get_next’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:297:10: error: conversion from ‘double’ to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=float-conversion]
  297 |   return __builtin_nextafter (num, INFINITY);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_trunc’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:348:13: error: conversion from ‘long long unsigned int’ to ‘ecma_binary_num_t’ {aka ‘unsigned int’} may change value [-Werror=conversion]
  348 |   binary &= ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH - unbiased_exp)) - 1);
      |             ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c: In function ‘ecma_number_parse_int’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:545:11: error: conversion from ‘int32_t’ {aka ‘int’} to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=conversion]
  545 |     value *= radix;
      |           ^~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-number.c:546:11: error: conversion from ‘int32_t’ {aka ‘int’} to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=conversion]
  546 |     value += digit;
      |           ^~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c: In function ‘ecma_utf8_string_to_number_by_radix’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c:333:15: error: conversion from ‘uint32_t’ {aka ‘unsigned int’} to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=conversion]
  333 |     num = num * radix + value;
      |               ^
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c:333:23: error: conversion from ‘uint32_t’ {aka ‘unsigned int’} to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=conversion]
  333 |     num = num * radix + value;
      |                       ^
cc1: all warnings being treated as errors
make[2]: *** [jerry-core/CMakeFiles/jerry-core.dir/build.make:272: jerry-core/CMakeFiles/jerry-core.dir/ecma/base/ecma-helpers-number.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c: In function ‘ecma_utf8_string_to_number’:
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c:630:50: error: ‘fraction_uint64’ undeclared (first use in this function)
  630 |   ecma_number_t num = (ecma_number_t) (uint32_t) fraction_uint64;
      |                                                  ^~~~~~~~~~~~~~~
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c:630:50: note: each undeclared identifier is reported only once for each function it appears in
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c:632:21: error: ‘e_sign’ undeclared (first use in this function); did you mean ‘sign’?
  632 |   ecma_number_t m = e_sign ? (ecma_number_t) 0.1 : (ecma_number_t) 10.0;
      |                     ^~~~~~
      |                     sign
/home/vayu/Programs/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.c:634:10: error: ‘e’ undeclared (first use in this function)
  634 |   while (e)
      |          ^
[ 13%] Building C object jerry-core/CMakeFiles/jerry-core.dir/ecma/builtin-objects/ecma-builtin-bigint-prototype.c.o
cc1: all warnings being treated as errors
make[2]: *** [jerry-core/CMakeFiles/jerry-core.dir/build.make:230: jerry-core/CMakeFiles/jerry-core.dir/ecma/base/ecma-helpers-conversion.c.o] Error 1
/home/vayu/Programs/jerryscript/jerry-core/api/jerryscript.c: In function ‘jerry_value_as_integer’:
/home/vayu/Programs/jerryscript/jerry-core/api/jerryscript.c:2251:27: error: conversion from ‘double’ to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=float-conversion]
 2251 |   if (ecma_number_is_nan (number))
      |                           ^~~~~~
/home/vayu/Programs/jerryscript/jerry-core/api/jerryscript.c:2256:28: error: conversion from ‘double’ to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=float-conversion]
 2256 |   if (ecma_number_is_zero (number) || ecma_number_is_infinity (number))
      |                            ^~~~~~
/home/vayu/Programs/jerryscript/jerry-core/api/jerryscript.c:2256:64: error: conversion from ‘double’ to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=float-conversion]
 2256 |   if (ecma_number_is_zero (number) || ecma_number_is_infinity (number))
      |                                                                ^~~~~~
/home/vayu/Programs/jerryscript/jerry-core/api/jerryscript.c:2263:35: error: conversion from ‘double’ to ‘ecma_number_t’ {aka ‘float’} may change value [-Werror=float-conversion]
 2263 |   return ecma_number_is_negative (number) ? -floor_fabs : floor_fabs;
      |                                   ^~~~~~
cc1: all warnings being treated as errors
make[2]: *** [jerry-core/CMakeFiles/jerry-core.dir/build.make:132: jerry-core/CMakeFiles/jerry-core.dir/api/jerryscript.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:179: jerry-core/CMakeFiles/jerry-core.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
==============================
Build failed with exit code: 2
==============================
LaszloLango commented 6 hours ago

Somewhat related to #5174