All BASIC

Message Boards => Translators => C BASIC => Topic started by: Charles Pegge on October 23, 2013, 02:53:24 AM

Title: C BASIC
Post by: Charles Pegge on October 23, 2013, 02:53:24 AM
This might be useful for a C emitter  :)

Code: [Select]

  #include <stdio.h>
  #define function
  #define gosub
  #define dim
  #define as
  #define then
  #define sub   void
  #define begin {
  #define end   }
  #define endif }
  #define and   &&
  #define or    ||

  function int main()
  begin
    dim as int a=2;
    sub mysubroutine()
    begin
     if ((a==2)and(a!=1)) then a+=40; else a=0;
    end
    gosub mysubroutine();
    printf("%i",a);
  end
Title: C BASIC
Post by: John on October 23, 2013, 10:05:11 AM
That is very cool Charles. The C #define and macros can make C digestible. Thanks for the interesting perspective.
Title: C BASIC
Post by: kryton9 on October 23, 2013, 07:13:26 PM
That's excellent Charles. I did the brace defines with begin & and, but never thought of the other defines.
Syntax coloring, can make it even more like BASIC
Title: C BASIC
Post by: John on October 23, 2013, 07:23:31 PM
I like that you can define syntax that is nothing more than decorations. (no-op place holders)
Title: C BASIC
Post by: Charles Pegge on October 24, 2013, 01:46:17 PM
Okay lets go hardcore  ;D

This is an exercise in modelling OOP

Code: [Select]

  #include <stdlib.h>
  #include <stdio.h>
  #define function
  #define method
  #define gosub
  #define dim
  #define as
  #define then
  #define sub   void
  #define begin {
  #define end   }
  #define endif }
  #define and   &&
  #define or    ||
  #define class typedef struct
  #define types typedef struct
  #define methods
  #define member ->
  #define addressof &
  #define has =
  #define NewSpace  malloc
  #define FreeSpace free

  #define create(A,B,C) A B=malloc((C)*sizeof(*B))
  #define copy(A,B,C) CopyInts((int*)A,(int*)B,C);

  /*

  ENTITIES
  ========

  Using Vector as a generic model for OOP

  VectorType
  VectorArray
  VectorClass
  VectorClassTable
  VectorMethods
  VectorObject

  NewVector
  FreeVector

  */

  sub CopyInts(int*d,int*s,int n)
  begin
    n=n/sizeof(int);
    int i;
    for (i=0;i<n;i++)
    begin
      *d=*s;
      d++;
      s++;
    end;
  end;


  types VectorStruct
  begin
    float x,y,z;
  end
  VectorType,*VectorArray;


  class VectorClassStruct
  begin
    void*vft;
    int count;
    VectorArray v;
  end
  *VectorObject;


  types VectorClassTableStruct
  begin
    method void  (*Redim)  (VectorObject vv,int n);
    method float (*Assign) (VectorObject vv, int i, float x,float y,float z);
    method float (*Scale)  (VectorObject vv, int i, float s);
  end
  VectorClassTable,*VectorMethods;


  methods

  method void VectorRedim(VectorObject vv,int n)
  begin
    VectorArray va has NewSpace(n*sizeof(VectorType));
    copy(va,vv member v,vv member count*sizeof(VectorType));
    free(vv member v);
    vv member v = va;
    vv member count = n;
  end;

  method float VectorAssign(VectorObject vv, int i, float x,float y,float z)
  begin
    VectorArray w has addressof vv member v[i];
    w member x = x;
    w member y = y;
    w member z = z;
  end;

  method float VectorScale(VectorObject vv,int i, float s)
  begin
    if (vv member count <= i) then VectorRedim(vv,i+16);
    VectorArray w has addressof vv member v[i];
    w member x *= s;
    w member y *= s;
    w member z *= s;
  end;

  function VectorMethods VectorClassTableBuild(void)
  begin
    static VectorClassTable sct;
    VectorMethods vm has addressof sct;
    vm member Redim  has addressof VectorRedim;
    vm member Assign has addressof VectorAssign;
    vm member Scale  has addressof VectorScale;
    return vm;
  end

  function VectorObject NewVector()
  begin
    static VectorMethods vm=0;
    if (vm==0) then vm = VectorClassTableBuild();
    create(VectorObject,vv,1);
    vv member vft = vm;
    vv member count = 16;
    vv member v has NewSpace(16*sizeof(VectorType));
    return vv;
  end

  sub FreeVector(VectorObject vv)
  begin
    FreeSpace(vv member v);
    FreeSpace(vv);
  end


  function int main()
  begin
    VectorObject vo = NewVector();
    printf("%i\n",vo member count);
    VectorMethods vm=vo member vft;
    vm->Assign(vo, 0, 1.0, 2.0, 3.0);
    printf("%f,%f,%f\n", vo member v[0].x, vo member v[0].y, vo member v[0].z);
    FreeVector(vo);
  end;
Title: C BASIC
Post by: John on October 24, 2013, 03:16:27 PM
Output of the above C BASIC program

Code: [Select]
jrs@laptop:~/C_BASIC$ gcc cbas_oop.c
jrs@laptop:~/C_BASIC$ ./a.out
16
1.000000,2.000000,3.000000
jrs@laptop:~/C_BASIC$

(http://nfocentrale.net/images/HardHatArea.gif)

Charles,

I have created this child board for your C BASIC project. Thanks for your contributions!

I guess it would be a good time for me to start digging through Peter's SB macros for hidden treasures.  :o

John
Title: C BASIC
Post by: kryton9 on October 24, 2013, 07:13:16 PM
Look how awesome this is and looks! 
Charles you are amazing!

Now if you can figure out how to use abstract data types, then you only need to make one header file to handle
any type. C++ makes this easy with templates.

I have not dived in depth, but know it can be done in C.

Here is a start (ADT: Abstract Data Type):
http://inst.eecs.berkeley.edu/~selfpace/studyguide/9C.sg/Output/ADTs.in.C.html
Title: C BASIC
Post by: John on October 24, 2013, 07:18:04 PM
How about putting all the BASIC defines in a .h file and keep the application code as close to BASIC as possible?
Title: C BASIC
Post by: Charles Pegge on October 24, 2013, 08:32:40 PM
Sure.

We will also need a set of string functions. Unlike regular Basic, String concatenation will have to be done in an Ellipsis function. Garbage collection will also have to be explicit, as well as OOP setup.

I don't know how far we can go with formal templates but the code is highly adaptable by various substitutions.

I think we can use this as a high-level C emitter for OxygenBasic, so all the hidden operations are made explicit.

Here is mark 3. There are very few traces of C left :)

Code: [Select]

  //#include <stdlib.h>
  #include <stdio.h>

  #define function
  #define method
  #define gosub
  #define dim
  #define as
  #define to
  #define limit
  #define step
  #define then
  #define sub   void
  #define begin {
  #define end   }
  #define endif }
  #define and   &&
  #define or    ||
  #define class typedef struct
  #define types typedef struct
  #define methods
  #define member ->
  #define addressof &
  #define has =
  #define incr ++
  #define decr --
  #define next ++
  #define prior --
  #define byref *
  #define ref   void*
  #define references = &
  #define NewSpace  malloc
  #define FreeSpace free

  #define create(A,B,C) A B=malloc((C)*sizeof(*B))
  #define copy(A,B,C) CopyInts((int*)A,(int*)B,C);

  /*

  ENTITIES
  ========

  Using Vector as a generic model for OOP

  VectorType
  VectorArray
  VectorClass
  VectorClassTable
  VectorMethods
  VectorObject

  NewVector
  FreeVector

  */

  sub CopyInts(int*d,int*s,int count)
  begin
    count /= sizeof(int); //itr beware packed types
    int i;
    for (i=0; limit i<count; step incr i)
    begin
      *d=*s;
      next d;
      next s;
    end;
  end;


  types VectorStruct
  begin
    float x,y,z;
  end
  VectorType,*VectorArray;


  class VectorClassStruct
  begin
    ref         vft;
    int         count;
    VectorArray v;
  end
  *VectorObject;


  types VectorClassTableStruct
  begin
    method void  (byref Redim)  (VectorObject this,int n);
    method float (byref Assign) (VectorObject this, int i, float x,float y,float z);
    method float (byref Scale)  (VectorObject this, int i, float s);
  end
  VectorClassTable,*VectorMethods;


  methods

  method void VectorRedim(VectorObject this, int n)
  begin
    create(VectorArray,va,n);
    copy(to va, this member v, this member count*sizeof(VectorType));
    free(this member v);
    this member v = va;
    this member count = n;
  end;

  method float VectorAssign(VectorObject this, int i, float x,float y,float z)
  begin
    if (this member count <= i) then VectorRedim(this, i+16);
    VectorArray w references this member v[i];
    w member x = x;
    w member y = y;
    w member z = z;
  end;

  method float VectorScale(VectorObject this, int i, float s)
  begin
    if (this member count <= i) then VectorRedim(this, i+16);
    VectorArray w references this member v[i];
    w member x *= s;
    w member y *= s;
    w member z *= s;
  end;

  function VectorMethods VectorClassTableBuild()
  begin
    static VectorClassTable t;
    VectorMethods vm references t;
    vm member Redim  references method VectorRedim;
    vm member Assign references method VectorAssign;
    vm member Scale  references method VectorScale;
    return vm;
  end

  function VectorObject NewVector()
  begin
    static VectorMethods vm;
    if (vm==0) then vm = VectorClassTableBuild();
    create(VectorObject,this,1);
    this member vft = vm;
    this member count = 16;
    this member v has NewSpace(16*sizeof(VectorType));
    return this;
  end

  sub FreeVector(VectorObject this)
  begin
    FreeSpace(this member v);
    FreeSpace(this);
  end


  function int main()
  begin
    VectorObject vo = NewVector();
    VectorMethods vm=vo member vft;
    vm->Assign(vo, 20, 1.0, 2.0, 3.0);
    vm->Scale(vo, 20, 4.0);
    printf("%i\n",vo member count);
    int i=20;
    printf("%f,%f,%f\n", vo member v[i].x, vo member v[i].y, vo member v[i].z);
    FreeVector(vo);
  end;
Title: C BASIC
Post by: John on October 25, 2013, 09:29:17 AM
Charles,

I'm now getting warnings with this version.

jrs@laptop:~/C_BASIC$ gcc cbas_oop2.c
cbas_oop2.c: In function ‘VectorRedim’:
cbas_oop2.c:100:5: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default]
cbas_oop2.c:102:5: warning: incompatible implicit declaration of built-in function ‘free’ [enabled by default]
cbas_oop2.c: In function ‘NewVector’:
cbas_oop2.c:139:5: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default]
cbas_oop2.c: In function ‘FreeVector’:
cbas_oop2.c:148:5: warning: incompatible implicit declaration of built-in function ‘free’ [enabled by default]
jrs@laptop:~/C_BASIC$ ./a.out
36
4.000000,8.000000,12.000000
jrs@laptop:~/C_BASIC$

Title: C BASIC
Post by: AIR on October 25, 2013, 10:28:30 AM
Uncomment stdlib line.
Title: Re: GTK BASIC
Post by: John on October 25, 2013, 11:02:15 AM
Thanks AIR!

jrs@laptop:~/C_BASIC$ gcc cbas_oop2.c
jrs@laptop:~/C_BASIC$ ./a.out
36
4.000000,8.000000,12.000000
jrs@laptop:~/C_BASIC$
Title: C BASIC
Post by: Charles Pegge on October 25, 2013, 12:53:39 PM
I installed the latest MingW, and to my horror I get this when I try to fire up GCC or any of the other apps. My 2009 version presented no problems.

Any ideas?



Title: C BASIC
Post by: John on October 25, 2013, 01:07:25 PM
I would use MinGW from the Nimrod for Windows 32 I posted. That would give you everything you need for C BASIC and allow you to mentor us along on the Nimrod piece as well.

Try adding something more than just gcc for your test.

jrs@laptop:~/C_BASIC$ gcc
gcc: fatal error: no input files
compilation terminated.
jrs@laptop:~/C_BASIC$
Title: C BASIC
Post by: Charles Pegge on October 25, 2013, 02:10:47 PM
Thanks John.

Nimrod icludes gcc version 4.7, and calm is restored.

I am shocked that a bum windows binary of gcc could be distributed (4.8.1). and no direct way of contacting the developers.
Title: C BASIC
Post by: John on October 25, 2013, 02:17:17 PM
Open source developers understand and acknowledge only one method of hearing your problems. Bug Tracker 

This may be related to your 4.8.1 issue.

http://sourceforge.net/p/mingw/bugs/2108/

Title: C BASIC
Post by: Charles Pegge on October 25, 2013, 09:41:28 PM
Yes it looks like the same bug.
Title: C BASIC
Post by: John on October 25, 2013, 10:05:33 PM
Looks like 4.8.1.4 solves the issue. The Nimrod 4.7 seems to work fine for me. I'm still bleeding from other cutting edges.  :D
Title: C BASIC
Post by: Charles Pegge on October 26, 2013, 02:47:31 AM
It has happened before:

http://forums.codeblocks.org/index.php?topic=10936.0

Next time I will make sure I always have a backup of key software.
Title: C BASIC
Post by: kryton9 on October 26, 2013, 02:47:10 PM
Sorry I couldn't get back earlier, you will see why in another post. Glad you got issues resolved.
Hope to get back soon enough.
Title: C BASIC
Post by: John on October 26, 2013, 10:36:29 PM
Charles,

Do you think it would be a lot of work doing a C BASIC version of Wetspot II? We already have a working QuickBASIC and gcc version to work with. My goal with this is to help QB programmers move there favorite games to C using your BASIC like C wrapper. I think there is a potential for a rebirth of retro games if we can get this simple enough to use.

John
Title: C BASIC
Post by: Charles Pegge on October 27, 2013, 10:44:29 PM
Not much work, I would take the GCC version and do symbol substitution. It's cheating slightly but the testing will be smooth. I see you have already been working on it :)

Here is the Basic.c include developed so far: The functions support strings and other dynamic objects.

Code: [Select]
  #include <stdlib.h>
  #include <stdio.h>


  #define function
  #define method
  #define gosub
  #define dim
  #define as
  #define to
  #define limit
  #define step
  #define then
  #define procedure void
  #define sub   void
  #define begin {
  #define end   }
  #define and   &&
  #define or    ||
  #define class typedef struct
  #define types typedef struct
  #define methods
  #define member ->
  #define addressof &
  #define has =
  #define incr ++
  #define decr --
  #define next ++
  #define prior --
  #define byref *
  #define ref   void*
  #define references = &
  #define FreeSpace free

  #define create(A,B,C) A B=NewSpace((C)*sizeof(*B))
  #define copy(A,B,C) CopyInts((int*)A,(int*)B,C)
  #define HiWord(n) ((n>>16)and 0xffff)
  #define LoWord(n) (n and 0xffff)

  //indexbase 1

  function void* NewSpace(int count)
  begin
    char *v =  malloc(count);
    int i;
    for (i=0; limit i<count; step incr i) v[i]=0; // set chars to null
    return (void*) v;
  end

  sub CopyBytes(char*d,char*s,int count)
  begin
    int i;
    for (i=0; limit i<count; step incr i)
    begin
      *d=*s;
      next d;
      next s;
    end;
  end;

  sub CopyWords(char*d,char*s,int count)
  begin
    int i;
    short*v=(short*)d;
    short*w=(short*)s;
    for (i=0; limit i<count; step incr i)
    begin
      *v=*w;
      next v;
      next w;
    end;
  end;

  sub CopyInts(int*d,int*s,int count)
  begin
    count /= sizeof(int); //itr beware packed types
    int i;
    for (i=0; limit i<count; step incr i)
    begin
      *d=*s;
      next d;
      next s;
    end;
  end;

  sub CopyWidth(char*t, int tw, char*s, int sw,int count)
  begin
    int i;
    if ((tw==sw)and(sw==2))
    begin
      CopyWords(s,t,count);
      return;
    end
    for (i=0; limit i<count; step i+=tw)
    begin
      *t=*s;
      t+=tw;
      s+=sw;
    end;
  end;

  function int ByteLen(char*s)
  begin
    int i=0;
    while (s[i]!=0) i++;
    return i;
  end

  function int WordLen(char*s)
  begin
    short*w=(short*)s;
    int i=0;
    while (w[i]!=0) i++;
    return i;
  end

  function int WordFill(char*s, int le, short c)
  begin
    short*w=(short*) s;
    int i=0;
    while (le--) w[i++]=c;
  end
Title: C BASIC
Post by: John on October 27, 2013, 10:57:58 PM
It seems to be going smoothly. I agree an automation tool would be helpful. I feel the IF/THEN/ELSE works fine and I'm on to CASE. I can do the easy stuff if you want concentrate on the no syntax match scenarios. Thanks for the update of your C BASIC library.
Title: C BASIC
Post by: Charles Pegge on October 28, 2013, 01:58:41 AM
switch is almose the same as select case, only you have to insert break; at the end of each case
Title: C BASIC
Post by: John on October 28, 2013, 02:47:42 AM
I just e-mail this to you before seeing this post.

Quote
Charles,

This is what I'm thinking for the C FOR/NEXT translation. I also change
the CASE to use the '_to_' for '..." in ranges. The 'to_' is use with
the FOR/NEXT.

Code: [Select]
  select_case (Game.status)
  begin_select
    case -500 _to_ -3:
      // The enemies are blocked by the clock
      incr Game.status++;
      if(Game.status == -2) then
        // Resumes the enemies
        Game.status = 0;
        if(Game.time < 16) then
          //ChangePal 0
        else_
          //ChangePal -1
        end_if
      end_if
      end_case
    case -2:
      // Do the lightnings
      Game.status = 0;
      for(int i = 0 to_ i < 80 step i++)
      begin_for
        DrawScreen();
      next
Title: C BASIC
Post by: John on October 28, 2013, 11:37:10 PM
I noticed that the C for() doesn't require {} if only a single statement follows. This breaks the current C BASIC rules and doesn't allow for a NEXT. My suggestion is that all C for() executing statement(s) be encased in a BEGIN_FOR/NEXT construct. ({})

C
Code: [Select]
int GetFreeObject()
{
for(int i = 0; i < MAXOBJS; i++)
if(Object[i].typ == 0) return i;

return (MAXOBJS-1);
}

C BASIC
Code: [Select]
FUNCTION int GetFreeObject()
BEGIN_FUNCTION
  FOR(int i = 0 TO i < MAXOBJS STEP i++)
  BEGIN_FOR
    IF(Object[i].typ == 0) THEN_DO RETURN i;
  NEXT
  RETURN (MAXOBJS-1);
END_FUNCTION

Another option is to add another keyword (END_FOR) and make NEXT optional. In the above C example it would look something like this.

Code: [Select]
FUNCTION int GetFreeObject()
BEGIN_FUNCTION
  FOR(int i = 0 TO i < MAXOBJS STEP i++)
    IF(Object[i].typ == 0) THEN_DO RETURN i;
  NEXT
  RETURN (MAXOBJS-1);
END_FUNCTION

Even though the above NEXT is optional, it would break the BASIC way FOR is understood if not use for readability.

If the FOR() executed multiple statements it takes the following formats.

Code: [Select]
FUNCTION int GetFreeObject()
BEGIN_FUNCTION
  FOR(int i = 0 TO i < MAXOBJS STEP i++)
  BEGIN_FOR
    IF(Object[i].typ == 0) THEN_DO RETURN i;
    PRINT i,"\n";
  END_FOR
  NEXT
  RETURN (MAXOBJS-1);
END_FUNCTION

Or without the NEXT.

Code: [Select]
FUNCTION int GetFreeObject()
BEGIN_FUNCTION
  FOR(int i = 0 TO i < MAXOBJS STEP i++)
  BEGIN_FOR
    IF(Object[i].typ == 0) THEN_DO RETURN i;
    PRINT i,"\n";
  END_FOR
  RETURN (MAXOBJS-1);
END_FUNCTION


Title: C BASIC
Post by: Charles Pegge on October 29, 2013, 02:27:43 AM
That is true for all C block constructs. If there is only one statement within the block then curly braces are optional. So including curly braces in all instances, is okay, and may be preferable for translators.

I've adopted the more generic begin..end construct, rather than integrating braces with if .. endif etc. I think the code is quite easy to follow for BASIC programmers, certainly easier to write. With the string library and class generics, I've got nearly 700 lines of sample code so far.

Here is a sample: (these functions also support wide characters)
Code: [Select]
  method StringObject StringRtrim(StringObject this)
  begin
    int i;
    int w=this->width;
    int n=this->count;
    char*c = w * n - w + CharBase(this,0);
    if (w<2)
    begin
      for (i==n-w; to i<=0; step decr i)
      begin
        if (*c>32) then break;
        decr c;
      end
      return StringGetMid(this, 1, i, -1);
    end
    else
    begin
      for (i==n-w; to i<=0; i-=w)
      begin
        if ((c[0]>32)or(c[1] != 0)) then break;
        c+=w;
      end
      return StringGetMid(this, 1, i>>1, -1);
    end
  end


  method int StringInstr(int i, StringObject this,  StringObject k)
  //MATCHING MIXED WIDTHS BUT ONLY ON THE LOWER BYTE
  begin
    char*tb = CharBase(this,0);
    char*tc=tb;
    char*kc=CharBase(k,0);
    char*te=tc+this->count*this->width;
    char*ke=tc+k->count*k->width;
    if (i<0) then i+=this->count+1; // offset from right
    decr i; //indexbase 0
    tc+=i*this->width; // offset
    if (tc>=te) then return 0;
    if (kc>=ke) then return 0;
    char*td;
    char*kd;
    int tw=this->width;
    int kw=k->width;
    while (tc<te)
    begin
      if (*tc==*kc)
      begin
        td=tc;
        kd=kc;     
        while (*td==*kd)
        begin
          td+=tw;
          kd+=kw;
          if (kc==ke) then return ((td-tb)>>(tw-1))+1;
          if (td==te) then return 0;
          if (*td==*tc) then tc=td-1; // possible next match
        end
      end
      tc+=tw;
    end
  end
 

  function StringMethods StringClassTableBuild()
  begin
    static StringClassTable t;
    StringMethods vm references t;
    vm->Redim    references method StringRedim;
    vm->Get      references method StringGet;
    vm->Set      references method StringSet;
    vm->GetChars references method StringGetChars;
    vm->SetChars references method StringSetChars;
    vm->Show     references method StringShow;
    vm->GetMid   references method StringGetMid;
    vm->SetMid   references method StringSetMid;
    vm->Join     references method StringJoin;
    vm->Asc      references method StringAsc;
    vm->Ucase    references method StringUcase;
    vm->Lcase    references method StringLcase;
    vm->Ltrim    references method StringLtrim;
    vm->Rtrim    references method StringRtrim;
    vm->Instr    references method StringInstr;
    return vm;
  end
Title: C BASIC
Post by: John on October 29, 2013, 09:00:04 AM
Quote
I've adopted the more generic begin..end construct, rather than integrating braces with if .. endif etc. I think the code is quite easy to follow for BASIC programmers, certainly easier to write. With the string library and class generics, I've got nearly 700 lines of sample code so far.

It's even easier and less typing to use {}.

Maybe we should call it the BEGIN/END language and tell people it works sort of like Brainfuck.  :o

I guess I got carried away. My attempt may have been a bit verbose but the plan was once they enter their BASIC like program, the user would have the option to run a SB utility that would turn it back into standard C. (keywords revert back to their assigned values) I'll wait until I see where you're going with this before I put any more effort into Wetspot II.

Please post your current #define keyword list so I have a better idea what your thoughts are.
Title: C BASIC
Post by: bigbass on October 29, 2013, 11:30:47 AM
Hey John


The expertise is from Charles Pegge and you !
I like how quickly the C BASIC looking syntax is being developed

*there are similar example demos that I have done for BaCon
with gtk and embedding C and ALIAS'es that could "bridge"
or connect together.

I do see C BASIC as a great prestep to porting code
and a simplified all in one BASIC syntax exchanged with C transparently

the game syntax ported
33 pages ya-ouch but a great test if it compiles and runs in C first


A suggestion have a include file that defines and does whatever macros
that will be needed it would be a light weight porting tool
to convert code to any BASIC

I have been working on this to have some transparent include file for BaCon
gtk2 and gtk3 have to have their own include files (there are still many demo widgets to convert)


Joe



some deps needed to compile the game
I may have other needed deps already installed



libsdl1.2-dev
libsdl-image1.2-dev
libsdl-mixer1.2-dev
Title: C BASIC
Post by: John on October 29, 2013, 11:59:37 AM
Welcome Joe and thanks for joining in on the C BASIC project. Charles is a joy to work with and somehow keeps it on our level.

Armando got SDL2 working on C9 for the project and I'll send you an invite so you can join AIR, Kent, Daniel and me.  I will try to install the needed SDL2 additions you posted that doesn't come with the standard distro that Wetspot II requires. If all possible, I want to standardize on SDL2 going forward. If we are going to attract QB/PB programmers, they will expect a transparent DOS BASIC graphics library to port the thousands of games feared loss to obsolescence.

The fun doesn't end here. Once the game/app is in C/SDL, C4droid will compile it to an Android APK with touch and other Android UI features.

Title: C BASIC
Post by: Charles Pegge on October 29, 2013, 01:04:35 PM
John, I have added your capitalised symbols to the list. 2 small changes to support pre-increment and pre-decrement. So we have a choice of coding styles.

  #define INCR ++
  #define DECR --

Code: [Select]
  #define function
  #define method
  #define gosub
  #define dim
  #define as
  #define to
  #define limit
  #define step
  #define then
  #define procedure void
  #define sub   void
  #define begin {
  #define end   }
  #define and   &&
  #define or    ||
  #define class typedef struct
  #define types typedef struct
  #define methods
  #define member ->
  #define addressof &
  #define has =
  #define incr ++
  #define decr --
  #define next ++
  #define prior --
  #define byref *
  #define ref   void*
  #define references = &
  #define FreeSpace free

  #define FUNCTION
  #define BEGIN_FUNCTION {
  #define END_FUNCTION }
  #define SUB void
  #define BEGIN_SUB {
  #define END_SUB }
  #define RETURN return
  #define CALL
  #define AND &&
  #define OR ||
  #define MOD %
  #define DIM
  #define AS
  #define LET
  #define INCR ++
  #define DECR --
  #define IF if
  #define BEGIN_IF {
  #define THEN {
  #define THEN_DO
  #define ELSE } else {
  #define END_IF }
  #define FOR for
  #define TO ;
  #define STEP ;
  #define BEGIN_FOR {
  #define NEXT }
  #define SELECT_CASE switch
  #define BEGIN_SELECT {
  #define CASE case
  #define _TO_ ...
  #define END_CASE break;
  #define CASE_ELSE default:
  #define END_SELECT }
  #define DO do {
  #define WHILE } while
Title: C BASIC
Post by: John on October 29, 2013, 01:15:32 PM
Great!

BK BASIC Have it your way. Burger King would be proud.   :-*

I think you touched on an importand aspect of C BASIC, that it is merely an illusion with heavy equipment (string lib / SDL) thinking it's BASIC.

Just in time for Halloween.  ;D

Title: C BASIC
Post by: John on October 29, 2013, 02:03:57 PM
My vote to keep things consistent and simple is to require encapsulating {} brackets for ALL constructs even though C doesn't require them for single statement constructs. It will help make both Charles's abbreviated version of C BASIC and my full flavored version easier to swap preferred keywords with each other.

@Charles - Sorry for sounding harsh about your abbreviated version as I realized after my post that you are also doing this as part of your C emitter for O2. The more BASiC looking version I'm doing and with hope of Joe's help is targeted at the QB/PB programmer looking for a way to extend that environments life.

Title: C BASIC
Post by: Charles Pegge on October 29, 2013, 04:35:41 PM
Well, it's still a very small list, but dramatically improves the readability of C code.

I find it quite easy to code in this way, and I hope to deliver the first of my heavy doughnuts with a further days testing: the StringClass for dynamic strings, which should also serve as a template for other kinds of objects.

Unfortunately, with the limitations of C syntax, you can't disguise dynamic strings to make them look like Basic strings, so we really need translators to reformulate the source and insert all the extras which are hidden from view in Basic.
Title: C BASIC
Post by: John on October 29, 2013, 04:43:31 PM
What we can't do in a #define, we should be able to handle with a macro and there is always the .h include closet to hide things in.

Title: C BASIC
Post by: kryton9 on October 29, 2013, 06:07:08 PM
Amazing progress guys, thanks.
Title: C BASIC - dynamic string functions
Post by: John on October 30, 2013, 05:19:20 PM
Quote from: Charles Pegge - thinBasic forum
I'm testing out some dynamic string functions:

Code: [Select]
  types StringClassTableStruct
  begin
    method StringObject (byref Redim)   (StringObject*pthis, int n, int wi, int cnt);
    method StringObject (byref Get)     (StringObject*r, StringObject this);
    method StringObject (byref Set)     (StringObject*pthis, StringObject s);
    method char*        (byref GetChars)(char**r, StringObject this, int wi);
    method StringObject (byref SetChars)(StringObject*pthis, char*c, int le, int wi);
    method StringObject (byref GetMid)  (StringObject*r, StringObject this, int s, int le, int wi);
    method StringObject (byref SetMid)  (StringObject*pthis, StringObject s, int i);
    method StringObject (byref Join)    (StringObject*pthis, int n,...);
    method StringObject (byref Ucase)   (StringObject*r, StringObject this);
    method StringObject (byref Lcase)   (StringObject*r, StringObject this);
    method StringObject (byref Ltrim)   (StringObject*r, StringObject this);
    method StringObject (byref Rtrim)   (StringObject*r, StringObject this);
    method StringObject (byref Insert)  (StringObject*pthis, StringObject s, int i);
    method StringObject (byref Delete)  (StringObject*pthis, int i, int le);
    method StringObject (byref Chr)     (StringObject*r, int a, int wi);
    method StringObject (byref Str)     (StringObject*r, double d);
    method int          (byref Show)    (StringObject this);
    method int          (byref Asc)     (StringObject this, int i);   // also supports wide chars
    method int          (byref Instr)   (int i, StringObject this,  StringObject k);
    method double       (byref Val)     (StringObject this);
  end
  StringClassTable,*StringMethods;

@Charles - Can you show an example with our Wetspot2 game in mind of a MID() C BASIC function in actions. Showing how strings are DIM'ed would also be helpful.

Title: Re: C BASIC
Post by: Charles Pegge on October 31, 2013, 11:36:24 AM
The full source code attached.

A few test statements:

Code: [Select]
  function TestStrings()
  begin
    dim as int           char8=1, char16=2, all=-1;
    dim as StringObject  uo=NewString(0,char8);
    dim as StringObject  vo=NewString(0,char8);
    dim as StringObject  wo=NewString(100,char8);
    dim as StringMethods sm=vo->StringMethods;
   
    sm->Show(vo);
    sm->SetChars(&uo,"LO",all,char8);
    sm->SetChars(&vo," HellO ",all,char8);
    sm->Ltrim(&vo,vo);
    sm->Rtrim(&vo,vo);
    sm->Ucase(&vo,vo);
    sm->Join(&wo,3,vo,vo,vo);
    sm->Show(uo);
    sm->Show(vo);
    sm->Show(wo);
    printf("%i\n",sm->Instr(6,wo,uo));
    sm->Lcase(&wo,wo);
    sm->Insert(&wo,uo,6);
    sm->Show(wo);
    sm->Delete(&wo,6,2);
    sm->Show(wo);
    sm->Str(&vo,42.0);
    sm->Show(vo);
    double v=sm->Val(vo);
    printf("%f\n",v);
    sm->SetChars(&vo,"Abc",all,char8);
    sm->Repeat(&wo,vo,7);
    sm->Show(wo);
    sm->Replace(&wo,vo,uo);
    sm->Show(wo);
    sm->Replace(&wo,uo,vo);
    sm->Show(wo);
    sm->SetChars(&uo,"<",all,char8);
    sm->SetChars(&vo,">",all,char8);
    sm->SetChars(&wo,"  Hello World! ",all,char8);
    sm->Show(uo);
    sm->Show(vo);
    sm->Show(wo);
    sm->Join(&wo,3,uo,sm->Ltrim(&wo,sm->Rtrim(&wo,sm->Ucase(&wo,wo))),vo);
    sm->Show(wo);
    sm->Join(&wo,3,uo,wo,vo);
    sm->Set(&vo,wo);
    sm->Show(vo);
    sm->GetMid(&vo,wo,3,6,1);
    sm->Show(vo);
    sm->SetMid(&vo,6,vo);
    sm->Show(vo);

    StringFree(&uo);
    StringFree(&vo);
    StringFree(&wo);
  end
