Skip to content

Commit f323766

Browse files
committed
fbdoc: wiki snapshop 2019-08-24
1 parent 517877f commit f323766

19 files changed

+1410
-28
lines changed

doc/manual/cache/CatPgProgrammer.wakka

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{{fbdoc item="keyword" value="ProPgFixLenArrays|Fixed-length Arrays"}}
3333
{{fbdoc item="keyword" value="ProPgVarLenArrays|Variable-length Arrays"}}
3434
{{fbdoc item="keyword" value="ProPgArrayIndex|Array Indexing"}}
35-
Passing Arrays to Procedures
35+
{{fbdoc item="keyword" value="ProPgPassingArrays|Passing Arrays to Procedures"}}
3636

3737
{{fbdoc item="subsect" value="Pointers"}}
3838
{{fbdoc item="keyword" value="ProPgPointers|Overview"}}
@@ -42,9 +42,10 @@
4242
{{fbdoc item="keyword" value="ProPgImplicitdeclarations|Implicit Declarations"}}
4343
{{fbdoc item="keyword" value="ProPgInitialization|Initialization"}}
4444
{{fbdoc item="keyword" value="ProPgStorageClasses|Storage Classes"}}
45-
Variable Lifetime
4645
{{fbdoc item="keyword" value="ProPgVariableScope|Variable Scope"}}
47-
Namespaces
46+
{{fbdoc item="keyword" value="ProPgVariableLifetime|Simple Variable Lifetime vs Scope"}}
47+
{{fbdoc item="keyword" value="ProPgObjectLifetime|Dynamic Object and Data Lifetime"}}
48+
{{fbdoc item="keyword" value="ProPgNamespaces|Namespaces"}}
4849
{{fbdoc item="keyword" value="ProPgVarProcLinkage|Variable and Procedure Linkage"}}
4950

5051
{{fbdoc item="section" value="User Defined Types"}}
@@ -56,8 +57,8 @@
5657
{{fbdoc item="keyword" value="ProPgProperties|Properties"}}
5758
{{fbdoc item="keyword" value="ProPgMemberAccessRights|Member Access Rights"}}
5859
{{fbdoc item="keyword" value="ProPgOperatorOverloading|Operator Overloading"}}
59-
Iterators
60-
New and Delete
60+
{{fbdoc item="keyword" value="ProPgTypeIterators|Iterators"}}
61+
{{fbdoc item="keyword" value="ProPgNewDelete|New and Delete"}}
6162
{{fbdoc item="keyword" value="ProPgTypeObjects|Types as Objects"}}
6263
<<>>{{fbdoc item="section" value="Statements and Expressions"}}
6364
Assignments
@@ -71,7 +72,7 @@
7172
{{fbdoc item="keyword" value="ProPgReturnValue|Returning a Value"}}
7273
Procedure Scopes
7374
{{fbdoc item="keyword" value="ProPgCallingConventions|Calling Conventions"}}
74-
Recursion
75+
{{fbdoc item="keyword" value="ProPgRecursion|Recursion"}}
7576
Constructors and Destructors
7677
{{fbdoc item="keyword" value="ProPgProcedurePointers|Pointers to Procedures"}}
7778
{{fbdoc item="keyword" value="CatPgVarArg|Variable Arguments"}}

