NerdLang / nerd

🔱 Javascript's God Mode. No VM. No Bytecode. No GC. Just native binaries.
https://nectarjs.com
MIT License
3.58k stars 127 forks source link

Compilation error __NERD_DIRNAME with fib.js, Debian 12 and pre-compiled nerd v0.0.16 #161

Open mavavilj opened 9 months ago

mavavilj commented 9 months ago

node nerd ../fib-main/fib.js

[*] Generating source file
[*] Compiling with preset: speed
[+] Creating Nerd binary lib for std_linux_0.0.16
g++ -std=c++17  -flto -Ofast   -c nerdcore/src/nerd.cpp -o "/home/me/Downloads/nerd-master/.nerd/cached_std_linux_0.0.16/nerd.o"
[+] Compiling with precompiled Nerd lib
/home/me/Downloads/nerd-master/.nerd/uxh7a/fib.cpp: In function ‘int main(int, char**)’:
/home/me/Downloads/nerd-master/.nerd/uxh7a/fib.cpp:77:17: error: ‘__NERD_DIRNAME’ was not declared in this scope
   77 |                 __NERD_DIRNAME = argv_str.substr(0, argv_str.find_last_of("/"));
      |                 ^~~~~~~~~~~~~~
Error: Command failed: g++  -std=c++17 "/home/me/Downloads/nerd-master/.nerd/cached_std_linux_0.0.16/nerd.o" "/home/me/Downloads/nerd-master/.nerd/uxh7a/fib.cpp" -Ofast  -flto -pthread -s   -o "/home/me/Downloads/nerd-master/fib"  
/home/me/Downloads/nerd-master/.nerd/uxh7a/fib.cpp: In function ‘int main(int, char**)’:
/home/me/Downloads/nerd-master/.nerd/uxh7a/fib.cpp:77:17: error: ‘__NERD_DIRNAME’ was not declared in this scope
   77 |                 __NERD_DIRNAME = argv_str.substr(0, argv_str.find_last_of("/"));
      |                 ^~~~~~~~~~~~~~

    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at Compiler.Compile (/home/me/Downloads/nerd-master/compiler/native/compiler.js:161:3)
    at /home/me/Downloads/nerd-master/nerd.js:481:13
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 2f 68 6f 6d 65 2f 6d 61 74 74 69 2f 44 6f 77 6e 6c 6f 61 64 73 2f 6e 65 72 64 2d 6d 61 73 74 65 72 2f 2e 6e 65 72 64 2f 75 78 68 37 61 2f 66 69 62 2e ... 294 more bytes>
  ],
  pid: 6703,
  stdout: <Buffer >,
  stderr: <Buffer 2f 68 6f 6d 65 2f 6d 61 74 74 69 2f 44 6f 77 6e 6c 6f 61 64 73 2f 6e 65 72 64 2d 6d 61 73 74 65 72 2f 2e 6e 65 72 64 2f 75 78 68 37 61 2f 66 69 62 2e ... 294 more bytes>
}
[!] Compilation error

fib.js: https://github.com/drujensen/fib

mavavilj commented 9 months ago

Not specific to fib.js. Error produced also with, e.g.:

hello.js

// hello world

NOTE:

Possibly the first report of this error, since other Issues seem to be using nectar as opposed to nerd.

mavavilj commented 9 months ago

Fixable by adding the type std::string to:

https://github.com/NerdLang/nerd/blob/400b367708c2fee58060f85fb8546a522c8add9c/self/compiler/native/squel/std.cpp#L77

Then the compiler finishes.

mavavilj commented 9 months ago

Also,

node nerd --run hello.ng
[*] Generating source file
[*] Compiling with preset: speed
lto-wrapper: warning: using serial compilation of 2 LTRANS jobs
lto-wrapper: note: see the ‘-flto’ option documentation for more information
../6yng6/nerdcore/src/./class/fixed_array.h: In member function ‘__ct_comp ’:
../6yng6/nerdcore/src/./class/fixed_array.h:50:50: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
   50 |                 value = new NerdCore::VAR[_length];
      |                                                  ^
/usr/include/c++/12/new:128:26: note: in a call to allocation function ‘operator new []’ declared here
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^

[*] Executing /root/Downloads/nerd-master/hello
Hello World !
adrien-thierry commented 9 months ago

could you try with GCC10 or 9 just to check if it comes from GCC ?

mavavilj commented 9 months ago

could you try with GCC10 or 9 just to check if it comes from GCC ?

The __NERD_DIRNAME problem persists, but is fixable as I wrote earlier.

in reply to: https://github.com/NerdLang/nerd/issues/161#issuecomment-1909469900

node ../nerd --run hello.js
[*] Generating source file
[*] Compiling with preset: speed

[*] Executing /root/Downloads/nerd-master/example/hello

I am not an expert on GCC, but to me the programming error at L75 and L77 at https://github.com/NerdLang/nerd/blob/400b367708c2fee58060f85fb8546a522c8add9c/self/compiler/native/squel/std.cpp#L75 looks evident, since L73 is never executed and thus the variable is never initialized.