May 01, 2024, 01:02:17 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


IWBasic v2.0 progress: compiler

Started by sapero, May 16, 2010, 02:48:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

Quote2. If I'm not mistaking, the IDE doesn't have an auto indent capability when writing code. I really miss this.
I don't know when it was added but I know EB 1.735 has auto indent.
It's down at the botton of the dialog where you set the IDE code colors.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Quote from: sapero on January 20, 2011, 05:31:35 PM
Working on a plugin system for the parser, which will make possible to generate code for any platform/cpu (Windows/Linux/Mac/Arm/Pic/Atmel...), assembler, or additional high level compiler.

Fancy that - my last program was written for the PC, and I was asked if it was
possible to produce it for the Mac, as well. Not at all possible now.
But very possible in the future, methinks. Good news!

Brian

talun

QuoteWorking on a plugin system for the parser, which will make possible to generate code for any platform/cpu (Windows/Linux/Mac/Arm/Pic/Atmel...), assembler, or additional high level compiler.

Console and/or GUI mode?

Sergio

ckoehn

Great!  Now if I can find a compiler for WinCE.  Need it already!!!  Been doing some programming for GPS Units and using eVB which works but is outdated.  ;D

Clint

LarryMc

January 23, 2011, 03:25:10 PM #79 Last Edit: January 24, 2011, 06:21:36 AM by Larry McCaughn
We're getting closer to the release of Ver 2.0.
I'm basically the holdup; trying to get all the changes/enhancements documented in the help file.
I've got it to the floorboard but I'm always slow at documentation.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Logman

Boy, don't I feel stupid. I've been using the IDE for two years now without the indent feature--wishing it had one--and all along it did. I searched in the manual for this and since I didn't initially see it, I've just lived with it.

Thanks  for pointing this our Larry. I sure missed it.

Can't wait for the release of 2.0.

Logman
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

sapero

January 25, 2011, 10:07:05 AM #81 Last Edit: January 25, 2011, 12:02:18 PM by LarryMc
Sergio, what do you mean with gui/console? These two are not related with the compiler, the linker cares about the subsystem.

Added OEM string modifier, to create strings with diacritical characters, which can be displayed in console window without calling CharToOem api:
print OEM"Ã,,…äáàâã"
Internally the string is encoded to an unicode string using the current codepage, then CharToOemW api is called, to convert it to console OEM. This api on Windows ME/98/95 is supported by Microsoft layer for unicode, so you will need to install it on the older systems, if you want to compile prorams with the OEM modifier.
The compiler will warn you if it fails to load unicows.dll.
On Windows 2000 or newer, the required api is available in user32.dll.

I have now a question: how would you like to set IWBasic IDE to unicode mode (utf8) ?
a) File/New/IWBasic unicode source file.
b) a popup menu named "Encoding" with ansi and utf8 items.
c) other (describe).

Barney

Quote from: sapero on January 25, 2011, 10:07:05 AM
I have now a question: how would you like to set IWBasic IDE to unicode mode (utf8) ?
a) File/New/IWBasic unicode source file.
b) a popup menu named "Encoding" with ansi and utf8 items.
c) other (describe).
a option is probably the best for most users
I'd prefer b option but not as a popup menu. A switch on the toolbar will do nicely.

Barney

talun


QuoteSergio, what do you mean with gui/console? These two are not related with the compiler, the linker cares about the subsystem.

Hi Sapero,

I'm sorry but I was unclear.
I wanted to know if you can create GUI applications using the normal IWBASIC syntax without having to resort to specific functions of the operating system (linux, MAC...).

bye

Sergio

sapero

Hopefully, the compiler's plugin will be responsible for conversion of the internal Basic commands for the target operating system.
Any configuration will be passed to the compiler in some universal form, for example: in the $OPTION directive:
$OPTION "plugin linux\qt.dll option1=value1 option2=value2 ..."

For example a plugin for Android OS could generate a complete java project, and then launch apkbuilder.bat to create an .apk file (or an native Linux executable) ready to upload to user's phone.

Egil

Quote from: sapero on January 25, 2011, 10:07:05 AM
I have now a question: how would you like to set IWBasic IDE to unicode mode (utf8) ?
a) File/New/IWBasic unicode source file.
b) a popup menu named "Encoding" with ansi and utf8 items.
c) other (describe).

Option a would be my choice :)

Egil
Support Amateur Radio  -  Have a ham  for dinner!

sapero

