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

factor out aborts #579 #581

Merged
merged 3 commits into from
Dec 15, 2024
Merged

factor out aborts #579 #581

merged 3 commits into from
Dec 15, 2024

Conversation

ekipan
Copy link
Contributor

@ekipan ekipan commented Dec 14, 2024

Thanks for build fix.

@ekipan
Copy link
Contributor Author

ekipan commented Dec 14, 2024

Apparently the issue reference doesn't totally work if it's in the title so just for completeness sake:

See #579.

@jkotlinski
Copy link
Owner

jkotlinski commented Dec 14, 2024 via email

@jkotlinski
Copy link
Owner

OK, this seems like an improvement. I am pondering various things now.

  • Is the new ABORTS useful somewhere in DurexForth itself? I am kind of wary about adding new words. But it would feel better if there was some immediate use for it.
  • Would it make sense to code golf it harder? I.e. add (abort") which does all the work in one word. Check condition, and either print error message and abort, or skip error message.

@ekipan
Copy link
Contributor Author

ekipan commented Dec 15, 2024

That means every runtime-untaken abort" turns from a single 0branch into rstack, counting, stack juggling etc. A bit more work. Plus I feel like you'd also need to pull a factor from lits to make it worth it, adding 12 cycles of jsr rts to every runtime string literal. Something like this?

: (lits) 1+ count 2dup + 1- ;
: lits r> (lits) >r ;

: (s") '"' parse dup c, 
here swap dup allot move ;
: s" postpone lits (s") ; immediate

\ ...

: (abort") r> (lits) >r rot 
if rvs type cr abort then 2drop ;
: abort" postpone (abort") (s") ;
immediate

@jkotlinski
Copy link
Owner

jkotlinski commented Dec 15, 2024

Uhh, that seems like a bad idea of mine. It is better to use if .. then for the conditional, otherwise it gets too slow.

@jkotlinski
Copy link
Owner

How about merging the PR as is? But I would like one change, rename aborts to (abort"). Then it is clear that it is a helper word to abort", and not a part of the official API.
That is, it does not need to be documented, and it can be later removed or changed without being a breaking change.

@ekipan
Copy link
Contributor Author

ekipan commented Dec 15, 2024

This of course does add more a bit more work in the case abort" is given a nonzero at runtime, but considering its purpose I'm sure that's okay. 12 cycles spent in the rare case a user program fails for a 9 bytes savings every time they compile the word.

@ekipan
Copy link
Contributor Author

ekipan commented Dec 15, 2024

Or I guess only 6 cycles, since abort doesn't rts :P

@jkotlinski
Copy link
Owner

jkotlinski commented Dec 15, 2024 via email

@jkotlinski jkotlinski merged commit f9bcc21 into jkotlinski:master Dec 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants