Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #456428

Re: linking sc to libgmp

From owl <owl@rooftop.invalid>
Newsgroups comp.os.linux.advocacy
Subject Re: linking sc to libgmp
Date 2018-06-25 22:17 +0000
Organization O.W.L.
Message-ID <az0xb803.aghou3@rooftop.invalid> (permalink)
References (1 earlier) <3f5ac451-83d5-49cb-b211-c42bbc5f75d9@googlegroups.com> <xy4a889b3.abhip3@rooftop.invalid> <259c70c2-e3c3-49d7-bf0d-75e0f2e14e8f@googlegroups.com> <s0z8b803.huo34@rooftop.invalid> <5963c2b2-f820-445e-81f5-53acc62c1747@googlegroups.com>

Show all headers | View raw


Steve Carroll <fretwizzer@gmail.com> wrote:
> On Monday, June 25, 2018 at 3:48:35 PM UTC-6, owl wrote:
>> Steve Carroll <fretwizzer@gmail.com> wrote:
>> > On Monday, June 25, 2018 at 3:20:02 PM UTC-6, owl wrote:
>> >> Steve Carroll <fretwizzer@gmail.com> wrote:
>> >> > On Monday, June 25, 2018 at 8:55:24 AM UTC-6, owl wrote:
>> >> >> Finally figured out how to create a built-in arbitrary precision
>> >> >> addition function for sc.  This first attempt simply adds two cells.
>> >> >> 
>> >> >> https://pewtube.com/user/owl/pdscsXX?autoplay=off
>> >> >> 
>> >> >> Because sc's internal floating-point representation is a double, and
>> >> >> therefore limited to that precision, the numbers for arbitrary precision
>> >> >> math must entered as strings, with the function returning a string.
>> >> >> 
>> >> >> The function itself was easy enough, but figuring out how to get
>> >> >> sc to save it took a lot of digging through the code. 
>> >> > 
>> >> > Why?
>> >> > 
>> >> 
>> >> Because it was buried in a non-obvious (to me) place.  The code that
>> >> causes the function to appear in the info line at the top when the
>> >> cursor is over a cell containing a function, as in the image below where
>> >> it shows:
>> >> 
>> >> A2 (78 2 0) <{@sadd(A0,A1)}
>> >> 
>> >> https://imgur.com/a/Z9f2Fsz
>> >> 
>> >> is also responsible for having the function written to a saved file.
>> >> This is the code (in interp.c):
>> >> 
>> >> void
>> >> decompile(register struct enode *e, int priority)
>> >> {
>> >>     register char *s;
>> >>     if (e) {
>> >>         int mypriority;
>> >>         switch (e->op) {
>> >> ...
>> >>          case SADD:      two_arg("@sadd(", e); break;
>> >> ...
>> >> }
>> >> 
>> >> Without that case statement, the function, even though working correctly,
>> >> displays as:
>> >> 
>> >> A2 (78 2 0) <{A0M(A1)}
>> >> 
>> >> and is written to a saved file as:
>> >> 
>> >> leftstring A2 = AOM(A1) 
>> >> 
>> >> When written that way, the function of course does not work when the file
>> >> is reloaded.  After adding that case statement, the function gets properly 
>> >> displayed as
>> >> 
>> >> A2 (78 2 0) <{@sadd(A0,A1)}
>> >> 
>> >> and written to the file as:
>> >> 
>> >> leftstring A2 = @sadd(A0,A1)
>> >> 
>> >> And now it works.  :)
>> > 
>> > This doesn't strictly apply here but it's always fun with no errors thrown 
>> > where you wish they would be if that thing is going to end up being the 
>> > eventual culprit. Yours is a bizarre situation but it's one of those little
>> > 'learning experiences' you treasure... until you forget it next time.
>> 
>> The main difficulty here was that the text is in a variable called "line"
>> (:O) that is printed by an ncurses function addstr() that is called by the
>> update() function in screen.c, and I could not for the life of me find
>> where it was supposed to be getting the correct string.  I ran tests
>> an was able append to it manually, but that was it.  Basically, it's
>> just a pain in the ass trying to navigate somebody else's complex code.
> 
> It doesn't help that you're doing the kind of thing you're not likely to find 
> any kind of documentation for. I was wondering what you meant earlier by 
> "digging through the code", this clears it up. If not via the tests, how did 
> you figure it out?

I went back to square one and grep'ed for various '@functionnames'.
I had missed it.  It didn't help that there are other places where such
strings appear similarly, such as with

ins_string("@sum("); 

appearing in an ironically unrelated function called write_line().
It also didn't help that the "line" variable is global.

Back to comp.os.linux.advocacy | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

linking sc to libgmp owl <owl@rooftop.invalid> - 2018-06-25 14:55 +0000
  Re: linking sc to libgmp Steve Carroll <fretwizzer@gmail.com> - 2018-06-25 13:10 -0700
    Re: linking sc to libgmp owl <owl@rooftop.invalid> - 2018-06-25 21:20 +0000
      Re: linking sc to libgmp Steve Carroll <fretwizzer@gmail.com> - 2018-06-25 14:33 -0700
        Re: linking sc to libgmp owl <owl@rooftop.invalid> - 2018-06-25 21:48 +0000
          Re: linking sc to libgmp Steve Carroll <fretwizzer@gmail.com> - 2018-06-25 14:56 -0700
            Re: linking sc to libgmp owl <owl@rooftop.invalid> - 2018-06-25 22:17 +0000
              Re: linking sc to libgmp Steve Carroll <fretwizzer@gmail.com> - 2018-06-25 15:23 -0700
                Re: linking sc to libgmp owl <owl@rooftop.invalid> - 2018-06-25 22:48 +0000
                Re: linking sc to libgmp Steve Carroll <fretwizzer@gmail.com> - 2018-06-26 08:11 -0700

csiph-web