Author Topic: Gauche Scheme  (Read 15365 times)

0 Members and 3 Guests are viewing this topic.

JRS

  • Guest
Re: Gauche Scheme
« Reply #15 on: January 23, 2015, 08:52:10 AM »
Thanks Rob for the Gauche update. I'm glad you're having so much fun.  :)

RobbeK

  • Guest
Re: Gauche Scheme
« Reply #16 on: January 27, 2015, 07:12:30 AM »
OK , some Gauche then ...  1st code ..  (2D skeleton, stolen from the examples  ;)

a test, iteration and recursion seem to run at the same speed

(use gl)
(use gl.glut)

(define (init)
  (gl-clear-color 0.0 0.0 0.0 0.0)
  (gl-shade-model GL_SMOOTH))

(define (sq x) (* x x))

(define (julia x y rc ic maxiter it orb)     ;;   recursion
  (if (or (= it maxiter) (> orb 4.0)) it
    (julia (+ (- (sq x) (sq y)) rc) (+ ic (* 2.0 x y)) rc ic maxiter (+ it 1) (abs (* y x)) )
))

(define (julia-it x y rc ic maxiter)            ;; iteration
  (let (( it 0) (orb 0) (tmp 0) )
    (while (and (< it maxiter) (< orb 4.0))
      (set! tmp x)
      (set! x (+ rc (- (sq x) (sq y))))
      (set! y (+ ic (* 2.0 tmp y)))
      (inc! it)
      (set! orb (abs (* x y))) )
 it ))

(define (fractal)
 
  (gl-begin GL_POINTS)
   (do ((i -2.5 (+ i 0.008)))
       ((> i 1.5))
    (do ((j -2.0 (+ j 0.008)))
        ((> j 2.0))
  (let ((k (/ (julia i j i j 16 0 0.0) 16.0)))
   (gl-color  0.0 k 0.0)
    )
   (gl-vertex  i j) ))
   (gl-end))

(define (disp)
  (gl-clear GL_COLOR_BUFFER_BIT)
  (fractal)
  (gl-flush)
  )

(define (reshape w h)
  (gl-viewport 0 0 w h)
  (gl-matrix-mode GL_PROJECTION)
  (gl-load-identity)
      (glu-ortho-2d -2.5 1.5 -2.0 2.0)
  (gl-matrix-mode GL_MODELVIEW)
  )

(define (keyboard key x y)
  (when (= key 27) (exit 0)))

(define (main args)
  (glut-init args)
  (glut-init-display-mode (logior GLUT_SINGLE GLUT_RGB))
  (glut-init-window-size 500 500)
  (glut-init-window-position 100 100)
  (glut-create-window "JULIA - MANDELBROT")
  (init)
  (gl-clear GL_COLOR_BUFFER_BIT)
  (gl-flush)
  (glut-display-func disp)
  (glut-reshape-func reshape)
  (glut-keyboard-func keyboard)
   
  (glut-main-loop)
  0)

both scripts attached

best Rob  (surface about 3x bigger than what came with the examples)

(jullia x y x y ....  ) is identical with a (mandelbrot x y ...... )
this formula does both   p.e.   (julia x y 0.0 -1.0  ....   ) is the dendrithe (?not correct anglais i think)

.
« Last Edit: January 27, 2015, 07:27:13 AM by RobbeK »

JRS

  • Guest
Re: Gauche Scheme
« Reply #17 on: January 27, 2015, 09:11:15 AM »
Thanks Rob!

You're right. I can't see any difference between the iteration and recursion versions.

Either way it's FAST.

Note: My tests are running on Ubuntu in true 64 bit while Rob is running on a 32 bit version of Linux.



.
« Last Edit: January 27, 2015, 08:39:18 PM by John »

RobbeK

  • Guest
Re: Gauche Scheme
« Reply #18 on: January 27, 2015, 11:28:44 AM »
Hi John,

Can even be sped up  ..
An advantage of lisp (in general) is that one does not need to set up UDT's to return composite values of functions ,  changed the code a little and the Julia (recursive ) gives back a list with both the orbit value and the number of iterations , here the orbit is used for the greens .

(julia .... )    ->  (list it orb)    ::   car -> iteration escape level   ::   cadr -> orbit escape level.

the knowledge about the performance of recursion is important (to me), because very often math. formulae are easier expressed by recursion , program flow certainly not  ;)