doc/manual/cache/DevArrays.wakka

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{{fbdoc item="title" value="Arrays"}}----
2+
An array in fbc is a collection of elements where each element has the same type and is accessed with an index in to the array.
3+
4+
Example:
5+
%%(freebasic)
6+
'' one dimensional array (1 index)
7+
dim a(1 to 10) as integer
8+
print a(1) '' first element (integer)
9+
print a(10) '' last element (integer)
10+
11+
'' two dimensional array (2 indexes)
12+
dim b(1 to 2, 1 to 5) as integer
13+
print b(1,1) '' first element (integer)
14+
print b(2,5) '' last element (integer)
15+
%%
16+
17+
{{fbdoc item="section" value="Array Dimensions and Bounds"}}
18+
19+
The number of dimensions refers to the number of indexes that are required to be given to access an element of an array. The number of dimensions may or may not be part of the declaration. If the number of dimensions are known at compile time within the scope that the array is used, fbc can check and error if the wrong number of indexes are specified.
20+
21+
The bounds of an array are the allowable minimum and maximum index values for each dimension. Accessing an array element with an index or indexes that are outside the array bounds of a dimension is undefined behaviour.
22+
23+
fbc can check and error if an index or indexes (access) are outside the bounds of the array when compiled with '-exx' or '-earray' compile options. If the array bounds are compile-time constant, and the array access is compile-time constant, fbc can check if an array access is outside the bounds of the array at compile time. Otherwise, the array bounds check must occur at run-time if either the bounds or the access is non-constant.
24+
25+
{{fbdoc item="section" value="Fixed dimension versus unknown dimension"}}
26+
27+
The number of dimensions may be fixed or unknown. fbc will attempt to determine the number of dimensions an array is expected to have based on declarations for the array. If fbc cannot determine the number of dimensions at compile time, the number of dimensions will become fixed on first redimension of the array at run time.
28+
29+
Example: fixed 2 dimension, dynamic bounds
30+
%%(freebasic)
31+
dim a(any, any) as integer
32+
redim a(1 to 2, 1 to 5)
33+
%%
34+
35+
Example: Dynamic dimension, dynamic bounds
36+
%%(freebasic)
37+
dim a() as integer
38+
39+
'' then only one of on first time use ...
40+
redim a(1 to 10)
41+
redim a(1 to 2, 1 to 5)
42+
redim a(1 to 2, 1 to 5, 1 to 3)
43+
%%
44+
45+
Once number of dimensions are known to fbc, within the scope of the array, fbc will error if any access to the error has wrong number of dimensions. Or if still unknown at compile time, as in the case of an array passed as argument to a procedure and resized, the number of dimensions become fixed at run time.
46+
47+
{{fbdoc item="section" value="Fixed bounds versus Dynamic bounds"}}
48+
49+
Fixed length arrays have array bounds that are known at compile-time. Dynamic (or variable length) arrays have array bounds that can be altered and resized at run-time, and may be considered unknown at compile time.
50+
51+
Example: fixed (constant) bounds and constant access
52+
%%(freebasic)
53+
dim a(1 to 10) as integer
54+
print a(11) '' compile time array out-of-bounds
55+
%%
56+
57+
Example: fixed bounds and non-constant access
58+
%%(freebasic)
59+
dim a(1 to 10) as integer
60+
dim i as integer
61+
print a(i) '' run time array out-of-bounds
62+
%%
63+
64+
Example: dynamic bounds
65+
%%(freebasic)
66+
dim a(any) as integer '' 1 dimensional, empty
67+
redim a(1 to 10) '' resized to 10 elements
68+
print a(11) '' run time array out-of-bounds
69+
print a(i) '' run time array out-of-bounds
70+
%%
71+
72+
{{fbdoc item="section" value="Static Array versus Dynamic Array"}}
73+
74+
Arrays may have static or dynamic memory allocation. The descriptor may be static or dynamic, and memory space for the data may be static or dynamic. The terms static and dynamic may be overused and so may lose meaning when describing an array. In this context static versus dynamic should not be confused with fixed-length or variable-length. In this context we are referring to how and where the array descriptor and it's associated data are allocated in memory, and to some extent the life time of the variable.
75+
76+
For an array descriptor to be valid, it must be initialized. An uninitialized array descriptor will almost certainly lead to undefined behaviour at run time.
77+
78+
The array descriptor itself may be allocated in .bss, .data, on stack or on heap, depending on the declaration of the array. Though typically not in .bss section because an array descriptor usually must be initialized to some non-zero default values to be usable.
79+
80+
The array's data may be located in .bss section, .data section, on stack or on heap, depending on the declaration of the array. In fbc's current implementation, the array data for variable-length arrays is always allocated on the heap (i.e. malloc()).
81+
82+
{{fbdoc item="section" value="Array Descriptor"}}
83+
84+
At compile time, fbc allocates an array descriptor to store and track information about the array.
85+
86+
From ##./inc/fbc-int/array.bi##):
87+
%%(freebasic)
88+
const FB_MAXDIMENSIONS as integer = 8
89+
90+
type FBARRAYDIM
91+
dim as uinteger elements '' number of elements
92+
dim as integer lbound '' dimension lower bound
93+
dim as integer ubound '' dimension upper bound
94+
end type
95+
96+
type FBARRAY
97+
dim as any ptr index_ptr '' @array(0, 0, 0, ... )
98+
dim as any ptr base_ptr '' start of memory at array lowest bounds
99+
dim as uinteger size '' byte size of allocated contents
100+
dim as uinteger element_len '' byte size of single element
101+
dim as uinteger dimensions '' number of dimensions
102+
dim as FBARRAYDIM dimTb(0 to FB_MAXDIMENSIONS-1)
103+
end type
104+
%%
105+
106+
If the number of dimensions is unknown at compile time, then the full ##FB_MAXDIMENSIONS## is allocated in the ##dimTb()## field. Otherwise, if the number dimensions is known at compile time, then only the number of dimensions needed are allocated. Therefore the allocated ##FBARRAY## data may be smaller than the declared ##FBARRAY## structure.
107+
108+
If an array is passed as argument to a procedure, an array descriptor is allocated. However, if the array is static, fixed length, and never passed as an argument, then all information about the array is known at compile time, including memory locations, and the allocation of a descriptor is optimized out, since all expressions involving the array are compile time constant.
109+
110+
The array descriptor may also be allocated at run time, as would be in the case of allocating a new UDT containing a variable-length array field member.
111+
112+
{{fbdoc item="subsect" value="FBARRAY.index"}}
113+
Pointer to the array data ##@array(0, 0, ...)##. This pointer may be outside of the actual array data as a kind of virtual pointer to use when calculating offsets using indexes in to the array.
114+
115+
{{fbdoc item="subsect" value="FBARRAY.base"}}
116+
Pointer to the array's memory at the array's lowest bound. For variable-length arrays allocated at run time, this points to the allocated memory region (i.e. malloc)
117+
118+
{{fbdoc item="subsect" value="FBARRAY.size"}}
119+
Total size in bytes of the array data. Size is equal to total number of elements in the array (all dimensions) multiplied by element length. i.e. ##size = dimTb(0).elements * element_len + dimTb(1).elements * element_len + ...##
120+
121+
{{fbdoc item="subsect" value="FBARRAY.element_len"}}
122+
Size in bytes of an individual element. Must be set to non-zero value.
123+
124+
{{fbdoc item="subsect" value="FBARRAY.dimensions"}}
125+
Number of valid dimensions in the dimTb() table. A value of zero (0) indicates that dimTb() has ##FB_MAXDIMENSIONS## avaiable, but the array does not yet have number of dimensions defined. On first REDIM, the number of dimensions will be set.
126+
127+
{{fbdoc item="subsect" value="FBARRAY.dimTb()"}}
128+
dimTb() is an array of ##FBARRAYDIM## to indicate the bounds of each dimension.
129+
130+
If the number of dimensions is unknown at compile time, then the full ##FB_MAXDIMENSIONS## is allocated in the ##dimTb()## field. Otherwise, if the number dimensions is known at compile time, then only the number of dimensions needed are allocated. Therefore the allocated ##FBARRAY## data may be smaller than the declared ##FBARRAY## structure.
131+
132+
{{fbdoc item="subsect" value="FBARRAYDIM.elements"}}
133+
Number of elements in the dimension. i.e. ##(ubound-lbound+1)##
134+
135+
{{fbdoc item="subsect" value="FBARRAYDIM.lbound"}}
136+
Lower bound is the lowest valid index in this dimension.
137+
138+
{{fbdoc item="subsect" value="FBARRAYDIM.ubound"}}
139+
Upper bound is the highest valid index in this dimension.
140+
141+
142+
{{fbdoc item="back" value="DevToc|FreeBASIC Developer Information"}}
143+
{{fbdoc item="back" value="DocToc|Table of Contents"}}

doc/manual/cache/DevBuildConfig.wakka

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ make install-rtlib install-gfxlib2 TARGET=i686-w64-mingw32
7979
- ##ENABLE_STANDALONE=1##
8080
Build a standalone FB setup instead of the normal Unix-style setup, see also: [[DevNormalVsStandalone|the standalone vs. normal comparison]]. This causes the makefile to use the standalone directory layout and to use ##-d ENABLE_STANDALONE## when building the compiler.
8181

82+
- ##ENABLE_STRIPALL=1##
83+
Enable the ##[[CompilerOptstrip|-strip]]## compiler option by default. If ##ENABLE_STRIPALL=1## is not given, this is the default for dos/win.
84+
85+
- ##ENABLE_STRIPALL=0##
86+
Enable the ##[[CompilerOptnostrip|-nostrip]]## compiler option by default. If ##ENABLE_STRIPALL=1## is not given, this is the default for linux (basically, everything other target besides dos.win).
87+
8288
- ##ENABLE_PREFIX=1##
8389
This causes the makefile to use ##-d ENABLE_PREFIX=$(prefix)## when building the compiler.
8490

@@ -99,6 +105,9 @@ make install-rtlib install-gfxlib2 TARGET=i686-w64-mingw32
99105
- ##-d ENABLE_STANDALONE##
100106
This makes the compiler behave as a standalone tool that cannot rely on the system to have certain programs or libraries. See [[DevNormalVsStandalone|the normal vs. standalone comparison]] for more information.
101107

108+
- ##-d ENABLE_STRIPALL##
109+
Enable the ##[[CompilerOptstrip|-strip]]## by default, otherwise ##[[CompilerOptnostrip|-nostrip]]## is default.
110+
102111
- ##-d ENABLE_SUFFIX=foo##
103112
This makes the compiler append the given suffix to the ##lib/freebasic/## directory name when searching for its own ##lib/freebasic/## directory. For example, ##-d ENABLE_SUFFIX=-0.24## causes it to look for ##lib/freebasic-0.24/## instead of ##lib/freebasic/##. Corresponding the ENABLE_SUFFIX=foo makefile option, this adjust the compiler to work in the new directory layout.
104113

doc/manual/cache/DevToc.wakka

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This area of the Wiki is for documenting everything about the compiler and the r
4040
{{fbdoc item="keyword" value="DevFbcParserSymbols|Symbols"}}
4141
{{fbdoc item="keyword" value="DevFbcTypes|Representation of data types"}}
4242

43+
{{fbdoc item="keyword" value="DevArrays|Arrays"}}
4344
{{fbdoc item="keyword" value="DevSelectCase|SELECT CASE"}}
4445
{{fbdoc item="keyword" value="ProPgProfiling|Profiling FB programs"}}
4546
{{fbdoc item="keyword" value="DevStructLayout|Structure packing/field alignment"}}

doc/manual/cache/KeyPgDots.wakka

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Used in place of procedure parameter to pass a variable number of arguments, or
2727

2828
Using an ellipsis behind the last parameter in a ##[[KeyPgPpdefine|#define]]## or ##[[KeyPgPpmacro|#macro]]## declaration allows creation of a variadic macro. This means it is possible to pass any number of arguments to the //variadic_parameter//, which can be used in the //body// as if it was a normal macro parameter. The //variadic_parameter// will expand to the full list of arguments passed to it, including commas, and can also be completely empty.
2929

30+
**Note:** To distinguish between the different arguments passed by //variadic_parameter//, you can first convert //variadic_parameter// to a string using the ##[[KeyPgOpPpStringize|Operator # (Preprocessor Stringize)]]##, then differentiate in this string (//#variadic_parameter//) each passed argument by locating the separators (usually a comma).
31+
3032
__Array Upper Bound__
3133

3234
Using an ellipsis in place of the upper bound in an array declaration causes the upper bound to be set according to the data that appears in the ##//expression_list//##. When the ellipsis is used in this manner, an initializer must appear, and cannot be ##[[KeyPgAny|Any]]##.

doc/manual/cache/KeyPgExtendsZstring.wakka

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ End Destructor
8989

9090
Operator Len (Byref v As vZstring) As Integer
9191
Return Len(Type<String>(v)) '' found nothing better than this ('vZstring.l' being private)
92-
End Operator
92+
End Operator '' (or: 'Return Len(Str(v))')
9393

9494
Dim As vZstring v = "FreeBASIC"
9595
Print "'" & v & "'", Len(v)
@@ -114,7 +114,7 @@ v[0] = Asc("-")
114114
Print "'" & v & "'", Len(v)
115115

116116
'Print "'" & Right(v, 5) & "'" '' 'Right' does not yet support types with 'Extends Zstring'
117-
Print "'" & Right(Str(v), 5) & "'" '' workaround
117+
Print "'" & Right(Str(v), 5) & "'" '' workaround (or: 'Right(Type<String>(v), 5)')
118118

119119
Sleep
120120
%%

doc/manual/cache/KeyPgPperror.wakka

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ Preprocessor diagnostic directive
99
The display message
1010

1111
{{fbdoc item="desc"}}
12-
##**#error**## stops compiling and displays ##//error_text//## when compiler finds it.
12+
##**#error**## interrupts compiling to display ##//error_text//## when compiler finds it, and then parsing continues.
1313

1414
This keyword must be surrounded by an ##[[KeyPgPpif|#if]] //<condition>//## ...##[[KeyPgPpendif|#endif]]##, so the compiler can reach ##**#error**## only if ##//<condition>//## is met.
15+
16+
In any case, the final status will be "Failed to compile".
1517

1618
{{fbdoc item="ex"}}
1719
{{fbdoc item="filename" value="examples/manual/prepro/error.bas"}}%%(freebasic)

doc/manual/cache/PrintToc.wakka

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@
773773
[[ProPgFixLenArrays|Fixed-length Arrays]]
774774
[[ProPgVarLenArrays|Variable-length Arrays]]
775775
[[ProPgArrayIndex|Array Indexing]]
776+
[[ProPgPassingArrays|Passing Arrays to Procedures]]
776777

777778
{{fbdoc item="subsect" value="Pointers"}}
778779
[[ProPgPointers|Overview]]
@@ -783,6 +784,9 @@
783784
[[ProPgInitialization|Initialization]]
784785
[[ProPgStorageClasses|Storage Classes]]
785786
[[ProPgVariableScope|Variable Scope]]
787+
[[ProPgVariableLifetime|Simple Variable Lifetime vs Scope]]
788+
[[ProPgObjectLifetime|Dynamic Object and Data Lifetime]]
789+
[[ProPgNamespaces|Namespaces]]
786790
[[ProPgVarProcLinkage|Variable and Procedure Linkage]]
787791

788792
{{fbdoc item="subsect" value="User Defined Types"}}
@@ -794,6 +798,8 @@
794798
[[ProPgProperties|Properties]]
795799
[[ProPgMemberAccessRights|Member Access Rights]]
796800
[[ProPgOperatorOverloading|Operator Overloading]]
801+
[[ProPgTypeIterators|Iterators]]
802+
[[ProPgNewDelete|New and Delete]]
797803
[[ProPgTypeObjects|Types as Objects]]
798804

799805
{{fbdoc item="subsect" value="Statements and Expressions"}}
@@ -805,6 +811,7 @@
805811
[[ProPgPassingArguments|Passing Arguments to Procedures]]
806812
[[ProPgReturnValue|Returning a Value]]
807813
[[ProPgCallingConventions|Calling Conventions]]
814+
[[ProPgRecursion|Recursion]]
808815
[[ProPgProcedurePointers|Pointers to Procedures]]
809816
[[CatPgVarArg|Variable Arguments]]
810817

doc/manual/cache/ProPgArrays.wakka

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Dim as integer multidim(1 to 2,1 to 5) = {{0,0,0,0,0},{0,0,0,0,0}}
6767
{{fbdoc item="see"}}
6868
- [[ProPgFixLenArrays|Fixed-length Arrays]]
6969
- [[ProPgVarLenArrays|Variable-length Arrays]]
70+
- [[ProPgArrayIndex|Array Indexing]]
71+
- [[ProPgPassingArrays|Passing Arrays to Procedures]]
7072
- [[ProPgVariableScope|Variable Scope]]
7173

7274
{{fbdoc item="back" value="CatPgProgrammer|Programmer's Guide"}}

0 commit comments

Comments
 (0)