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

simplified u.r - albeit not sure whether it can be called a simplification. It's shorter though. #45

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Bushmills
Copy link
Contributor

penalty is more use of return stack.

Copy link
Contributor Author

@Bushmills Bushmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return stack use may actually not be higher, as I wrote, because your version buffers chars there, while mine stacks recursion return addresses there. I do use more user stack though, because digits remain there.

0 base @ um/mod
?dup if rot recurse else swap 0 max spaces then
digits + c@ emit ;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your code but please reformat according to my conventions, including running stack diagrams on the right. I'm a stickler about stylistic consistency within a code base.

true ( true )
else ( adr )
find-position ( )
?dup 0= if
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the origin code in this case as it seems clearer to me.

: (indent) ( -- ) lmargin @ #out @ - 0 max spaces ;
: (indent) ( -- ) lmargin @ #out @ -
\ 0 max \ unnecessary, as spaces does that too.
spaces ;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting: if the definition fits entirely on one line, it can follow the stack diagram. Otherwise the entire body must be on a 3-space indent and the ; is on a line by itself

then
2drop
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems hardly worth the effort. Your formulation compiles to slightly shorter code, but the improvement is so slight...

@@ -142,7 +142,7 @@ variable break-type variable break-addr variable where-break
: bare-if? ( ip-of-branch-target -- f )
/branch - /token - dup token@ ( ip' possible-branch-acf )
dup ['] branch = \ unconditional branch means else or repeat
if drop drop false exit then ( ip' acf )
if 2drop false exit then ( ip' acf )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay but add another space before the then (fixing my formatting error).

then ( adr,type )
r> drop ( adr,type )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope you aren't going to continue to swamp me with little tweaks of this magnitude...

else
emit
emit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the tabs and trailing whitespace

@@ -1,5 +1,6 @@
: pluck ( x1 x2 x3 - x1 x2 x3 x1 ) 2 pick ;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting: 2 spaces before closing ;

: move ( from to len -- )
-rot 2dup u< if rot cmove> else rot cmove then
pluck pluck u< if cmove> else cmove then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 spaces before then

: ok ;
: trigger 0 0 2>r 2r> drop drop ; immediate
: trigger 0 0 2>r 2r> drop drop ; immediate \ what's that for? "magic" 0. return stack marker?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for triggering a logic analyzer in some scenario. I forget the details. It could go away.

@Bushmills
Copy link
Contributor Author

Bushmills commented Oct 5, 2019 via email

@MitchBradley
Copy link
Owner

I tried to apply the recursive version of u.r, but it doesn't work because "recurse" is defined later in the load sequence. That version of dot is only used for debugging the build. Once the problem is found, dot.fth is omitted from the build and the real versions of u.r and friends are used. I haven't used it for a very long time. It is not even loaded by default - the line that loads it in basics.fth is commented out. My version doesn't work either, due to some relatively recent changes. I fixed my version just in case. I don't see much value in optimizing it since the code never appears in a final build.
How about we close this pull request and you can submit another with any fixes or improvements that you think are important.

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