forked from xHarbour-org/xharbour
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdiff.txt
711 lines (478 loc) · 19.4 KB
/
xdiff.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
xHarbour offers many syntax extensions over Harbour and Clipper, including:
ARRAY ELEMENT BYREF
-------------------
xHArbour supports passing an array element BYREF as a function argument.
SomeFunc( @aArray[ nIndex ] )
For sample usage please review tests\arrbyref.prg
ASSOCIATE CLASS:
----------------
The ASSOCIATE CLASS syntax allows the xHarbour developer to replace the
standard classes for native types with any alternative class, including
classes dervied from the standard classes. As well as complete support
for Operator Overloading for native types.
Syntax:
-------
ASSOCIATE CLASS <ClassName> WITH TYPE
ARRAY|BLOCK|CHARACTER|DATE|LOGICAL|NIL|NUMERIC|POINTER
For sample usage please review tests\associat.prg
OVERRIDE CLASS:
---------------
The OVERRIDE CLASS syntax allows the xHarbour developer to override the
behaviour of any existing class (including native type classes) using the
flowwing syntax:
OVERRIDE METHOD <SomeMethod> [IN] CLASS <SomeClass> WITH [METHOD] <SomeFunc>
[SCOPE <Scope>]
For sample usage please review tests\override.prg
EXTEND CLASS:
-------------
The EXTEND CLASS syntax allows the xHarbour developer to extend any existing
class (including native type classes) using the flowwing syntax:
EXTEND CLASS <SomeClass> WITH DATA|VAR <SomeVar>
[SCOPE <Scope>] [<Persistent: PERSISTENT> ] [<Case: NOUPPER>]
EXTEND CLASS <SomeClass> WITH METHOD <SomeFunc>
EXTEND CLASS <SomeClass> WITH MESSAGE <SomeMessage> METHOD <SomeFunc>
EXTEND CLASS <SomeClass> WITH MESSAGE <SomeMessage> INLINE <SomeCode>
For sample usage please review tests\extend.prg
EXTENDABLE Native Types:
------------------------
Native xHarbour types may be extended using the following syntax:
EXTEND [TYPE] ARRAY|BLOCK|CHARACTER|DATE|LOGICAL|NIL|NUMERIC|POINTER
WITH METHOD <SomeFunc>
EXTEND [TYPE] ARRAY|BLOCK|CHARACTER|DATE|LOGICAL|NIL|NUMERIC|POINTER
WITH MESSAGE <SomeMessage> METHOD <SomeFunc>
EXTEND [TYPE] ARRAY|BLOCK|CHARACTER|DATE|LOGICAL|NIL|NUMERIC|POINTER
WITH MESSAGE <SomeMessage> INLINE <SomeCode>
The above will then allow utilization of native types as OOP Objects with
regard to the specified method[s].
[NOTE, you do not need to use ENABLE TYPE CLASS syntax to utilize this
extension.]
For sample usage please review tests\exttype.prg
NATIVE Types as OOP objects:
----------------------------
You may usee the following syntax to anable OOP support for native types:
ENABLE CLASS TYPE ALL
ENABLE TYPE CLASS ARRAY|BLOCK|CHARACTER|DATE|LOGICAL|NIL|NUMERIC|POINTER
The above will allow usage as follow:
? 3:AsString + " apples."
All native types support the :AsString() method. Arrays support:
Add( xValue )
AddAll( oCollection )
AtIndex( nPos )
AtPut( nPos, xValue )
Append( xValue )
AsString()
Collect( bCollect )
Copy()
DeleteAt( nPos )
Do( bBlock )
IndexOf( xValue )
Init( nLen )
InsertAt( nPos, xValue )
Remove( xValue )
Scan( bScan )
as well as a simulated size property
Other types most notably CHARACTER will likely offer most of the above Array
support plus few additional methods.
BIT Operators:
--------------
xHarbour support (including compile time optimization) BIT operations:
AND, OR, XOR, SHIFT RIGHT, SHIFT LEFT
Except for 'XOR' C syntax is used:
& == and
| == or
^^ == xor
>> == shift right
<< == shift left
Please NOTE that 'AND' (&) *requires* trailing white space, or else MACRO
Context will be assumed, to maintain Clipper compatability.
Please review tests\tstbitop.prg for a sample.
HASH Variable type:
-------------------
Hashes are mainly arrays with non numerical keys
LOCAL hVar := Hash()
LOCAL hVar1 := { => } // Alternate hash declaration method.
LOCAL dDate := ctod( "02/01/2004" )
// complete charset & case sensitive
// string key support (case sens. can be turned on/off)
hVar[ e"first Key\n" ] := 10
// Date key support!!
hVar[ dDate ] := 20
// Non integer numerical key support
hVar[ 25.2 ] := 30
// Set operation support
hVar1 := hVar - { dDate => 0 } // removing dDate key
For more deails, see doc/hash.txt
XML Support:
------------
hFile := FOpen( cFileName )
xmlDoc := TXmlDocument():New( hFile )
xmlNode := xmlDoc:oRoot:oChild
cXml := xmlNode:Path()
// there are methods to find nodes (but also attributes, values and data):
xmlNode := xmlDoc:FindFirstRegex( cNode )
// to modify them:
xmlNode:SetAttribute( "Name", "MyNode" )
// or to add them
xmlNode:InsertAfter( TXmlNode:New(HBXML_TYPE_TAG, "ANewNode" ) )
// and to write them back
hFile := FCreate( "output.xml" )
xmlDoc:Write( hFile )
More details in doc/hbxml.txt
Indirect execution support:
---------------------------
Other than codeblocks, xHarbour provides the inderect execution function
HB_ExecFromArray() that has the following syntax:
HB_ExecFromArray( cFuncName, [aParams] ) --> result
HB_ExecFromArray( @nFuncId(), [aParams] ) --> result
HB_ExecFromArray( bCodeBlock, [aParams] ) --> result
HB_ExecFromArray( oObject, cMethodName, [aParams] ) --> result
HB_ExecFromArray( oObject, nMethodID, [aParams] ) --> result
HB_ExecFromArray( aExecutableArray ) --> result
Other array parameter in HB_ExecFromArray past the function name or address,
the codeblock or the object and method identifier is directly passed as
that function, codeblock or method parameters (element 1 being the first
parameter and so on); the return of the function, codeblock or method,
if present, is returned.
An executable array is an array that has the elements structured as the other
HB_ExecFromArray function calls:
{ cFuncName, param1, ..., paramN }
{ @nFuncId(), param1, ..., paramN }
{ bCodeBlock, param1, ..., paramN }
{ oObject, cMethodName, param1, ..., paramN }
{oObject, nMethodID, param1, ..., paramN }
For more details, see doc/en/indirect.txt
Portable Service-like startup:
------------------------------
HB_Service( .T. )
puts the calling process in background.
HB_ServiceLoop()
Process some task in main application loop for non I/O
based program (as services), like i.e. Windows message
handling and GC collecting (can be used from any
platform, it's duty varies from platform to platform).
STANDARD LOG system:
-------------------
#include "hblog.ch"
INIT LOG [ON] ;
[FILE([nFilPrio [,cFileName[,nFileSize[,nFileCount] ] ] ] ) ] ;
[CONSOLE( [nConPrio] ) ] ;
[MONITOR( [nMonPrio [,nMonPort] ] ) ] ;
[SYSLOG( [nSysPrio [,nSysId] ] ) ] ;
[EMAIL ([nEmaPrio [,cHelo[,cServer[,cDest[,cSubject[,cFrom]]]]]])] ;
[DEBUG ( [nDebugPrio [,nMaxDebugPrio]] )] ;
[NAME cName]
LOG xVar1, ... , xVarn [PRIO[RITY] nPriorityLevel ]
CLOSE LOG
Read doc/hblog.txt for further details; hblog system has also a
function API to access the standard logger and an object oriented custom
log object support.
Protable signal and error handling system:
------------------------------------------
#include "hb_serv.ch"
HB_PushSignalHandler( nSignalMask, @SigHandler() )
HB_PushSignalHandler( nSignalMask, "SigHandlerFuncName" )
HB_PushSignalHandler( nSignalMask, {| aEvent | SigHandler Codeblock} )
In case any of the nSignalMask signals or error are received, the SigHandler
function is called with an array of low level system dependant data.
HB_PopSignalHandler()
Removes a previously pushed signal hanlder.
HB_ServiceLoop()
Interprets some important Windows WM_ messages as signals to be handled
by signal handlers.
See doc/hbsignal.txt for further details.
OOP Macros:
-----------
Objects now support macros:
Syntax:
-------
- <Obj>:&Macro
- <Obj>:&Macro.Suffix
- <Obj>:&( <MacroExp> )
WITH OBJECT now supports macros:
Syntax:
-------
- :&Macro
- :&Macro.Suffix
- :&( <MacroExp> )
Extended Literal Strings:
-------------------------
xHarbour introduces a new kind of literal strings known as "Extended
Literal Strings".
Syntax:
-------
E"..."
The literal string may contain Escape Codes following the C language
conventions, like:
\n -> New Line character.
\t -> Tab character.
\r -> CR character.
\" -> literal <"> character.
\' -> literal <'> character.
\\ -> literal <\> character.
PERSISTENT Codeblocks:
----------------------
Codeblocks may be persisted. Persisted Blocks must be restored within an
Application containing the Compiled Module which the original Block was
created at.
Syntax:
-------
HB_SaveBlock( <Block> ) -> PersistedBlock Stream
HB_RestoreBlock( <PersistedBlock> ) -> Block
Module Scope:
-------------
OOP Scoping supports PRIVATE/HIDDEN, PROTECTED, and READONLY scopes. Classes
sharing the SAME compilation unit may freely access such restricted access
Members, without causing any scope violation.
Properties by Reference:
------------------------
Instance Variables of Objects may be passed by REFERENCE to Functions and
Methods.
Syntax:
-------
SomeFunction( @<SomeObj>:<SomeVar> )
Associative Arrays:
-------------------
Associative Arrays are like LITE Objects. Properties may be added on the fly
without any declaration, much like new PRIVATE or PUBLIC can be created by
simply assigning a value.
Associative Arrays, may use Objects Syntax (':' operator) or Array Index Syntax
('[]' operator) with the Property Name as the INDEX.
New Property will automatically be created upon first assignment.
Syntax:
-------
<lValue> := TAssociativeArray()
<AA>[ "<NewProperty>" ] := <xValue>
<AA>:<NewProperty> := <xValue>
<AA>[ "<Property>" ]
<AA>:<Property>
SWITCH syntax:
-----------
SWITCH <Exp>
CASE <Constant>
...
[EXIT]
[More Cases ...]
[DEFAULT]
...
END
NOTE: This syntax is modeled after the C 'switch' flow control. It offers
great speed benefit [30-300%] over DO CASE flow control, but is
restricted to comparing only constants.
Constants may be: Numerics (only Integers, Longs), Single Character,
Strings [much like in C], and any combination of the above using the
following operators:
+, -, & (BIT and), and | (BIT or)
Additionally valid contants may be
enclosed within ().
WARNING: Those NOT familiar with the C switch flow control, should understand
that unlike DO CASE, you MUST explicitly use the EXIT statement or
else logic will FALL THROUGH to the NEXT CASE, until stopped at a
EXIT, or END statements.
At first this might seem VERY ODD, but it provides great flexibility
exactly like the C model.
See tests/switch.prg to for a sample and to learn how the FALL-THROUGH
logic works.
Multi Threading (MT) Support:
-----------------------------
xHarbour supports MT applications. There is still some more work to be done,
but you can already take advantage of this very powerful feature.
Basic sample can be found at:
tests/mttest.prg
Syntax:
-------
StartThread ( @MyThreadFunc() [, xParam1 [,xParamN ] ] )
Syntax:
-------
CRITICAL [STATIC] FUNCTION|PROCEDURE( [xParam1 [, xParamN ] ] )
NOTE: MT Application must link against the MT versions of the Libraries, i.e.
vmmt.lib, rtlmt.lib, ppmt.lib, rddmt.lib, dbfntxmt.lib, and dbfcdxmt.lib.
The full description of MT is beyond the scope of this document; see more
in doc/thread.txt and doc/xhbt_internals.txt
Portable Sockets Support:
-------------------------
LOCAL Socket
Socket := InetConnect( "www.host.com", nPort )
Socket := InetSend( "Hello from me" )
InetClsoe( Socket )
The full description is beyond the scope of this document; see doc/inet.txt
for further details.
Perl-5 compatible RegEx:
------------------------
xHarbour includes PCRE which is a full feature, Perl 5 compatible, Regular
Expression engine. Full feature Search & Replace classes are currently under
construction, but you may already use the full power of RegEx searches,
new operators, HAS and LIKE.
cExp HAS cPatern|RegEx => bFound
cExp LIKE cPatern|RegEx => bLike
As well as full featured Functions:
HB_Atx( <cRegEx>, <cTargetString> [, lCaseSensitive [, [@]nStart ]
[, [@]nLen ] ] ] ) => cFoundText
RegexComp( cPattern, [bCaseSens [, bNewLine]] ) --> REGEX
HB_Regex( cPattern, cString, [bCaseSens, [, bNewLine]] ) --> aMatches
HB_RegexMatch( cPattern, cString, [bCaseSens, [, bNewLine]] ) --> bFound
TRY syntax:
-----------
TRY
...
[THROW( <Exp> )]
...
[CATCH [<CatcherVar>]]
...
[FINALLY]
...
END
The above is very similar to Clipper BEGIN SEQ, BREAK(), RECOVER USING, END,
but is more inline with more "modern" languages, and dismisses the need to
worry about Error Codeblock.
CATCH is optional, and <CatcherVar> is optional, even when CATCH is used.
FINALLY is optional, and if specified code within the FINALLY section is
guranteed to be executed after the TRY section has been executed, and the
CATCH section if activated, unless the CATCH section throws an UNHANDLED
Error. This means that the FINALLY section will be executed even if the CATCH
section re-throws the error, or attempt to RETURN. In such cases the requested
operation which forces OUT of the the TRY section will be deffered until AFTER
the FINALLY section has been completed.
IN operator: ------------
<Exp> IN <Array_or_StringExp> => .T./.F.
The IN operator is very similar to the $ operator, but is valid on *both*
Strings and Arrays. IN is much faster than the equivalent:
aScan( <Array>, <Exp> ) > 0
Variable Parameters syntax:
---------------------------
Function <cFuncName>( ... )
The above definition allows this Function to receive up to 254 parameters.
You may retrieve an ARRAY with all the parameters using:
HB_aParams()
The above is appropriate for such functions that may receive any number of
generic parameters, which normally will then be processed in a loop, or with
hard coded IF statements based on PCount(). Instead the above is much easier to
code, requires less memory, and is faster than
declaring the parameters.
GLOBAL variables:
-----------------
GLOBAL <Id1> [,<Id2> [,<IdN>]]
GLOBAL Variables are a new kind of a declared variables. They have PUBLIC like
visibility, but are faster than even STATICs. GLOBALs can be referenced from
other modules.
Syntax:
-------
GLOBAL EXTERNAL <Id1> [,<Id2> [,<IdN>]]
GLOBAL Variables have the added benefit of being *directly* accessible from C
code too.
True C Type Structures:
-----------------------
C STRUCTURE <strucName> [Align <align>]
[ MEMBER <memberName> IS <CTYPEDEF> ]
[ MEMBER <memberName[<arrayLength>]> IS <CTYPEDEF> ]
[ MEMBER <memberName> IS <CTYPEDEF>(<arrayLength>) ]
[ MEMBER <memberName> IS|INPLACE <strucName> ]
[ MEMBER <memberName> AS <strucName> ]
[ ... ]
END C STRUCTURE
C Structure can be passed *directly* TO and FROM C code. The full description
is beyond the scope of this document - please refer to cstruct.txt in doc
folder.
WITH OBJECT syntax:
-------------------
WITH OBJECT <exp>
...
:<exp>
...
END
HB_QWith() can also be used to retrieve the current WITH OBJECT within a
WITH OBJECT block.
HB_SetWith() may be used to SET or RESET the value of the WITH OBJECT
from an expression, much like the WITH OBJECT construct.
The above syntax not only saves typing, but is also MUCH faster than
equivalent conventional coding.
FOR EACH Syntax:
----------------
// <ElementOrProperty> must be a declared variable.
FOR EACH <ElementOrProperty> IN <ArrayOrObject>
// ElementOrProperty holds value of each respective element or property.
<ElementOrProperty>
HB_EnumIndex() // Returns current Position Index.
[LOOP]
[EXIT]
NEXT
The FOR EACH syntax is not only more elegant than:
FOR Counter := 1 TO Len(Array)
Element := Array[Counter]
...
NEXT
but is also MUCH faster - and it also supports enumerating all properties in
an object.
Full access to OLE Servers:
---------------------------
CreateObject( "ServerName" ) => oOleObject
Create new instance of an Ole Server.
GetActiveObject( "ServerName" ) => oOleObject
Get existing instance of an Ole Server.
All documented methods and properties of such Server should be directly
accessible.
Strings may be indexed like arrays:
-----------------------------------
<StringExp>[<IndexExp>]
String as Array Index can also accepts a numeric as an assigned value:
<StringExp>[<IndexExp>] := 65 // Same as := 'A'
String Index and all Strings of 1 character length automatically carry a
secondary CHAR type, which means they are also compatible with numeric
operations.
cVar := "hello"; cVar[1] -= 32 // -> "Hello"
Negative Array Index:
---------------------
Both Arrays and Strings may be indexed with negative numbers (Reversed),
where -1 indexes the LAST Element (or NIL if the Array is empty):
cVar[-1] // => "o"
// assuming cVar is the value "Hello" as per above.
#[x]uncommand and #[x]untranslate directives:
---------------------------------------------
#uncommand and #untranslate directives allow the removal of a given rule from
the active rules used by the Pre-Processor. It is very much like the #undefine
directive.
Extended macro support:
-----------------------
&cMacro.<suffix>
will compile correctly even if cMacro is a declared var.
Optimizations:
--------------
String additions is more than 50 times faster than Harbour.
PCODE based optimized SubStr(), Left(), and Right() functions.
Much optimized code for FOR LOOPs, :=, +=, -=, -, +, when involving declared
variables and numeric values.
Optimized WHILE .T. loops.
The underlying ITEM API has been rewritten (source/vm/fastitem.c) and is far
faster and consumes much less memory.
Much extended Expression Optimizer produces faster code for common functions,
and code notations. For example, it will automatically convert:
aTail( <aArray> ) to aArray[-1]
SubStr( <cString>, X, 1 ) to cString[X]
which will execute much faster than the above common code.
Optimized generation of Line numbers and other similar optimizations which
end up in producing smaller and faster executables.
Built-in support for SET TRACE [On|Off] and TraceLog() function.
Optimized and extended Garbage Collector.
Optimized OOP system.
Full support for Clipper undocumented OOP internals (not available in Harbour).
Built-in support for OLE in Win32.
Enhanced aIns() and aDel() dismiss need for subsequent [common] aSize().
New HB_FuncPtr(), HB_ObjMsgPtr() and HB_Exec().
The xHarbour Run-Time library was re-written to take advantage of all above
syntax extensions, and is taking full advantage of the resulting speed
improvements.
Fixed:
------
HB_Qself() returns correct QSelf() even from inside Codeblocks (inline
methods).
@ x,y GET &xMacro.Suffix
-> Clipper complains: Error C2081 Macro of declared symbol.
@ x,y GET &( xMacro )
-> Clipper complains: Error C2047 GET contains complex macro.
@ x,y GET &( xMacro )[...]
-> Clipper complains: Error C2047 GET contains complex macro.
xHarbour is about twice as fast as Clipper on most common operations
[excluding console screen output and DBF access], and about 25% to 1000%
faster than Harbour.
xHarbour should compile and execute all valid Clipper and Harbour code,
without any modifications - such code will be automatically optimized to take
advantage of xHarbour extensions.