Title: Re: C BASIC
Post by: John on October 31, 2013, 12:16:36 PM
No go on Ubuntu 64.  :-[

jrs@laptop:~/C_BASIC/cbstrlib$ gcc ClassString.c -o cbstrtest
jrs@laptop:~/C_BASIC/cbstrlib$ ./cbstrtest

Segmentation fault (core dumped)
jrs@laptop:~/C_BASIC/cbstrlib$

Windows XP (VirtualBox)

F:\C_BASIC>dir
 Volume in drive F is Dev
 Volume Serial Number is 0C60-620E

 Directory of F:\C_BASIC

10/31/2013  12:20 PM    <DIR>          .
10/31/2013  12:20 PM    <DIR>          ..
10/29/2013  11:10 PM             1,987 Basic.c
10/31/2013  06:23 PM            18,841 ClassString.c
10/31/2013  11:47 AM             5,078 ClassString.zip
09/01/2011  10:48 AM                19 setpath.bat
               4 File(s)         25,925 bytes
               2 Dir(s)  36,116,520,960 bytes free

F:\C_BASIC>gcc ClassString.c -o cbstrtest.exe

F:\C_BASIC>cbstrtest

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH

F:\C_BASIC>
Title: Re: C BASIC
Post by: Charles Pegge on October 31, 2013, 12:24:30 PM
Sounds like a pointer problem. Do you have a 32 bit system?
Title: Re: C BASIC
Post by: John on October 31, 2013, 12:26:19 PM
Sounds like a pointer problem. Do you have a 32 bit system?

I have a Ubuntu 12.04 LTS 32 bit in a VirtualBox. Would that do?
Title: Re: C BASIC
Post by: John on October 31, 2013, 12:32:46 PM
Using the -m32 switch works.

jrs@laptop:~/C_BASIC/cbstrlib$ gcc -m32 ClassString.c -o cbstrtest
jrs@laptop:~/C_BASIC/cbstrlib$ ./cbstrtest

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
jrs@laptop:~/C_BASIC/cbstrlib$
Title: Re: C BASIC
Post by: Charles Pegge on October 31, 2013, 01:36:00 PM
I installed a windows 64 bit MingW (I selected version 4.7.0) and it works fine - produces quite a hunky binary though. (80k)

This link downloads an interactive installer for many different versions of Mingw:

http://sourceforge.net/projects/mingwbuilds/postdownload?source=dlp
Title: Re: C BASIC
Post by: John on October 31, 2013, 01:40:20 PM
I guess that means I have to give up on O2 assist and hope AIR will keep us alive. (on 64 bit Linux)

Code: [Select]
jrs@laptop:~/C_BASIC/cbstrlib$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
jrs@laptop:~/C_BASIC/cbstrlib$
Title: Re: C BASIC
Post by: John on October 31, 2013, 02:06:03 PM
I manually upgraded gcc to 4.7.3 and I'm still getting the seg. fault.

Code: [Select]
jrs@laptop:~/C_BASIC/cbstrlib$ ./cbstrtest

Segmentation fault (core dumped)
jrs@laptop:~/C_BASIC/cbstrlib$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-2ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04)
jrs@laptop:~/C_BASIC/cbstrlib$