January 27, 2011, 04:15:56 AM #86 Last Edit: January 27, 2011, 05:08:01 AM by sapero
Added $MACRO directive:
$macro sum(a,b) (a+b)
$macro sum(a,b,c) (a+b+c)

print sum(1,2)
print sum(1,2,4)


A macro will override a function with the same name and number of parameters:
declare import,sum(int a,int b),int
declare import,sum(int a,int b,int c),int
print sum(1,2) ' function
$macro sum(a,b) (a+b)
print sum(1,2) ' macro
print sum(1,2,3) ' function


You can call a function from inside your macro:
$macro ListboxDeleteAllItems(win,id) (SENDMESSAGE(win,LB_RESETCONTENT,0,0,id))

ListboxDeleteAllItems(d1,IDC_MYLISTBOX)


A macro can be undefined: $UNDEF MacroName NumberOfParameters
$undef sum 2
$endef sum 3


To check if a macro is defined, use $IFDEF MacroName.

Logman

Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

sapero

January 28, 2011, 12:07:14 PM #88 Last Edit: January 29, 2011, 04:41:29 AM by sapero
Macros are supported in enumerations and $IF conditions.

Added a special macro: defined(name) - returns TRUE if the parameter 'name' is defined. The 'defined' keyword is now reserved.
$define MYCOND
$define WIN32
'$define MAC

$if defined(WIN32) && defined(MAC)
$error "WIN32 and MAC is defined"
$elif defined(WIN32) && defined(MYCOND)
$error "WIN32 and MYCOND is defined"
$elif defined(WIN32) && !defined(MYCOND)
$error "WIN32 is defined, but MYCOND is not defined"
$elif defined(MAC) && defined(MYCOND)
$error "MAC and MYCOND is defined"
$elif defined(MAC) && !defined(MYCOND)
$error "MAC is defined, but MYCOND is not defined"
$else
$error "unhandled case"
$endif


The look-up precedence in macros is:
1. symbols from macro definition - $macro name(this, and_this) (expression)
2. variables
3. constants
So if you refer "A" symbol in a macro, the compiler will first try to find macro parameter A, then A variable, and finally an constant A.

LarryMc

As I mentioned earlier I'm working on the Docs for Ver 2.0.
Right now I figure I'm around 1/2 way through adding all that needs to be added to support the V2.0 changes (not including what Sapero has added in the last few days).

I generated a PDF help file a few minutes ago.  It has 86 more pages than the version I have that came with EB 1.737.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

WayneA

This is an exciting time in the history of IBasic and its derivatives.

Great work sapero!
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

sapero

January 30, 2011, 03:11:26 AM #91 Last Edit: February 10, 2011, 04:51:57 AM by sapero
Thanks!
Added support for multiple expressions in a single macro, use ":" to separate them
$macro INITPOINT(pt,xx,yy) (pt.x=xx : pt.y=yy)

POINT p
INITPOINT(p,3,4)


Note: the = operator inside a macro will always assign a value, and == will compare. This exception makes possible to assign values in macros.

If you define a macro with multiple expressions, only the first expression (leftmost) can be used to return a value. The return value from additional expressions will be ignored, and if neccessary, temporary strings or UDT's will be deleted.
$macro mymacro(a,b)(a:b)
print mymacro(APPEND("a","b"), APPEND("c","d"))

The first APPEND will be printed, the second APPEND will be executed and it's temporary result will be deleted before the macro returns.

$END directive will mark the end of file, any text following it will be ignored.

sapero

February 09, 2011, 01:42:14 PM #92 Last Edit: February 13, 2011, 07:07:27 AM by sapero
The LEN statement can be now used in expressions requiring a constant value, known at compile time. Almost any expression passed to LEN is supported, but string.
const MYCONST = len(1) + len(int) + len(myarray[1,2,3,4,5]) + len(my_int_variable) + len(*<POINT>p)

A function name passed to LEN will return the size of this subroutine. But the subroutine must exists in current source file (or in any included file). In this case, LEN will complete while assembling.

A new statement SIZEOF will always return the size in bytes of memory reserved for a variable (numbers, arrays, strings, classes, ...). SIZEOF will always evaluate at compile time, without generating code. SIZEOF(1) is 4, sizeof(string) is 255, and so on.
iwstring iw[32]
' compute the maximum number of characters
const NumberOfCharacters = sizeof(iw) / sizeof(iw[0])
print NumberOfCharacters ' 32


A subroutine definition can wrap to multiple lines. There is only one requirement (as for today): the "_" character must be the last in a line, not even space is allowed.
sub multiline( /*comments go here*/_
int a,_
int b)
print a,b
endsub


GLOBAL keyword is now accepting multiple variables:
GLOBAL a,b,c,d1

Added more options and command line switches, see first post.
The parser will load $$$lib.link file to memory, to prevent generating multiple libs with the same name. Relative libs can be resolved (to full paths) at compile time, and optionally the relative or full paths can be quoted.

BUGFIX: if you compile a file with tilde in the name (like "~.eba" or "~.iwb"), the assembler stops with critical error at the first "%line" macro (such file name should be quoted).

sapero

I have finished with the first implementation of thread-private variables
Quote from: MSDNThread Local Storage (TLS) is the mechanism by which each thread in a given multithreaded process allocates storage for thread-specific data. In standard multithreaded programs, data is shared among all threads of a given process, whereas thread local storage is the mechanism for allocating per-thread data.
declare import,CreateThread(pointer q,int q,int q, pointer q,int q,pointer q),int
declare import,WaitForSingleObject(int q,int q)
declare import,CloseHandle(int q)

' define some per-thread variables
thread int x,y
thread POINT pt

' main thread
x = 1
y = 2
pt.x = 3
pt.y = 4

print "main thread:"
DumpVariables(0) ' shows 1,2,3,4

' run a secondary thread

print "\nsecondary thread:" ' shows 0,0,0,0
int  dwId
int hThread = CreateThread(0,0,&DumpVariables,0,0,&dwId)
if (hThread)
WaitForSingleObject(hThread, -1)
CloseHandle(hThread)
endif

sub DumpVariables(int reserved)
print "thread int x = ",x
print "thread int y = ",y
print "thread POINT pt.x = ", pt.x
print "thread POINT pt.y = ", pt.y
endsub


The thread keyword must be specified first, to take effect (first in a line). The compiler updates an internal UDT as it sees the thread variables, so if you want to share thread variables between multiple source files, define them in an include file, or use the same order in all source files.

Logman

Nice work Sapero. It will be great having a native THREAD command/capability in IWBasic. Will there be an accompanying MUTEX command?

Logman
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

sapero

February 14, 2011, 06:10:18 AM #95 Last Edit: February 14, 2011, 06:14:44 AM by sapero
Threads and mutexes are native resources, easy to use and implement a wrapper. Each time I need to use a mutex, I do it in a different way. Using the direct apis is always better than calling a general and very limited command. A Lock/Unlock mutex commands could be implemented in a simple class with two methods. But is we start writing wrappers for all possible things, it will be Basic-MFC (with the M renamed) :)
Could you give me a suggestion, example code - how do you see it?

Recent changes:
You can include an .asm file directly from your IWBasic source file, using the build-in $INCLUDE directive. You can also add .asm file to your IWBasic project. File name extension must be .asm, to handle it correctly.

You can change the order of variables definitions from right to left, to left to right.
int a,b,c,d ' d is defined first, then c,b,a  (default)
$option "DimOrder left"
int e,f,g,h ' e will be defined first, then f,g,h

LarryMc

$option "DimOrder left"
would imply there is a
$option "DimOrder right"to undo it?
I only ask because I don't know why I would use the option in the first place. ???

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

There is push,pop,left,right and default. If you don't care in which order the variables are defined, you don't need to use this option.
If you for example convert some C/C++ code - a structure, the order in C is "left" and IWBasic uses "right":

struct POINT
{
int x,y; // x is first
};

' 1.
type POINT
int y,x ' x is first
endtype

' 2.
type POINT
int x ' x is first
int y
endtype

' 3.
$option "DimOrder left"
type POINT
int x,y ' x is first
endtype

LarryMc

I've been working on the documentation for several weeks now for Ver 2.0.

The problem is that Sapero can make enhancements/changes faster than I can document them properly in the help file.
This means that I'm loosing ground almost every day and the release date for 2.0 is getting pushed back further and further.

After discussing the problem with LarryS the following has been decided.
Today is the cutoff date for changes that will appear in Ver 2.0.
This topic is going to be locked and not changed further.
As a result I will have a firm endpoint for my documentation effort.
When I'm finished then 2.0 will be released.

Sapero will continue on with his enhancements/changes which will be included at a later date in ver 2.1.
In a private area of the forums, Sapero will document his efforts on 2.1.  When 2.0 is released his postings for 2.1 will be moved to the open forum for all to see.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Rock Ridge Farm (Larry)

We have drawn a line in the sand.
IWBasic2.0  is going to release as soon as Larry Mc can wrap up the help files.
I expect to release no later than Mar 1 (hope, hope)

Larry