Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 41

Thread: Cdecl (-> dll)

  1. #21
    Hello Rob,

    I agree, this do functionality is cool. But tastes (and tasks) differ and, while someone may be more interested in asking the computer a simple "Why?" to hear a competent "Because!" in response, others may be more fascinated by "How?". I belong to the latter bunch, hence my interest in the building blocks rather than the building proper. There wasn't a single toy left unbroken in my kid's room when I was a boy; all of them were taken apart to see how they did what they were supposed to do.

    Please read this - that's the story of Hal 2014. I'm sure you're going to like it.

    And yes, your "magma" is very impressive.
    Last edited by mike lobanovsky; 06-05-2014 at 19:20.
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  2. #22
    Sorry (very) late reply ..

    Thank you both for the links and the fresh O2 ...

    I switched to NewLisp now , the new FFI is much clearer , easier than on the previous Lisp I tried. (but not giving up the "classics" )
    99% was very easy , 1% very difficult -- Lisp has no pointer data type , (mainly because it is useless anyway - mainly only strings use a "flat memory model" , the rest uses pointers (a very lot of them) to connect things -- i've used O2 to allocate memory in case I use a Java server (that needs addresses for fast graphics color-arrays (rgb) -> screen :: the openGL/glu/glut works directly without any problems ... )

    Charles, don't know if the 2012 O2 edition is the standard/stable version at this moment ... if you compile ->DLL the caller program will generate a windows error on exit (i tried a few Lisps (via FFI and CFFI ) and Racket Scheme ffi/unsafe ) .. the newer version does it perfect and clean ....
    (ah, yes, is there a function in O2 de-allocating the claimed memory , so I can give it back to the system - the arrays needed for Java swing (while r g b values are not represented by bytes or char bur 32bit integers !! -- )
    best Rob
    (in fact what I did , makes not much sense -- NewLisp is already perfectly embeddable in tB ...

    hi Mike, demolishing things -- well , we have to get in , to get out , not ;-)

  3. #23
    Hi Rob,

    Earlier versions of Oxygen are deep alpha

    My curiosity about Lisp is aroused, and I wonder whether Lisp S expressions could be useful in Basic. I like the way in which declarations, operators, functions and any other construct, existent and yet to be invented, all have uniform syntax.

    I see no problem in representing classes, types pointers, and all the other things we use in Basic.

    Concerning memory allocation: If O2 allocates the memory for Lisp then it can also free it at the end, but where the allocation comes from any outside system, one would need to know how it was created.

  4. #24
    Hi Charles,

    I was dreaming about dynamic allocation/de-allocation .. but it's no problem , for the graphics I set up 3 int arrays (int needed for Java) r g & b and oxygen returns @r , @g , @b to Lisp using it for calling Java that needs these pointers. NewLisp does have (address) but the data structures are wrong (except for strings, but then I have to set up huge null character strings to start and processing these is slow - and I stll have to simulate 32 bit integers )
    For the moment I can do graphical windows where the w*h <= 1024² - it are flat memory models so the width and height do not matter , it always fits. (but not in an economic way ;-)

    "all have uniform syntax..." yes ! exactly -- even the macro declarations !

    (define-macro (my-if test true-action false-action)
    (if (eval test) (eval true-action) (eval false-action)))

    this gives enormous possibilities -- writing your own be it strict, be it lazy , be it whateve.



    that eval is of course one of the powertools of Lisp , because data=code and code=date we can do something as

    (setq L '(1 2 3 4)) a list L containing (1 2 3 4)

    (eval (push '+ L)) -> 10 destructive mehtod : L changed
    (eval (cons '+ L)) -> 10 constructive method : L did not change - the new formula only existed during calculations

    to make it even more spectacular

    (eval (copy (push '+ L))) --- constructive from a destructive mechanism !!!

    all this means '+ is just another "data" , it can be replaced with anythihng during runtime -- formulae themselves can morph.
    (making it an AI and proving tool).

    I think ACL2 is build on Gnu Common Lisp :
    http://www.cs.utexas.edu/users/moore...G-APPLICATIONS


    classes
    Lisp comes with context's (and also FOOP)
    something as p.e
    (context 'circles) (context 'squares) and later from their specific definitions ...

    (area:circle r) (area:square z)

    a final teaser from Lisp :

    ;--------------------------------------------------------------------------------------------

    9.17 Bayesian analysis

    Statistical methods developed initially by Reverend Thomas Bayes in the 18th century
    have proved versatile and popular enough to enter the programming languages of today. In
    newLISP, two functions, bayes-train and bayes-query, work together to provide an easy
    way to calculate Bayesian probabilities for datasets.
    Here's how to use the two functions to predict the likelihood that a short piece of text is
    written by one of two authors.
    First, choose texts from the two authors, and generate datasets for each. I've chosen Oscar
    Wilde and Conan Doyle.


    (set 'doyle-data
    (parse (lower-case
    (read-file "/Users/me/Documents/sign-of-four.txt")) {\W} 0))

    (set 'wilde-data
    (parse (lower-case
    (read-file "/Users/me/Documents/dorian-grey.txt")) {\W} 0))

    The bayes-train function can now scan these two data sets and store the word frequencies
    in a new context, which I'm calling Lexicon:


    (bayes-train doyle-data wilde-data 'Lexicon)

    This context now contains a list of words that occur in the lists, and the frequencies of each.
    For example:
    Lexicon:_always
    ;-> (21 110)


    ie the word always appeared 21 times in Conan Doyle's text, and 110 times in Wilde's.
    Next, the Lexicon context can be saved in a file:
    (save "/Users/me/Documents/lex.lsp" 'Lexicon)
    and reloaded whenever necessary with:
    (load "/Users/me/Documents/lex.lsp")


    With training completed, you can use the bayes-query function to look up a list of words
    in a context, and return two numbers, the probabilities of the words belonging to the first
    or second set of words. Here are three queries. Remember that the first set was Doyle, the
    second was Wilde:

    (set 'quote1
    (bayes-query
    (parse (lower-case
    "the latest vegetable alkaloid" ) {\W} 0) 'Lexicon))
    ;-> (0.973352412 0.02664758802)

    (set 'quote2
    (bayes-query
    (parse
    (lower-case
    "observations of threadbare morality to listen to" ) {\W} 0) 'Lexicon))
    ;-> (0.5 0.5)

    (set 'quote3
    (bayes-query
    (parse
    (lower-case
    "after breakfast he flung himself down on a divan
    and lit a cigarette" ){\W} 0) 'Lexicon))
    ;-> (0.01961482169 0.9803851783)

    These numbers suggest that quote1 is probably (97% certain) from Conan Doyle, that quote2
    is neither Doylean nor Wildean, and that quote3 is likely to be from Oscar Wilde.
    Perhaps that was lucky, but it's a good result. The first quote is from Doyle's A Study in
    Scarlet, and the third is from Wilde's Lord Arthur Savile's Crime, both texts that were
    not included in the training process but - apparently - typical of the author's vocabulary.
    The second quote is from Jane Austen, and the methods developed by the Reverend are
    unable to assign it to either of the authors.

    ;-----------------------------------------------------------

    I think I mainly use Lisp because in the 1980's I wrote a lot of interfaces between AutoDesk's AutoLisp and Siemens p-codes (CAD/CAM) - there's nothing that can be done in another language - but sometimes the solutions are very elegant.
    It also comes with complex numbers on board and things like De Moivre's CIS function built - in ..


    best Rob

  5. #25
    Thanks for your Lisp material, Rob.

    For the implementation of eval, Oxygen can do run-time compiling, albeit with some limitations on static var space.


    To allocate dynamic memory in Oxygen, you can create a string of nulls and pass the strptr

    s=nuls 1024 * 1024 * 3
    p=strptr s


    You can overlay any structure array onto p:

    type pixel byte r,g,b
    pixel px at p


    px can now be used as an array

    px[n].y ...

    Strings have the advantage of being garbage-collected, but you can also allocate null memory bytes directly:

    p=getmemory 1024 * 1024 * 3

    and explicitly free it when done:

    freememory p
    Last edited by Charles Pegge; 17-05-2014 at 18:51.

  6. #26
    Thanks Charles,

    I can finish my FMI now (foreign memory interface ;-)
    Is there an example of "eval"/run-time compiling somewhere so I can understand it ?

    Picking in on those variadic function, in Lisp it is exctremely easy -- in the lambda list just put "&rest"

    (defun foo (& rest) .... can be mixed with everything else &optional, &key etc ... mechanisms enough to crawl trough the parameter list.

    As said NewLISP is perfectly embeddable in tB (it's a less than 300Kb , and it are only strings going trough the pipe ...
    I made an example :
    http://www.thinbasic.com/community/a...0&d=1394703339

    (from http://www.thinbasic.com/community/s...hlight=newlisp )

    best Rob
    Last edited by RobbeK; 18-05-2014 at 13:45.

  7. #27
    Hi Rob,

    Here is an example of dynamic compiling taken from OxygenBasic\examples\DynamicCompile\

    This runs in JIT mode but I have encountered a problem when trying to run it as an EXE/DLL. In any case it requires Oxygen.dll to provide the run-time compiling.

    You can of course, manipulate source code strings in thinBasic and do primary compiling in the usual way.

    
      '-------------------------------------
      'RUNTIME COMPILING FROM STRINGS
      'WITH ACCESS TO ALL PARENTAL VARIABLES
      '-------------------------------------
    
    
      '-----------------------------------------------
      function evaluate (string s,float b,e) as string
      '===============================================
      '
      double x,y,z
      sys a,p
      string v,u,tab,cr,er
      '
      p=1
      cr=chr(13,10)
      tab=chr(9)
      v=nuls 4000
      mid v,p,s+cr+cr
      p+=4+len s
      '
      a=compile s
      er=error
      if er then
        print "runtime error: "  er : exit function
      end if
      for x=b to e
        call a
        u=str(x) tab str(y) cr
        mid v,p,u : p+=len u
      next
      '
      freememory a
      '
      function=left v,p-1
      '
      end function
    
    
    
    
      
      print evaluate "y=x*x*x",1,10
      print evaluate "y=sqrt x",1,9
    
    Last edited by Charles Pegge; 18-05-2014 at 16:16.

  8. #28
    Thanks so much, Charles !

    (forgot to search in the examples this time -- the idea adapting the Japi lib for Lisp came from your files however)

    You can't directly give strings (or the input-stream) to exo2/gxo2 ?

    best Rob

  9. #29
    Hi Rob,

    I have fixed that problem for binaries that include dynamic compiling.

    A few notes for the above example:

      'uncomment to create an oxygen-dependent binary
      '#file "t.exe"
    
    
      ' if oxygen.dll is in a different directory then
      ' create a file named 'oxygen.cfg' containing its pathname,
      ' for example:
      ' ..\..\oxygen.dll
      '
      ' this will be read by the binary to find and load oxygen.
    


    Latest:
    http://www.thinbasic.com/community/showthread.php?12175

  10. #30
    Thanks Charles, got it !!

    Is it possible to keep the dynamic compiling in memory only ? (or doesn't it matter by reason of the file/mem cache ...

    I had an about similar problem in Scheme. Using bitmaps and even colors as objects made it very slow, so I built an memory image buffer simply composed with color lists '(color r g b) , but then I had to make a roundabout over "disk"

    ,-----------------------

    (set! im (color-list->bitmap buffer n n ))
    (save-image im "im.png" )
    (set! bmp (read-bitmap "im.png"))
    (new message% [parent mframe] [label bmp])
    (send mframe show #t)

    ;----------------------------------

    surprisingly this works very fast (no memory mapped files needed )


    best Rob, and thanks for your expert help !
    Last edited by RobbeK; 19-05-2014 at 10:40.

Page 3 of 5 FirstFirst 12345 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •