Author Topic: C BASIC  (Read 72633 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
C BASIC - Alternatives
« Reply #150 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.



 


« Last Edit: November 29, 2013, 01:05:08 AM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: C BASIC
« Reply #151 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.


Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C BASIC
« Reply #152 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.

« Last Edit: December 17, 2013, 07:01:58 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
C BASIC OOP
« Reply #153 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 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$


Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
C BASIC - Wine 64 bit
« Reply #154 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>
« Last Edit: January 16, 2014, 09:47:44 PM by John »

Offline Charles Pegge

  • BASIC Developer
  • Posts: 69
Re: C BASIC
« Reply #155 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.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C BASIC
« Reply #156 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.  :-\

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C BASIC - Wine 64 bit
« Reply #157 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)



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



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
« Last Edit: January 19, 2014, 10:54:36 PM by John »