Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - iNPRwANG

#1
Source funtion could not get the corresponding result while nest list element type of arrays, code like this:



> (array 1)
(nil)
> (setq *a* (array 1))
(nil)
> (setf (nth 0 *a*) '(1 2 3))
(1 2 3)
> (source '*a*)
"(set '*a* (array 1 (flat '(rn  (1 2 3)))))rnrn"
>


The *a* symbol's value is: ((1 2 3)), bt the result: (set '*a* (array 1 (flat '((1 2 3))))) regard the *a* to (1), is this a bug?
#2
Here are some share tips of doing remoting debug with newLisp : )



Before, I suggested to add a "debugConsole" function for embedded newLisp library debugging, that can establish a new console window for windows GUI applications and can do the step debug in the window.



Now, I want to step debug the newLisp for embedded device, such as android devices or embedded linux facilities, a remote debugger can make debug works be very comfortable.



With these codes, U may have a simple remote debug without change any newLisp's source, these two parts code is a remote debugger services and a debugger terminal, the debugger services looks like this:



(import "libc.so.6" "dup2")

;Standard input value, stdin. Its value is 0.
(constant 'STDIN_FILENO 0)
   
;Standard output value, stdout. Its value is 1.
(constant 'STDOUT_FILENO 1)
   
;Standard error value, stderr. Its value is 2.
(constant 'STDERR_FILENO 2)

(println STDOUT_FILENO)

(set 'socket (net-listen 1234))
(set 'cnn (net-accept socket))
(net-close socket)

(println "Connection successed!")

;/* duplicate socket on stdout */
(dup2 cnn STDOUT_FILENO)

;  /* duplicate socket on stderr too */
(dup2 cnn STDIN_FILENO)

(debug (fibo 2))

(exit)


The "fibo" function is a route you want to debug, and the debugger terminal looks like this:




(set 'socket (net-connect "127.0.0.1" 1234))
(println "Connection successed!")

(setq g_end "s|tep n|ext c|ont q|uit >")

(catch
(let ((buffer (dup "x00" 1))
 (output ""))
(while true
;判断是否 s|tep n|ext c|ont q|uit > 结尾,如果是,则打印出来后再读取一个字符

(net-select socket "e" 0)
(when (net-error)
(println (net-error))
(throw 'Exception))

(net-receive socket buffer 1)
(print buffer)

(setq output (append output buffer))
(when (ends-with output g_end)
(setq output "")

(letn ((cmd (read-line))
  (send_cmd (append cmd "n")))
(net-send socket send_cmd)
)
)
)
)
'Result)

(exit)





Then, run the debugger services and then run the debugger terminal, U will like the remote debuger practice : )



Under are some notes for remote debug with a newLisp library:



The library of newLisp does not use the standard IO for debugger, unless you set a debug console flag for it. The "newlispLibConsole" exported function of newLisp.so can be called and to enable the flag, then it will use the standard IO and the above codes will works good.
#3
Use this makefile can compile newLisp to newlisp-js in emscripten v1.37 by enable webassembly support.

Notice of the  "-s WASM=1" option let the emscripten generate webassembly, and should use the " -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' " for function exporting (the "ccall" and "cwrap" not export by default in emscripten version above 1.3)



The approximate performance about webassembly enabled newlisp-js is 5% faster than asm.js version (tested in Firefox 58.0.1), and the total file size is less than the asm.js version about 20%.



# makefile for newLISP v. 10.5.x and after with UTF8 support for the Emscripten SDK
#
# With Emscripten version v1.22.0 all execption handling related problems
# known have been solved. (November 2014)
#
# see also: https://github.com/kripken/emscripten/wiki
#
# Uses custom random() and srandom() in nl-filesys.c
#
# Does not implement the newLISP functions:
# semaphore, net-packet, net-service, fork, spawn, sync, abort
#
# Will not do file and network I/O functions in the sandboxed JavaScript
# environment
#
# Generates newlisp-js-lib.js and newlisp-js-lib.html.
# The html file can be discarded use newlisp-js/newlisp-js.html instead
#
# this makefile has been tested on a MAC OSX 10.9/10 platforms

OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o
 nl-sock.o nl-web.o nl-xml-json.o nl-matrix.o nl-debug.o pcre.o nl-utf8.o unix-lib.o

CFLAGS = -m32 -Wall -c -DMAC_OSX -DLIBRARY -DEMSCRIPTEN -DSUPPORT_UTF8

CC = emcc

default: $(OBJS)
 cp qa-specific-tests/qa-bench newlisp-js
 cp modules/canvas.lsp newlisp-js
 $(CC) $(OBJS) -m32 -O2 -s WASM=1 -o newlisp-js-lib.html -s EXPORTED_FUNCTIONS="['_newlispEvalStr']"
 -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
 -s TOTAL_MEMORY=33554432 --closure 1
 --embed-file newlisp-js/readme.txt --embed-file newlisp-js/qa-bench --embed-file newlisp-js/canvas.lsp
 rm newlisp-js/qa-bench newlisp-js/canvas.lsp

.c.o:
 $(CC) -O2 --closure 1 $(CFLAGS) $<

$(OBJS): primes.h protos.h makefile_emscripten_lib_utf8

#5
I'v tried to traced into guiserver, and found that the "cls.getClass().getResource()" call get a null point result in Jre 9.0.1, I changed the code to "cls.getResource()" and the result is corrected.



The code looks like this:



guiserver.java:180


Quote
   public static Image getImageFromPath(String path,  Class cls)

      {

      if(path.startsWith("/local/")) {         

         return(Toolkit.getDefaultToolkit().getImage(cls.getResource("/images" + path.substring(6))));

         //return(Toolkit.getDefaultToolkit().getImage(cls.getClass().getResource("/images" + path.substring(6))));

      }

      else

         return(Toolkit.getDefaultToolkit().getImage(path));

      }



   public static ImageIcon getIconFromPath(String path, Class cls)

      {

      if(path.startsWith("/local/"))

         //return(new ImageIcon(Toolkit.getDefaultToolkit().getImage(cls.getClass().getResource("/images" + path.substring(6)))));

         return(new ImageIcon(Toolkit.getDefaultToolkit().getImage(cls.getResource("/images" + path.substring(6)))));

      else

         return(new ImageIcon(path));

      }
#6
OS version is win10 x64 1709 (Chinese simplified).

   

    After I upgraded Jre from 8.x to 9.0.1, and running any newLisp script that used guiserver(such as the widgets-demo.lsp), all of the program that use the internal image (such as gs:image-button that use a image "/local/newLISP32.png") will cause a error message. And, the program will finally startup and show the main interface with not any image.



    I am not good at Java, I can not delimit is it a incompatible changes by Jre 9.x ?
#7
Why this forum's link not exists in newlisp's home page?
#8
The newlisp module has exported a function named "newlispCallback", that's able to make a callback from a C function pointer, and then call it from newlisp.



For more reference to:

http://www.newlisp.org/downloads/CodePatterns.html">//http://www.newlisp.org/downloads/CodePatterns.html
#9
And in the debugging state, the code's behavior is different from direct run.

Such as this example:



(define (test)
(setq *a* (array 1))
(rest *a*))

(test)


By direct run this code, the rest function apply to an 1 element array, it throw the error:


Quote
ERR: array index out of bounds in function rest : 1

called from user defined function test


By run debug for step inspect, the rest function result a nil, that looks like no problem.



(define (test )
  (setq *a* (array 1))
  #(rest *a*)#
  (println "OK"))

RESULT: nil


This cause people hard to find issuses from debugging.
#10
newLISP in the real world / Crashed while step debug
October 20, 2014, 08:23:45 PM
I have obtain newlisp.exe from:

http://www.newlisp.org/downloads/UTF-8_win32/">//http://www.newlisp.org/downloads/UTF-8_win32/



Verion is 10.6.0.



And let it run this program:



(define (db-clear-sync-queues-vlog clearlist)
(let ((conds '())
 (sql ""))

(dolist (_item clearlist)
(if (and (> (length _item) 1)
(string? (nth 0 _item))
(number? (nth 2 _item))
)
(extend conds (list (format "(tablename='%s' and orderid=%d)" (nth 0 _item) (nth 2 _item))))
)
)

(setq sql (append "delete from tbl_sync_queues_vlog where " (join conds " or ")))
))

(debug (db-clear-sync-queues-vlog '(("tbl_test" "2014-10-21 10:35:35.873000000" 1))))


While in step debugging, the debug output like this:



(define (db-clear-sync-queues-vlog clearlist)
  (let ((conds '()) (sql ""))
   (dolist (_item clearlist)
    (if (and (> (length _item) 1) (string? (nth 0 _item)) (number? (nth 2 _item)))
     (extend conds (list (format "(tablename='(null)' and orderid=10503914)" (nth 0 _item)
        (nth 2 _item))))))
   (setq sql (append "delete from tbl_sync_queues_vlog where " (join conds " or ")))))


Take notice of the string "(tablename='(null)' and orderid=10503914)", that's different from my code.



And while I step and step, the program will crash in this step:



(define (db-clear-sync-queues-vlog clearlist)
  (let ((conds '()) (sql ""))
   #(dolist (_item clearlist)
    (if (and (> (length _item) 1) (string? (nth 0 _item)) (number? (nth 2 _item)))
     (extend conds (list (format "(tablename='(null)' and orderid=10503914)" (nth 0 _item)
        (nth 2 _item))))))#
   (setq sql (append "delete from tbl_sync_queues_vlog where " (join conds " or ")))))


Any suggestions??
#11
Quote from: "Lutz"... and you also should try:

(import "msvcrt.dll" "sscanf" "cdecl") ; <- C-calling conventions for varargs


C-calling conventions may handle variable number of arguments in sscanf better.


Well, I had found the issue just now.
#12
I had met some problem with my compiled newLisp,such as http://newlispfanclub.alh.net/forum/viewtopic.php?f=16&t=4099">//http://newlispfanclub.alh.net/forum/viewtopic.php?f=16&t=4099 and this problem.



Now I packed my compiler, libs and uploaded it:



http://211.95.60.98:9090/">http://211.95.60.98:9090/



Mingw.7z                     my used compiler

libffi-3.0.10.7z            my libffi(no changed)

newlisp10.5.0.7z         my compiled binary



newlisp version is 10.5.0, build with: makefile_mingw_utf8_ffi, the issue may reproduce.
#13
OS is windows xp sp3, these code works better on newLisp 10.4.5:



(import "msvcrt.dll" "sscanf")

(let ((day 0) (mon 0) (year 0))
(sscanf "1990-01-01" "%d-%d-%d" (address year) (address mon) (address day)))


But crashed on newLisp 10.5.0, is any changes of the int datatype address?
#14
newLISP in the real world / Re: net-eval multi thread
September 27, 2012, 06:40:33 PM
My solution is use a http server which has the reverse proxy feature, such as Nginx.



First, start multipile newLisp instance as local http servers, let them listening for http request.

Second, configure the Nignx as a reverse proxy, it can hold the http request from user, and dispatch the request to each newLisp instance, the Nginx may use "load balancing" to process the request.



The code of Nginx config file in http segment like this:

upstream localhost {
server localhost:4242;
server localhost:4243;
}
#15
newLISP in the real world / Re: Catch form problem
June 14, 2012, 02:24:48 AM
Please close this subject, I known what's my mistake :)