best Rob

 addendum : added fastMandel2.scm   calculates the orbit the classic way by its distance to (0,0) (infact it does the square of the distance ::: x²+y²  -- the speed is remarkable for a scripting language (imho)

.
« Last Edit: January 27, 2015, 12:21:59 PM by RobbeK »

JRS

  • Guest
Re: Gauche Scheme
« Reply #19 on: January 27, 2015, 01:04:53 PM »
Quote
the speed is remarkable for a scripting language

The difference between an interpreter and compiler in many cases is you don't have to look at ugly with the interpreter.   :o
« Last Edit: January 27, 2015, 02:06:19 PM by John »

JRS

  • Guest
Re: Gauche Scheme
« Reply #20 on: January 27, 2015, 04:32:23 PM »
Very Nice!

It displayed instantly here so I can't see what a compiler brings to the table.

Code: Scheme
  1. (use gl)
  2. (use gl.glut)
  3.  
  4. (define (init)
  5.   (gl-clear-color 0.0 0.0 0.0 0.0)
  6.   (gl-shade-model GL_SMOOTH))
  7.  
  8. (define (sq x) (* x x))
  9.  
  10. (define (julia x y rc ic maxiter it orb)
  11.   (if (or (= it maxiter) (> orb 4.0)) (list it orb)
  12.     (julia (+ (- (sq x) (sq y)) rc) (+ ic (* 2.0 x y)) rc ic maxiter (+ it 1) (+ (sq x) (sq y)) )
  13. ))
  14.  
  15. (define (julia-it x y rc ic maxiter)
  16.   (let (( it 0) (orb 0) (tmp 0) )
  17.     (while (and (< it maxiter) (< orb 4.0))
  18.       (set! tmp x)
  19.       (set! x (+ rc (- (sq x) (sq y))))
  20.       (set! y (+ ic (* 2.0 tmp y)))
  21.       (inc! it)
  22.       (set! orb (abs (* x y))) )
  23.  it ))
  24.  
  25. (define (fractal)
  26.  
  27.   (gl-begin GL_POINTS)
  28.    (do ((i -2.5 (+ i 0.008)))
  29.        ((> i 1.5))
  30.     (do ((j -2.0 (+ j 0.008)))
  31.         ((> j 0.0))
  32.   (let* ((info (julia i j i j 17 0 0.0))
  33.          (k (/ (car info) 17.0))
  34.          (orb (cadr info)  ))
  35.  
  36.    (gl-color  (sq k) (/ 1.8 orb) 0.1)
  37.     )
  38.    (gl-vertex  i j)
  39.    (gl-vertex i (- (abs j) 0.008)  )))
  40.    (gl-end))
  41.  
  42.  
  43. (define (disp)
  44.   (gl-clear GL_COLOR_BUFFER_BIT)
  45.   (fractal)
  46.   (gl-flush)
  47.   )
  48.  
  49. (define (reshape w h)
  50.   (gl-viewport 0 0 w h)
  51.   (gl-matrix-mode GL_PROJECTION)
  52.   (gl-load-identity)
  53.       (glu-ortho-2d -2.5 1.5 -2.0 2.0)
  54.   (gl-matrix-mode GL_MODELVIEW)
  55.   )
  56.  
  57. (define (keyboard key x y)
  58.   (when (= key 27) (exit 0)))
  59.  
  60. (define (main args)
  61.   (glut-init args)
  62.   (glut-init-display-mode (logior GLUT_SINGLE GLUT_RGB))
  63.   (glut-init-window-size 500 500)
  64.   (glut-init-window-position 100 100)
  65.   (glut-create-window "JULIA - MANDELBROT")
  66.   (init)
  67.   (gl-clear GL_COLOR_BUFFER_BIT)
  68.   (gl-flush)
  69.   (glut-display-func disp)
  70.   (glut-reshape-func reshape)
  71.   (glut-keyboard-func keyboard)
  72.    
  73.   (glut-main-loop)
  74.   0)
  75.  

.
« Last Edit: January 27, 2015, 08:39:35 PM by John »

Mike Lobanovsky

  • Guest
Re: Gauche Scheme
« Reply #21 on: January 27, 2015, 07:30:17 PM »
Hi Rob,



The uglyest looking Mandelbrot presentation I ever saw. All made up of taste buds on the tongue of a little green alien.





Some light at the end of the tunnel.




 ;D

RobbeK

  • Guest
Re: Gauche Scheme
« Reply #22 on: January 28, 2015, 06:22:25 AM »
Hi John, Mike

the ugliest , yep , quickly changed into the tunnel view  ;)

Tested the complex numbers now :  working with complex numbers always slows down things - but writing a complex 4th degree function in x, y takes some time on paper (while not difficult).   (see attachment , also including Sin(z²) )   speed is still very good.
The whole Mandelbrot/Julia simplifies into

(define (juliaC z c maxiter it orb)
   (if (or (= it maxiter) (> orb 4.0)) (list it orb)
     (juliaC (+  (* z z)  c) c maxiter (+ it 1) (abs (* z z)))))


Tk/Tcl is working too now -- just (John) do you find any info on any kind of  FFI  ??  (there are some texts in Japanese , but ;..)

best Rob

.
« Last Edit: January 28, 2015, 06:43:31 AM by RobbeK »

JRS

  • Guest
Re: Gauche Scheme
« Reply #23 on: January 28, 2015, 09:58:55 AM »
Hi Rob,

Can you try this FFI extension for Gauche?

c-wrapper - A Generic Wrapper for C Libraries

Let me know how it goes.

JRS

  • Guest
Re: Gauche Scheme
« Reply #24 on: January 28, 2015, 01:06:02 PM »
The c-wrapper library compiled for me and was able to run the Breakout SDL example.