That sucks, I can't compile using the -m32 switch any longer.  :'(

jrs@laptop:~/C_BASIC/cbstrlib$ gcc -m32 ClassString.c -o cbstrtest
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
jrs@laptop:~/C_BASIC/cbstrlib$
Title: Re: C BASIC
Post by: kryton9 on October 31, 2013, 02:25:09 PM
I have found this to be the best and most stable release with no worries for Code::Blocks on windows:
You have no external requirements as you do with some mingw releases. This makes exe's that just work!
It supports GDI+ now too.

codeblocks-12.11mingw-setup_user.exe
Berlios download link:    http://prdownload.berlios.de/codeblocks/codeblocks-12.11mingw-setup_user.exe
Sourceforge download link:   http://sourceforge.net/projects/codeblocks/files/Binaries/12.11/Windows/codeblocks-12.11mingw-setup_user.exe
Title: Re: C BASIC
Post by: Charles Pegge on October 31, 2013, 02:33:15 PM
It seems to me that these binary releases of GCC are not comprehensively tested!

I think my pointers are clean anyway, so it's not an obvious error. It will have to be traced by deconstruction.

I don't want to risk Ubuntu64 on my PC at this time  - I already have one Ubuntu disrupting my partitions, albeit not seriously.
Title: Re: C BASIC
Post by: John on October 31, 2013, 02:44:45 PM
I tried going to gcc 4.8 but still no joy.

jrs@laptop:~/C_BASIC/cbstrlib$ gcc --version
gcc (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

jrs@laptop:~/C_BASIC/cbstrlib$

My 32 bit gcc is still screwed as well.

jrs@laptop:~/C_BASIC/cbstrlib$ gcc -m32 ClassString.c -o cbstrtest
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
jrs@laptop:~/C_BASIC/cbstrlib$
Title: Re: C BASIC
Post by: John on October 31, 2013, 02:48:31 PM
Charles,

If you get a free Cloud9 IDE account you can use the C9 (Nimrod) setup we are all using (or the default workspace that comes with your account) to test your stuff.  (Red Hat 64 bit Linux)
Title: Re: C BASIC
Post by: John on October 31, 2013, 02:58:40 PM
I was able to get the -m32 (32 bit Linux executables) on my Ubuntu 12.04 64 bit laptop working again. I found how to upgrade the 32 bit version to gcc 4.8. I still can't run your string library example on 64 bit Linux yet. (compiles fine)

Code: [Select]
jrs@laptop:~/C_BASIC/cbstrlib$ gcc -m32 ClassString.c -o cbstrtest
jrs@laptop:~/C_BASIC/cbstrlib$ ./cbstrtest

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
jrs@laptop:~/C_BASIC/cbstrlib$ gcc --version
gcc (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

jrs@laptop:~/C_BASIC/cbstrlib$ gcc ClassString.c -o cbstrtest
jrs@laptop:~/C_BASIC/cbstrlib$ ./cbstrtest

Segmentation fault (core dumped)
jrs@laptop:~/C_BASIC/cbstrlib$

Code: [Select]
jrs@laptop:~/C_BASIC/cbstrlib$ file cbstrtest
cbstrtest: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x88155d3a448d4b91cafae97a76affb99dfe2b70a, not stripped
jrs@laptop:~/C_BASIC/cbstrlib$ ldd cbstrtest
linux-vdso.so.1 =>  (0x00007fff344f2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f42b12f0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f42b16da000)
jrs@laptop:~/C_BASIC/cbstrlib$

jrs@laptop:~/C_BASIC/cbstrlib$ file cbstrtest
cbstrtest: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x20f2190faea74967e2a989396eb82492b48130b4, not stripped
jrs@laptop:~/C_BASIC/cbstrlib$ ldd cbstrtest
linux-gate.so.1 =>  (0xf7732000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf755e000)
/lib/ld-linux.so.2 (0xf7733000)
jrs@laptop:~/C_BASIC/cbstrlib$


Title: Re: C BASIC
Post by: John on October 31, 2013, 08:32:41 PM
I thought I would mention that the string library Charles wrote is in the abrivated version of C BASIC. Lovin It!

Basic.c
Code: [Select]
  #include <stdlib.h>
  #include <stdio.h>


  #define function
  #define method
  #define gosub
  #define dim
  #define as
  #define to
  #define limit
  #define step
  #define then
  #define procedure void
  #define sub   void
  #define begin {
  #define end   }
  #define and   &&
  #define or    ||
  #define class typedef struct
  #define types typedef struct
  #define member ->
  #define addressof &
  #define has =
  #define incr ++
  #define decr --
  #define next ++
  #define prior --
  #define byref *
  #define ref   void*
  #define references = &
  #define FreeSpace free

  #define FUNCTION
  #define BEGIN_FUNCTION {
  #define END_FUNCTION }
  #define SUB void
  #define BEGIN_SUB {
  #define END_SUB }
  #define RETURN return
  #define CALL
  #define AND &&
  #define OR ||
  #define MOD %
  #define DIM
  #define AS
  #define LET
  #define INCR ++
  #define DECR --
  #define IF if
  #define BEGIN_IF {
  #define THEN {
  #define THEN_DO
  #define ELSE } else {
  #define END_IF }
  #define FOR for
  #define TO ;
  #define STEP ;
  #define BEGIN_FOR {
  #define NEXT }
  #define SELECT_CASE switch
  #define BEGIN_SELECT {
  #define CASE case
  #define _TO_ ...
  #define END_CASE break;
  #define CASE_ELSE default:
  #define END_SELECT }
  #define DO do {
  #define WHILE } while

  #define create(A,B,C) A B=NewSpace((C)*sizeof(*B))
  #define copy(A,B,C) CopyBytes((char*)A,(char*)B,C)
  #define HiWord(n) ((n>>16)and 0xffff)
  #define LoWord(n) (n and 0xffff)

  //indexbase 1

  function void* NewSpace(int count)
  begin
    char *v =  malloc(count);
    int i;
    for (i=0; limit i<count; step incr i) v[i]=0; // set chars to null
    return v;
  end


  sub CopyBytes(void*dv,void*sv,int count)
  begin
    char*s=sv;
    char*d=dv;
    int i;
    for (i=0; limit i<count; step incr i)
    begin
      *d=*s;
      next d;
      next s;
    end
  end

Output

jrs@laptop:~/C_BASIC/cbstrlib$ ./cbstrtest

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
jrs@laptop:~/C_BASIC/cbstrlib$


ClassString.c
Code: [Select]

  #include "Basic.c"

  /*

  ENTITIES:
  =========

  StringType
  CharArray
  StringClass
  StringClassTable
  StringMethods
  StringObject
  StringParameters

  PROCEDURES
  ==========
  New
  Free

  METHODS:
  ========
  Get
  Set
  Move
  Action
  Show
  (other Operations...)
  Translate
  Rotate

  */



  typedef char StringType,*CharArray;

  class StringClassStruct
  begin
    ref    StringMethods;
    int    count;
    int    width;
    int    nbytes;
  end
  StringClass,*StringObject;



  types StringClassTableStruct
  begin
    method StringObject (byref Redim)   (StringObject*pthis, int n, int wi, int cnt);
    method StringObject (byref Set)     (StringObject*pthis, StringObject s);
    method char*        (byref GetChars)(char**r, StringObject this, int wi);
    method StringObject (byref SetChars)(StringObject*pthis, char*c, int le, int wi);
    method StringObject (byref GetMid)  (StringObject*r, StringObject this, int s, int le, int wi);
    method StringObject (byref SetMid)  (StringObject*pthis, int i, StringObject s);
    method StringObject (byref Join)    (StringObject*pthis, int n,...);
    method StringObject (byref Repeat)  (StringObject*pthis, StringObject s ,int n);
    method StringObject (byref Replace) (StringObject*pthis, StringObject f , StringObject r);
    method StringObject (byref Ucase)   (StringObject*r, StringObject this);
    method StringObject (byref Lcase)   (StringObject*r, StringObject this);
    method StringObject (byref Ltrim)   (StringObject*r, StringObject this);
    method StringObject (byref Rtrim)   (StringObject*r, StringObject this);
    method StringObject (byref Insert)  (StringObject*pthis, StringObject s, int i);
    method StringObject (byref Delete)  (StringObject*pthis, int i, int le);
    method StringObject (byref Chr)     (StringObject*r, int a, int wi);
    method StringObject (byref Str)     (StringObject*r, double d);
    method int          (byref Show)    (StringObject this);
    method int          (byref Asc)     (StringObject this, int i);   // also supports wide chars
    method int          (byref Instr)   (int i, StringObject this,  StringObject k);
    method double       (byref Val)     (StringObject this);
  end
  StringClassTable,*StringMethods;

  #define Left(S,I)   GetMid(S,1,(I),-1)
  #define Right(S,I)  GetMid(S,-(I),-1,-1)
  #define aChr(R,N)   Chr(R,N,1)
  #define wChr(R,N)   Chr(R,N,2)


  sub CopyWidth(char*t, int tw, char*s, int sw,int count)
  begin
    int i;
    if(tw==2)
    begin
      if (sw==2)
      begin
        short*ss=(short*) s;
        short*ts=(short*) t;
        for (i=0; limit i<count; step incr i)
        begin
          *ts=*ss;
          incr ts;
          incr ss;
        end
        return;
      end
      if (sw==1)
        begin
        short*ts=(short*) t;
        for (i=0; limit i<count; step incr i)
        begin
          *ts=*s;
          incr ts;
          incr s;
        end
        return;
      end
    end
    // otherwise copy lower bytes only
    for (i=0; limit i<count; step incr i)
    begin
      *t=*s;
      t+=tw;
      s+=sw;
    end
  end


  function int ByteLen(char*s)
  begin
    int i=0;
    while (s[i] !=0 ) i++;
    return i;
  end


  function int WordLen(char*s)
  begin
    short*w=(short*) s;
    int i=0;
    while (w[i] !=0 ) i++;
    return i;
  end


  function int WordFill(char*s, int le, short c)
  begin
    short*w=(short*) s;
    int i=0;
    while (le--) w[i++]=c;
  end


  function CharArray strptr(StringObject s)
  begin
    return (void*) s + sizeof(StringClass);
  end


  function StringObject StringTransfer(StringObject*r,StringObject s)
  begin
    if (*r==s) return s;         // no transfer
    if (*r != 0 ) then free(*r); // free old string
    *r=s;                        // ref new string
    return s;                    // return new string
  end


  function char* CharTransfer(char**r, char*s)
  begin
    if (*r==s) return s;         // no transfer
    if (*r != 0 ) then free(*r); // free old string
    *r=s;                        // ref new string
    return s;                    // return new string
  end



  function StringMethods StringClassTableBuild();


  function StringObject NewString(int nc, int wi)
  begin
    static StringMethods vm;
    if (vm==0) then vm = StringClassTableBuild();
    StringObject this has NewSpace(sizeof(StringClass)+2+nc*wi);
    this->StringMethods = vm;
    this->count = nc;
    this->width = wi;
    this->nbytes=nc*wi;
    return this;
  end


  sub StringFree(StringObject*pthis)
  begin
    StringObject this=*pthis;
    if (this==0) FreeSpace(this);
    *pthis=0;
  end


  //methods

  method StringObject StringRedim(StringObject*pthis, int nc,int wi,int cnt)
  begin
    StringObject this=*pthis;
    int tc=0;
    int tw=1;
    int nb=0;
    if (this)
    begin
      tc=this->count;
      tw=this->width;
      nb=this->nbytes;
    end
    if (wi<0) then wi=tw; //default width
    if ((nb<nc*wi)or(wi != tw)or(nb==0))
    begin
      StringObject v=NewString(nc,wi);
      int n=nc;
      if (n>tc) n=tc;
      if ((this)and(cnt)) then CopyWidth(to strptr(v), wi, strptr(this), tw, n+1);
      return StringTransfer(pthis,v);
    end
    else
    begin
      this member count = nc;
      return this;
    end
  end


  method StringObject StringSet(StringObject*pthis, StringObject s)
  begin
    StringObject this=*pthis;
    if (this->count < s->count) then this = NewString(s->count,this->width);
    CopyWidth(strptr(this),this->width,strptr(s),s->width,s->count);
    return StringTransfer(pthis,this);
  end


  method char* StringGetChars(char**r, StringObject this, int wi)
  begin
    char*s = NewSpace(wi * this->count +2);
    CopyWidth(s, wi, strptr(this), this->width, this->count+1);
    return CharTransfer(r,s);
  end


  method StringObject StringSetChars(StringObject*pthis, char*s, int le, int wi)
  begin
    StringObject this=*pthis;
    if (le<0) then
    begin
      if (wi==2)
      begin
        le=WordLen(s);
      end
      else
      begin
        le=ByteLen(s);
      end     
    end
    StringObject t=this;
    if (this->nbytes < le*wi) then t = NewString(le,this->width);
    char*k=strptr(t);
    int tw = t->width;
    CopyWidth(k, tw, s, wi, le); // autoconvert
    t->count=le;
    k+=le*tw;
    k[0]=0;   // null terminators
    k[1]=0;
    return StringTransfer(pthis,t);
  end


 method StringObject StringGetMid(StringObject*r, StringObject this, int i, int le, int wi)
  begin
    int lt=this member count;
    if (wi<0) then wi=this->width; // default to this width
    if (le<0) then le=lt;          // default max
    if (i<0) then i+=lt+1;         // offset from right
    decr i;                        // indexbase 0
    if (le+i>lt) then le=lt-i;     // clip length
    if (i<0) then i=0; //clamp lower offset
    StringObject s=*r;
    if ((s==0)or(s->nbytes < le*wi)) then s = NewString(le,wi);
    char*k=strptr(s);
    CopyWidth(k, wi, strptr(this)+i*this->width, this->width, le);
    k+=le*wi;
    k[0]=0;
    k[1]=0;
    s->count=le;
    s->width=wi;
    return StringTransfer(r,s);
  end


  method StringObject StringSetMid(StringObject*pthis, int i, StringObject s)
  begin
    StringObject this=*pthis;
    int lt=this member count;
    int le=s member count;
    if (i<0) then i+=1+lt;
    decr i;
    char*k = strptr(this)+ i * this->width;
    if (le+i>=lt) then le = lt-i;
    CopyWidth(k, this->width, strptr(s), s->width, le);
    return this;
  end


  method StringObject StringJoin(StringObject*pthis,int n,...)
  begin
    StringObject c = *pthis;
    int ne=0;
    int i;
    char* k;
    int wid=1;
    StringObject *p=(StringObject*) addressof n;
    StringObject s;
    int tot=0;
    for (i=1; to i<=n; step incr i)
    begin
      s=p[i];
      tot+=s->count;
      if (s->width == 2) then wid=2;
      if(s==c) then ne=1; // force new join-buffer
    end
    if ((ne==1)or(c==0)or( c->nbytes < tot*wid)) then c=NewString(tot,wid);
    char* m = strptr(c);
    for (i=1; to i<=n; step incr i)
    begin
      s=p[i];
      k=strptr(s);
      CopyWidth(m, wid, k, s->width, s->count);
      m+=(s->count * wid);
    end
    m[0]=0; // terminating null byte
    m[1]=0; // terminating null byte (extra for wide strings)
    c->count = tot;
    c->width = wid;
    return StringTransfer(pthis,c);
  end


  method StringObject StringRepeat(StringObject*pthis, StringObject s ,int n)
  begin
    int i;
    char* k=strptr(s);
    int tot=s->count*n;
    int wid=s->width;
    StringObject c = *pthis;
    if ((c==0)or( c->nbytes < tot*wid)) then c=NewString(tot,wid);
    char* m=strptr(c);
    for (i=1; to i<=n; step incr i)
    begin
      CopyWidth(m, wid, k, s->width, s->count);
      m+=(s->count * wid);
    end
    m[0]=0; // terminating null byte
    m[1]=0; // terminating null byte (extra for wide strings)
    c->count = tot;
    c->width = wid;
    return StringTransfer(pthis,c);
  end


  method StringObject StringLcase(StringObject*r, StringObject this)
  begin
    int i;
    int w=this->width;
    int n=this->count;
    StringObject s=*r;
    if ((s==0)or(s != this)) then s = StringSet(&s,this);
    char*c = strptr(s);
    char a;
    for (i=0; to limit i<n; incr i)
    begin
      a=*c;
      if ((a>65)and(a<91)) then *c=a+32;
      c+=w;
    end
    return StringTransfer(r,s);
  end


  method StringObject StringUcase(StringObject*r, StringObject this)
  begin
    int i;
    int w=this->width;
    int n=this->count;
    StringObject s=*r;
    if ((s==0)or(s != this)) then  s = StringSet(&s,this);
    char*c = strptr(s);
    char a;
    for (i=0; to limit i<n; incr i)
    begin
      a=*c;
      if ((a>96)and(a<123)) then *c=a-32;
      c+=w;
    end
    if (*r != this) then return StringTransfer(r,s);
    return this;
  end


  method StringObject StringLtrim(StringObject*r, StringObject this)
  begin
    int i;
    StringObject u=*r;
    int w=this->width;
    int n=this->count;
    char*c = strptr(this);
    if (w<2)
    begin
      i=0;
      while (i++ < n)
      begin
        if (*c>32) then break;
        c+=w;
      end
      return StringTransfer(r,StringGetMid(&u,this,i,-1,w));
    end
    else
    begin
      i=0;
      while (i++ <n)
      begin
        if ((c[0]>32)or(c[1] != 0)) then break;
        c+=w;
      end
      return StringTransfer(r,StringGetMid(&u,this,(i>>1)+1,-1, w));
    end
  end


  method StringObject StringRtrim(StringObject*r, StringObject this)
  begin
    int i;
    StringObject u=*r;
    int w=this->width;
    int n=this->count;
    char*c = w * n - w + strptr(this);
    if (w<2)
    begin
      i=n;
      while(i-- >0)
      begin
        if (*c>32) then break;
        decr c;
      end
      return StringTransfer(r,StringGetMid(&u,this, 1, i+1, -1));
    end
    else
    begin
      i=n;
      while (i-- >0)
      begin
        if ((c[0]>32)or(c[1] != 0)) then break;
        c+=w;
      end
      return StringTransfer(r,StringGetMid(&u,this, 1, (i>>1)+1, -1));
    end
  end

  method StringObject StringInsert(StringObject*pthis, StringObject s, int i)
  begin
    StringObject this=*pthis;
    int c=this->count;
    int w=this->width;
    StringObject tl=NewString(c,w);
    StringObject tr=NewString(c,w);
    StringJoin(pthis,3,StringGetMid(&tl,this,1,i-1,w), s, StringGetMid(&tr,this,i,-1,w));
    StringFree(&tl);
    StringFree(&tr);
    return *pthis;
  end


  method StringObject StringDelete(StringObject*pthis, int i, int le)
  begin
    StringObject this=*pthis;
    int c=this->count;
    int w=this->width;
    StringObject tl=NewString(c,w);
    StringObject tr=NewString(c,w);
    StringJoin(pthis,2,StringGetMid(&tl,this,1,i-1,w), StringGetMid(&tr,this,i+le,-1,w));
    StringFree(&tl);
    StringFree(&tr);
    return *pthis;
  end


  method StringObject StringChr(StringObject*r, int a, int wi)
  begin
    int le=wi;
    StringObject s=*r;
    if ((s==0)or(s->nbytes < le*wi)) then s = NewString(le,wi);
    s->count=le;
    s->width=wi;
    short*k=(short*) strptr(s);
    *k=a;
    return StringTransfer(r,s);
  end


  method StringObject StringStr(StringObject*r, double d)
  begin
    int wi=1;
    int le=32;
    StringObject s=*r;
    if ((s==0)or(s->nbytes < le*wi)) then s = NewString(le,wi);
    char*k=strptr(s);
    sprintf(k,"%f",d);
    s->count=ByteLen(k);
    s->width=wi;
    return StringTransfer(r,s);
  end


  method int StringShow(StringObject this)
  begin
    CharArray w=strptr(this);
    printf("%s\n", w); // itr wide chars
  end


  method int StringAsc(StringObject this, int i)   // also supports wide chars
  begin
    if (i<0) then i+=this->count+1;            // offset from right
    if ((i>this->count)or(i<1)) then return 0; // out of range
    decr i;                                    // indexbase 0
    int wi=this->width;
    if (wi==1) then return *(strptr(this)+i);
    if (wi==2)
    begin
      short *a = (short*)  strptr(this)+i*2;
      return *a;
    end
  end


  method int StringInstr(int i, StringObject this,  StringObject k)
  //MATCHING MIXED WIDTHS BUT ONLY ON THE LOWER BYTE
  begin
    char*tb = strptr(this);
    char*tc=tb;
    char*kc=strptr(k);
    char*te=tc+this->count*this->width;
    char*ke=kc+k->count*k->width;
    if (i > this->count) then return 0;  // offset past end
    if (this->count==0) then return 0;  // null search string
    if (k->count==0) then return i;     // null keyword
    if (i<0) then i+=this->count+1;     // offset from right
    decr i;                             //indexbase 0
    tc+=i*this->width;                  // offset
    char*td;
    char*kd;
    int tw=this->width;
    int kw=k->width;
    while (tc<te)
    begin
      if (*tc==*kc)
      begin
        td=tc;
        kd=kc;     
        while (*td==*kd)
        begin
          td+=tw;
          kd+=kw;
          if (kd==ke) then return ((tc-tb)>>(tw-1))+1; // match complete
          if (td==te) then return 0;                   // end of main string
          if (*td==*tc) then tc=td-tw;                 // possible next match
        end
      end
      tc+=tw;
    end
  end

  method double StringVal(StringObject this)
  begin
  double d;
  sscanf(strptr(this),"%lf ",&d);
  return d;
  end


  method StringObject StringReplace(StringObject*pthis, StringObject f , StringObject r)
  begin
    StringObject this=*pthis;
    if ((this==0)or(f==0)or(r==0)) then return this;
    if ((this->count==0)or(f->count==0)) then return this;
    int n=0;
    int i=1;
    while (i)
    begin
      i=StringInstr(i,this,f);
      if (i)
      begin
        n++;
        i+=f->count;
      end
    end
    n *= (r->count - f->count);
    int tot = n + this->count;
    StringObject c = NewString(tot, this->width);
    char* m = strptr(c);
    int b=1,j=1;
    while (j)
    begin
      j=StringInstr(b,this,f);
      if (j)
      begin
        if (j>b) then CopyWidth(m, c->width,strptr(this)+b-1,this->width,j-b);
        m += c->width * (j-b);
        CopyWidth(m,c->width,strptr(r),r->width,r->count);
        m += c->width * r->count;
        b=j + f->count; // skip by keyword length
      end
    end
    // remainder
    j = this->count + 1;
    if (j>b)
    begin
      CopyWidth(m,c->width,strptr(this)+b-1,this->width,j-b);
      m += c->width * (j-b);
    end
    m[0]=0; // terminating null byte
    m[1]=0; // terminating null byte (extra for wide strings)
    return StringTransfer(pthis,c);
  end


  function StringMethods StringClassTableBuild()
  begin
    static StringClassTable t;
    StringMethods vm references t;
    vm->Redim    references method StringRedim;
    vm->Set      references method StringSet;
    vm->GetChars references method StringGetChars;
    vm->SetChars references method StringSetChars;
    vm->GetMid   references method StringGetMid;
    vm->SetMid   references method StringSetMid;
    vm->Join     references method StringJoin;
    vm->Repeat   references method StringRepeat;
    vm->Replace  references method StringReplace;
    vm->Ucase    references method StringUcase;
    vm->Lcase    references method StringLcase;
    vm->Ltrim    references method StringLtrim;
    vm->Rtrim    references method StringRtrim;
    vm->Insert   references method StringInsert;
    vm->Delete   references method StringDelete;
    vm->Chr      references method StringChr;
    vm->Str      references method StringStr;
    vm->Show     references method StringShow;
    vm->Asc      references method StringAsc;
    vm->Instr    references method StringInstr;
    vm->Val      references method StringVal;
    return vm;
  end

  function TestStrings()
  begin
    dim as int           char8=1, char16=2, all=-1;
    dim as StringObject  uo=NewString(0,char8);
    dim as StringObject  vo=NewString(0,char8);
    dim as StringObject  wo=NewString(100,char8);
    dim as StringMethods sm=vo->StringMethods;
   
    sm->Show(vo);
    sm->SetChars(&uo,"LO",all,char8);
    sm->SetChars(&vo," HellO ",all,char8);
    sm->Ltrim(&vo,vo);
    sm->Rtrim(&vo,vo);
    sm->Ucase(&vo,vo);
    sm->Join(&wo,3,vo,vo,vo);
    sm->Show(uo);
    sm->Show(vo);
    sm->Show(wo);
    printf("%i\n",sm->Instr(6,wo,uo));
    sm->Lcase(&wo,wo);
    sm->Insert(&wo,uo,6);
    sm->Show(wo);
    sm->Delete(&wo,6,2);
    sm->Show(wo);
    sm->Str(&vo,42.0);
    sm->Show(vo);
    double v=sm->Val(vo);
    printf("%f\n",v);
    sm->SetChars(&vo,"Abc",all,char8);
    sm->Repeat(&wo,vo,7);
    sm->Show(wo);
    sm->Replace(&wo,vo,uo);
    sm->Show(wo);
    sm->Replace(&wo,uo,vo);
    sm->Show(wo);
    sm->SetChars(&uo,"<",all,char8);
    sm->SetChars(&vo,">",all,char8);
    sm->SetChars(&wo,"  Hello World! ",all,char8);
    sm->Show(uo);
    sm->Show(vo);
    sm->Show(wo);
    sm->Join(&wo,3,uo,sm->Ltrim(&wo,sm->Rtrim(&wo,sm->Ucase(&wo,wo))),vo);
    sm->Show(wo);
    sm->Join(&wo,3,uo,wo,vo);
    sm->Set(&vo,wo);
    sm->Show(vo);
    sm->GetMid(&vo,wo,3,6,1);
    sm->Show(vo);
    sm->SetMid(&vo,6,vo);
    sm->Show(vo);


    StringFree(&uo);
    StringFree(&vo);
    StringFree(&wo);
  end

  function int main()
  begin
    TestStrings();
  end
Title: Re: C BASIC
Post by: John on October 31, 2013, 09:07:15 PM
Charles,

For grins, I thought I would try compiling your example on CompileOnline</>com. Here is the error message(s) returned. At least it compiled on Ubuntu 64.

Code: [Select]
$gcc main.c util.c -o demo -lm -pthread -lgmp -lreadline 2>&1
/tmp/ccwFWePC.o: In function `NewSpace':
util.c:(.text+0x0): multiple definition of `NewSpace'
/tmp/ccvJm61t.o:main.c:(.text+0x0): first defined here
/tmp/ccwFWePC.o: In function `CopyBytes':
util.c:(.text+0x47): multiple definition of `CopyBytes'
/tmp/ccvJm61t.o:main.c:(.text+0x47): first defined here
collect2: error: ld returned 1 exit status

While ROFL with my CompileOnline attempt, it thought I would play the same trick with C9. He fell for it too.  :)

Code: [Select]
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ ls -l
total 24
-rw-r-----. 1 525387a75973caafd40003a0 525387a75973caafd40003a0  1987 Nov  1 00:17 Basic.c
-rw-r-----. 1 525387a75973caafd40003a0 525387a75973caafd40003a0 18841 Nov  1 00:17 ClassString.c
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ gcc ClassString.c -o cbstrtest
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ ./cbstrtest

Segmentation fault
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $
Title: Re: C BASIC
Post by: John on October 31, 2013, 10:19:44 PM
Charles,

With my trusty Got Here! debugger, I was able to get through the program with three function classes disabled.

Code: [Select]
  function TestStrings()
  begin
    dim as int           char8=1, char16=2, all=-1;
    dim as StringObject  uo=NewString(0,char8);
    dim as StringObject  vo=NewString(0,char8);
    dim as StringObject  wo=NewString(100,char8);
    dim as StringMethods sm=vo->StringMethods;
   
 
    sm->Show(vo);
    sm->SetChars(&uo,"LO",all,char8);
    sm->SetChars(&vo," HellO ",all,char8);
    sm->Ltrim(&vo,vo);
    sm->Rtrim(&vo,vo);
    sm->Ucase(&vo,vo);
//  sm->Join(&wo,3,vo,vo,vo);
    sm->Show(uo);
    sm->Show(vo);
    sm->Show(wo);
    printf("%i\n",sm->Instr(6,wo,uo));
    sm->Lcase(&wo,wo);
//    sm->Insert(&wo,uo,6);
    sm->Show(wo);
//    sm->Delete(&wo,6,2);
    sm->Show(wo);
    sm->Str(&vo,42.0);
    sm->Show(vo);
  double v=sm->Val(vo);
    printf("%f\n",v);
    sm->SetChars(&vo,"Abc",all,char8);
    sm->Repeat(&wo,vo,7);
    sm->Show(wo);
    sm->Replace(&wo,vo,uo);
    sm->Show(wo);
    sm->Replace(&wo,uo,vo);
    sm->Show(wo);
    sm->SetChars(&uo,"<",all,char8);
    sm->SetChars(&vo,">",all,char8);
    sm->SetChars(&wo,"  Hello World! ",all,char8);
    sm->Show(uo);
    sm->Show(vo);
    sm->Show(wo);
//    sm->Join(&wo,3,uo,sm->Ltrim(&wo,sm->Rtrim(&wo,sm->Ucase(&wo,wo))),vo);
    sm->Show(wo);
//    sm->Join(&wo,3,uo,wo,vo);
    sm->Set(&vo,wo);
    sm->Show(vo);
    sm->GetMid(&vo,wo,3,6,1);
    sm->Show(vo);
    sm->SetMid(&vo,6,vo);
    sm->Show(vo);

    StringFree(&uo);
    StringFree(&vo);
    StringFree(&wo);
  end

scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ gcc ClassString.c -o cbstrtest
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ ./cbstrtest

LO
HELLO

28229868


42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
  Hello World!
  Hello World!
Hello
HelloH
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $
Title: Re: C BASIC
Post by: Charles Pegge on October 31, 2013, 11:43:19 PM
Thanks John,

With that info, I know exactly where to look. the insert and delete functions both use join.

It could be the ellipsis "..." failing to support 64 bit integer/pointer params. It is the only feature not used by the other functions.

  method StringObject StringJoin(StringObject*pthis,int n,...)
Title: Re: C BASIC
Post by: John on November 01, 2013, 12:28:13 AM
Don't know if this helps ...

Title: Re: C BASIC
Post by: Charles Pegge on November 01, 2013, 12:55:24 AM
I have swapped the first 2 parameters of join.

This might work..?
Title: Re: C BASIC
Post by: John on November 01, 2013, 01:21:53 AM
Nope.

Code: [Select]
jrs@laptop:~/C_BASIC/cbstrlib$ ./cbstrtest

Segmentation fault (core dumped)
jrs@laptop:~/C_BASIC/cbstrlib$

My gut feeling is since non-delcared variables are being passed in the "..." and the caller doesn't know what is being passed so follows the compiler rules and bumps up to the next larger type. (to be safe) That's all fine and dandy on 32 bit as there is clipping/non-expanding types used but on 64 bit the after burners kick in and blows up your barn.
Title: Re: C BASIC
Post by: Charles Pegge on November 01, 2013, 01:26:21 AM
okay, the ellipsis will have to go. I will use an array instead.
Title: Re: C BASIC
Post by: Charles Pegge on November 01, 2013, 02:08:19 AM
printf uses ellipsis and pointers for printing strings, so logically speaking, it should work.

The problem appears to be specific to GCC linux 64. (I'm now using the GCC win64)

Anyway - this version has no ellipses:

    StringObject c1[ ]={vo,vo,vo};
    sm->Join(3,&wo,c1);
Title: Re: C BASIC
Post by: John on November 01, 2013, 09:16:00 AM
Thanks Charles, works great!

Ubuntu 12.04 LTS 64 bit

jrs@laptop:~/C_BASIC/cbstrlib$ gcc ClassString.c -o strlib
jrs@laptop:~/C_BASIC/cbstrlib$ ./strlib

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
jrs@laptop:~/C_BASIC/cbstrlib$

Cloud9 IDE - Red Hat Linux 64 bit

scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ ./cbstrtest

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $
Title: Re: C BASIC
Post by: Charles Pegge on November 01, 2013, 11:05:45 AM
That's great news, John! I don't think there will be many more 64bit issues.

We can use this code as a template  to build all kinds of objects, though it is quite cumbersome when used directly, compared to Basic String-handling.
Title: Re: C BASIC
Post by: John on November 01, 2013, 11:17:35 AM
I feel it's time we start introducing macros to seamlessly embedded your BASIC string functions into C code.

FWIW CompileOnline.com

Code: [Select]
$gcc main.c util.c -o demo -lm -pthread -lgmp -lreadline 2>&1
/tmp/cc19kTA2.o: In function `NewSpace':
util.c:(.text+0x0): multiple definition of `NewSpace'
/tmp/ccI4TuYH.o:main.c:(.text+0x0): first defined here
/tmp/cc19kTA2.o: In function `CopyBytes':
util.c:(.text+0x47): multiple definition of `CopyBytes'
/tmp/ccI4TuYH.o:main.c:(.text+0x47): first defined here
collect2: error: ld returned 1 exit status

I wonder if it's the default compiler switches he is using? I will try them on C9 and see if I see the same.

scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ gcc ClassString.c -o demo -lm -pthread -lgmp -lreadline
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $ ./demo

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
scriptbasic@nimrod:~/639761/projects/John/C_BASIC/libcbasic $
Title: Re: C BASIC
Post by: AIR on November 01, 2013, 11:44:18 AM
printf uses ellipsis and pointers for printing strings, so logically speaking, it should work.

In most implementations, it also makes use of stdarg (va_list, va_start, va_end).

In MBC, join is done like this:

Code: [Select]
char * join(int n, ...)
{
  int i = n, tmplen = 0;
  char *strtmp, *s_;

  va_list marker;
  va_start(marker, n); // Initialize variable arguments
  while(i-- > 0)
  {
    s_ = va_arg(marker, char *);
    if(s_) tmplen += strlen(s_);
  }
  strtmp = BCX_TmpStr(tmplen);
  va_end(marker); // Reset variable arguments
  i = n;
  va_start(marker, n); // Initialize variable arguments
  while(i-- > 0)
  {
    s_ = va_arg(marker, char *);
    if(s_) strcat(strtmp, s_);
  }
  va_end(marker); // Reset variable arguments
  return strtmp;
}
Title: Re: C BASIC
Post by: kryton9 on November 01, 2013, 11:58:44 AM
Once I get the tutorials finished, I will upload all of these code snippets into the proper branches and hopefully with the tutorials complete, everyone can start using git.
AIR recommends the command line so later today I will make a complete tutorial using the command line too. So users can use Git GUI or Git Bash after today.

Till then the google code site is in a dubious state while I work on it.
Title: C BASIC - CompileOnLine.com
Post by: John on November 01, 2013, 12:08:53 PM
I was able to get Charles's string library compiled on CompileOnLine</>com (http://www.compileonline.com/compile_c_online.php). The trick with getting it working was combining the two C programs into one. The multi-file feature doesn't seem to work for me.
Title: Re: C BASIC
Post by: John on November 01, 2013, 12:51:36 PM
AIR is 100% correct with his comment about using stdarg (va_list, va_start, va_end).  IUP uses it in all of their versions of the code.
Title: C BASIC - String Function Macros
Post by: John on November 02, 2013, 12:58:46 AM
I have added our first set of string related function macros.

Code: [Select]
/* Function MACRO Define's */
  #define LTRIM(x) sm->Ltrim(&x, x)
  #define RTRIM(x) sm->Rtrim(&x, x)
  #define UCASE(x) sm->Ucase(&x, x)
  #define LCASE(x) sm->Lcase(&x, x)

  function TestStrings()
  begin
    dim as int           char8=1, char16=2, all=-1;
    dim as StringObject  uo=NewString(0,char8);
    dim as StringObject  vo=NewString(0,char8);
    dim as StringObject  wo=NewString(100,char8);
    dim as StringMethods sm=vo->StringMethods;
   
    sm->Show(vo);
    sm->SetChars(&uo,"LO",all,char8);
    sm->SetChars(&vo," HellO ",all,char8);
    // sm->Ltrim(&vo,vo);
    LTRIM(vo);
    // sm->Rtrim(&vo,vo);
    RTRIM(vo);
    // sm->Ucase(&vo,vo);
    UCASE(vo);
    StringObject c1[]={vo,vo,vo};
    sm->Join(3,&wo,c1);
    sm->Show(uo);
    sm->Show(vo);
    sm->Show(wo);
    printf("%i\n",sm->Instr(6,wo,uo));
    // sm->Lcase(&wo,wo);
    LCASE(wo);

jrs@laptop:~/C_BASIC/cbstrlib$ ./strlib

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
jrs@laptop:~/C_BASIC/cbstrlib$
Title: Re: C BASIC
Post by: kryton9 on November 02, 2013, 01:37:52 AM
Guys, I think all of this can be done easier once we have abstract data types in place.
You won't need to make StringObject or VectorObject etc.
Also for making classes it will be very handy and having dynamic arrays of any type, linked lists, queses, stacks all that stuff.
Just wanted you to keep that in mind.
Title: Re: C BASIC
Post by: John on November 02, 2013, 01:50:51 AM
I'm creating the C BASIC overlay to C with #define (static & function) as much as possible. We are not creating a new language, just making the one we know compile as a C program. Feel free to fork C BASIC in whatever direction you wish. That's what makes projects like this so much fun.

Title: Re: C BASIC
Post by: kryton9 on November 02, 2013, 01:53:32 AM
Sounds like the right plan. You guys got the main stuff down already in a very short amount of time!
Title: Re: C BASIC
Post by: John on November 02, 2013, 02:07:57 AM
Kent,

I don't want to take anything away from the power of C. What Charles has envisioned is to help BASIC programmers get over their initial fear of C and create simple but useful programs. The Wetspot II QuickBASIC game is a test of the theory with a big reward if it works. We will see nursing homes with old BASIC programmer residents using C BASIC to port their QB DOS games supplementing their Medicaid with Google Play checks. It's all good and just relax and have fun working together as a group. There is no pressure to do more than you can give.

John
Title: Re: C BASIC
Post by: Charles Pegge on November 02, 2013, 12:56:20 PM
The String class, I think is a very good model for abstraction , to create other classes. Most other classes will be a simplification of the string class, in terms of storage and access. This one supports 16bit and 8bit characters, and I am now adding dynamic string arrays.

The string functions can also be called directly without going via the vm (virtual methods) table, which is a little simpler for non-OOP styles of BASIC.

Another test for you, John: Using the ellipsis StdArg protocol demonstrated by Armando. I created a function called JoinN to test ellipsis. It is only called onece in the test code, but that should be sufficient.
Title: Re: C BASIC
Post by: John on November 02, 2013, 01:06:23 PM
Code: [Select]
jrs@laptop:~/C_BASIC/cbstrlib$ gcc ClassString.c -o stdargtest
ClassString.c: In function ‘StringJoinN’:
ClassString.c:449:24: error: expected expression before ‘StringObject’
       s=va_arg(marker, StringObject); // get next StringObject
                        ^
ClassString.c:460:24: error: expected expression before ‘StringObject’
       s=va_arg(marker, StringObject); // get next StringObject
                        ^
jrs@laptop:~/C_BASIC/cbstrlib$

Can you join me on chat to work through this?
Title: Re: C BASIC
Post by: John on November 02, 2013, 01:18:15 PM
My screwup. Unzip renamed your copy of Basic.c and left mine. Works GREAT!

jrs@laptop:~/C_BASIC/cbstrlib$ gcc ClassString.c -o stdargtest
jrs@laptop:~/C_BASIC/cbstrlib$ ./stdargtest

LO
HELLO
HELLOHELLOHELLO
9
helloLOhellohello
hellohellohello
42.000000
42.000000
AbcAbcAbcAbcAbcAbcAbc
LOLOLOLOLOLOLO
AbcAbcAbcAbcAbcAbcAbc
<
>
  Hello World!
<HELLO WORLD!>
<<HELLO WORLD!>>
HELLO
HELLOH
jrs@laptop:~/C_BASIC/cbstrlib$
Title: Re: C BASIC
Post by: Charles Pegge on November 02, 2013, 01:36:32 PM
Thanks John. Yes, I put all the <includes> into Basic.c

<StdArg.h> is the only extra, so you can add it to yours. Thank you Armando for resolving this dilemma.

<math.h> will also be useful.
Title: Re: C BASIC
Post by: John on November 02, 2013, 01:57:20 PM
If the truth were to be known, C was created by a lazy BASIC programmer that can't type.  :)

Code: [Select]
for (i=0; limit i<count; step incr i)
The INCR for STEP is a nice addition. I'm still mulling over the limit vs. TO variation.
Title: Re: C BASIC
Post by: kryton9 on November 02, 2013, 05:04:38 PM
Wanted to Join in for a short bit of Fun.
Quote
#include <stdio.h>
#include <stdlib.h>

#define FOR(x,y) int i;for(i=x;i<=y;i++){
/* #define BEGIN { */
#define NEXT }
int main()
{
    FOR(1,5)
        printf("Hello world!\n");
    NEXT
    return 0;
}
Title: Re: C BASIC
Post by: kryton9 on November 02, 2013, 05:18:37 PM
Join Fun 2, then back to video making :)
Quote
#include <stdio.h>
#include <stdlib.h>

#define BEGIN {
#define FOR(x,y) int i;for(i=x;i<=y;i++){
#define FORS(x,y,z) for(i=x;i<=y;i+=z){
#define NEXT }
#define PRINT(a) printf((a));
#define END return 0;}

int main()
BEGIN
    FOR(1,3)
        PRINT("Join \n")
    NEXT
    FORS(1,10,2)
        PRINT("Fun!\n")
    NEXT
END
Title: Re: C BASIC
Post by: kryton9 on November 02, 2013, 05:25:48 PM
Last one I promise :)
Quote
#include <stdio.h>
#include <stdlib.h>

#define FOR(x,y) int i;for(i=x;i<=y;i++){
#define FORS(x,y,z) for(i=x;i<=y;i+=z){
#define NEXT }
#define PRINT(a) printf((a));
#define START int main(){
#define FINISH return 0;}
#define FINISH_ERROR return 1;}


START
    FOR(1,3)
        PRINT("Join \n")
    NEXT
    FORS(1,10,2)
        PRINT("Fun!\n")
    NEXT
FINISH

Title: Re: C BASIC
Post by: John on November 02, 2013, 05:33:44 PM
I'm glad you're having fun with this!

I knew I shouldn't have posted those function macros. (opening Pandora's box)  :o

