Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid unitname generated for directories that look like numeric literals #240

Open
jrfondren opened this issue Nov 13, 2023 · 1 comment
Labels

Comments

@jrfondren
Copy link

Code example

local function f() <nodce> end

When compiled in a directory named '001-example', an invalid unitname is generated:

$ nelua 001-example/test.nelua
/home/jfondren/.cache/nelua/test.c:79:13: error: invalid suffix "_example_test_f" on integer constant
   79 | static void 001_example_test_f(void);
      |             ^~~~~~~~~~~~~~~~~~
/home/jfondren/.cache/nelua/test.c:79:13: error: expected identifier or ‘(’ before numeric constant
/home/jfondren/.cache/nelua/test.c:81:6: error: invalid suffix "_example_test_f" on integer constant
   81 | void 001_example_test_f(void) {
      |      ^~~~~~~~~~~~~~~~~~
/home/jfondren/.cache/nelua/test.c:81:6: error: expected identifier or ‘(’ before numeric constant
error: C compilation for '/home/jfondren/.cache/nelua/test' failed

Expected behavior

I expected a unitname like XXX_example, as is done with non-Latin characters.

Workaround

Files can set an explicit unitname with

## pragmas.unitname = 'X001_example'

Environment

x86_64 linux
Nelua 0.2.0-dev
Build number: 1605
Git date: 2023-11-05 16:12:59 -0300
Git hash: decf713
Semantic version: 0.2.0-dev.1605+decf713c
Copyright (C) 2019-2023 Eduardo Bart (https://nelua.io/)

@jrfondren jrfondren added the bug label Nov 13, 2023
@stefanos82
Copy link

stefanos82 commented Nov 13, 2023

Can you provide a full demo to check it on my side? I have tested the code excerpt you shared and could not reproduce the behavior you shared above.

My bad; I forgot to run the script with 001-example included.

Indeed it would be handy to create something like first-character-breadcrumb appended to script's parent directory; in my case, /home/stefanos/nelua/various/ could become hsnv that could get appended to 001-example.

In other words, it should become hsnv_001_example_f_f(void).

Update as of 16-11-2023: Coincidentally, I have discovered by accident that Crystal language creates a caching directory for improving re-building compilation speeds inside $HOME/.cache/, much like Nelua does, but with the following format: home-stefanos-code-crystal-hello_world.cr/; this is my $HOME/stefanos/code/crystal/ directory with filename hello_world.cr.

This type of format could also be used to avoid the aforementioned buggy behavior while maintaining readability for developers that want to investigate the generate C code and know which file came from where exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants