Freebasic 1.20.0 Development

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
coderJeff
Site Admin
Posts: 4358
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

In latest fbc, added the first part for profiling freebasic programs.

Started a topic for this in the documentation sub forum:
Profiling freebasic programs
coderJeff
Site Admin
Posts: 4358
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

Before returning to work on strings, I find myself with a puzzle to solve before I can move on. I started fully testing the build process for release packages since the recent additions. With manual intervention it is certainly possible make all 1.20 release builds from 1.10.x and pass the test suite etc. But, I am struggling with the automation - which downloads an fbc package, bootstraps it, and then builds a new release. In particular transition from debian 11 to debain 12 on ARM. I'm caught by the self referencing nature of this process, between fbc, makefile, build script, bootstrap package, and release package. Without a maintainer for their particular distro putting up some kind of effort, it seems we would need a flawless working bootstrap package already made and released, to make it all completely auto-magical for the end user to build their own.

I want to fix and change the process in places at sometimes. I don't know where to break things in this already established and seemingly circular dependant process cycle.

Perhaps I am over thinking it, or someone knows a better way to think about this to help me move on. TIA
Xusinboy Bekchanov
Posts: 809
Joined: Jul 26, 2018 18:28

Re: Freebasic 1.20.0 Development

Post by Xusinboy Bekchanov »

I can't compile code like this:

Code: Select all

#define __USE_GTK3__

#ifdef __USE_GTK4__
	#include once "gir_headers/Gir/Gtk-4.0.bi"
#else
	#include once "gtk/gtk.bi"
#endif

#ifdef __USE_GTK4__
	gtk_init()
#else
	gtk_init(0, 0)
#endif
Gives an error message:
Untitled.bas(10) error 1: Argument count mismatch, expanding: GTK_INIT in 'gtk_init()'
In GTK4 these two arguments have been removed. How to fix it?
SARG
Posts: 1800
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Freebasic 1.20.0 Development

Post by SARG »

It's a bug.

Example in a short code

Code: Select all

#define foo(a,b) foo1(a,b)

#ifdef notdefined
	not a statement   <-- don't throw an error 
	foo()            <--- throw an error
#endif
Löwenherz
Posts: 91
Joined: Aug 27, 2008 6:26
Location: Bad Sooden-Allendorf, Germany

Re: Freebasic 1.20.0 Development

Post by Löwenherz »

This example Works with a Pointer

Code: Select all

#Define foo(a,b) foo1(a,b)

#Ifdef notdefined
   Not a 'statement 
   @foo() 'go
  ' foo() ' No Go 
   foo1() ''go
#EndIf

Print "ok"
sleep
coderJeff
Site Admin
Posts: 4358
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

Last few of weekends, working on:
- demangler - which evidently is non-trivial to implement from scratch. Itanium c++ ABI gives a BNF grammar, which, oh joy, has left recursive productions and lots of special notes.
- testing of release packages (trying to sort out my build scripts)

Of note to users:
In some side project I was working on, I was annoyed that PEEK, POKE, SWAP, couldn't be used as non-static members of a class, so these names have been demoted from keywords to quirkwords in lastest fbc 1.20.0. I don't think should break anything.


FWIW, I wanted to write this class, but PEEK was not allowed (before this latest change):

Code: Select all

type WstringBuffer
	const INPUT_BUFFER_SIZE = 1024

	private:
		as long m_head
		as long m_tail
		as long m_length
		as wstring * INPUT_BUFFER_SIZE m_buffer

	public:
		declare constructor()
		declare destructor()
		declare sub Clear()
		declare const function EOF() as long
		declare const function Peek() as long
		declare function Read() as long
		declare function Write( byval ch as long ) as long
		declare const property Length() as long
		declare const operator cast() as const wstring ptr
end type

constructor WStringBuffer()
	m_head = 0
	m_tail = 0
	m_length = 0
end constructor

destructor WStringBuffer()
end destructor

sub WStringBuffer.Clear( )
	m_head = 0
	m_tail = 0
	m_length = 0	
end sub 

property WstringBuffer.Length() as long
	return m_length
end property

function WstringBuffer.EOF() as long
	return (m_length = 0)
end function

const function WstringBuffer.Peek() as long
	dim ret as long = -1
	if( m_length > 0 ) then
		ret = cast(long, m_buffer[m_head])
	end if
	return ret
end function

function WstringBuffer.Read() as long
	dim ret as long = -1
	if( m_length > 0 ) then
		ret = cast(long, m_buffer[m_head])
		m_length -= 1
		m_head += 1
		m_head mod= INPUT_BUFFER_SIZE
	end if
	return ret
end function

function WstringBuffer.Write( byval ch as long ) as long
	dim ret as long = -1
	if( m_length < INPUT_BUFFER_SIZE ) then
		m_buffer[m_tail] = cast(long, ch)
		ret = cast(long, m_buffer[m_tail])
		m_length += 1
		m_tail += 1
		m_tail mod= INPUT_BUFFER_SIZE
	end if
	return ret
end function

const operator WstringBuffer.Cast() as const wstring ptr
	return @m_buffer
end operator
shadow008
Posts: 90
Joined: Nov 26, 2013 2:43

Re: Freebasic 1.20.0 Development

Post by shadow008 »

coderJeff wrote: Jun 17, 2024 0:30 Of note to users:
In some side project I was working on, I was annoyed that PEEK, POKE, SWAP, couldn't be used as non-static members of a class, so these names have been demoted from keywords to quirkwords in lastest fbc 1.20.0. I don't think should break anything.
Nice. I had this exact same problem implementing the stream class for my Serializer framework. I ended up just not implementing those as I couldn't come up with good enough synonyms.

Since SWAP is in the discussion I've been meaning to ask: why does it enforce no parenthesis? It's the only keyword I've seen that rejects optional parenthesis.

e.g.

Code: Select all

dim as integer x,y
swap(x,y) 'error 7: Expected ')', found ','
Lost Zergling
Posts: 577
Joined: Dec 02, 2011 22:51
Location: France

Re: Freebasic 1.20.0 Development

Post by Lost Zergling »

Related old topic around SWAP : https://www.freebasic.net/forum/viewtop ... 3&start=30
I use Swap in lzle code (hashtag).
I use it little, but it is particularly useful and critical in its context, because it allows to exchange pointer names of different scopes, in a context in which "Reallocate" could not be used because the success of the allocation shall be guaranteed (failure of some tests with Reallocate on fbc 1.07 and 1.09 in the aforementioned context, just not using swap).
I don't use peek or poke, but swap is much less specific because it applies to several variables types.
I fear what code I could substitute to it so that I no longer have an unsupported keyword in the future.
fxm
Moderator
Posts: 12239
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

Many, many other names, like now SWAP, are also in the quirk word class (see src/compiler/symb-keyword.bas).
Therefore this does not mean that they are necessarily sure to be deleted in the future.
Lost Zergling
Posts: 577
Joined: Dec 02, 2011 22:51
Location: France

Re: Freebasic 1.20.0 Development

Post by Lost Zergling »

@fxm. Ha, ok, thx.
coderJeff
Site Admin
Posts: 4358
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

SARG wrote: Jun 11, 2024 15:56 It's a bug.

Example in a short code

Code: Select all

#define foo(a,b) foo1(a,b)

#ifdef notdefined
	not a statement   <-- don't throw an error 
	foo()            <--- throw an error
#endif
It's something, for sure, but, I don't know I would call it a bug. Macros are super global and handled by the lexer, and so skipping over macro expansion even before the parser gets a chance to understand what it is looking at is asking for something different than what fbc does now. Currently, macro's can contain source text fragments including pre-processor statements that may or may not have matching open and closing statements. For example, macro's can contain an #if without #endif or #endif without #if.
coderJeff
Site Admin
Posts: 4358
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

shadow008 wrote: Jun 17, 2024 4:27 Since SWAP is in the discussion I've been meaning to ask: why does it enforce no parenthesis? It's the only keyword I've seen that rejects optional parenthesis.
fbc doesn't enforce it exactly; the parser just doesn't have any logic to check for optional parentheses. Like ?, PRINT, and ERASE, and many other statements.
coderJeff
Site Admin
Posts: 4358
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

Xusinboy Bekchanov wrote: Jun 11, 2024 8:04 In GTK4 these two arguments have been removed. How to fix it?
Perhaps implement your own entry point?

Code: Select all

#ifdef __USE_GTK4__
	#define generic_gtk_init() gtk_init()
#else
	#define generic_gtk_init() gtk_init(0, 0)
#endif

generic_gtk_init()
Xusinboy Bekchanov
Posts: 809
Joined: Jul 26, 2018 18:28

Re: Freebasic 1.20.0 Development

Post by Xusinboy Bekchanov »

coderJeff wrote: Jun 18, 2024 0:21
Xusinboy Bekchanov wrote: Jun 11, 2024 8:04 In GTK4 these two arguments have been removed. How to fix it?
Perhaps implement your own entry point?

Code: Select all

#ifdef __USE_GTK4__
	#define generic_gtk_init() gtk_init()
#else
	#define generic_gtk_init() gtk_init(0, 0)
#endif

generic_gtk_init()
Yes, that solves it.
fxm
Moderator
Posts: 12239
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

Lost Zergling wrote: Jun 17, 2024 12:33 I use Swap in lzle code (hashtag).
I use it little, but it is particularly useful and critical in its context, because it allows to exchange pointer names of different scopes, in a context in which "Reallocate" could not be used because the success of the allocation shall be guaranteed (failure of some tests with Reallocate on fbc 1.07 and 1.09 in the aforementioned context, just not using swap).
I am interested and surprised by this behavior where REALLOCATE fails, but another separate ALLOCATE (with the same size) succeeds ?
Post Reply