Author Topic: TinyScheme  (Read 63646 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Re: TinyScheme
« Reply #105 on: September 04, 2014, 10:42:53 PM »

Does SB use long long?

This, and pointers  are the only 64bit integers, int and long int are 32 bit, under Windows OS's.

There is a table towards the end:
http://en.wikipedia.org/wiki/64-bit_computing

JRS

  • Guest
Re: TinyScheme
« Reply #106 on: September 04, 2014, 11:42:01 PM »
The New Data Types

I'm changing my longs to long64 for the 64 bit Windows version of TinyScheme. If it works there then I will do the same for a custom version of SB.

Update:

Using the above 64 bit MS new types TinyScheme compiled okay. Still the same problem though.

Good-night.


« Last Edit: September 05, 2014, 01:22:28 AM by John »

JRS

  • Guest
Re: TinyScheme
« Reply #107 on: September 05, 2014, 07:59:44 AM »
Mike,

Do you have time to give the TinyScheme library a compile on Windows 64 bit? I'm miffed why this isn't working.

TIA

John

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #108 on: September 05, 2014, 08:02:14 AM »
John,

You should also be aware that there are differences between Windows and Linux' formating placeholders for the C language printf() function used to emulate BASIC's PRINT. For example, the Windows msvcrt.dll which SB is linked against under 32 bits doesn't understand a Linuxoid ll or LL prefix to %d or %u to print a 64-bit signed or unsigned long long integer. So %I64d or %I64u must be used instead of Linuxoid %lld or %llu, respectively.

I am not 100% sure but similar restrictions may apply to integers and floats under 64 bits too. If you don't observe proper formating prefixes in your source code under 32 bits, you will always get a signed value printed where you'd expect its unsigned analog. Perhaps you're seeing a similar side effect but this time under your 64 bits. This needs further investigation.

JRS

  • Guest
Re: TinyScheme
« Reply #109 on: September 05, 2014, 08:08:51 AM »
Good info Mike!

Before I even look at SB's issues on Windows 64 bit, TinySheme is my target at this point. If we can get that working correctly then SB will have a path to follow. Any help you can provide to get us by this, it would be greatly appreciated.

If I remember correctly there were only a couple 64 bit long problems with the SB extension modules but SB core seemed to work out of the box with just compiler switches. (Linux)

John

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #110 on: September 05, 2014, 08:24:40 AM »
The problem I'm talking about concerns the printf() function alone. It doesn't pertain to 64-bit SB being generally compilable under Linux and Windows or not. The differences may be platform specific to the C languages and dynamic libraries used on the respective platform. At any rate, the printf() format is hardcoded in your sources as a string so the compiler wouldn't check or correct it for you automatically. This is your responsibility to give the platform dependent runtime library a proper format string for BASIC's PRINT (or TS' (display), for that matter) to behave as expected on both platforms.

JRS

  • Guest
Re: TinyScheme
« Reply #111 on: September 05, 2014, 08:29:26 AM »
I understand what you're saying now. I'll have another peek at scheme.c for printf() format options.

JRS

  • Guest
Re: TinyScheme
« Reply #112 on: September 05, 2014, 12:25:37 PM »
Success!

I got it to work partially listening to what Charles and Mike suggested.

  • Change all longs to long long.
  • Change all %l to %ll.
That's it. I still need to do the TSX TinyScheme extension DLL but things are looking up. I'll post a beta after a little more testing.

I got some warnings about 64 bit integers being mapped to standard integers and will convert them in the next round and see if it still works.


scheme.c(2691) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data



C:\TS-64>tinyscheme king.scm
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   4294967296
 field 34  number of grains   8589934592
 field 35  number of grains   17179869184
 field 36  number of grains   34359738368
 field 37  number of grains   68719476736
 field 38  number of grains   137438953472
 field 39  number of grains   274877906944
 field 40  number of grains   549755813888
 field 41  number of grains   1099511627776
 field 42  number of grains   2199023255552
 field 43  number of grains   4398046511104
 field 44  number of grains   8796093022208
 field 45  number of grains   17592186044416
 field 46  number of grains   35184372088832
 field 47  number of grains   70368744177664
 field 48  number of grains   140737488355328
 field 49  number of grains   281474976710656
 field 50  number of grains   562949953421312
 field 51  number of grains   1125899906842624
 field 52  number of grains   2251799813685248
 field 53  number of grains   4503599627370496
 field 54  number of grains   9007199254740992
 field 55  number of grains   18014398509481984
 field 56  number of grains   36028797018963968
 field 57  number of grains   72057594037927936
 field 58  number of grains   144115188075855872
 field 59  number of grains   288230376151711744
 field 60  number of grains   576460752303423488
 field 61  number of grains   1152921504606846976
 field 62  number of grains   2305843009213693952
 field 63  number of grains   4611686018427387904
 field 64  number of grains   -9223372036854775808

C:\TS-64>
« Last Edit: September 05, 2014, 12:44:28 PM by John »

JRS

  • Guest
Re: TinyScheme
« Reply #113 on: September 05, 2014, 02:04:20 PM »
Mike,

I have attached the VC12 output from the compile of scheme.c and the source. Can you have a peek and let me know your recommendation for dealing with these warnings?

John

.

JRS

  • Guest
TinyScheme - Windows 64 bit download
« Reply #114 on: September 05, 2014, 02:17:27 PM »
This version passed the King's Reward test but hasn't address warnings yet.

Rob,

Can you start your testing and try working with large numbers beyond the scope of 32 bit?

Thanks!



.
« Last Edit: September 05, 2014, 02:46:21 PM by John »

Charles Pegge

  • Guest
Re: TinyScheme
« Reply #115 on: September 05, 2014, 03:06:50 PM »
Based on examples/math/BCDMul.o2bas

Code: [Select]
'
'================================
'MONSTROUS INTEGER MULTIPLICATION
'================================

'------------------------------------------------------
function multiply(ia as string, ib as string) as string
'======================================================

dim as string a,b,c,d
dim as long pa,pb,pc,pd,la,lb,lc,ld
dim as long nd,sh,qa

a=ia
b=ib
la=len a
lb=len b
lc=la+lb'+10
ld=lc'+20
c=nuls lc 'LINE ACCUMULATOR
d=nuls ld 'BLOCK ACCUMULATOR
pa=*a
pb=*b
pc=*c
pd=*d


pushad



'SETUP POINTERS
'==============

mov esi,pa : add esi,la
mov edi,pb : add edi,lb
mov edx,pc : add edx,lc
mov ebx,pa


mov qa,esi 'RIGHT START POSITION FOR NUMBER A
mov nd,edi 'SETUP NEXT DIGIT POINTER (B NUMBER)
mov sh,edx 'SETUP POSITION SHIFT POINTER



'CONVERT FROM ASCII TO BINARY CODED DECIMAL
'==========================================


mov edi,pa
mov ecx,la
(
 dec ecx
 jl exit
 sub byte [edi],48
 inc edi
 repeat
)
mov edi,pb
mov ecx,lb
(
 dec ecx : jl exit
 sub byte [edi],48
 inc edi
 repeat
)



nextline:
'========

'MULTIPLY BY ONE DIGIT
'WORKING FROM RIGHT TO LEFT

dec edi
mov cl,[edi]
mov ch,0
(
  dec esi
  cmp esi,ebx : jl exit
  mov al,[esi]
  mov ah,0
  mul cl
  add al,ch 'ADD CARRY VALUE
  mov ch,0  'CLEAR CARRY VALUE
  (
    cmp al,10
    jl exit   'NO CARRY
    mov ch,10 'DIVISOR
    div ch    '
    mov ch,al 'CARRY VAL IN CH
    mov al,ah 'REMAINDER NOW IN AL
  )
  dec edx
  mov [edx],al
  repeat
)
'FINAL CARRY
(
  cmp ch,0
  jz exit
  dec edx
  mov [edx],ch
)

'ADD TO BLOCK ACCUMULATOR
'========================

mov esi,pc : add esi,lc
mov edi,pd : add edi,ld
mov ah,0
mov ebx,pc


'BCD ADDITION
'
'WORKING FROM RIGHT TO LEFT

(
  dec esi
  cmp esi,ebx : jl exit
  dec edi
  mov al,0
  xchg al,[esi] 'LOAD AND THEN CLEAR LINE DIGIT
  mov cl,[edi]
  add al,ah 'PREVIOUS CARRY
  add al,cl 'OPERAND
  (
   mov ah,0
   cmp al,10 : jl exit
   sub al,10
   inc ah
  )
  mov [edi],al
  repeat
)


mov ebx,pa

mov esi,qa  'START POSITION FOR NUMBER A

mov edi,nd 'NEXT DIGIT IN NUMBER B
dec edi
mov nd,edi

cmp edi,pb : jle fwd done

'SHIFT OUTPUT TO LINE ACCUM

mov edx,sh
dec edx
mov sh,edx


jmp long nextline



done:



'CONVERT FROM BCD TO ASCII
'=========================


mov edi,pd
mov ecx,ld
add ecx,edi
(
 cmp edi,ecx : jge exit
 add byte [edi],48 : inc edi
 repeat
)



'TRIM LEADING ZEROS
'==================


mov edi,pd
mov ecx,ld
add ecx,edi
(
 cmp edi,ecx : jge exit
 mov al,[edi]
 inc edi
 cmp al,48 : jg exit
 repeat
)
sub edi,pd
mov nd,edi


popad

function=mid(d,nd,ld)

end function


=====
'MAIN
=====


===================

'https://defuse.ca/big-number-calculator.htm

===================

dim as string a,b,ans

a="1"
for i=1 to 10000
a=multiply(a,"2")
next

cr=chr(13,10)
t="2^" i-1 "=" cr a cr
print t
putfile "t.txt",t

===================
 


Result:
Code: [Select]
2^10000=
19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376

JRS

  • Guest
Re: TinyScheme
« Reply #116 on: September 05, 2014, 03:11:23 PM »
Very cool Charles.

I remember you doing something in BCD math for the MD5 / SP Pro time function in SB. I may have another peek at that code after the above example.  8)

JRS

  • Guest
Re: TinyScheme
« Reply #117 on: September 05, 2014, 05:51:48 PM »
I found another Scheme tutorial that might be helpful to Lisp newbies like me.

The Scheme Programming Language (Book Online)

JRS

  • Guest
Re: TinyScheme
« Reply #118 on: September 05, 2014, 10:39:48 PM »
Charles / Mike,

I'm trying to understand these warning messages of downgrading my integers. I wonder did I get long long happy and screw up everything else? The following is a good example of a C function creating a mismatch of types.

Code: C
  1. static num num_mod(num a, num b) {
  2.  num ret;
  3.  long e1, e2, res;
  4.  ret.is_fixnum=a.is_fixnum && b.is_fixnum;
  5.  e1=num_ivalue(a);
  6.  e2=num_ivalue(b);
  7.  res=e1%e2;
  8.  /* modulo should have same sign as second operand */
  9.  if (res * e2 < 0) {
  10.     res += e2;
  11.  }
  12.  ret.value.ivalue=res;
  13.  return ret;
  14. }
  15.  

Making e1, e2, res a long long makes res complain of a type mismatch. I can't seem to get around this.


RobbeK

  • Guest
Re: TinyScheme
« Reply #119 on: September 06, 2014, 12:47:08 AM »
Hi John,

And the idea to embed NewLisp ??     (there're libs for Linux and Mac too )

"newLISP is a Lisp-like, general-purpose scripting language. It is especially well-suited for applications in AI, simulation, natural language processing, big data, machine learning and statistics. Because of its small resource requirements, newLISP is excellent for embedded systems applications. Most of the functions you will ever need are already built in. This includes networking functions, support for distributed and multicore processing, and Bayesian statistics."

Attached , I embedded it into GFA (the German IBM which went down around a decade ago -- the compiler is abandonware for the moment (seems, no one claims it).   -- ( a good compiler, producing native code , and allows in-line assembler)  - it has no big numbers , but here they are borrowed from NewLisp.

(for fun : the 128 x does 2 chess boards)
source is in the html file

best Rob


.
« Last Edit: September 06, 2014, 02:35:42 AM by RobbeK »