I encourage as many creative variations as possible.

Title: Re: C BASIC
Post by: kryton9 on November 02, 2013, 06:24:38 PM
I'm glad you're having fun with this!

I knew I shouldn't have posted those function macros. (opening Pandora's box)  :o

I encourage as many creative variations as possible.

  • Brief - Charles
  • Full flavored traditional - John
  • K BASIC - Kent (currently in too much candy mode)

I want to be a big Thorn in the Side of the C++ Standards Committee for not making things better. I had high hopes for C++11, but after
going through a new book on it. C is the way to go, but with a nice overlay as you guys have started.
With the help here I would love to see a light weight c++ alternative that uses ANSI C underneath so no conflicts or special compilers needed.

So no BASIC in my branch name... CppThorn or perhaps just Thorn or ThornC (The Humanistic Overlay Release of New C )
orC  Overlay Release C
Title: Re: C BASIC
Post by: John on November 02, 2013, 06:37:49 PM
A C++ BASIC is a GREAT idea. Mike (JRS forum member) posted a C++ example that was suppose to be a brain twister but when converted to C BASIC, Hello World could have been its brother.  :D

You have been a C++ / BASIC fan as long as I have know of you. (forums)
Title: Re: C BASIC
Post by: kryton9 on November 02, 2013, 07:09:23 PM
Will give it a shot with the guys here if we can pull it off. The pressure is off because Nimrod is out there and what Oxygen will eventually become, even more so than now.
Title: Re: C BASIC
Post by: AIR on November 02, 2013, 07:39:56 PM
A C++ BASIC is a GREAT idea.

Koff....MBC....Koff....BC9....koff ;D ;D

Just sayin.....

