Author Topic: TinyScheme  (Read 63640 times)

0 Members and 3 Guests are viewing this topic.

RobbeK

  • Guest
Re: TinyScheme
« Reply #90 on: September 02, 2014, 10:05:22 AM »
Sure,

;;-----------------------------------------------------------------------------------------------------------

 

(define pi (* 2 (acos 0)))

(define zeta (lambda (lim n acc)
  (if (zero? lim) acc
      (zeta (- lim 1) n (+ acc (/ 1.0 (expt lim n)))))))


(define pi-list (lambda  (n L)
  (if (zero? n) L
      (pi-list (- n 1) (cons (expt pi n) L)))))

(define almost (lambda (x )
  (let (( tst (round x)))
    (if  (< (abs (- x tst)) 0.00001) (round x) 0)
  )))

(define not-zero? (lambda (i maxx L)
  (if (or (= i (- maxx 1) ) (> (car L) 0)) (list i (car L))
      (not-zero? (+ i 1) maxx (cdr L)))))


         
(define (iter x)
     (let ( ( piL (pi-list 20 '() )) (res '() ) (solution 0))
       (do ((i 2 (+ i 1)))
           ((= i x))
         (let (( x (zeta 1000000 i 0)))
           (set! res (map (lambda (y) (/ y x)) piL))
           (set! res (map almost res))
           (set! solution (not-zero? 0 (length res) res ))
           (when (> (cadr solution) 0)
             (display "Zeta ")
             (display i) (display " = (expt pi ")
             (display (+ 1 (car solution)))
             (display ") / ")
             (display (cadr solution))  (newline) ))))
    (display "finished"))


(newline)
(display "Zeta (probing) TinyScheme" ) (newline)
(display "-------------------------" ) (newline)
(newline)
(iter 12)

;;------------------------------------------------------------------------------------------------------------

of course slower than the DrRacket Scheme

best Rob

JRS

  • Guest
Re: TinyScheme
« Reply #91 on: September 02, 2014, 10:39:28 AM »
Thanks Rob!


jrs@laptop:~/sb/sb22/TS$ time tinyscheme zeta.scm

Zeta (probing) TinyScheme
-------------------------

Zeta 2 = (expt pi 2) / 6.0
Zeta 4 = (expt pi 4) / 90.0
Zeta 6 = (expt pi 6) / 945.0
Zeta 8 = (expt pi 8) / 9450.0
Zeta 10 = (expt pi 10) / 93555.0
finished
real   2m39.188s
user   2m38.518s
sys   0m0.520s
jrs@laptop:~/sb/sb22/TS$


Yes. Your compiled version runs significantly faster.
« Last Edit: September 02, 2014, 10:46:51 AM by John »

JRS

  • Guest
Re: TinyScheme
« Reply #92 on: September 02, 2014, 02:40:08 PM »
Rob,

Can you check out the attached TinyScheme compiler/optimizer written in TS and see if it works?
 
Here is another link to a compiler. Scheme to ASM. Written in Scheme like the above. May not work with TinyScheme.

I gave the ur-scheme compiier a try in MIT/GNU Scheme and it seems to work. I loaded the compiler.scm and started typing in Scheme commands and it converted them to ASM on the fly.

Code: ASM
  1.         # (end of standard library prologue)
  2. (quit)
  3.         # get procedure
  4.         push %eax
  5.         movl (_wlist_14), %eax
  6.         # apply procedure
  7.         call ensure_procedure
  8.         movl 4(%eax), %ebx
  9.         movl $0, %edx
  10.         call *%ebx
  11.         pop %eax
  12. (display (+ 2 2))
  13.         push %eax
  14.         movl $1 + 2<<2, %eax
  15.         push %eax
  16.         movl $1 + 2<<2, %eax
  17.         # inlined integer add
  18.         call ensure_integer
  19.         xchg %eax, (%esp)
  20.         call ensure_integer
  21.         pop %ebx
  22.         add %ebx, %eax
  23.         dec %eax
  24.         # get procedure
  25.         push %eax
  26.         movl (_display_2), %eax
  27.         # apply procedure
  28.         call ensure_procedure
  29.         movl 4(%eax), %ebx
  30.         movl $1, %edx
  31.         call *%ebx
  32.         pop %eax
  33.  

Update: I loaded thet compile.scm (ur-scheme compiler) in TinySchment and it processed the compiler code and returning a T (true). It didn't convert commands I typed in like MIT/GNU Scheme but that was a issue mentioned in the docs about TinyScheme. The other cool thing it support 64 bit and doesn't require any external libraries to execute the code. I'm thinking this could be a neat way to create TinyScheme foreign functions. Charles should take a look at this.
 

.
« Last Edit: September 02, 2014, 05:26:20 PM by John »

JRS

  • Guest
Re: TinyScheme
« Reply #93 on: September 02, 2014, 07:06:53 PM »
Here is Ackermann converted to ASM.

Code: [Select]
(define (ack m n)
  (cond ((= m 0) (+ n 1))
        ((= n 0) (ack (- m 1) 1))
        (else (ack (- m 1) (ack m (- n 1))))))

(define (main . args)
  (run-benchmark
    "ack"
    ack-iters
    (lambda (result) (equal? result 4093))
    (lambda (m n) (lambda () (ack m n)))
    3
    9))

        .section .data
_ack_1:
        .long 2 + 256<<2
        .text
        # compute initial value for global variable
        # jump past the body of the lambda
        jmp _ack_2
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_ack_3:
        .long 0xca11ab1e
        .long _ack_4
        .long 0
        .text
        .type _ack_4, @function
_ack_4:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $2, %edx
        jnz argument_count_wrong
        # discarding useless value in %eax
        pop %eax
        # %ifeq
        push %eax
        movl 0(%ebp), %eax
        push %eax
        movl $1 + 0<<2, %eax
        cmpl %eax, (%esp)
        pop %eax
        pop %eax
        jnz _ack_5
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 4(%ebp), %eax
        # inlined integer add
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        pop %ebx
        add %ebx, %eax
        dec %eax
        jmp _ack_6
_ack_5:
        # %ifeq
        push %eax
        movl 4(%ebp), %eax
        push %eax
        movl $1 + 0<<2, %eax
        cmpl %eax, (%esp)
        pop %eax
        pop %eax
        jnz _ack_7
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 0(%ebp), %eax
        # inlined integer subtract
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        sub %eax, (%esp)
        pop %eax
        inc %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
        jmp _ack_8
_ack_7:
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 4(%ebp), %eax
        # inlined integer subtract
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        sub %eax, (%esp)
        pop %eax
        inc %eax
        push %eax
        movl 0(%ebp), %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        call *%ebx
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 0(%ebp), %eax
        # inlined integer subtract
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        sub %eax, (%esp)
        pop %eax
        inc %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
_ack_8:
_ack_6:
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _ack_4, .-_ack_4
_ack_2:
        push %eax
        movl $_ack_3, %eax
        # initialize global variable with value
        movl %eax, (_ack_1)
        pop %eax
        .section .data
_main_1:
        .long 2 + 256<<2
        .text
        # compute initial value for global variable
        # jump past the body of the lambda
        jmp _main_2
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_3:
        .long 0xca11ab1e
        .long _main_4
        .long 0
        .text
        .type _main_4, @function
_main_4:
        # make space for variadic argument list
        pop %ebx
        push %ebx
        push %ebx
        # push desired %esp on return
        lea 8(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        call package_up_variadic_args
        # discarding useless value in %eax
        pop %eax
        push %eax
        movl $1 + 9<<2, %eax
        push %eax
        movl $1 + 3<<2, %eax
        # jump past the body of the lambda
        jmp _main_5
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_6:
        .long 0xca11ab1e
        .long _main_7
        .long 0
        .text
        .type _main_7, @function
_main_7:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $2, %edx
        jnz argument_count_wrong
        # discarding useless value in %eax
        pop %eax
        # move arg from stack to heap: m
        push %eax
        movl 0(%ebp), %eax
        # moving top of stack to newly allocated heap var
        # allocate bytes: 8
        push %eax
        movl (arena_pointer), %eax
        add $8, (arena_pointer)
        cmpl $end_arena, (arena_pointer)
        ja arena_full
        # now %eax points to newly allocated memory
        movl $0x1ce11ed, (%eax)
        pop 4(%eax)
        # move arg from stack to heap: n
        push %eax
        movl 4(%ebp), %eax
        # moving top of stack to newly allocated heap var
        # allocate bytes: 8
        push %eax
        movl (arena_pointer), %eax
        add $8, (arena_pointer)
        cmpl $end_arena, (arena_pointer)
        ja arena_full
        # now %eax points to newly allocated memory
        movl $0x1ce11ed, (%eax)
        pop 4(%eax)
        # jump past the body of the lambda
        jmp _main_8
        .text
        .type _main_9, @function
_main_9:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $0, %edx
        jnz argument_count_wrong
        # fetch artifact from closure: 0 m
        push 12(%eax)
        # fetch artifact from closure: 1 n
        push 16(%eax)
        # discarding useless value in %eax
        pop %eax
        # fetching heap var pointer 1
        push %eax
        movl -20(%ebp), %eax
        # fetch current value from the heap
        movl 4(%eax), %eax
        # fetching heap var pointer 0
        push %eax
        movl -16(%ebp), %eax
        # fetch current value from the heap
        movl 4(%eax), %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_9, .-_main_9
_main_8:
        # allocate bytes: 20
        push %eax
        movl (arena_pointer), %eax
        add $20, (arena_pointer)
        cmpl $end_arena, (arena_pointer)
        ja arena_full
        # now %eax points to newly allocated memory
        movl %eax, %ebx
        movl $0xca11ab1e, (%ebx)
        movl $_main_9, 4(%ebx)
        movl $2, 8(%ebx)
        # fetching heap var pointer 0
        push %eax
        movl -16(%ebp), %eax
        movl %eax, 12(%ebx)
        pop %eax
        # fetching heap var pointer 1
        push %eax
        movl -20(%ebp), %eax
        movl %eax, 16(%ebx)
        pop %eax
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_7, .-_main_7
_main_5:
        push %eax
        movl $_main_6, %eax
        # jump past the body of the lambda
        jmp _main_10
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_11:
        .long 0xca11ab1e
        .long _main_12
        .long 0
        .text
        .type _main_12, @function
_main_12:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $1, %edx
        jnz argument_count_wrong
        # discarding useless value in %eax
        pop %eax
        push %eax
        movl $1 + 4093<<2, %eax
        push %eax
        movl 0(%ebp), %eax
        # get procedure
        push %eax
        movl (_equalP_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_12, .-_main_12
_main_10:
        push %eax
        movl $_main_11, %eax
        push %eax
        movl (_main_13), %eax
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_14:
        .long 0xbabb1e
        .long 3
        .ascii "ack"
        .text
        push %eax
        movl $_main_14, %eax
        # get procedure
        push %eax
        movl (_main_15), %eax
        # apply procedure
        # Tail call; nargs = 6
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 20(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push -8(%ebx)
        push -12(%ebx)
        push -16(%ebx)
        push -20(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $6, %edx
        jmp *%ebx
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_4, .-_main_4
_main_2:
        push %eax
        movl $_main_3, %eax
        # initialize global variable with value
        movl %eax, (_main_1)
        pop %eax

JRS

  • Guest
Re: TinyScheme
« Reply #94 on: September 02, 2014, 09:54:41 PM »
I created a set of TinyScheme test scripts from the urscheme compiler distribution. Attached is the .scm scripts and the Script BASIC script to run them.

Code: Text
  1. jrs@laptop:~/tinyscheme/urscheme-3$ time scriba TS-test.sb > TS-test.out
  2.  
  3. real    0m2.673s
  4. user    0m2.664s
  5. sys     0m0.004s
  6. jrs@laptop:~/tinyscheme/urscheme-3$ ls test.*
  7. test.append.scm          test.cons.scm           test.fib.scm            test.map.scm            test.quadruple.scm      test.string2symbol.scm
  8. test.assq.scm            test.crufty.scm         test.firstclassops.scm  test.memq.scm           test.quote.scm          test.stringappend.scm
  9. test.case.scm            test.definelist.scm     test.funkyid.scm        test.negative.scm       test.quotient.scm       test.stringlength.scm
  10. test.charalpha.scm       test.doubledefine.scm   test.implicitbegin.scm  test.niladic.scm        test.remainder.scm      test.symbol2string.scm
  11. test.charint.scm         test.emptyvariadic.scm  test.lessthan.scm       test.number2string.scm  test.reverse.scm        test.tailcall.scm
  12. test.charwhitespace.scm  test.equal.scm          test.let.scm            test.or.scm             test.set.scm            test.variadic.scm
  13. test.closure.scm         test.eqv.scm            test.list2string.scm    test.out                test.simplestring.scm   test.write.scm
  14. test.cond.scm            test.fib2.scm           test.literalchar.scm    test.predicates.scm     test.string2number.scm
  15.  


.

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #95 on: September 03, 2014, 12:30:04 AM »
Hi John,

This thingy looks very neat and according to the dev's report, it works much faster than its compatibles and it yields significantly denser machine code output.

But it has one very important weakness: it doesn't support floating-point maths, which renders it impractical for everyday use. It needs much more work on the asm side of its engine. LISP language pattern recognition is already there and fixed-point asm translation too but the equivalent floating-point translation blocks remain yet to be developed.

In all other respects, this material is very instructive. Thanks for sharing.

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #96 on: September 03, 2014, 01:22:54 AM »
Quote from: John
compiler.ss.zip (25.82 kB - downloaded 1 times.)

John,

Where are all the other parts of this compiler package? There should be other scripts to match it with:

match.ss
helpers.ss
driver.ss
fmts.pretty
wrapper.ss


and also a tests.ss integrity and regression test script.

This doesn't look like the ur-scheme compiler that you've pointed to in your message. Where does it come from then?

JRS

  • Guest
Re: TinyScheme
« Reply #97 on: September 03, 2014, 05:53:51 AM »
Quote
Where are all the other parts of this compiler package?

Good question! The author only posted the compiler and mentioned the other files weren't included.  :-\

I then moved on to urscheme which seems incomplete on the functionality level. I was able to get the compiler to compile and the first test.append.scm with Chicken Scheme and MIT/GNU Scheme. That is where I left it last night. This is WAY over my head and I'm glad you have shown some interest in this for the Lisp in BASIC projects.


Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #98 on: September 03, 2014, 06:45:20 AM »
This is WAY over my head and I'm glad you have shown some interest in this for the Lisp in BASIC projects.

Hi John,

Nooooo, it's darn simple once you get the feeling of it. It's much simpler than BASIC. It's only half a dozen keywords like car or cdr or let and all the rest of the language can be built right from these ones! :D

So, John, I've suddenly lost all interest in Lisp-in-Basic. It doesn't have to be so complicated at all and I don't want to waste my time on it any more. I can write my own Scheme JIT compiler right away instead. And this is what I'm going to do in the coming few days.

I'll post here the SBLisp proto shortly as promised and I'll also post the FBLisp code as I have it now on the FBSL forum. FBLisp has some enhancements that are making it 30% faster than SBLisp but unfortunately I can't port them to SB, sorry.

And there won't be any OxyLISP from me either because I now consider this approach to be a dead end. I've better things in mind now. :)

Yet the experience has been really entertaining and instructive.

JRS

  • Guest
Re: TinyScheme
« Reply #99 on: September 03, 2014, 07:02:26 AM »
Quote
Yet the experience has been really entertaining and instructive.

That was the whole point of that project. I think we all can say that the time spent was worth the effort. I would of never did the TinyScheme ext. module. if it wasn't for SBLisp.


JRS

  • Guest
TinyScheme Windows 64 w/TSX
« Reply #100 on: September 03, 2014, 05:32:28 PM »
Good News!

I was able to compile the TinySheme.exe and TSX.dll for Windows 64 bit using VC12 (VS2013).

Let me know if you can now see big numbers.

I gave the King's Reward a try but it wouldn't go beyond 32 fields and displayed zeros from then on. Windows sucks! Same results under Wine 64 bit.


jrs@laptop:~/.wine/drive_c/TS/TS64$ file tinyscheme.exe
tinyscheme.exe: PE32+ executable (console) x86-64, for MS Windows
jrs@laptop:~/.wine/drive_c/TS/TS64$ file tsx.dll
tsx.dll: PE32+ executable (DLL) (GUI) x86-64, for MS Windows


Maybe Mike would have better luck. Windows 64 bit is an unpredictable lonely place.

FYI - Here is the official TinyScheme logo.




.
« Last Edit: September 04, 2014, 04:52:03 PM by John »

JRS

  • Guest
Re: TinyScheme
« Reply #101 on: September 04, 2014, 05:45:29 PM »
Can someone confirm there is either a problem with MS 64 bit or TinyScheme compiled under it? Is this strictly a large number multiplication issue or does it go deeper than that?  Call me paranoid but using a 32 bit compiler to compile 64 bit code seems FU.

@Charles - Can you create a Kings Reward in O2 as a 64 bit application and verify Windows 64 bit math works?

JRS

  • Guest
Re: TinyScheme
« Reply #102 on: September 04, 2014, 06:10:32 PM »
I just tested the 64 bit Windows SB version of Kings Reward and it seems to have a similar problem. Must be MS VC12. This same program works fine on Linux to 64 fields.

Code: [Select]
' Kings Reward

grains = 1
PRINT "The reward of the King\n----------------------\n\n"
FOR field = 1 to 64
  PRINT FORMAT("field %g number of grains %d\n", field, grains)
  grains = grains * 2
NEXT

Code: [Select]
C:\sb22_64\TS>scriba king.sb
The reward of the King
----------------------

field 1 number of grains 1
field 2 number of grains 2
field 3 number of grains 4
field 4 number of grains 8
field 5 number of grains 16
field 6 number of grains 32
field 7 number of grains 64
field 8 number of grains 128
field 9 number of grains 256
field 10 number of grains 512
field 11 number of grains 1024
field 12 number of grains 2048
field 13 number of grains 4096
field 14 number of grains 8192
field 15 number of grains 16384
field 16 number of grains 32768
field 17 number of grains 65536
field 18 number of grains 131072
field 19 number of grains 262144
field 20 number of grains 524288
field 21 number of grains 1048576
field 22 number of grains 2097152
field 23 number of grains 4194304
field 24 number of grains 8388608
field 25 number of grains 16777216
field 26 number of grains 33554432
field 27 number of grains 67108864
field 28 number of grains 134217728
field 29 number of grains 268435456
field 30 number of grains 536870912
field 31 number of grains 1073741824
field 32 number of grains -2147483648
field 33 number of grains -2147483648
field 34 number of grains -2147483648
field 35 number of grains -2147483648
field 36 number of grains -2147483648
field 37 number of grains -2147483648
field 38 number of grains -2147483648
field 39 number of grains -2147483648
field 40 number of grains -2147483648
field 41 number of grains -2147483648
field 42 number of grains -2147483648
field 43 number of grains -2147483648
field 44 number of grains -2147483648
field 45 number of grains -2147483648
field 46 number of grains -2147483648
field 47 number of grains -2147483648
field 48 number of grains -2147483648
field 49 number of grains -2147483648
field 50 number of grains -2147483648
field 51 number of grains -2147483648
field 52 number of grains -2147483648
field 53 number of grains -2147483648
field 54 number of grains -2147483648
field 55 number of grains -2147483648
field 56 number of grains -2147483648
field 57 number of grains -2147483648
field 58 number of grains -2147483648
field 59 number of grains -2147483648
field 60 number of grains -2147483648
field 61 number of grains -2147483648
field 62 number of grains -2147483648
field 63 number of grains -2147483648
field 64 number of grains -2147483648

C:\sb22_64\TS>

 
« Last Edit: September 04, 2014, 06:29:56 PM by John »

Charles Pegge

  • Guest
Re: TinyScheme
« Reply #103 on: September 04, 2014, 07:30:22 PM »
Hi John,

The only problem in o2 64 bit is the negative sign in the final result.

This can be resolved by using the extended type

Code: [Select]

% filename "t.exe"

includepath "$/inc/"
include "RTL64.inc"
include "console.inc"

' Kings Reward

sys grains = 1
PRINT "The reward of the King"
FOR field = 1 to 64
  PRINTL "field number of grains " & field & ", " & grains
  grains = grains * 2
NEXT

waitkey

/*
The reward of the King
field number of grains 1, 1
field number of grains 2, 2
field number of grains 3, 4
field number of grains 4, 8
field number of grains 5, 16
field number of grains 6, 32
field number of grains 7, 64
field number of grains 8, 128
field number of grains 9, 256
field number of grains 10, 512
field number of grains 11, 1024
field number of grains 12, 2048
field number of grains 13, 4096
field number of grains 14, 8192
field number of grains 15, 16384
field number of grains 16, 32768
field number of grains 17, 65536
field number of grains 18, 131072
field number of grains 19, 262144
field number of grains 20, 524288
field number of grains 21, 1048576
field number of grains 22, 2097152
field number of grains 23, 4194304
field number of grains 24, 8388608
field number of grains 25, 16777216
field number of grains 26, 33554432
field number of grains 27, 67108864
field number of grains 28, 134217728
field number of grains 29, 268435456
field number of grains 30, 536870912
field number of grains 31, 1073741824
field number of grains 32, 2147483648
field number of grains 33, 4294967296
field number of grains 34, 8589934592
field number of grains 35, 17179869184
field number of grains 36, 34359738368
field number of grains 37, 68719476736
field number of grains 38, 137438953472
field number of grains 39, 274877906944
field number of grains 40, 549755813888
field number of grains 41, 1099511627776
field number of grains 42, 2199023255552
field number of grains 43, 4398046511104
field number of grains 44, 8796093022208
field number of grains 45, 17592186044416
field number of grains 46, 35184372088832
field number of grains 47, 70368744177664
field number of grains 48, 140737488355328
field number of grains 49, 281474976710656
field number of grains 50, 562949953421312
field number of grains 51, 1125899906842624
field number of grains 52, 2251799813685248
field number of grains 53, 4503599627370496
field number of grains 54, 9007199254740992
field number of grains 55, 18014398509481984
field number of grains 56, 36028797018963968
field number of grains 57, 72057594037927936
field number of grains 58, 14411518807585587
field number of grains 59, 28823037615171174
field number of grains 60, 57646075230342349
field number of grains 61, 1.152921504606847E+18
field number of grains 62, 2.305843009213694E+18
field number of grains 63, 4.6116860184273879E+18
field number of grains 64, -9.2233720368547758E+18
*/

JRS

  • Guest
Re: TinyScheme
« Reply #104 on: September 04, 2014, 08:06:47 PM »
I'm on Windows 7 64 at the moment and just tried a TDM-GCC-64 compiled version of SB and it has the same issue. I wonder what a 64 bit C version would do.

I noticed O2 goes exponential expression at 61 fields. SB Linux goes integer to the end.

Code: Script BASIC
  1. a = 100000000000
  2. PRINT "100000000000 = ",a,"\n"
  3.  


C:\sb22_64\TS>scriba bignum.sb
100000000000 = -2147483648

C:\sb22_64\TS>


I even tried to print the HEX of a but got the same results.  :(


@Charles - What do you think SB & TinyScheme issue is?
« Last Edit: September 04, 2014, 10:40:52 PM by John »