This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Android REPL on Kawa - unable to create functions on the fly


* teyc [2012-01-26 11:21] writes:

> Continuing with my adventures running a Kawa REPL on Android, I've
> encountered a difficulty defining functions on the fly. This is due to a
> limitation of the Android's java implementation. Are there any switches I
> could toggle to run Kawa wholly interpreted?

Setting gnu.expr.ModuleExp:compilerAvailable makes it possible to
evaluate lambdas.   I guess some other forms, e.g., define-simple-class
absolutely require bytecode generation so will still not work.  Also it
seems that global variables defined in one thread are not visible to
other threads; I've never figured out how to fix that.

Below is my current version that uses Kawa's TelnetRepl which fixes some
other issues.

Helmut


(module-static #t)

(module-compile-options
 warn-unknown-member: #t
 warn-undefined-variable: #t
 )

(define-syntax try-with-resources
  (syntax-rules ()
    ((try-with-resources () body ...)
     (begin body ...))
    ((try-with-resources ((var val) (vars vals) ...) body ...)
     (let ((var val)) 
       (try-finally 
        (try-with-resources ((vars vals) ...) body ...)
        (invoke var 'close))))))

(define (msg (fstring string) #!rest args)
  (android.util.Log:v "kawa-hello" (apply format fstring args)))

(define (start-telnet-repl (socket java.net.Socket))
  (let ((lang (gnu.expr.Language:getDefaultLanguage)))
    (msg "starting telnet repl ~a ~a" socket lang)
    (kawa.TelnetRepl:serve lang socket)))

(define (start-repl port)
  (try-with-resources ((server (java.net.ServerSocket port)))
   (let loop ()
     (msg "listing on ~a (~a)" port server)
     (let ((socket (server:accept)))
       (msg "connected ~a " socket)
       (start-telnet-repl socket)
       (loop)))))

(define-variable *activity* #f)

(define (init-kawa activity)
  (kawa.standard.Scheme:registerEnvironment)
  (set! gnu.expr.ModuleExp:compilerAvailable #f)
  (set! gnu.expr.ModuleExp:alwaysCompile #f)
  (set! *activity* activity)
  (future (start-repl 4444)))

(define-simple-class hello (android.app.Activity)
  ((onCreate saved-state ::android.os.Bundle) ::void
   (let ((self (this)))
     (invoke-special android.app.Activity self 'onCreate saved-state)
     (init-kawa self)
     (self:setContentView 
      (android.widget.TextView 
       self
       text: "Hello, Android from Kawa Scheme!")))))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]