Code: Scheme
  1. ;; -*- coding: utf-8; mode: scheme -*-
  2. ;;
  3. ;; breakout.scm - Breakout
  4. ;;
  5. ;;   Copyright (c) 2007 KOGURO, Naoki (naoki@koguro.net)
  6. ;;   All rights reserved.
  7. ;;
  8. ;;   Redistribution and use in source and binary forms, with or without
  9. ;;   modification, are permitted provided that the following conditions
  10. ;;   are met:
  11. ;;
  12. ;;   1. Redistributions of source code must retain the above copyright
  13. ;;      notice, this list of conditions and the following disclaimer.
  14. ;;   2. Redistributions in binary form must reproduce the above copyright
  15. ;;      notice, this list of conditions and the following disclaimer in the
  16. ;;      documentation and/or other materials provided with the distribution.
  17. ;;   3. Neither the name of the authors nor the names of its contributors
  18. ;;      may be used to endorse or promote products derived from this
  19. ;;      software without specific prior written permission.
  20. ;;
  21. ;;   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. ;;   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. ;;   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. ;;   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. ;;   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. ;;   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  27. ;;   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. ;;   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. ;;   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. ;;   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. ;;   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ;;
  33. ;;   $Id: $
  34. ;;
  35.  
  36. (use c-wrapper)
  37. (use srfi-1)
  38. (use srfi-27)
  39.  
  40. (c-load '("SDL.h" "SDL_mixer.h" "stdio.h" "stdlib.h" "sdl_helper.c")
  41.         :cppflags-cmd "sdl-config --cflags"
  42.         :libs-cmd "sdl-config --libs; echo '-lSDL_mixer'"
  43.         :import (list (lambda (header sym)
  44.                         (#/\/SDL\/.*\.h$/ header))
  45.                       'NULL
  46.                       'run_sdl_main)
  47.         :compiled-lib "sdllib")
  48.  
  49. (define *screen* #f)
  50. (define-constant *screen-width* 640)
  51. (define-constant *screen-height* 480)
  52. (define-constant *screen-depth* 8)
  53. (define *unit* 8)
  54.  
  55. (define *ball-rect* #f)
  56. ;; vx and vy must be a multiple of *unit*.
  57. (define *ball-vx* 0)
  58. (define *ball-vy* 0)
  59. (define *ball-count* 0)
  60. (define-constant *ball-size* *unit*)
  61.  
  62. (define *paddle-rect* #f)
  63. (define *paddle-width* (* 8 *unit*))
  64. (define *paddle-vx* 0)
  65.  
  66. (define *block-list* '())
  67. (define *block-start-x* 0)
  68. (define *block-start-y* 0)
  69. (define *block-end-x* 0)
  70. (define *block-end-y* 0)
  71.  
  72. (define-constant *block-width* (* 6 *unit*))
  73. (define-constant *block-height* (* 3 *unit*))
  74.  
  75. (define *tick* 0)
  76. (define *tick-threshold* 20)
  77.  
  78. (define *bounce-sound* #f)
  79. (define *shoot-sound* #f)
  80.  
  81. (define (init)
  82.   (SDL_Init (logior SDL_INIT_VIDEO SDL_INIT_AUDIO))
  83.   (set! *screen* (SDL_SetVideoMode *screen-width* *screen-height*
  84.                                    *screen-depth*
  85.                                    (logior SDL_HWSURFACE
  86.                                            SDL_DOUBLEBUF)))
  87.   (SDL_WM_SetCaption "Breakout" NULL)
  88.   (set! *paddle-rect* (make <SDL_Rect>))
  89.   (set! (ref *paddle-rect* 'w) *paddle-width*)
  90.   (set! (ref *paddle-rect* 'h) *unit*)
  91.  
  92.   (Mix_OpenAudio 44100 AUDIO_S16SYS 2 1024)
  93.   (set! *bounce-sound* (Mix_LoadWAV "cursor5.wav"))
  94.   (set! *shoot-sound* (Mix_LoadWAV "cursor6.wav"))
  95.   (init-game))
  96.  
  97. (define (init-game)
  98.   (set! (ref *paddle-rect* 'x) (- (/ *screen-width* 2)
  99.                                   (/ (ref *paddle-rect* 'w) 2)))
  100.   (set! (ref *paddle-rect* 'y) (- *screen-height* (* 3 *unit*)))
  101.   (set! *ball-count* 2)
  102.   (make-blocks))
  103.  
  104. (define (make-block x y color)
  105.   (let ((rect (make <SDL_Rect>)))
  106.     (set! (ref rect 'x) (+ x 1))
  107.     (set! (ref rect 'y) (+ y 1))
  108.     (set! (ref rect 'w) (- *block-width* 2))
  109.     (set! (ref rect 'h) (- *block-height* 2))
  110.   (vector (list x y (+ x *block-width*) (+ y *block-height*))
  111.           rect
  112.           color)))
  113.  
  114. (define (block-vertical-reflect? block x y vx)
  115.   (receive (sx sy ex ey) (apply values (vector-ref block 0))
  116.     (and (<= sy y ey)
  117.          (or (and (= x sx) (< 0 vx))
  118.              (and (= x ex) (< vx 0))))))
  119.  
  120. (define (block-horizontal-reflect? block x y vy)
  121.   (receive (sx sy ex ey) (apply values (vector-ref block 0))
  122.     (and (<= sx x ex)
  123.          (or (and (= y sy) (< 0 vy))
  124.              (and (= y ey) (< vy 0))))))
  125.  
  126. (define (block-hit? block x y)
  127.   (receive (sx sy ex ey) (apply values (vector-ref block 0))
  128.     (and (<= sx x ex) (<= sy y ey))))
  129.  
  130. (define (make-blocks)
  131.   (do ((block-list '())
  132.        (level 0 (+ level 1))
  133.        (colors '(#o700 #o770 #o373 #o077 #o007) (cdr colors))
  134.        (y (* 7 *unit*) (+ y *block-height*)))
  135.       ((<= 5 level)
  136.        (set! *block-list* block-list))
  137.     (do ((x (* 1 *unit*) (+ x *block-width*)))
  138.         ((<= *screen-width* (+ x *block-width*)))
  139.       (push! block-list (make-block x y (car colors)))))
  140.   (set! *block-start-x* *screen-width*)
  141.   (set! *block-start-y* *screen-height*)
  142.   (set! *block-end-x* 0)
  143.   (set! *block-end-y* 0)
  144.   (for-each (lambda (block)
  145.               (receive (sx sy ex ey) (apply values (vector-ref block 0))
  146.                 (when (< sx *block-start-x*)
  147.                   (set! *block-start-x* sx))
  148.                 (when (< sy *block-start-y*)
  149.                   (set! *block-start-y* sy))
  150.                 (when (< *block-end-x* ex)
  151.                   (set! *block-end-x* ex))
  152.                 (when (< *block-end-y* ey)
  153.                   (set! *block-end-y* ey))))
  154.             *block-list*))
  155.                
  156. (define (teardown)
  157.   (Mix_CloseAudio)
  158.   (SDL_Quit))
  159.  
  160. (define clear-screen
  161.   (let ((rect (make <SDL_Rect>)))
  162.     (set! (ref rect 'x) 0)
  163.     (set! (ref rect 'y) 0)
  164.     (set! (ref rect 'w) *screen-width*)
  165.     (set! (ref rect 'h) *screen-height*)
  166.     (lambda ()
  167.       (SDL_FillRect *screen* (ptr rect) 0))))
  168.  
  169. (define (draw-paddle)
  170.   (SDL_FillRect *screen* (ptr *paddle-rect* ) #o777))
  171.  
  172. (define (move-paddle-left)
  173.   (set! *paddle-vx* (- *unit*)))
  174.  
  175. (define (move-paddle-right)
  176.   (set! *paddle-vx* *unit*))
  177.  
  178. (define (move-paddle)
  179.   (let ((new-x (+ (ref *paddle-rect* 'x) *paddle-vx*))
  180.         (w (ref *paddle-rect* 'w)))
  181.     (when (< new-x 0)
  182.       (set! new-x 0))
  183.     (when (< (- *screen-width* w) new-x)
  184.       (set! new-x (- *screen-width* w)))
  185.     (set! (ref *paddle-rect* 'x) new-x)))
  186.  
  187. (define (stop-paddle)
  188.   (set! *paddle-vx* 0))
  189.  
  190. (define (draw-ball)
  191.   (when *ball-rect*
  192.     (SDL_FillRect *screen* (ptr *ball-rect*) #o777)))
  193.  
  194. (define (move-ball)
  195.   (let ((reflect? #f))
  196.     (define (reflect-x)
  197.       (set! *ball-vx* (- *ball-vx*))
  198.       (set! reflect? #t))
  199.     (define (reflect-y)
  200.       (set! *ball-vy* (- *ball-vy*))
  201.       (set! reflect? #t))
  202.     (when *ball-rect*
  203.       (let ((new-x (+ (ref *ball-rect* 'x) *ball-vx*))
  204.             (new-y (+ (ref *ball-rect* 'y) *ball-vy*))
  205.             (paddle-x (ref *paddle-rect* 'x))
  206.             (paddle-y (ref *paddle-rect* 'y))
  207.             (paddle-w (ref *paddle-rect* 'w))
  208.           (paddle-h (ref *paddle-rect* 'h))
  209.           (w (ref *ball-rect* 'w))
  210.           (h (ref *ball-rect* 'h)))
  211.         (when (< new-x 0)
  212.           (reflect-x)
  213.           (set! new-x (- new-x)))
  214.         (when (< (- *screen-width* w) new-x)
  215.           (reflect-x)
  216.           (set! new-x (- (* 2 (- *screen-width* w)) new-x)))
  217.         (when (< new-y 0)
  218.           (reflect-y)
  219.           (set! new-y 0))
  220.         (when (and (<= paddle-y new-y (+ paddle-y paddle-h))
  221.                    (<= paddle-x new-x (+ paddle-x paddle-w)))
  222.           (reflect-y)
  223.           (when (or (and (= paddle-x new-x)
  224.                          (< 0 *ball-vx*))
  225.                     (and (= (+ paddle-x paddle-w (- *unit*)) new-x)
  226.                          (< *ball-vx* 0)))
  227.             (reflect-x))
  228.           (set! new-y (- paddle-y h)))
  229.         (when (< (- *screen-height* h) new-y)
  230.           (dec! *ball-count*)
  231.           (set! *ball-rect* #f))
  232.         (when (and (<= *block-start-x* new-x *block-end-x*)
  233.                    (<= *block-start-x* new-y *block-end-y*))
  234.           (do ((block-list *block-list* (cdr block-list))
  235.                (result '() (cons (car block-list) result)))
  236.               ((or (null? block-list)
  237.                    (block-hit? (car block-list) new-x new-y))
  238.                (unless (null? block-list)
  239.                  (when (block-vertical-reflect? (car block-list) new-x new-y
  240.                                                 *ball-vx*)
  241.                    (reflect-x))
  242.                  (when (block-horizontal-reflect? (car block-list) new-x new-y
  243.                                                   *ball-vy*)
  244.                    (reflect-y))
  245.                  (set! *block-list* (append result (cdr block-list)))))))
  246.         (when *ball-rect*
  247.           (set! (ref *ball-rect* 'x) new-x)
  248.           (set! (ref *ball-rect* 'y) new-y))
  249.         (when reflect?
  250.           (Mix_PlayChannel -1 *bounce-sound* 0))))))
  251.  
  252. (define (shoot-ball)
  253.   (unless *ball-rect*
  254.     (let ((paddle-x (ref *paddle-rect* 'x))
  255.           (paddle-y (ref *paddle-rect* 'y))
  256.           (paddle-w (ref *paddle-rect* 'w))
  257.           (paddle-h (ref *paddle-rect* 'h)))
  258.       (set! *ball-rect* (make <SDL_Rect>))
  259.       (set! (ref *ball-rect* 'w) *ball-size*)
  260.       (set! (ref *ball-rect* 'h) *ball-size*)
  261.       (set! (ref *ball-rect* 'x) (+ paddle-x (/ paddle-w 2)))
  262.       (set! (ref *ball-rect* 'y) paddle-y)
  263.       (set! *ball-vx* (* (- (* 2 (random-integer 2)) 1) *unit*))
  264.       (set! *ball-vy* (- *unit*))
  265.       (format #t "ball: ~a~%" *ball-count*)
  266.       (Mix_PlayChannel -1 *shoot-sound* 0))))
  267.  
  268. (define (draw-blocks)
  269.   (for-each (lambda (block)
  270.               (SDL_FillRect *screen*
  271.                             (ptr (vector-ref block 1))
  272.                             (vector-ref block 2)))
  273.             *block-list*))
  274.  
  275. (define (poll-event event)
  276.   (SDL_PollEvent (ptr event))
  277.   (unless (< 0 (SDL_PollEvent (ptr event)))
  278.     (let ((type (ref event 'type)))
  279.       (cond
  280.        ((eq? type SDL_QUIT)
  281.         #f)
  282.        ((eq? type SDL_KEYDOWN)
  283.         (case (ref* event 'key 'keysym 'sym)
  284.           ((27)
  285.            #f)
  286.           ((32)
  287.            (shoot-ball)
  288.            #t)
  289.           ((122)
  290.            (move-paddle-left)
  291.            #t)
  292.           ((120)
  293.            (move-paddle-right)
  294.            #t)
  295.           (else
  296.            #t)))
  297.        (else
  298.         #t)))))
  299.  
  300. (define (sdl-main argc argv)
  301.   (init)
  302.   (let ((event (make <SDL_Event>)))
  303.     (do ((continue? (poll-event event) (poll-event event)))
  304.         ((not continue?) #f)
  305.       (clear-screen)
  306.       (move-paddle)
  307.       (let ((delta (- (SDL_GetTicks) *tick*)))
  308.         (when (< *tick-threshold* delta)
  309.           (move-ball)
  310.           (set! *tick* (SDL_GetTicks))))
  311.       (draw-paddle)
  312.       (draw-ball)
  313.       (draw-blocks)
  314.       (stop-paddle)
  315.       (SDL_Flip *screen*)
  316.       (cond
  317.        ((< *ball-count* 0)
  318.         (print "GAME OVER!!")
  319.         (init-game))
  320.        ((null? *block-list*)
  321.         (set! *ball-rect* #f)
  322.         (make-blocks)))))
  323.   (teardown)
  324.   0)
  325.  
  326. (define (main args)
  327.   (run_sdl_main (length args) args sdl-main))
  328.  
  329. ;; end of file
  330.  


.

RobbeK

  • Guest
Re: Gauche Scheme
« Reply #25 on: January 28, 2015, 01:28:57 PM »
Hi John,

No success here , tells me libc.so.6 is not present  in /libx32...   , while it is there both in /libx32  and /usr/libx32  ..somewhat annoying
There is a lazy-ffi I found on a Jap site , but it also gives an error (reported (recently) by others - this code is 8 yrs. old and seemed to work in the past)  trying DynComp now


best Rob   

JRS

  • Guest
Re: Gauche Scheme
« Reply #26 on: January 28, 2015, 01:39:21 PM »
FWIW - I use the --prefix=/usr for all my 64 bit package builds.

Code: [Select]
./configure --prefix=/usr
make
sudo make install

JRS

  • Guest
Re: Gauche Scheme
« Reply #27 on: January 28, 2015, 08:27:31 PM »
I thought I would run the testsuite examples but there were no compiled .so libraries, just source. The Makefile in the directory when run said nothing to be done.  :-\

I compile the gcc_extension.c example manually so I could run the corresponding Gauche .scm example.

Code: C
  1. #include "gcc_extension.h"
  2.  
  3. void inc_foo(struct foo *v, int mode)
  4. {
  5.     ++(v->a);
  6.     switch (mode) {
  7.     case FLOAT_MODE:
  8.         ++(v->b);
  9.         break;
  10.     case STRUCT_MODE:
  11.         ++(v->c);
  12.         ++(v->d);
  13.         break;
  14.     default:
  15.         break;
  16.     }
  17.     ++(v->e);
  18.     ++(v->f);
  19.     ++(v->g);
  20. }
  21.  

Code: Scheme
  1. ;;;
  2. ;;; Test GCC extension
  3. ;;;
  4.  
  5. (use gauche.test)
  6.  
  7. (test-start "gcc_extension")
  8. (use c-wrapper)
  9. (test-module 'c-wrapper)
  10.  
  11. (c-load-library "./gcc_extension")
  12. (c-include "./gcc_extension.h")
  13.  
  14. (test "Unnamed struct/union fields within structs/unions 1"
  15.       '(2 3.0 4 5 6.0)
  16.       (lambda ()
  17.         (let ((foo (make (c-struct 'foo))))
  18.           (set! (ref foo 'a) 1)
  19.           (set! (ref foo 'b) 2)
  20.           (set! (ref foo 'e) 3)
  21.           (set! (ref foo 'f) 4)
  22.           (set! (ref foo 'g) 5)
  23.           (inc_foo (ptr foo) FLOAT_MODE)
  24.           (map (cut ref foo <>) '(a b e f g)))))
  25.  
  26. (test "Unnamed struct/union fields within structs/unions 2"
  27.       '(2 3 4.0 5 6 7.0)
  28.       (lambda ()
  29.         (let ((foo (make (c-struct 'foo))))
  30.           (set! (ref foo 'a) 1)
  31.           (set! (ref foo 'c) 2)
  32.           (set! (ref foo 'd) 3)
  33.           (set! (ref foo 'e) 4)
  34.           (set! (ref foo 'f) 5)
  35.           (set! (ref foo 'g) 6)
  36.           (inc_foo (ptr foo) STRUCT_MODE)
  37.           (map (cut ref foo <>) '(a c d e f g)))))
  38.  
  39. ;; epilogue
  40. (test-end)
  41.  


jrs@laptop:~/c-wrapper/testsuite$ gcc gcc_extension.c -c -fPIC -o gcc_extension.o
jrs@laptop:~/c-wrapper/testsuite$ gcc -shared gcc_extension.o -o gcc_extension.so
jrs@laptop:~/c-wrapper/testsuite$ gosh gcc_extension-test.scm
Testing gcc_extension ...                                       
testing bindings in #<module c-wrapper> ... ok
test Unnamed struct/union fields within structs/unions 1, expects (2 3.0 4 5 6.0) ==> ok
test Unnamed struct/union fields within structs/unions 2, expects (2 3 4.0 5 6 7.0) ==> ok
passed.
jrs@laptop:~/c-wrapper/testsuite$


 

RobbeK

  • Guest
Re: Gauche Scheme
« Reply #28 on: January 29, 2015, 01:56:16 AM »
Hi John,

Some of the tests work,  but the important

Testing c-wrapper (inline) ...                                   
gosh: "error": can't load libc (/libx32/libc.so.6: cannot open shared object file: No such file or directory)

but , it's there and when I do a sudo apt-get install , it tells I have the most up to date version.
Does it expect the libc.so.6 tp be in another path ????

I rebuilt the packages the way you do it

./configure --prefix=/usr
make clean .............    etc

 :-\   Rob


however, what i urgently need is this one :
http://quasiquote.org/log2/Scheme/Gauche/Gauche-lazy-ffi        (libffi-dev is intalled, but can not get the lazy-ffi working for the moment)

but :

/usr/lib/gauche-0.9/site/i686-pc-linux-gnu/lazy-ffi.so: undefined symbol: strlcpy
"(stdin)":1:(use lazy-ffi)
..........................;

« Last Edit: January 29, 2015, 02:09:30 AM by RobbeK »

JRS

  • Guest
Re: Gauche Scheme
« Reply #29 on: January 29, 2015, 09:34:14 AM »
Rob,

I was able to get the c-wrapper inline-test.scm example to work. I had to use the full path for libc.so.6 and compile ffitest.so.

Code: Scheme
  1. ;;;
  2. ;;; inline function test
  3. ;;;
  4.  
  5. (use gauche.test)
  6.  
  7. (test-start "c-wrapper (inline)")
  8. (use c-wrapper)
  9.  
  10. (c-load-library "/lib/x86_64-linux-gnu/libc.so.6")
  11. (c-load-library "./ffitest")
  12. (c-include '("stdio.h" "stdlib.h" "./ffitest.h"))
  13.  
  14. (test "constant"
  15.       1
  16.       (lambda ()
  17.         (return_const)))
  18.  
  19. (test "string"
  20.       "foo"
  21.       (lambda ()
  22.         (x->string (return_string))))
  23.  
  24. (test "ref array"
  25.       10
  26.       (lambda ()
  27.         (let ((a (make (c-array <c-int> 3))))
  28.           (set! (ref a 0) 0)
  29.           (set! (ref a 1) 10)
  30.           (set! (ref a 2) 20)
  31.           (ref_array a))))
  32.  
  33. (test "func call without argument"
  34.       '(-2 -1 0 1 2)
  35.       (lambda ()
  36.         (funccall1)
  37.         (list (ref test_array 0)
  38.               (ref test_array 1)
  39.               (ref test_array 2)
  40.               (ref test_array 3)
  41.               (ref test_array 4))))
  42.  
  43. (test "func call with arguments"
  44.       3
  45.       (lambda ()
  46.         (funcall2 1 2)))
  47.  
  48. (test "ref struct (. operator)"
  49.       1
  50.       (lambda ()
  51.         (ref_struct1)))
  52.  
  53. (test "ref struct (-> operator)"
  54.       1
  55.       (lambda ()
  56.         (let ((a (make (c-struct 'test_sint))))
  57.           (set! (ref a 'value) 1)
  58.           (ref_struct2 (ptr a)))))
  59.  
  60.  
  61. (test "post increment"
  62.       2
  63.       (lambda ()
  64.         (post_inc)))
  65.  
  66. (test "post decrement"
  67.       1
  68.       (lambda ()
  69.         (post_dec)))
  70.  
  71. (test "pre increment"
  72.       2
  73.       (lambda ()
  74.         (pre_inc)))
  75.  
  76. (test "pre decrement"
  77.       1
  78.       (lambda ()
  79.         (pre_dec)))
  80.  
  81. (test "unary plus"
  82.       1
  83.       (lambda ()
  84.         (unary_plus)))
  85.  
  86. (test "unary minus"
  87.       -1
  88.       (lambda ()
  89.         (unary_minus)))
  90.  
  91. (test "unary logical negation"
  92.       '(0 1)
  93.       (lambda ()
  94.         (list (unary_logneg 1) (unary_logneg 0))))
  95.  
  96. (test "unary bitwise negation"
  97.       -2
  98.       (lambda ()
  99.         (unary_bitneg 1)))
  100.  
  101. (test "unary reference"
  102.       123
  103.       (lambda ()
  104.         (unary_ref)))
  105.  
  106. (test "unary dereference"
  107.       456
  108.       (lambda ()
  109.         (ref (deref (unary_deref)))))
  110.  
  111. (test "sizeof"
  112.       #t
  113.       (lambda ()
  114.         (eq? (c-sizeof <c-int>) (op_sizeof))))
  115.  
  116. (test "mul"
  117.       6
  118.       (lambda ()
  119.         (mul 2 3)))
  120.  
  121. (test "divi"
  122.       3
  123.       (lambda ()
  124.         (divi 18 6)))
  125.  
  126. (test "mod"
  127.       1
  128.       (lambda ()
  129.         (mod 5 2)))
  130.  
  131. (test "add"
  132.       3
  133.       (lambda ()
  134.         (add 1 2)))
  135.  
  136. (test "sub"
  137.       -1
  138.       (lambda ()
  139.         (sub 1 2)))
  140.  
  141. (test "left shift"
  142.       4
  143.       (lambda ()
  144.         (left_shift 1 2)))
  145.  
  146. (test "right shift"
  147.       2
  148.       (lambda ()
  149.         (right_shift 8 2)))
  150.  
  151. (test "lesser than"
  152.       '(1 0 0)
  153.       (lambda  ()
  154.         (list (op_lt 1 2) (op_lt 2 2) (op_lt 2 1))))
  155.  
  156. (test "greater than"
  157.       '(0 0 1)
  158.       (lambda  ()
  159.         (list (op_gt 1 2) (op_gt 2 2) (op_gt 2 1))))
  160.  
  161. (test "lesser than or equal"
  162.       '(1 1 0)
  163.       (lambda  ()
  164.         (list (op_lteq 1 2) (op_lteq 2 2) (op_lteq 2 1))))
  165.  
  166. (test "greater than or equal"
  167.       '(0 1 1)
  168.       (lambda  ()
  169.         (list (op_gteq 1 2) (op_gteq 2 2) (op_gteq 2 1))))
  170.  
  171. (test "equal"
  172.       '(0 1 0)
  173.       (lambda  ()
  174.         (list (op_eq 1 2) (op_eq 2 2) (op_eq 2 1))))
  175.  
  176. (test "not equal"
  177.       '(1 0 1)
  178.       (lambda  ()
  179.         (list (op_noteq 1 2) (op_noteq 2 2) (op_noteq 2 1))))
  180.  
  181. (test "bitwise and"
  182.       1
  183.       (lambda ()
  184.         (bitand 11 5)))
  185.  
  186. (test "bitwise or"
  187.       15
  188.       (lambda ()
  189.         (bitor 11 5)))
  190.  
  191. (test "bitwise xor"
  192.       14
  193.       (lambda ()
  194.         (bitxor 11 5)))
  195.  
  196. (test "logical and"
  197.       '(1 0 0 0)
  198.       (lambda ()
  199.         (list (op_logand 1 1 1)
  200.               (op_logand 1 1 0)
  201.               (op_logand 0 1 1)
  202.               (op_logand 0 1 0))))
  203.  
  204. (test "logical or"
  205.       '(1 1 1 0)
  206.       (lambda ()
  207.         (list (op_logor 1 1 1)
  208.               (op_logor 1 1 0)
  209.               (op_logor 0 1 1)
  210.               (op_logor 0 1 0))))
  211.  
  212. (test "assign mul"
  213.       6
  214.       (lambda ()
  215.         (assign_mul 2 3)))
  216.  
  217. (test "assign div"
  218.       3
  219.       (lambda ()
  220.         (assign_div 18 6)))
  221.  
  222. (test "assign mod"
  223.       1
  224.       (lambda ()
  225.         (assign_mod 5 2)))
  226.  
  227. (test "assign_add"
  228.       3
  229.       (lambda ()
  230.         (assign_add 1 2)))
  231.  
  232. (test "assign_sub"
  233.       -1
  234.       (lambda ()
  235.         (assign_sub 1 2)))
  236.  
  237. (test "assign left shift"
  238.       4
  239.       (lambda ()
  240.         (assign_left_shift 1 2)))
  241.  
  242. (test "assign right shift"
  243.       2
  244.       (lambda ()
  245.         (assign_right_shift 8 2)))
  246.  
  247. (test "assign bitwise and"
  248.       1
  249.       (lambda ()
  250.         (assign_bitand 11 5)))
  251.  
  252. (test "assign bitwise or"
  253.       15
  254.       (lambda ()
  255.         (assign_bitor 11 5)))
  256.  
  257. (test "assign bitwise xor"
  258.       14
  259.       (lambda ()
  260.         (assign_bitxor 11 5)))
  261.  
  262. (test "multi expr"
  263.       10
  264.       (lambda ()
  265.         (multi_expr 2 5)))
  266.  
  267. (test "while"
  268.       55
  269.       (lambda ()
  270.         (test_while)))
  271.                
  272. (test "while break"
  273.       55
  274.       (lambda ()
  275.         (test_while_break)))
  276.                
  277. (test "while continue"
  278.       55
  279.       (lambda ()
  280.         (test_while_continue)))
  281.                
  282. (test "do while"
  283.       55
  284.       (lambda ()
  285.         (test_dowhile)))
  286.                
  287. (test "do while break"
  288.       55
  289.       (lambda ()
  290.         (test_dowhile_break)))
  291.                
  292. (test "do while continue"
  293.       0
  294.       (lambda ()
  295.         (test_dowhile_continue)))
  296.                
  297. (test "for"
  298.       55
  299.       (lambda ()
  300.         (test_for)))
  301.                
  302. (test "for noinit, notest, noupdate"
  303.       55
  304.       (lambda ()
  305.         (test_for_noinit_notest_noupdate)))
  306.                
  307. (test "for noinit, notest"
  308.       55
  309.       (lambda ()
  310.         (test_for_noinit_notest)))
  311.                
  312. (test "for noinit, noupdate"
  313.       55
  314.       (lambda ()
  315.         (test_for_noinit_noupdate)))
  316.                
  317. (test "for noinit"
  318.       55
  319.       (lambda ()
  320.         (test_for_noinit_noupdate)))
  321.  
  322. (test "for notest, noupdate"
  323.       55
  324.       (lambda ()
  325.         (test_for_notest_noupdate)))
  326.                
  327. (test "for notest"
  328.       55
  329.       (lambda ()
  330.         (test_for_notest)))
  331.                
  332. (test "for noupdate"
  333.       55
  334.       (lambda ()
  335.         (test_for_noupdate)))
  336.  
  337. (test "offset"
  338.       #t
  339.       (lambda ()
  340.         (eq? (offset_calc) (c-offsetof (c-struct 'test_uchar) 'value))))
  341.  
  342. (test "not_supported"
  343.       #t
  344.       (lambda ()
  345.         (procedure? not_supported)))
  346.  
  347. ;; epilogue
  348. (test-end)
  349.  


jrs@laptop:~/c-wrapper/testsuite$ gosh inline-test.scm
Testing c-wrapper (inline) ...                                   
test constant, expects 1 ==> ok
test string, expects "foo" ==> ok
test ref array, expects 10 ==> ok
test func call without argument, expects (-2 -1 0 1 2) ==> ok
test func call with arguments, expects 3 ==> ok
test ref struct (. operator), expects 1 ==> ok
test ref struct (-> operator), expects 1 ==> ok
test post increment, expects 2 ==> ok
test post decrement, expects 1 ==> ok
test pre increment, expects 2 ==> ok
test pre decrement, expects 1 ==> ok
test unary plus, expects 1 ==> ok
test unary minus, expects -1 ==> ok
test unary logical negation, expects (0 1) ==> ok
test unary bitwise negation, expects -2 ==> ok
test unary reference, expects 123 ==> ok
test unary dereference, expects 456 ==> ok
test sizeof, expects #t ==> ok
test mul, expects 6 ==> ok
test divi, expects 3 ==> ok
test mod, expects 1 ==> ok
test add, expects 3 ==> ok
test sub, expects -1 ==> ok
test left shift, expects 4 ==> ok
test right shift, expects 2 ==> ok
test lesser than, expects (1 0 0) ==> ok
test greater than, expects (0 0 1) ==> ok
test lesser than or equal, expects (1 1 0) ==> ok
test greater than or equal, expects (0 1 1) ==> ok
test equal, expects (0 1 0) ==> ok
test not equal, expects (1 0 1) ==> ok
test bitwise and, expects 1 ==> ok
test bitwise or, expects 15 ==> ok
test bitwise xor, expects 14 ==> ok
test logical and, expects (1 0 0 0) ==> ok
test logical or, expects (1 1 1 0) ==> ok
test assign mul, expects 6 ==> ok
test assign div, expects 3 ==> ok
test assign mod, expects 1 ==> ok
test assign_add, expects 3 ==> ok
test assign_sub, expects -1 ==> ok
test assign left shift, expects 4 ==> ok
test assign right shift, expects 2 ==> ok
test assign bitwise and, expects 1 ==> ok
test assign bitwise or, expects 15 ==> ok
test assign bitwise xor, expects 14 ==> ok
test multi expr, expects 10 ==> ok
test while, expects 55 ==> ok
test while break, expects 55 ==> ok
test while continue, expects 55 ==> ok
test do while, expects 55 ==> ok
test do while break, expects 55 ==> ok
test do while continue, expects 0 ==> ok
test for, expects 55 ==> ok
test for noinit, notest, noupdate, expects 55 ==> ok
test for noinit, notest, expects 55 ==> ok
test for noinit, noupdate, expects 55 ==> ok
test for noinit, expects 55 ==> ok
test for notest, noupdate, expects 55 ==> ok
test for notest, expects 55 ==> ok
test for noupdate, expects 55 ==> ok
test offset, expects #t ==> ok
test not_supported, expects #t ==> ok
passed.
jrs@laptop:~/c-wrapper/testsuite$