Author Topic: TinyScheme  (Read 63644 times)

0 Members and 4 Guests are viewing this topic.

JRS

  • Guest
Re: TinyScheme
« Reply #135 on: September 06, 2014, 03:02:03 PM »
If you compiled with no changes to scheme.c, you will not have 64 bit range.

See my example changing long to long long and the fprint %ll change. I had a bunch of warnings saying that integers were truncated but it worked.


JRS

  • Guest
Re: TinyScheme
« Reply #136 on: September 06, 2014, 03:07:48 PM »
Rob,

newLisp looks interesting up to the point of being 32 bit across the board. They need to run on 64 bit before I will spend any time with it.


Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #137 on: September 06, 2014, 03:17:06 PM »
If you compiled with no changes to scheme.c, you will not have 64 bit range.

See my example changing long to long long and the fprint %ll change. I had a bunch of warnings saying that integers were truncated but it worked.

Ok,

So I'm a fool, a spado, and a liar.

Well well...

.

JRS

  • Guest
Re: TinyScheme
« Reply #138 on: September 06, 2014, 04:24:59 PM »
Mike,

The reason Rob added the .01 so 32 bit wouldn't overflow. Use this code in your tests.

Code: [Select]
(define (grains x)
   (let loop ((i 1) (j 1))
     (display " field ") (display i)
     (display "  number of grains   ")(display j)  (newline)
     (when (< i x) (loop (+ i 1) (* 2 j) )))) ; 'when' is an alias to 'if'
     
(define (main)
   (display "The reward of the King") (newline)
   (display "----------------------") (newline)
   (newline)
   (grains 64))
(main)
(newline)
(quit)

How it should look.


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>


Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #139 on: September 06, 2014, 06:25:09 PM »
Understood -- you want 64-bit integer math bitness. Then your last number isn't a mistake. That's a hex

F3 33 33 33   33 33 33 34

that causes a negative sign in a long long. To see it positive in TS, you'll have to have either unsigned long long or 128-bit integer calc altogether which aren't there by original design and platform implementation, respectively.

So all you wanna do is get rid of compiler warnings? Then 3 files have to be fixed -- scheme.c, scheme.h, and scheme-private.h. There are only a couple of printf() formats to fix but there are also a lot of function and variable redefinitions dependent on ivalue that now have to become long long int's (or rather __int64's, in VC parlance). Can do it for you tomorrow if you like.

.
« Last Edit: September 06, 2014, 08:58:21 PM by Mike Lobanovsky »

JRS

  • Guest
Re: TinyScheme
« Reply #140 on: September 06, 2014, 06:49:49 PM »
That would be great Mike. I'm sure Rob will applicate the effort as well.

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #141 on: September 06, 2014, 08:55:22 PM »
Rob doesn't use 64 bits, John.

Anyway, here's the 64-bit solution with the sources fixed. I don't guarantee 100% quality but all warnings have been cleared, not suppressed, but eliminated by redeclaration.  Please test.

.

JRS

  • Guest
Re: TinyScheme
« Reply #142 on: September 06, 2014, 09:13:13 PM »
Looks good Mike. Here is the results of the recompile using msvcbuild.bat.

Code: Text
  1. C:\TS64\TS_VC_64\src>msvcbuild.bat
  2.  
  3. C:\TS64\TS_VC_64\src>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /MT scheme.c dy
  4. nload.c
  5. scheme.c
  6. dynload.c
  7. Generating Code...
  8.  
  9. C:\TS64\TS_VC_64\src>link /nologo /out:tinyscheme.exe scheme.obj dynload.obj
  10.    Creating library tinyscheme.lib and object tinyscheme.exp
  11.  
  12. C:\TS64\TS_VC_64\src>tinyscheme.exe mk_init_scm.scm
  13.  
  14. C:\TS64\TS_VC_64\src>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /DUSE_EMB_INIT=1 /MT scheme.c dynload.c
  15. scheme.c
  16. dynload.c
  17. Generating Code...
  18.  
  19. C:\TS64\TS_VC_64\src>link /nologo /out:bin\tinyscheme.exe scheme.obj dynload.obj
  20.    Creating library bin\tinyscheme.lib and object bin\tinyscheme.exp
  21.  
  22. C:\TS64\TS_VC_64\src>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /DUSE_EMB_INIT=1 /MDd scheme.c dynload.c
  23. scheme.c
  24. dynload.c
  25. Generating Code...
  26.  
  27. C:\TS64\TS_VC_64\src>link /nologo /out:bin\tinyscheme_d.exe scheme.obj dynload.obj
  28.    Creating library bin\tinyscheme_d.lib and object bin\tinyscheme_d.exp
  29.  
  30. C:\TS64\TS_VC_64\src>del scheme.obj dynload.obj tinyscheme.* init_scm.h
  31.  
  32. C:\TS64\TS_VC_64\src>
  33.  

I think Rob is running Windows 7 64 bit. (not positive)  Prior examples he posted tend to make me think he is 64 bit aware. I don't think it is about not wanting to used a 64 bit version of TS but nothing was available on that platform. newLisp is 32 bit only. (Linux as well)

Thanks again for this effort. I would like to get the TSX (TinyScheme Extensions) working if all possible. Can you send me a guide of changes you made to TS so I fix TSX?


JRS

  • Guest
Re: TinyScheme
« Reply #143 on: September 06, 2014, 10:06:44 PM »
I was able to compile newLisp for Linux 64 bit.

newLISP® v.10.6.0 Development Release Notes


jrs@laptop:~/NewLisp/newlisp-10.6.0$ ./newlisp
newLISP v.10.6.0 64-bit on Linux IPv4/6, options: newlisp -h

> (+ 2 2)
4
> (exit)
jrs@laptop:~/NewLisp/newlisp-10.6.0$ ./newlisp -h

newLISP v.10.6.0 Copyright (c) 2014 Lutz Mueller. All rights reserved.

usage: newlisp [file | url ...] [options ...] [file | url ...]

options:

 -h this help
 -n no init.lsp (must be first)
 -x <source> <target> link
 -v version
 -s <stacksize>
 -m <max-mem-MB> cell memory
 -e <quoted lisp expression>
 -l <path-file> log connections
 -L <path-file> log all
 -w <working dir>
 -c no prompts, net-eval, HTTP
 -C force prompts
 -t <usec-server-timeout>
 -p <port-no>
 -d <port-no> daemon mode
 -http only mode
 -6 IPv6 mode

more info at http://newlisp.org

jrs@laptop:~/NewLisp/newlisp-10.6.0$

« Last Edit: September 06, 2014, 10:43:56 PM by John »

RobbeK

  • Guest
Re: TinyScheme
« Reply #144 on: September 07, 2014, 01:31:27 AM »
It is important to find your way through the labyrint of Lisp numbers --
Both Scheme R5RS ( and > ) and Common Lisp should be "full numeric tower" , however most of the Schemes are not (p.e; BigLoo, Chicken , Stalin aren't (and many more ).

so :   (let ( (a 1) (b 1.0))    ) means a is integer and b a floating point number

in CL the integer can be a bignumber ; to force it into a regular integer (for reason of speed ) , one can say in CL
(declare (type fixnum a)  (type real b) )  -- also forcing b into a real number and not a complex number.

both languages should have fractions  (/ 4)  means 1/4  , to convert it (in CL) use (float (/ 4)) -> 0.25  in Scheme one does
(exact->inexact (/ 4)) -> 0.25

Furthermore the "top" schemes have fx* , fx+, fx- etc...  iirc they are calle monodiadic ???  operators ? , they are restricted to two arguments ...   (once again to gain higher execution speed of the code)

NewLisp
----------
uses separate operators   + , - , * , / for integers and big numbers  and  add , sub , mul , div for floats or forcing into floats.
(be careful for (inc ) and (++ ) etc , too.
The bignumbers are invoked by adding an L at the tail   0L is a bignumber thus.

(+ 1 0L) makes 1L (look in the documentation for the correct operators   p.e.   (gcd  ) does not work on big numbers;

etc etc ...

best Rob   (some things may be very application specific )
-- running everything in 32 bit ----   (sadly)

John, glad to read you could compile it ,  imho NewLISP is au pair with languages as Perl and Python -- http://www.newlisp.org/CodePatterns.html   -- the FFI is superb , for string and integer arguments and results , you even do not have to declare those , it is possible to set up structures in Lisp, reading C structs .... etc ...

Hi, Mike ...  Aero ,  8)   ok -- unaware once again -- for myself the antique look of Japi is not important , probably for many others it is  ::)
« Last Edit: September 07, 2014, 06:41:21 AM by RobbeK »

JRS

  • Guest
Re: TinyScheme
« Reply #145 on: September 07, 2014, 07:11:02 AM »
Quote
-- running everything in 32 bit ----   (sadly)

Are you saying you only have a 32 bit PC or are you saying you prefer 32 bit Lisp languages?

Quote
John, glad to read you could compile it ,  imho NewLISP is au pair with languages as Perl and Python --


I found a distribution of newLISP that had multiple makefile(s) for different platforms. Unfortunately there was only a 32 bit Windows solution.

I still need to get the TSX extension working on Win64 and fix SB. Taking on a newLISP isn't practical for me at the moment.  :-\
« Last Edit: September 07, 2014, 07:37:43 AM by John »

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #146 on: September 07, 2014, 09:03:44 AM »
Hi John,

No, what I'm seeing in your BAT file report isn't good at all. That's why I said "use the solution; your bat file is too simplistic". If the cl that you're using is a VC12 from VS2013 then what it currently generates is a 32-bit debug-mode console application linked against the MSVCR120.DLL runtime, albeit with 64-bit integer calc. This DLL may or may not be installed on the user PC.

All your source files must be cl-ed with a /MT switch. This links them with a static runtime library as opposed to /MD which is the above DLL or /MDd which is its debug-mode counterpart.

Then if you're concerned about the size of the resultant exe then you should use the /O1 switch (optimize for size) rather than /O2 (optimize for speed) which would add extra 30KB or so.

Lastly, all your object files must be link-ed with a /MACHINE:X64 switch to generate a 64-bit executable. If omitted, a 32-bit binary is generated. I would also recommend adding an explicit /SUBSYSTEM:CONSOLE switch here to preclude any unwisely assumptions on behalf of the linker.

As for the other parts of the project, all their structures and functions that are communicating with TS directly or via memory calls should be aware that TS' ivalue and len parameters and their  dependencies are now defined as __int64 rather than int or long, and all rvalue and its dependencies are defined as long double rather than double. The latter doesn't make much difference for Windows where both doubles and long doubles are 8-byte quantities, but it may make a difference in Linux where long doubles are 12 bytes in size IIRC.

So look through my fixes searching for __int64 and long double and make sure all functions and structures in the other parts of the projects are redefined accordingly. This may require a lot of trial and error in real time.


JRS

  • Guest
Re: TinyScheme
« Reply #147 on: September 07, 2014, 09:23:52 AM »
Mike,

I'm using VS 2013 and selected the 64 bit VC12 console compiler from the tools short cuts. What do you mean by use the solution? The solution provided by the project is the msvcbuild.bat which assumes you selected the correct CL for the job.

I will do a DIFF of your changes to scheme.c and the supporting files and carry them forward with the TSX module that has its own msvcbuild.bat.

John

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #148 on: September 07, 2014, 09:36:19 AM »
A solution is the MS Visual Studio's .sln file which unites one or more interdependent VC projects into a common workspace. Double clicking on it under Windows will spawn your VS2013 with the TS sources opened and project settings adjusted exactly as I set them. You can inspect them in the Project->Properties... dialog (see C/C++->Command Line and Linker->Comand Line sections) and you can also rebuild the project or the entire solution via the respective Build->Rebuild menu items.

This is how enlightened programmers usually work under Windows these days. Leave comman-line .bat and makefiles to stray Linux visitors.

:)

JRS

  • Guest
Re: TinyScheme
« Reply #149 on: September 07, 2014, 09:50:05 AM »
Unfortunately SB is a command line build system that supports multiple platforms. I'm willing to use more modern tools on Windows for extension libraries but that's it. SB is built from scratch from C files. (headers, syntax tables, docs, ...) Peter Verhas did an amazing job 12 years ago with his build system.