Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: It works for me.

  1. #1
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152

    It works for me.

    I tried Free Pascal (FPC Version: 2.4.2).

    It is a compiler.

    It can make DLLs.

    I guess that means, theoretically, it could be called by thinBasic.

    -----------------------------------------------------------------------------------------------

    (I didn't see there was a forum for it at thinBasic, until I looked to upload this post.)

    I haven't the vaguest notion about SDKs.

    I definitely need to have a serious run with it and see if I can make a thinBasic SDK for Free Pascal in order to be able to develop thinBasic module under Free Pascal.
    http://www.thinbasic.com/community/showthread.php?8349-Free-Pascal-2.2.0-released

    If it happens, it would be nice.
    I think if I knew how to make a DLL and call it from thinBasic, I would be incentivized.
    For me, I don't want PowerBasic, and, I don't want C.
    I would like Fortran or Free Pascal - if I knew how to make an SDK, and it was easy, I would try to do one or both myself.

    -----------------------------------------------------------------------------------------------

    website:

    http://www.freepascal.org/

    documentation:
    There are 7 documents in PDF files.
    (The Run-Time Library (RTL) units reference manual, is 1739 pages.)

    http://www.freepascal.org/docs.var

    IDE = Lazurus

    http://www.lazarus.freepascal.org/

    Free Pascal + Lazurus --> installer (76.2 MB)

    http://sourceforge.net/projects/lazarus/files/

    Test:
    (compiled to RAM, and run from IDE)

    ' code ----------------------------------------------------------------------------------------------------------------------
    
    program test;
    
    uses sysutils,dateutils;
    
    const
    // n equals one billion
    n=1000000000;
    
    var
    i:longint;
    f:extended;
    t1,t2: tdatetime;
    
    begin
    t1:=now;
    
    // Calculate the square roots.
    for i:=1 to n do
    begin
    f:=sqrt(i);
    end;
    
    // Write the statistics.
    t2:=now;
    f:= millisecondsbetween(t2,t1)/1000;
    writeln('time to calculate the square roots of 1 to ',n,':');
    writeln('elapsed seconds = ',f);
    writeln;
    
    // Write some square root values.
    for i:=1 to 9 do
    begin
    writeln(i,' ',sqrt(i));
    end;
    
    readln;
    end.
    
    ' output --------------------------------------------------------------------------------------------------------------------
    
    time to calculate the square roots of 1 to 1000000000:
    elapsed seconds =  2.1450000000000000E+0001
    
    1  1.0000000000000000E+0000
    2  1.4142135623730950E+0000
    3  1.7320508075688773E+0000
    4  2.0000000000000000E+0000
    5  2.2360679774997897E+0000
    6  2.4494897427831781E+0000
    7  2.6457513110645906E+0000
    8  2.8284271247461901E+0000
    9  3.0000000000000000E+0000
    
    Last edited by danbaron; 20-11-2011 at 10:04.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10
    If you want to have an insode about thinBasic modules ...
    in thinBasic Journal issue number 2 at page 32 I started to explain what is a thinBasic module and how it works

    Than go into your thinBasic installation directory and check under directory \thinBasic\SDK\
    You will find SDK.ZIP file where there are examples on how to create a thinBasic module but unfortunately not for Pascal. We had for Delphi in the past.
    If there will be real interest I can have a look and revamp it in some way.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Dan
    there's an example on how to make a dll in the demo\win32 folder.
    but it won't compile as is, the compiler does not like the string function length by itself so you need to assign it to a variable, writing it out probably would work also, here's the modified testdll.pas
    the change is in the procedure p1
    {
      Copyright (c) 1998 by Pierre Muller
      Win32 DLL usage example. It needs dlltest.pp
    }
    library testdll;
    function GetModuleFileName(hModule:longint;lpszPath:pchar;cchPath:longint):longint;
      stdcall; external 'kernel32' name 'GetModuleFileNameA';
    procedure beep(ID:longint);
      stdcall; external 'user32' name 'MessageBeep';
    var
      teststr : string;
    procedure P1(var s:string);export;
    var
      p:array[0..255] of char;
      l:integer;
    begin
      l:=length(s);
      getmodulefilename(Hinstance,@p,255);
      writeln('DLL: Hello, I''m DLL ',pchar(@p));
    end;
    procedure P2(x:longint);export;
    begin
      writeln('DLL: Argument X=',x);
      writeln('DLL: New teststr="',teststr,'"');
    end;
    procedure P3(var t);export;
    var
      p : pointer;
    begin
      p:=Addr(T);
      p:=p;
    end;
    procedure P4(x1:pointer);export;
    begin
      Inc(x1);
    end;
    procedure NewExit;
    begin
      beep(0);
      writeln('DLL: Exit from testdll');
    end;
    exports
     P1 index 1,
     P2 name 'Proc2',
     P3,
     P4 resident,
     teststr name 'FPC_string';
    begin
      writeln('DLL: HInstance ',Hinstance,'  PrevInst ',Hprevinst,'  DLLReason ',DLLreason,'  DLLParam ',DLLparam);
      teststr:='DLL init done';
      exitproc:=@newExit;
    end.
    
    Last edited by jack; 20-11-2011 at 17:32.

  4. #4
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    Thanks Johan.

    I found it.

    I think I see the change,

    "l:=length(s);".

    ----------------------------------------------

    So far, making a thinBasic module looks complicated to me.

    Under the example for PowerBasic, I see 6 files called, "UserDefinedLib", with different extensions.

    As of now, from my viewpoint, it looks like magic.

    But many modules exist, so, apparently, people do it.

    Dan
    Last edited by danbaron; 20-11-2011 at 21:57.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  5. #5
    Im still not sure what is thinBasic modul...
    Is this some kind of static lib?

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10
    Quote Originally Posted by danbaron View Post
    So far, making a thinBasic module looks complicated to me.
    Under the example for PowerBasic, I see 6 files called, "UserDefinedLib", with different extensions.
    As of now, from my viewpoint, it looks like magic.
    But many modules exist, so, apparently, people do it.
    The only two important files are:
    1. thinCore.inc
      Consider it as a C header file. Is the interface exposed by thinBasic Core engine to all modules. It contains all the functions avaibale in thinCore.dll (thinBasic Core engine) and thanls to those interfaces your module functions will be able to be executed by a running script.
    2. UserDefinedLib.bas
      Is the example module created to show how to create a thinbasic module.
      Just copy it into another one and personalize it

    Quote Originally Posted by Aurel View Post
    Im still not sure what is thinBasic modul...
    Is this some kind of static lib?
    This is one of those case reading something about is important.
    I strongly suggest to read from page 32 of thinBasic Journal issue number 2.

    In any case nothing strange. A thinBasic module is a standard 32bit DLL that implements 2 important functions: LoadLocalSymbols and possibly, but not mandatory, UnLoadLocalSymbols
    The rest is done by the continuous interaction between Core engine (thinCore.dll) and developed module functions during script execution.

    If you are interested, please give me a very easy function (described with its syntax you would like to have in thinbasic) you would like to have in an hypotetical module and I will write it for you explaining all the steps.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    Very good.

    I was hoping to receive such a reply from you.

    I'm slowly working on things which are compiled.

    This gives me hope that they will be able to be used with thinBasic.

    And therefore, my motivation is increased.

    I will bookmark this thread.

    Thank you.
    Dan.


    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10
    Dan,

    Pascal is my preferred programming language after Basic.

    I'm also motivated to see if FreePascal can be used for developing thinBasic modules. It seems to have all we need to interface numbers, I need to test about dynamic string direct compatibility or some transformations are needed.

    I've just downloaded Lazarus + FreePascal
    My first step will be how to use DLLs from FreePascal. This will open the road to use thinCore.dll

    I cannot promise anything at the moment because I will work on this in my spare time but I will try.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10
    Dear Dan,

    I had some time and I developed a extremely base example of a thinBasic module developed with Free Pascal.
    Module implements a single function called HalfNumber whose syntax is the following:
    n = HalfNumber(AnyNumericExpression) AS Extended
    
    In order to keep things as simple as possible, for the moment I've implemented a function that expects just a numeric expression as input.
    As soon as you have got the whole picture we can see how to develop a new keyword that expects additional parameters.

    Attached all the needed files:
    • a Lazarus project you can open and compile or change as you need.
      It produces the DLL module.
      Attention: if you compile source code by manual, library MUST be compiled using -WR directive (Generate a relocatable library. This library can be moved To another location In memory If the ImageBase address it wants Is already In use)
    • a thinBasic example using such a module
    Here the source code of the Free Pascal module just to have a look at it before downloading.
    library FreePascalExample;
    
    
    {$mode objfpc}{$H+}
    
    
    uses
      Classes, Windows
      { you can add units after this };
    
    
    {$R *.res}
    
    
    
    
    // ------------------------------------------------------
    // thinBasic_LoadSymbol_Delphi is used to declare new keywords in thinBasic language
    function thinBasic_LoadSymbol_Delphi(SymbolName: string; ReturnCode: LongInt; FunctionOrSubPointer: pointer; ForceOverWrite: LongInt = 0): LongInt; stdcall; external 'thinCore.dll';
    // ------------------------------------------------------
    
    
    // Tell thinCore to parse a single numeric expression
    // ------------------------------------------------------
    function thinBasic_Parse1Number (): Extended; stdcall; external 'thinCore.dll' ;
    // ------------------------------------------------------
    
    
    
    
    // ------------------------------------------------------
    // Ok, here we are with our first new thinBasic new keyword function
    // Syntax of the function will be: n = HalfNumber(AnyNumericExpression) AS Extended
    function Exec_HalfNumber(): Extended; stdcall;
    var
      MyExt: Extended;
    begin
         //thinBasic_Parse1Number will parse any numeric expression it will encounter
         //passing back the result of the operation
         MyExt := thinBasic_Parse1Number;
         //Now that we have a number, we can get its half and return result
         Exec_HalfNumber := MyExt / 2;
    end;
    
    
    // ------------------------------------------------------
    // LoadLocalSymbols is automatically executed by thinCore
    // consider LoadLocalSymbols as entry point of the module
    // when "Uses" key is encountered
    // LoadLocalSymbols is the place where all internal module functions
    // must be declared to thinCore using "thinBasic_LoadSymbol_Delphi" function
    // LoadLocalSymbols can also be used to initialize any variable or element needed by module
    // LoadLocalSymbols IS MANDATORY and MUST be present in all thinBasic module
    // ------------------------------------------------------
    function LoadLocalSymbols(sPath: WideString): Longint; cdecl;
    begin
         // messagebox(0, Pointer(sPath),'Hello World from module. Path of module is',MB_OK or MB_ICONSTOP);
    
    
         // here we are telling that the module implements a new thinBasic function called "HalfNumber"
         // and it is connected to Exec_HalfNumber function
         thinBasic_LoadSymbol_Delphi ('HalfNumber', 10, @Exec_HalfNumber, 0);
    
    
         // Just return zero
         LoadLocalSymbols := 0;
    end;
    
    
    
    
    // ------------------------------------------------------
    // UnLoadLocalSymbols is executed by thinCore when thinBasic is going
    // to unload from memory
    // Use UnLoadLocalSymbols to execute any needed module clean up
    // UnLoadLocalSymbols is NOT mandatory to exist
    // ------------------------------------------------------
    function UnLoadLocalSymbols(): Longint; cdecl;
    begin
         UnLoadLocalSymbols := 0;
    end;
    
    
    
    
    exports
           LoadLocalSymbols, UnLoadLocalSymbols;
    end.
    

    Hope this can help to start.
    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    Thank you, I downloaded the folder (I don't know how you do that stuff so fast.).

    I'm already working on something, and, I want to get it to work first.

    http://en.wikipedia.org/wiki/Toom–Cook_multiplication

    First I started it with C, then, I abandoned it and went to PowerBasic, then, I abandoned it and went to Fortran (gfortran).

    Gfortran works good (with Code::Blocks, http://darmar.vgtu.lt/, multi-file projects work approximately perfectly), and, I think before long I should have something to show.

    But, anyway, Toom-Cook is not the fastest way of multiplying big integers, Schonhage-Strassen is faster.

    http://en.wikipedia.org/wiki/Schönhage–Strassen_algorithm

    I am doing Toom-Cook instead of Schonhage-Strassen, because, I understand Toom-Cook, and, I don't understand Schonhage-Strassen.

    Schonhage-Strassen uses the Fast Fourier Transform (FFT), hopefully, in the future I will be able to implement it.

    Both Toom-Cook and Schonhage-Strassen function recursively, so, to me, they are not so easy to do.

    I am just feeling my way along.

    I want to get Toom-Cook to work so that, at least I have something to start with.

    At some point, I would like to implement all of the math functions for arbitrary size large numbers (both integers and floating point), besides arithmetic, also, trig, exponential, log, etc.

    Whether or not being able to calculate the sine of a number to 10,000 decimal places has practical value, people are fascinated by being able to do it.

    So, the whole thing is interesting to me, it's not clear that I can do it, so, it's a challenge, like climbing a mountain.

    Making it (a little at a time) into a thinBasic module, is an additional challenge.

    ----------------------------------------------------------------------------------------------------------------------------------------------

    The first language I ever used at the university to make big projects was Turbo Pascal.

    There, they didn't care what language you used, they only cared about the output you got.

    Then, I abandoned Turbo Pascal for Modula-2.

    Modula-2 is basically Turbo Pascal with units.

    Both Pascal and Modula-2 were created by Niklaus Wirth.

    http://en.wikipedia.org/wiki/Niklaus_Wirth

    ----------------------------------------------------------------------------------------------------------------------------------------------

    I think that for sure I can do everything I want to, using Free Pascal.

    So, if we can get it to cooperate with thinBasic, then, I say, very good.

    (Of course, once you get something to work in one language, it's pretty easy to translate it into another.)

    Dan

    Last edited by danbaron; 22-11-2011 at 08:28.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

Page 1 of 2 12 LastLast

Similar Threads

  1. ThinBASIC works also under Linux
    By martin in forum General
    Replies: 7
    Last Post: 12-03-2013, 08:26
  2. fantasia: how souls works
    By zak in forum Shout Box Area
    Replies: 1
    Last Post: 11-11-2011, 12:38

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
  •