A.
Title: Re: C BASIC
Post by: John on November 02, 2013, 07:47:41 PM
I choked on the MBC/BCX globals.  :(

I'm sure MBC, BaCon and IUP will be valuable resources for the C BASIC project. Do you envision C++ being a lot more work?
Title: Re: C BASIC
Post by: John on November 02, 2013, 08:19:23 PM
This may not be a good comparison but the happy ending to the effort is motivating.

(http://drastic-ds.com/styles/subsilver2/imageset/drastic_logo.png)

Quote
Congrats Exophase and Lordus on surpassing 50.000 sales ( $7.95 a pop) on Google Play in little over a month! You guys deserve the success.
Title: Tease Shot for the Night
Post by: kryton9 on November 03, 2013, 03:28:09 AM
I will go to bed leaving you guys this tease screenshot. This is C?  Yes, it is :)  hehehehehe 6:30am you have to fogive me.

FOR     normal for default step of 1
FORS   normal for with step

FORR    for Reverse default step -1
FORRS    for Reverse with step

I didn't post the code, because I want to get it to a single for function to do all of the above. Too tired now to do it.
Title: C BASIC - #define definitions
Post by: John on November 03, 2013, 06:34:32 PM
Will each of you (Charles excluded) please post your current #define / macro lists? Charles has established the core C BASIC keyword syntax which will be known as the default for C BASIC. All other variations will be treated as sub-projects and maintained by their creators. It's time to share so please get your current lists posted. I will be posting my current QB45 (traditional BASIC) #define list shortly.

C BASIC - Charles's #include(s) and #define(s) as of 2013-11-3
Code: [Select]
  #include <stdarg.h>
  #include <stdlib.h>
  #include <stdio.h>

  #define function
  #define method
  #define gosub
  #define dim
  #define as
  #define to
  #define limit
  #define step
  #define then
  #define procedure void
  #define sub   void
  #define begin {
  #define end   }
  #define and   &&
  #define or    ||
  #define class typedef struct
  #define types typedef struct
  #define member ->
  #define addressof &
  #define has =
  #define incr ++
  #define decr --
  #define next ++
  #define prior --
  #define byref *
  #define ref   void*
  #define references = &
  #define FreeSpace free
Title: C BASIC - QB / Traditional BASIC #define(s)
Post by: John on November 03, 2013, 07:35:56 PM
This is my current list with a focus of converting the Wetspot II once QB now C game to C BASIC. My end goal is Android (C4droid/SDL) and a migration path for the hundreds of DOS games (and their authors/advocates) searching for a new life. If this is a direction you might be interested in co-developing with me, I can use all the help I can get. I have already reached out to forums I feel would be receptive and has an large active community. The Dingoonity.org (http://boards.dingoonity.org/) (22,307 members) has an secondary Android interest which I hope to embellish. Here is a couple links to threads I have going there.

Wetspot II (http://boards.dingoonity.org/gcw-releases/wetspot-2-(preliminary-beta)/) - Thread started by the author of the C version of Wetspot II.

DOSBox (http://boards.dingoonity.org/android-devices/androld-dosbox/) - Started out as a FYI DOSBox for Android thread and has progressed into introducing C4droid and SDL.

Code: [Select]
  #define FUNCTION
  #define BEGIN_FUNCTION {
  #define END_FUNCTION }
  #define SUB void
  #define BEGIN_SUB {
  #define END_SUB }
  #define RETURN return
  #define CALL
  #define AND &&
  #define OR ||
  #define MOD %
  #define DIM
  #define AS
  #define LET
  #define INCR ++
  #define DECR --
  #define IF if
  #define BEGIN_IF {
  #define THEN {
  #define THEN_DO
  #define ELSE } else {
  #define END_IF }
  #define FOR for
  #define TO ;
  #define STEP ;
  #define BEGIN_FOR {
  #define NEXT }
  #define SELECT_CASE switch
  #define BEGIN_SELECT {
  #define CASE case
  #define _TO_ ...
  #define END_CASE break;
  #define CASE_ELSE default:
  #define END_SELECT }
  #define DO do {
  #define WHILE } while

//  Funtion MACRO Define's
  #define LTRIM(x) sm->Ltrim(&x, x)
  #define RTRIM(x) sm->Rtrim(&x, x)
  #define UCASE(x) sm->Ucase(&x, x)
  #define LCASE(x) sm->Lcase(&x, x)
Title: C BASIC - PowerBASIC #define(s)
Post by: John on November 03, 2013, 07:51:42 PM
It would be great if someone would like to take ownership of doing a PowerBASIC version of  the C BASIC #define(s).


Title: Re: C BASIC
Post by: kryton9 on November 03, 2013, 08:09:30 PM
Why aren't you guys using the c-basic-project source code site?

I put the code from the posts to here:
Charles's:
https://code.google.com/p/c-basic-project/source/browse/c_basic.h

John's:
https://code.google.com/p/c-basic-project/source/browse/john/Basic.c

I will put all my code later tonight to the site. Please start using it. You can
do it via the google interface for now.
Title: Re: C BASIC
Post by: John on November 03, 2013, 08:45:20 PM
My folder on Google Code contains what I wish to post at this point. It also contains files you posted I can't delete. I updated my README for the folder with where my head is at the moment with this project.

Title: Re: C BASIC
Post by: kryton9 on November 03, 2013, 08:49:37 PM
John, I see you named it with a c extension. It should be a .h extension. I will delete the one I put up for you and link yours in my previous post.
Title: Re: C BASIC
Post by: John on November 03, 2013, 09:05:09 PM
I would prefer to maintain my own folder with no site default files.
Title: Re: C BASIC
Post by: AIR on November 03, 2013, 09:40:35 PM
Pushed a proof-of-concept C++ implementation.  Not ready for posting here, so please don't.

Read my readme text file.

A.
Title: Re: C BASIC
Post by: kryton9 on November 03, 2013, 10:03:39 PM
I would prefer to maintain my own folder with no site default files.

John, don't understand what that means.
Tell me exactly what you want and I will do it for you.
Do it local on your computer take a screenshot with all trees expanded for your folder
and I can then duplicate that on the google code site for you.
Title: Re: C BASIC
Post by: kryton9 on November 03, 2013, 10:04:24 PM
Pushed a proof-of-concept C++ implementation.  Not ready for posting here, so please don't.

Read my readme text file.

A.
Great will check it out! ... it looks like you are using c++ instead of c
underneath just glancing
Quote
Pushed a proof-of-concept C++ implementation.
I guess that said that it all. Neat looking for sure!
Title: Re: C BASIC
Post by: John on November 03, 2013, 10:49:06 PM
I would prefer to maintain my own folder with no site default files.

John, don't understand what that means.
Tell me exactly what you want and I will do it for you.
Do it local on your computer take a screenshot with all trees expanded for your folder
and I can then duplicate that on the google code site for you.

I don't think we need all the structure at this point as we are still getting started. Remember, we are doing this in our spare time and any additional steps or new things to learn is going to take away from the reason we all came to the party in the first place. Just do what you think will help the project. I don't want to scare anyone away making this too complex. The theme of this project is making things simple and adding all these layers are counter productive. IMHO
Title: Re: C BASIC
Post by: kryton9 on November 03, 2013, 11:01:04 PM
Updated my folder here the first version of for_next
Now that I figured out a clear way to handle nested for loops,
I will converge the various FOR, FORS, FORR, FORRS into 1 FOR

I am trying a different route. Trying to make BASIC like syntax, but
even better than basic original if I can. As you see declaring variables
is at a minimum.

https://code.google.com/p/c-basic-project/source/browse/kent/for_next

Which standard of C are we trying to match?
3.2 K&R C
3.3 ANSI C and ISO C
3.4 C99
3.5 C11
3.6 Embedded C
Title: Re: C BASIC
Post by: kryton9 on November 04, 2013, 01:28:44 AM
I have been reading about the different C standards. I guess C11 is not fully supported yet, but C99 has lots of cool things:

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

I have had problems and this is why:
http://www.mingw.org/wiki/C99


For windows the only free compliant C99 compiler:
Pelles C   Full   Supports all C99 features.[22]
http://en.wikipedia.org/wiki/C99#Implementations

I was using c++ and mingw32 and codeblocks are outstanding for that, but not C,  I think its kind of funny.
Well a good reason to use Pelle C. http://www.smorgasbordet.com/pellesc/

update: My code gave warnings in mingw32 but compiled and ran fine. In PelleC I am getting many errors with the same code.
Title: Re: C BASIC
Post by: AIR on November 04, 2013, 05:37:39 AM
You should fix your warnings.

Have you tried defining USE_MINGW_ANSI_STDIO in your code?

BTW, itoa is NOT a part of the C standard.  I think it's mostly Microsoft-specific, but other compilers have it.  Not GCC on non-Windows platforms, though.

You can try your STR() as a function (just waking up, so quickly thrown together):

Code: [Select]
char* STR(int val){
    static char tmpStr[256]={0};
    int ret=0;
   
    ret = snprintf(tmpStr,256,"%d",val);
    if (ret){
        return tmpStr;
    }else{
        return strncpy(tmpStr,"",1);
    }
}

The above compiles with both gcc and g++ on my Mac.  Just a bunch of printf warnings, because of missing format specifiers in your code.

A.



Title: Re: C BASIC
Post by: AIR on November 04, 2013, 10:20:34 AM
Found a VERY cool utility call ACK (http://beyondgrep.com/).

It's like grep on steroids (grep is a *nix tool to search files for matching strings).

It's written in perl (which is ok on Windows too, because perl is installed with the Git Windows package) which makes it totally cross-platform.

I'm using it to create a Keywords.txt file, without having to manually type in the keywords, or cut and paste.

Here's an example, pulling the keywords out of #define statements:

Code: [Select]
ack '#define (\w+)' cppbas.inc  --output='$1'
And here is the output, ready for piping to a file:
Quote from: OUTPUT
MAIN
ENDMAIN
DECLARE
FUNCTION
ENDFUNCTION
DIM
AS
SUB
ENDSUB
BEGIN
END
AND
OR
CLASS
TYPE
ADDRESS
INCR
DECR
NEXT
PRIOR
BYREF
NOT
IF
THEN
ELSE
ENDIF
FOR
TO
STEP
SELECT
CASE
_TO_
ENDCASE
CASE_ELSE
ENDSELECT
WHILE
CONSTANT
STR
BOOL
integer
INTEGER
VECTOR
MAP
TRUE
FALSE

Now that only shows you your #defines.  What if you also created functions for this project, and wanted to output those including those with a return type identifier like "$" for strings?
Code: [Select]
ack '^FUNCTION \w+ (\w+.|\w+)' cppbasrt.inc  --output='$1''
Quote from: FUNCTION NAMES
REVERSE$
LTRIM$
RTRIM$
TRIM$
LEFT$
MID$
RIGHT$
INSTR
LCASE$
UCASE$
MCASE$
LOADFILE$
SPLITPATH$
ENC$
REPLACE$

And how about outputting the actual function prototypes?
Code: [Select]
ack '^FUNCTION (.+\))' cppbasrt.inc  --output='$1'
Quote from: FUNCTION PROTOTYPES
CSTRING REVERSE$(CSTRING src)
CSTRING LTRIM$ (CSTRING s)
CSTRING RTRIM$ (CSTRING s)
CSTRING TRIM$ (CSTRING s)
CSTRING LEFT$ (CSTRING s, INTEGER length)
CSTRING MID$ (CSTRING s, INTEGER start, INTEGER length)
CSTRING RIGHT$ (CSTRING s, INTEGER length)
INTEGER INSTR (CSTRING  s,CSTRING  match,INTEGER offset)
CSTRING LCASE$ (CSTRING str)
CSTRING UCASE$ (CSTRING str)
CSTRING MCASE$ (CSTRING S)
CSTRING LOADFILE$ (CSTRING N)
CSTRING SPLITPATH$ (CSTRING FPATH, INTEGER mask)
CSTRING ENC$ (CSTRING  A, INTEGER L, INTEGER R)
CSTRING REPLACE$(CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace)

Having the ability to do this so easily will make it easier to document your keywords.

A.
Title: Re: C BASIC
Post by: kryton9 on November 04, 2013, 02:18:50 PM
You should fix your warnings.

Have you tried defining USE_MINGW_ANSI_STDIO in your code?

BTW, itoa is NOT a part of the C standard.  I think it's mostly Microsoft-specific, but other compilers have it.  Not GCC on non-Windows platforms, though.

You can try your STR() as a function (just waking up, so quickly thrown together):

Code: [Select]
char* STR(int val){
    static char tmpStr[256]={0};
    int ret=0;
   
    ret = snprintf(tmpStr,256,"%d",val);
    if (ret){
        return tmpStr;
    }else{
        return strncpy(tmpStr,"",1);
    }
}

The above compiles with both gcc and g++ on my Mac.  Just a bunch of printf warnings, because of missing format specifiers in your code.

A.[/size]

Thanks AIR, but I am trying to go as far as I can with macros and defines. And the warnings I had were similar nothing to worry about warnings.
I got the errors not with gcc(not compliant with all standards), but with PelleC which is compliant with all C standards.

No one has responded to the standard we are all targeting. The standard will have a dramatic effect on what can be done.
For example read this, this morning from Herbert Schildt's "The Complete C Reference 4th Edition":
Quote
Perhaps the most important features added by C99 are the new keywords:
inline
restrict
_Bool
_Complex
_Imaginary
Other major additions include
• Variable-length arrays
• Support for complex arithmetic
• The long long int data type
• The //comment
• The ability to intersperse code and data
• Additions to the preprocessor
• Variable declarations inside the for statement
• Compound literals
• Flexible array structure members
• Designated initializers
• Changes to the printf( ) and scanf( ) family of functions
• The _ _func_ _ predefined identifier
• New libraries and headers
Most of the features added by C99 are innovations created by the standardization committee, of
which many were based on language extensions offered by a variety of C implementations. In a few
cases, however, features were borrowed from C++. The inline keyword and // style comments are
examples. It is important to understand that C99 does not add C++-style classes, inheritance, or
member functions. The consensus of the committee was to keep C as C.
Features Removed
The single most important feature removed by C99 is the ''implicit int" rule. In C89, in many cases
when no explicit type specifier is present, the type int is assumed. This is not allowed by C99. Also
removed is implicit function declaration. In C89, if a function was not declared before it is used, an
implicit declaration is assumed. This is not supported by C99. Both of these changes may require
existing code to be rewritten if compatibility with C99 is desired.
Features Changed
C99 incorporates several changes to existing features. For the most part, these changes expand
features or clarify their meaning. In a few cases, the changes restrict or narrow the applicability of a
feature. Many such changes are small, but a few are quite important, including:
• Increased translation limits
• Extended integer types
• Expanded integer type promotion rules
• Tightening of the return statement
As it affects existing programs, the change to return has the most significant effect because it might
require that code be rewritten slightly.

Thanks for the exporting routines in Perl!!
Title: Re: C BASIC
Post by: John on November 04, 2013, 02:39:02 PM
Quote
No one has responded to the standard we are all targeting.

Not true. It was stated early on that C BASIC core will be developed on all platforms using gcc/g++. Variations can do what they wish.
Title: Re: C BASIC
Post by: kryton9 on November 04, 2013, 02:48:54 PM
But that doesn't specify the standard John, gcc is different levels of compliance on windows vs linux. I provided the links earlier.

Should we all develop in Linux via Virtual Machines or Direct if installed as such?
Title: Re: C BASIC
Post by: John on November 04, 2013, 02:54:01 PM
I think the minimal level of gcc Charles will accept with C BASIC is 4.7.x on ALL platforms.
Title: Re: C BASIC
Post by: AIR on November 04, 2013, 04:09:22 PM
Gcc version doesn't really matter here, I think.

c99 should be as low as we go, if you want to go the std= route.

I generally don't bother though, because you do lose some gnu stuff when you specify that.  Just like you do when you specify gnu99 instead.

What we really need to talk about is what compiler we're going to standardize on.  I'm doing cross-platform stuff, so gcc/g++/clang/clang++ is what I'm prepared to use.  Since I'm on a Mac, and they all tie in to LLVM anyway, it's what I'd like to stick with.

A.
Title: Re: C BASIC
Post by: kryton9 on November 04, 2013, 06:14:41 PM
I know John said gcc and that is fine with me.

This is just for information.
But I just did some tests with PelleC (the most compliant free C compiler)  and all of our C codes fail.
I tried with the following options:
32 bit, C99
64 bit, C99
32 bit, C11
64 bit, C11
They have all the headers for all C99 and C11 plus what is below-- With these all enabled and disabled:
Private #include files
The #include files classified as private are not part of the ISO C11 standard. They are a mix of files from the Posix standard ("a useful selection"), Microsoft, and Pelle.

I will work in a vm linux distro from now on.



Title: Re: C BASIC
Post by: AIR on November 04, 2013, 07:11:45 PM
That's the nature of the beast.

When I was working on the LinuxBC project, we tried backporting what we had created to that point to Windows and PellesC.  Epic Fail.  We would have had to basically rewrite a lot of what we had produced, and decided to not bother since BCX already ran on Windows.  Getting it to run under MinGW was a challenge, but it wasn't until later that it was actually done (Mostly by James Fuller, where you at son?)

Bottom line, PellesC is an excellent C compiler (and more) implementation, but it's not GNU C.  If you want to target the largest possible number of platforms, you really have no choice but to use GNU C/C++.  And there's a wealth of information/examples all over the net that you can tap as well.

A.
Title: Re: C BASIC
Post by: John on November 04, 2013, 07:21:52 PM
Quote
Mostly by James Fuller, where you at son?

I was wondering that myself. James is already a member of the All BASIC forum and I would of thought as soon as you mentioned the C++ BASIC direction you were taking, James would have been jumping on board and helping with your effort. I hope James still likes us.  :-*
Title: C BASIC - Overlay or Translator ?
Post by: John on November 05, 2013, 02:54:20 AM
I was chatting with Armando about his direction with C++ and using the more advanced features it offers over C. AIR has an advantage as he has done this before in a sense with the MBC. (fork of BCX) AIR made the comment that #define(s) and macros are just part of C BASIC and a parser will be needed. I wasn't sure what AIR meant and I had to go. After thinking about it for awhile I'm wondering if AIR is not only going to write a C BASIC overlay for C++ but creating a BASIC to C BASIC converter as well?

I thought the C BASIC project was using #define(s) and making C look more like BASIC. I wasn't prepared for a translator layer as part of this project. I can see a BASIC programmer taking his/her BASIC code and adapting it to C BASIC but with the full knowledge that portions of the BASIC code will need to be translated to C format.

I noticed Kent's last example and the multiple FOR definitions. C only has one format for FOR and I think we have done a good job making it look like BASIC.

Code: [Select]
FOR ( int i = 0 TO i < MAXENEMIES STEP INCR )
BEGIN_FOR
    IF ( Enemy[i].typ > 0 ) THEN_DO CALL KillEnemy(i);
NEXT

With the version of C BASIC I'm forging ahead with, I have no plans to go any further than what you see above as a BASIC like FOR/NEXT loop in C.
Title: Re: C BASIC
Post by: Charles Pegge on November 05, 2013, 07:13:33 AM
Am I right in thinking that Pelles is confined to Windows (and windows Mobile)? I would still be interested to know what kinds of error it generates from GCC-compliant source code.

Compared to the lax ways of Basic, I find GCC nit-picking enough :)

As well as strings, I'm also working on lexing and parsing units and who knows; may be the rest of OxygenBasic will follow. But these should stand on their own as detachable layers.

It's too early to make any posting to GIThub - there would be far too many revisions, but I can maintain a zip here, as a separate thread.
Title: Re: C BASIC
Post by: AIR on November 05, 2013, 10:06:15 AM
It's too early to make any posting to GIThub - there would be far too many revisions, but I can maintain a zip here, as a separate thread.

I've done a total of 17 check-ins in the last 24hrs. Doing so makes it easy to go back to something if I need to.  It also allows one to see the evolution of the "product".

Even a single check-in a day (like at the end of your daily coding session) would be preferable to trying to keep track of which zip file is the most current in the forum.

But of course it's your call...

A.
Title: Re: C BASIC
Post by: John on November 05, 2013, 10:12:37 AM
Thanks Charles for the update. At this early stage I would say working with us on Coud9 IDE so we can all benefit as you go would be great. It would also give you a 64 bit Linux to test on. The site is non-public and we aren't pushing anything to git from there. I would still like to schedule a time where we can all get together on chat and talk about issues and goals.

Title: Re: C BASIC
Post by: kryton9 on November 05, 2013, 01:09:35 PM
Just my opinion here, but what Charles has done in terms of look and feel in OxygenBASIC is the Language of the future. And all of this yet without a proper IDE and all it can bring.
It has clean syntax and lots power and very small footprint. Has a very nice Object Oriented Programming Syntax.

The problem, and again this is just my opinion, is that it should have been written in C++ to take advantage of all the power it has and bring things quicker into OxygenBASIC. Also this would allow other developers to join into the core development.

I think between all of us we could tap into what c++ offers without all the crappy syntax. I think if Charles is willing is to move OxyenBasic towards a foundation written in C++11.
OxygenBasic already has very powerful string capabilities, perhaps that could just be compiled to an obj file and just linked into the new c++?

Modern languages need:
Templating
Operator Overloading
Support for Advanced Data Structures and Algorithms

We just need to make it so much more elegant and pleasant than C++ makes it.

Also mingw supports c++11 pretty well, so we could all work in gcc/g++ on platform of choice and be up to date and Standards Compliant as much as possible as of today.
Title: Re: C BASIC
Post by: kryton9 on November 05, 2013, 02:04:31 PM
Quote
Mostly by James Fuller, where you at son?

I was wondering that myself. James is already a member of the All BASIC forum and I would of thought as soon as you mentioned the C++ BASIC direction you were taking, James would have been jumping on board and helping with your effort. I hope James still likes us.  :-*

Found him here:
http://forum.basicprogramming.org/index.php/topic,3103.0.html
Title: Re: C BASIC
Post by: kryton9 on November 05, 2013, 02:06:19 PM
Am I right in thinking that Pelles is confined to Windows (and windows Mobile)? I would still be interested to know what kinds of error it generates from GCC-compliant source code.

Compared to the lax ways of Basic, I find GCC nit-picking enough :)

As well as strings, I'm also working on lexing and parsing units and who knows; may be the rest of OxygenBasic will follow. But these should stand on their own as detachable layers.

It's too early to make any posting to GIThub - there would be far too many revisions, but I can maintain a zip here, as a separate thread.

It is limited platforms Charles, so I wouldn't bother. At least with GCC you can find help for any problem.
Title: Re: C BASIC
Post by: AIR on November 05, 2013, 03:34:02 PM
Modern languages need:
Templating
Operator Overloading
Support for Advanced Data Structures and Algorithms

We just need to make it so much more elegant and pleasant than C++ makes it.

Sounds like you should take another look at Nimrod.
Title: Re: C BASIC
Post by: kryton9 on November 05, 2013, 04:53:50 PM
I agree Nimrod is really cool and takes the pressure off here. But I think this project if we can get some of the great developers out there to join in, I know we can come up with a game changer.
I know John has been trying for awhile to bring all the talent together, this project could be it.

I installed Manjaro Linux for the third time in a VirtualBox. The reason being, it would let me create a root account, but then it wouldn't let me use it at log in. So I thought, perhaps in my sleepy state I did something wrong-- so I tried it again, and still the same thing. Third time was the charm, normal user install, no root. Now to install the development environment on it. It is based on Arch Linux, so I should never have to install it again. It uses running updates.
Title: Re: C BASIC
Post by: John on November 05, 2013, 06:42:48 PM
I think anyone willing to learn a new high level language should consider Nimrod.
Title: Re: C BASIC
Post by: AIR on November 05, 2013, 07:19:26 PM
It seems like I'm the only one bothering to upload to Github.  Where is the other code?  I'm not doing this by myself, you know, it's supposed to be a collaboration.

At the very least some feedback would be good (Not you, John, you've already helped track down one bug.  Thanks for that!).

At this point, I'm wondering if I should even continue with this.

Hit me up on the IRC channel.

A.
Title: Re: C BASIC
Post by: John on November 05, 2013, 10:22:02 PM
Quote
It seems like I'm the only one bothering to upload to Github.  Where is the other code?  I'm not doing this by myself, you know, it's supposed to be a collaboration.

Maybe you forgot to put out the Free Lunch sign.

(http://cdn5.quotall.com/wp-content/uploads/2013/05/Freelunch.gif)
Title: Re: C BASIC
Post by: kryton9 on November 05, 2013, 11:15:36 PM
First, I believe in this project in one form or another. In a very short time, it has shown in not one way but many ways that this can really be something.

The big BUT, I think we are getting ahead of ourselves and avoiding sitting down, planning and laying things out a bit. And it is going to bite us big time soon.

John, I would call the project leader since he put all of this together and brought us all in at one point or another. On the other hand he is running lots of sites,
and many projects, as he said he is facilitator and has done a bang up job giving us so many tools to work with.

So someone else has to be the projects leader in terms of making this work and head of programming.

We have great test code, but our code does not work on all platforms. John stated he wanted to bring the BASIC guys into the C world, well most BASIC programmers
came from Atari's, Commodores, Sinclairs well you get the idea. Then MS-DOS came to be and we had GW-BASIC, well all of those guys are in the MS Windows world.

I am seeing nothing but incompatibility problems with all our code as I mentioned a few times already. We need to have a meeting, I mean a hangout with video, voice, share desktops etc.
to really hammer out stuff. We need all of us there.

John has posted many times lets all meet, I am the only one who replied with my available times. This is not collaborating and as AIR said is just wasting everyone's time.

Anyways, I am not ranting. I want this to succeed. But we need to be in sync, have a plan a road map and specific goals to meet.

Here is what is happening tonight when I try to run Air's awesome looking code using MingW in Windows (Where GW-BASIC and PoweBasic users are at, which seems to be our target audience).

If we do hangouts, we can record them and upload them to youtube. So if someone misses a meeting, they can watch later and see where the group is at.

My humble suggestions that I think in addition to the wonderful things we already have:
1. Google Drive for easy Collaborative Documentation of Project Objectives, Road Map and status of each phase. We have all sorts of document formats that can be edited very easily by many users in real time.
2. Use the Google Code site we have to store all of the daily latest code snapshots. I am going to make a video on how to do this without Git tonight.
Just a quickie so everyone uses the Google Code site.  Cloud9 is nice, but for experimentation and things in my opinion, not to do this whole project in.
3. We need to schedule when we can meet in a hangout to hammer out all of our opinions in an organized and visual way. I am going to buy a more powerful computer and get a better internet connection just to not hold up the group with my weak netbook and slow internet. But I won't spend the money till I hear that we are all committed to this.

Anyways, the code everyone has put together is outstanding that this project is doable and once we are better organized and can make our case to the programming public the more people we should get like JC Fuller, Daniel and all the talent that is out there.

I hope we can move forward TOGETHER!
Title: Re: C BASIC
Post by: kryton9 on November 06, 2013, 03:51:11 AM
Little update to my code. No warnings and no errors in mingw on windows at least. Its on the google code site.
Title: Re: C BASIC
Post by: AIR on November 06, 2013, 08:10:46 AM
Here is what is happening tonight when I try to run Air's awesome looking code using MingW in Windows (Where GW-BASIC and PoweBasic users are at, which seems to be our target audience).

The missing headers error message under Windows is very easy to fix, which I have done.  Go grab the latest.  I was able to compile and run with both MinGW-32 AND 64.

A.
Title: Re: C BASIC
Post by: kryton9 on November 06, 2013, 10:48:11 AM
Armando, compiles now fine on Windows.
 
I get a few warnings. The reason is that in the string class almost all, if not all ints type parameters are unsigned ints-- you are using signed ints in your sting functions.
I know this is just a demo and a very impressive one at that, but you said we should fix all warnings, so that is why I mentioned it.
Title: Re: C BASIC
Post by: AIR on November 06, 2013, 11:22:45 AM
Really.

What flags are you passing to g++?  I don't get ANY warnings here, using MinGW 4.8.1
Title: Re: C BASIC
Post by: kryton9 on November 06, 2013, 11:56:43 AM
Screenshot with all details Armando.
Title: Re: C BASIC
Post by: AIR on November 06, 2013, 12:53:06 PM
Yeah, I enabled -Wall and saw that on Windows, but not on my Mac compiling using -m32.  When I use the default, or -m64 I don't see it either.

At any rate, it's fixed.  I changed the int's to size_t's, and all is well in the world again.  Works on Mac 32/64 and MinGW 32/64 with no warnings.  Updated the repository.

Thanks for the bug report.

A.
Title: Re: C BASIC
Post by: kryton9 on November 06, 2013, 08:39:59 PM
Air your code is missing from the google code site?
Title: Re: C BASIC
Post by: AIR on November 06, 2013, 08:55:50 PM
Yes.  Placed it in a private repository.
Title: Re: C BASIC
Post by: John on November 06, 2013, 09:07:47 PM
At this point while concepts are still being investigated and nothing is cast in stone, I recommend posting your code on the All BASIC C9 development site to share with the other developers. Post milestones to All BASIC for public feedback and sharing.

Title: Re: C BASIC
Post by: kryton9 on November 07, 2013, 12:54:05 PM
Ok I will move my stuff there today later too.
Title: Re: C BASIC
Post by: John on November 07, 2013, 01:04:47 PM
Sorry Kent!

The main goal of setting up the Google Code site was not as a file repository but a documentation tool. After seeing what Joe did for the BaCon project on Google Code wiki, I was sure that was the way to go. Unfortunately Joe has gone  MIA and this effort may have been for nothing. Until I hear from Joe, I 'm not putting any more time in to Google Code.

Update: Joe has removed himself as a member of All BASIC. He never responded to the e-mails I sent him either. I wouldn't have put all this effort in setting up Google Code if his comments of being interested in the C BASIC project wasn't just BS.

Title: Re: C BASIC
Post by: kryton9 on November 07, 2013, 05:28:57 PM
No worries, I think having 1 site where the experimental code is, is a good idea.  I will remove my videos from youtube to avoid any confusion to anyone stumbling up on them too. See you guys on C9.
Title: Re: C BASIC
Post by: John on November 07, 2013, 05:51:01 PM
Those that might be interested in C BASIC will download the examples we have posted here and try it on their own environment. We aren't offering more than a text file of defines and C libraries from Charles when he is ready to release them.
Title: C BASIC - Google Code
Post by: John on November 07, 2013, 07:54:15 PM
The Google Code site is specifically for Charles's version of C BASIC. Those that are doing variations should request a membership on the All BASIC Cloud9 IDE site and join the other variation developers there. As these versions mature and are ready to release for feedback, public workspaces on the All BASIC C9 IDE account will be made available. Check the All BASIC site frequently for progress of these projects.

It you would like to contribute to the All BASIC C BASIC project, examples and documentation are needed for the core C BASIC implementation. (using Charles Pegge's defines and libraries)

The All BASIC Developer site offers a forum for BASIC (like) authors and advocates/co-developers. If you have questions or would like to share your comments with the group, an IRC/chat and mailing list are available to non-members.

Title: C BASIC - Status Unknown
Post by: John on November 09, 2013, 12:32:46 PM
It seems the C BASIC project as far as a C direction by Charles has faded. I haven't heard anything from Charles and my e-mails are being ignored. I will do what I can to support AIR's JADE effort as it seems to have a lot of promise. I'm not a C++ programmer so I will be sitting in the back of the bus on this trip.



Title: Re: C BASIC
Post by: AIR on November 09, 2013, 01:41:23 PM
OH NO YOU WON'T!

Time to get your hands dirty, Son!  I'm not doing this all by myself, been through that with MBC.  I don't care if anyone sucks at c++, I'm no freaking expert either.

Bottom line:  Either contribute something, or this will fade away too.
Title: Re: C BASIC
Post by: John on November 09, 2013, 01:56:57 PM
Quote
Bottom line:  Either contribute something, or this will fade away too.

I have been contributing.


All I'm saying is that Kent will have to take a more active role. I'm still getting my arms around C. I'm willing to learn. I just don't know how much help I'm going to be.


Title: Re: C BASIC
Post by: kryton9 on November 09, 2013, 05:29:37 PM
Actually what AIR has done is amazing already. He has already gotten it to a point where it is just a matter of selecting the libraries you want to write a wrapper for.
I am in the process of doing simple SDL2 and SFML2 tests, instead of wrappers for those libraries.

I want to see how Jade mixed with the c++ standard code for those libraries looks like.
This way, we won't have to maintain wrapper libraries if it is easy enough to follow.

The SDL examples AIR has made already have some SDL things wrapped to look nice and tidy.

Title: Re: C BASIC
Post by: kryton9 on November 09, 2013, 05:31:48 PM
I know Charles has been busy updating Oxygen to match up with the latest thinBASIC, as there has been some guys using both oxygen and thinbasic to make some nice demos using both and Petr has added new things to tbgl to match their requests. So I am sure that took some time to get that all working.
Title: Re: C BASIC
Post by: Charles Pegge on November 09, 2013, 08:12:57 PM
Hello guys,

I've been very busy over the last week or so on the C project, and had to withdraw myself from any distraction. Unfortunately that means disregarding all email (except for bills and taxes!), though I have endeavoured to follow all your forum deliberations. Email is not a good mode of communication for me.

There are many months of work ahead that I need to do for the OxygenBasic project, and I think this C stuff is going to be a major part of it, and I can post all the components here or GitHub, once they are structurally stable and free of any fundamental design flaws.

My preference is for C over C++, since C is universally available, and covers all the essentials for a translator/emitter - not all distros include C++. Though I am willing to be persuaded otherwise :)

Title: Re: C BASIC
Post by: John on November 09, 2013, 08:24:31 PM
Thanks for the update Charles. The best place to post your code at this point is C9. CINT is installed there for C testing and debugging. There we can all contribute and share ideas. BitBucket is what AIR and I use for our variations. (private repositories / invitation only)

Title: Re: C BASIC
Post by: kryton9 on November 09, 2013, 09:00:49 PM
Hi Charles, you got and have had a vision in your mind and it is coming together. Just keep doing what you are doing and see how far it goes. Nice to hear that C BASIC and what is going on in Oxygen are mind melding together :)
Title: Re: C BASIC
Post by: John on November 11, 2013, 12:31:28 PM
My plan is to get everything working with C BASIC on Linux before making any attempts at WINBox. I think JADE (C++) is a better solution for Windows 64 bit. If Charles wants to support the Windows platform with C BASIC, it would be great.

Title: Re: C BASIC
Post by: John on November 15, 2013, 09:58:04 PM
There are C operators that don't have a traditional BASIC equivalent. I'm trying not to introduce new BASIC keywords when learning the C functionality makes more sense. I think there needs to be a README or something that explains what they mean and do. The idea behind C BASIC to to make C look more like BASIC not convert every C symbol to BASIC syntax. C BASIC is meant to help BASIC programmers become C programmers without the huge learning curve.



Title: Re: C BASIC
Post by: John on November 15, 2013, 11:36:13 PM
I have converted the SDL 1.2 sprites demo to C BASIC in the GUI thread (http://www.allbasic.info/forum/index.php?topic=282.msg3269#msg3269) if you want to have a peek. (Windows XP, Ubuntu 64 & Android)

Title: C BASIC - SDL/OpenGL source code posted
Post by: John on November 22, 2013, 12:20:47 AM
I just finished converting the SDL/OpenGL example to C BASIC (http://www.allbasic.info/forum/index.php?topic=282.msg3274#msg3274). It's impressive to be able to drag the window around the screen and the spinning high color cube doesn't skip a beat. I'm going to try and get it to compile on Android and Windows. I'll post the screen shots like the SDL Sprites demo done earlier.

I didn't have to add any new keywords to cbasic.h and it compiled the first time I tried.  8)
Title: C BASIC - Bitbucket Project Site
Post by: John on November 22, 2013, 10:37:46 AM
I have opened the C BASIC Bitbucket repository / project site to the public for read access and issue tracking. I was told by the IUP author that 3.9 is scheduled for a Nov. 25th 2013 release date. My plan is to convert some of the 3.9 specific demos to C BASIC and get them up on the project site.

Comments and suggestions welcome.

Title: C BASIC - Alternatives
Post by: John on November 28, 2013, 11:59:10 PM
I have to say that I'm totally miffed why everyone is ignoring C BASIC (JADE for the C++ crowd) when we have shown the same program running on Windows (32/64 bit), Linux (64 bit), OSX (64 bit) and Android (ARM native compiled). All I've heard from everyone is that BASIC is dead and no one takes it serious. C isn't dead and the ease of use of BASIC as a syntax seems like a great match. With all the cool code and seemingly bright BASIC programmers behind it, why have they gone brain dead with Microsoft's demise? The only thing I can think of is that all the BASIC programmers are retired or about to do so and learning anything else is a waste of time.

I have a few more years left in me and it couldn't be a better time in (computing) history to capitalize on the dramatic shift how business and the tools being used has opened up new opportunities even as individuals can profit from.  C BASIC (JADE) will have you programming in C/C++ in record time without a major learning curve. There is nothing new here folks. I have been a BASIC advocate for over 35 years. I think C BASIC is a way to extend BASIC's useful life by transitioning it to C. Do we really need to use BASIC to C translators that create unreadable C code which is in essence  a subset of the true power of C? What I have noticed developing C BASIC is that it transforms C's multi-meaning symbolic syntax to understandable flow and the C syntax that isn't masked with C BASIC syntax become easier to read.



 


Title: Re: C BASIC
Post by: AIR on November 29, 2013, 10:24:10 AM
My thoughts:

At the end of the day, people don't care about the implementation details.  They care about the end result.

If we take a look at the most popular languages of the non-C variety, what do they have in common?

They're easy to use, and don't require getting one's "hands dirty" with lower level stuff.

Back when BASIC came with all home computers, that was the big promise.  Today, I believe that is what still determines the popularity of a programming language.  That, and a community where people can talk about and share code/tips for a given language.

Title: Re: C BASIC
Post by: John on December 17, 2013, 06:56:25 PM
Quote from: sean_vn (FreeBASIC Forum) Dec 18, 2013 1:36
C BASIC

I see it as an idea being sketched out. I don't think it is being presented as a finished product. Presumably a light weight compiler is the next step, if that should seem like a good idea. Being able to use C libraries directly is a big advantage. Making .bi files is a joyless task. I kinda liked the Go programming language but they have fundamentally rejected the shared library concept. However shared libraries are the only really successful example of code reuse. Also the internal Go libraries where too big and had too many things I would never need. The ability to return multiple values from a function provides a really great way to do error handling. You can take or leave a returned error signal as you wish. That is much better than the ugly try/catch situation in Java.

I would like a light weight programming language with a simple object orientated system such as with Go. I also would want to be able to do GUI's and graphics very easily, have access to shared libraries and be able to insert assembly language statements (in Intel syntax!).

The C BASIC concept unfolded as multi-directional projects trying to find the best way to convert BASIC code to C. At first the direction was Nimrod as a transitional language to eventually get to C. Charles presented the C BASIC concept as a way to make his C emitter code look more like BASIC using the C preprocessor to redefine C symbols. Armando and I expanding on the concept to create JADE and C BASIC variations of Charles's initial thrust.

Charles has contributed his C BASIC Class Library to the project and the last I heard is working on an expression parser to make using his class library easier to use and more BASIC like. I'm overjoyed how well things have worked out to this point and looking forward to where Charles is going to take this next.

Title: C BASIC OOP
Post by: John on December 18, 2013, 02:10:46 PM
One of the members of the FreeBASIC forum is keeping the flame burning with the C BASIC thread by introducing GObject Introspection (https://wiki.gnome.org/action/show/Projects/GObjectIntrospection) as a way to handle the deficiencies of C. I tried the Hello World Greeter example and thought I would bring up the concept here.

Quote
What is introspection?

GObject introspection is a middleware layer between C libraries (using GObject) and language bindings. The C library can be scanned at compile time and generate a metadata file, in addition to the actual native C library. Then at runtime, language bindings can read this metadata and automatically provide bindings to call into the C library. 

tut-greeter.h
Code: [Select]
/* -*- Mode: c; c-basic-offset: 4 -*-
 *
 * GOBject Introspection Tutorial
 *
 * Written in 2013 by Simon Kågedal Reimer <skagedal@gmail.com>
 *
 * To the extent possible under law, the author have dedicated all
 * copyright and related and neighboring rights to this software to
 * the public domain worldwide. This software is distributed without
 * any warranty.
 *
 * CC0 Public Domain Dedication:
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

#ifndef __TUT_GREETER_H__
#define __TUT_GREETER_H__

#include <glib.h>
#include <glib-object.h>

#define TUT_GREETER_TYPE \
    (tut_greeter_get_type())
#define TUT_GREETER(o) \
    (G_TYPE_CHECK_INSTANCE_CAST ((o), TUT_GREETER_TYPE, TutGreeter))
#define TUT_GREETER_CLASS(c) \
    (G_TYPE_CHECK_CLASS_CAST ((c), TUT_GREETER_TYPE, TutGreeterClass))
#define TUT_IS_GREETER(o) \
    (G_TYPE_CHECK_INSTANCE_TYPE ((o), TUT_GREETER_TYPE))
#define TUT_IS_GREETER_CLASS(c) \
    (G_TYPE_CHECK_CLASS_TYPE ((c),  TUT_GREETER_TYPE))
#define TUT_GREETER_GET_CLASS(o) \
    (G_TYPE_INSTANCE_GET_CLASS ((o), TUT_GREETER_TYPE, TutGreeterClass))

typedef struct _TutGreeter TutGreeter;
typedef struct _TutGreeterPrivate TutGreeterPrivate;
typedef struct _TutGreeterClass TutGreeterClass;

struct _TutGreeter {
    GObject parent;
};

struct _TutGreeterClass {
    GObjectClass parent;
};

GType tut_greeter_get_type () G_GNUC_CONST;

TutGreeter* tut_greeter_new (void);

void tut_greeter_greet (TutGreeter *greeter);

#endif /* __TUT_GREETER_H__ */

tut-greeter.c
Code: [Select]
/* -*- Mode: c; c-basic-offset: 4 -*-
 *
 * GOBject Introspection Tutorial
 *
 * Written in 2013 by Simon Kågedal Reimer <skagedal@gmail.com>
 *
 * To the extent possible under law, the author have dedicated all
 * copyright and related and neighboring rights to this software to
 * the public domain worldwide. This software is distributed without
 * any warranty.
 *
 * CC0 Public Domain Dedication:
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

#include <stdio.h>
#include "tut-greeter.h"

/**
 * SECTION: tut-greeter
 * @short_description: A greeter.
 *
 * The #TutGreeter is a class to display friendly greetings.
 */

G_DEFINE_TYPE (TutGreeter, tut_greeter, G_TYPE_OBJECT)

#define TUT_GREETER_GET_PRIVATE(o) \
    (G_TYPE_INSTANCE_GET_PRIVATE ((o), TUT_GREETER_TYPE, TutGreeterPrivate))

struct _TutGreeterPrivate {
    gchar *greetee; /* The entity to greet */
};

enum
{
    PROP_0,

    PROP_GREETEE,

    N_PROPERTIES
};

static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };

static void
tut_greeter_init (TutGreeter *object)
{
    TutGreeterPrivate *priv = TUT_GREETER_GET_PRIVATE (object);

    priv->greetee = NULL;
}

static void
tut_greeter_finalize (GObject *object)
{
    TutGreeterPrivate *priv = TUT_GREETER_GET_PRIVATE (object);

    g_free (priv->greetee);
    G_OBJECT_CLASS (tut_greeter_parent_class)->finalize (object);
}

static void
tut_greeter_set_property (GObject      *object,
  guint         property_id,
  const GValue *value,
  GParamSpec   *pspec)
{
    TutGreeterPrivate *priv = TUT_GREETER_GET_PRIVATE (object);

    switch (property_id) {
    case PROP_GREETEE:
g_free (priv->greetee);
priv->greetee = g_value_dup_string (value);
break;

    default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
    }
}

static void
tut_greeter_get_property (GObject    *object,
  guint       property_id,
  GValue     *value,
  GParamSpec *pspec)
{
    TutGreeterPrivate *priv = TUT_GREETER_GET_PRIVATE (object);

    switch (property_id) {
    case PROP_GREETEE:
g_value_set_string (value, priv->greetee);
break;

    default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
    }
}

static void
tut_greeter_class_init (TutGreeterClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    object_class->set_property = tut_greeter_set_property;
    object_class->get_property = tut_greeter_get_property;
    object_class->finalize = tut_greeter_finalize;

    /**
     * TutGreeter:greetee:
     *
     * The entity to greet.
     */
    obj_properties[PROP_GREETEE] =
g_param_spec_string ("greetee",
     "Greetee",
     "The entity to greet.",
     "World",
     G_PARAM_READWRITE |
     G_PARAM_CONSTRUCT);

    g_object_class_install_properties (object_class,
       N_PROPERTIES,
       obj_properties);

    g_type_class_add_private (object_class, sizeof (TutGreeterPrivate));
}


/**
 * tut_greeter_new:
 *
 * Allocates a new #TutGreeter.
 *
 * Return value: a new #TutGreeter.
 */
TutGreeter*
tut_greeter_new ()
{
    TutGreeter *greeter;

    greeter = g_object_new (TUT_GREETER_TYPE, NULL);
    return greeter;
}

/**
 * tut_greeter_greet:
 * @greeter: a #TutGreeter
 *
 * Prints a friendly greeting.
 *
 * Return value: nothing.
 */
void
tut_greeter_greet (TutGreeter *greeter)
{
    TutGreeterPrivate *priv;
    g_return_if_fail (greeter != NULL);

    priv = TUT_GREETER_GET_PRIVATE (greeter);

    printf ("Hello, %s!\n", priv->greetee);
}

main.c
Code: [Select]
/* -*- Mode: c; c-basic-offset: 4 -*-
 *
 * GOBject Introspection Tutorial
 *
 * Written in 2013 by Simon Kågedal Reimer <skagedal@gmail.com>
 *
 * To the extent possible under law, the author have dedicated all
 * copyright and related and neighboring rights to this software to
 * the public domain worldwide. This software is distributed without
 * any warranty.
 *
 * CC0 Public Domain Dedication:
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

#include <glib.h>
#include "tut-greeter.h"

int main (int argc, char *argv[])
{
    TutGreeter *greeter;
    g_type_init();
    greeter = tut_greeter_new ();
    tut_greeter_greet (greeter);

    return 0;
}

jrs@laptop:~/C_BASIC/gobjintro$ make
cc `pkg-config --cflags glib-2.0 gobject-2.0` -g    -c -o tut-greeter.o tut-greeter.c
cc `pkg-config --cflags glib-2.0 gobject-2.0` -g    -c -o main.o main.c
cc -o greeter tut-greeter.o main.o `pkg-config --libs glib-2.0 gobject-2.0`
jrs@laptop:~/C_BASIC/gobjintro$ ./greeter
Hello, World!
jrs@laptop:~/C_BASIC/gobjintro$

Title: C BASIC - Wine 64 bit
Post by: John on January 16, 2014, 09:05:34 PM
Charles,

I'm sorry for taking so long to get back to you on your question about if I could compile 64 bit Windows C applications under Wine using gcc 64 bit.

Good News!

Wine Command Console
Code: [Select]
C:\TDM-GCC-64\examples>dir
Volume in drive C has no label.
Volume Serial Number is 0000-0000

Directory of C:\TDM-GCC-64\examples

 1/16/2014   8:55 PM  <DIR>         .
 1/16/2014   8:55 PM  <DIR>         ..
 1/16/2014   8:55 PM            57  hello.c
       1 file                        57 bytes
       2 directories    151,265,079,296 bytes free


C:\TDM-GCC-64\examples>gcc hello.c -o hello

C:\TDM-GCC-64\examples>./hello
Hello World

C:\TDM-GCC-64\examples>

Linux Terminal
Code: [Select]
jrs@laptop:~/.wine/drive_c/TDM-GCC-64/examples$ ls -l
total 132
-rw-rw-r-- 1 jrs jrs     57 Jan 16 20:55 hello.c
-rwxrwxr-x 1 jrs jrs 127203 Jan 16 20:56 hello.exe
jrs@laptop:~/.wine/drive_c/TDM-GCC-64/examples$ file hello.exe
hello.exe: PE32+ executable (console) x86-64, for MS Windows
jrs@laptop:~/.wine/drive_c/TDM-GCC-64/examples$
jrs@laptop:~/.wine/drive_c/TDM-GCC-64/examples$ strip -s hello.exe
jrs@laptop:~/.wine/drive_c/TDM-GCC-64/examples$ ls -l
total 20
-rw-rw-r-- 1 jrs jrs    57 Jan 16 20:55 hello.c
-rwxrwxr-x 1 jrs jrs 15872 Jan 16 21:10 hello.exe
jrs@laptop:~/.wine/drive_c/TDM-GCC-64/examples$

Bad News!

I tried to compile your CBasicStringClassLibrary under TDM-CGG-64 and it defaulted to a 32 bit executable. When I forced the -m64 compiler switch, this is the message I got.

Code: [Select]
C:\c_basic>gcc -m64 Test.c -o Test
Test.c:1:0: sorry, unimplemented: 64-bit mode not compiled in

C:\c_basic>
Title: Re: C BASIC
Post by: Charles Pegge on January 17, 2014, 04:35:39 AM
Ok, I think the question is: can Wine64 run both 32bit and 64bit ms-windows apps, in general.
Title: Re: C BASIC
Post by: John on January 17, 2014, 09:10:56 AM
I tried running the 64 bit version of Notepad.exe from Windows 7 64 bit with no luck.  :-\
Title: Re: C BASIC - Wine 64 bit
Post by: John on January 18, 2014, 06:49:33 PM
Good News!

IUP 3.10 was released and included a 64 bit version of Lua in one of the downloads for Windows 64. I thought I would give it a try under Wine thinking Microsoft Notepad has hidden code to prevent running on Wine. (wouldn't surprise me)

(http://files.allbasic.info/C_BASIC/luawin64.png)

Here is the 64 bit Windows version of 7-Zip running under Wine.

(http://files.allbasic.info/C_BASIC/7zip64wine.png)

FYI: ScriptBasic Windows 64 bit runs on Wine. I tried the version that AIR compiled awhile back with TDM-GCC-64. (SB 2.1) If I can find a 64 bit version of Perl for Windows 64 bit, I will try to compile the SB 2.2 release for Windows 64 bit under Wine.

Wine console
Code: [Select]
Wine CMD Version 5.1.2600 (1.6.1)

Z:\home\jrs>wmic OS get OSArchitecture
OSArchitecture
64-bit

Z:\home\jrs>

XP VirtualBox (cmd console)
Code: [Select]
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\John>wmic OS get OSArchitecture
Node - XPVM
ERROR:
Code = 0x80041017
Description = Invalid query
Facility = WMI

C:\Documents and Settings\John>

It seems Wine is emulating a 64 bit version of XP. :o