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

lua: add sj.get_modules #252

Closed
wants to merge 4 commits into from
Closed

Conversation

lordheavy
Copy link
Contributor

Maybe naïve, but it works mostly fine.

@lordheavy lordheavy mentioned this pull request Dec 12, 2024
sjasm/lua_sjasm.cpp Outdated Show resolved Hide resolved
@ped7g
Copy link
Collaborator

ped7g commented Dec 13, 2024

Looks like a good start... any chance to add few tests? :)
especially curious about:

  • setting up lua variable during pass1 and using it on other pass - makes sure that the string is copied to lua-session-memory while still being valid
  • nested modules (pre,inside,post, in the inner/outer module), to verify always the correct one is returned
  • outside of module (or no module at all) -> should return empty string IMHO?
  • also makes me wonder what nested module returns, full namespace or just current module...

I will do deeper review of the code later when working on merge on this to think about further edge cases and to implement these if nobody else does, but I appreciate any effort trying to get the ball rolling, thank you.

@lordheavy
Copy link
Contributor Author

test.asm.txt

results:
SjASMPlus Z80 Cross-Assembler v1.20.3 (https://github.com/z00m128/sjasmplus)
== outside of a module:
my_var=""
== entering module plop:
my_var=""
my_var="plop"
== entering module plip:
my_var="plop"
my_var="plop.plip"
== leaving module plip
== returning in module plop:
my_var="plop.plip"
my_var="plop"
== leaving module plop
== outside of a module:
my_var="plop"
my_var=""
Pass 1 complete (0 errors)

Really better than sj.get_module_namespace()
@fmafma
Copy link

fmafma commented Dec 15, 2024

I think the function should return the full namespace; it's easy to split on dots if needed.

The function should then just be renamed sj.get_namespace()?

@lordheavy
Copy link
Contributor Author

I think the function should return the full namespace; it's easy to split on dots if needed.

The function should then just be renamed sj.get_namespace()?

It returns the full namespace, but only for modules, so the function will be sj.get_modules()

@lordheavy lordheavy changed the title lua: add sj.get_module_namespace lua: add sj.get_modules Dec 24, 2024
@ped7g
Copy link
Collaborator

ped7g commented Dec 28, 2024

any further plans to change this or why is it still in "draft"? After very quick overview this seems to me good enough to review thoroughly and merge, I didn't spot anything missing.

Or are you waiting for the windows stuff fixed? I will try in following days, but no promises. But also this doesn't really depend on that. :)

@lordheavy
Copy link
Contributor Author

No, you can review and merge (if it's good enough ofc).

@ped7g ped7g marked this pull request as ready for review December 28, 2024 17:43
@ped7g
Copy link
Collaborator

ped7g commented Dec 28, 2024

Wait a second, why does not sj.insert_label(...) add current namespace (also to local labels, etc).

I see a reason why it was stripped of extra arguments depending on internal implementation around v1.20.0 and more flexible API bridge exposing those, but I'm failing to see logic behind the behavior: label string is not processed as usual but used verbatim as is

The current docs are not going into such details so their description could fit any implementation (it just does specify it's regular label, so you can't redefine it in the same pass, etc).

IMO this is bug and the sj.insert_label should be fixed, so the module namespace will be added automatically when the LUA script is running inside module.

That doesn't invalidate this new addition, just does modify results of the tests (which I will patch).

@fmafma - let me know if you see some issue with such fix and disagree about the idea (whether it breaks your current projects - I'm sorry, but I would prefer to rather have it working in "right" way and fix your projects, but I'm wondering if it's only me considering current behavior "wrong").

Also the current tests fails on two asserts because of what insert_label exactly does... :D ... but that's not the point of get_modules test, so I will patch that too.

All that said, it's almost perfect PR saving me ton of "thinking" time being indecisive about this and that, it's lot more easier to ponder about solid proposal and eventually patch 2-3 lines than starting from scratch. Amazing work @lordheavy , thank you.

@ped7g ped7g self-assigned this Dec 28, 2024
@ped7g ped7g added the RFC Request For Comments (opinions) label Dec 28, 2024
@ped7g ped7g added this to the v1.21.0 milestone Dec 28, 2024
@fmafma
Copy link

fmafma commented Dec 28, 2024

I have no problem to adapt my code to the correct behaviour of this fix! Thank you both for this nice addition.

BTW, I was wondering if in a future revision (2.x?), MODULE should not be replaced by NAMESPACE (NS)? This way, one could use it to create sub-namespaces. Of course, it can be done right now by stacking MODULE blocs, but it is less intuitive that NS. Just a though. Maybe just add NS alias to MODULE?

@ped7g
Copy link
Collaborator

ped7g commented Dec 29, 2024

merged with small test adjustment

@ped7g ped7g closed this Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments (opinions)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants