doc improvements; added lazarus example

This commit is contained in:
Araq
2011-07-24 23:07:40 +02:00
parent a6daf71520
commit ef039a1325
12 changed files with 5556 additions and 58 deletions

View File

@@ -594,7 +594,7 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
inc(r.pos, 2) # skip "(\10"
inc(r.line)
L = 0
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
setlen(r.files, L + 1)
r.files[L] = decode(r)
inc(r.pos) # skip #10
@@ -604,7 +604,7 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
of "INCLUDES":
inc(r.pos, 2) # skip "(\10"
inc(r.line)
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
w = r.files[decodeInt(r)]
inc(r.pos) # skip ' '
inclCrc = decodeInt(r)
@@ -618,7 +618,7 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
of "DEPS":
inc(r.pos) # skip ':'
L = 0
while (r.s[r.pos] > '\x0A'):
while r.s[r.pos] > '\x0A':
setlen(r.modDeps, L + 1)
r.modDeps[L] = r.files[decodeInt(r)]
inc(L)
@@ -672,7 +672,7 @@ proc newRodReader(modfilename: string, crc: TCrc32,
initIITable(r.imports.tab) # looks like a ROD file
inc(r.pos, 4)
var version = ""
while not (r.s[r.pos] in {'\0', '\x0A'}):
while r.s[r.pos] notin {'\0', '\x0A'}:
add(version, r.s[r.pos])
inc(r.pos)
if r.s[r.pos] == '\x0A': inc(r.pos)
@@ -728,8 +728,8 @@ proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym =
# find the reader with the correct moduleID:
for i in countup(0, high(gMods)):
var rd = gMods[i].rd
if (rd != nil):
if (rd.moduleID == moduleID):
if rd != nil:
if rd.moduleID == moduleID:
d = IITableGet(rd.index.tab, id)
if d != invalidKey:
result = decodeSymSafePos(rd, d, info)
@@ -745,14 +745,14 @@ proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym =
else:
# own symbol:
result = decodeSymSafePos(r, d, info)
if (result != nil) and (result.kind == skStub): loadStub(result)
if result != nil and result.kind == skStub: loadStub(result)
proc loadInitSection(r: PRodReader): PNode =
if (r.initIdx == 0) or (r.dataIdx == 0): InternalError("loadInitSection")
if r.initIdx == 0 or r.dataIdx == 0: InternalError("loadInitSection")
var oldPos = r.pos
r.pos = r.initIdx
result = newNode(nkStmtList)
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
var d = decodeInt(r)
inc(r.pos) # #10
var p = r.pos
@@ -763,7 +763,7 @@ proc loadInitSection(r: PRodReader): PNode =
proc loadConverters(r: PRodReader) =
# We have to ensure that no exported converter is a stub anymore.
if (r.convertersIdx == 0) or (r.dataIdx == 0):
if r.convertersIdx == 0 or r.dataIdx == 0:
InternalError("importConverters")
r.pos = r.convertersIdx
while (r.s[r.pos] > '\x0A'):
@@ -809,9 +809,9 @@ proc checkDep(filename: string): TReasonForRecompile =
# we cannot break here, because of side-effects of `checkDep`
else:
result = rrRodDoesNotExist
if (result != rrNone) and (gVerbosity > 0):
if result != rrNone and gVerbosity > 0:
MsgWriteln(`%`(reasonToFrmt[result], [filename]))
if (result != rrNone) or (optForceFullMake in gGlobalOptions):
if result != rrNone or optForceFullMake in gGlobalOptions:
# recompilation is necessary:
r = nil
gMods[idx].rd = r

View File

@@ -117,12 +117,12 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode): PRope =
# we do not write comments for now
# Line information takes easily 20% or more of the filesize! Therefore we
# omit line information if it is the same as the father's line information:
if (finfo.fileIndex != n.info.fileIndex):
if finfo.fileIndex != n.info.fileIndex:
appf(result, "?$1,$2,$3", [encodeInt(n.info.col), encodeInt(n.info.line),
encodeInt(fileIdx(w, toFilename(n.info)))])
elif (finfo.line != n.info.line):
elif finfo.line != n.info.line:
appf(result, "?$1,$2", [encodeInt(n.info.col), encodeInt(n.info.line)])
elif (finfo.col != n.info.col):
elif finfo.col != n.info.col:
appf(result, "?$1", [encodeInt(n.info.col)])
# No need to output the file index, as this is the serialization of one
# file.
@@ -135,7 +135,7 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode): PRope =
of nkCharLit..nkInt64Lit:
if n.intVal != 0: appf(result, "!$1", [encodeInt(n.intVal)])
of nkFloatLit..nkFloat64Lit:
if n.floatVal != 0.0: appf(result, "!$1", [encodeStr(w, $(n.floatVal))])
if n.floatVal != 0.0: appf(result, "!$1", [encodeStr(w, $n.floatVal)])
of nkStrLit..nkTripleStrLit:
if n.strVal != "": appf(result, "!$1", [encodeStr(w, n.strVal)])
of nkIdent:
@@ -274,7 +274,7 @@ proc symStack(w: PRodWriter) =
if w.converters != nil: app(w.converters, " ")
app(w.converters, encodeInt(s.id))
elif IiTableGet(w.imports.tab, s.id) == invalidKey:
addToIndex(w.imports, s.id, m.id) #if not IntSetContains(debugWritten, s.id) then begin
addToIndex(w.imports, s.id, m.id) #if not Contains(debugWritten, s.id):
# MessageOut(w.filename);
# debug(s.owner);
# debug(s);

View File

@@ -587,7 +587,7 @@ Named arguments
---------------
Often a procedure has many parameters and it is not clear in which order the
parameters appeared. This is especially true for procedures that construct a
parameters appear. This is especially true for procedures that construct a
complex data type. Therefore the arguments to a procedure can be named, so
that it is clear which argument belongs to which parameter:

140
examples/lazarus/nimlaz.lpi Executable file
View File

@@ -0,0 +1,140 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<Version Value="7"/>
<General>
<Flags>
<LRSInOutputDirectory Value="False"/>
</Flags>
<MainUnit Value="0"/>
<TargetFileExt Value=".exe"/>
<UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="1"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
<Language Value=""/>
<CharSet Value=""/>
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="nimlaz.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="nimlaz"/>
<CursorPos X="17" Y="21"/>
<TopLine Value="1"/>
<EditorIndex Value="1"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
<CursorPos X="26" Y="27"/>
<TopLine Value="1"/>
<EditorIndex Value="0"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="12" HistoryIndex="11">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="27" Column="1" TopLine="1"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="15" Column="3" TopLine="1"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="17" Column="26" TopLine="1"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="16" Column="18" TopLine="1"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="20" Column="43" TopLine="2"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="21" Column="48" TopLine="16"/>
</Position6>
<Position7>
<Filename Value="nimlaz.lpr"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position7>
<Position8>
<Filename Value="unit1.pas"/>
<Caret Line="52" Column="17" TopLine="9"/>
</Position8>
<Position9>
<Filename Value="unit1.pas"/>
<Caret Line="51" Column="12" TopLine="9"/>
</Position9>
<Position10>
<Filename Value="nimlaz.lpr"/>
<Caret Line="21" Column="3" TopLine="1"/>
</Position10>
<Position11>
<Filename Value="nimlaz.lpr"/>
<Caret Line="20" Column="1" TopLine="1"/>
</Position11>
<Position12>
<Filename Value="nimlaz.lpr"/>
<Caret Line="21" Column="7" TopLine="1"/>
</Position12>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
<Version Value="8"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)/"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

21
examples/lazarus/nimlaz.lpr Executable file
View File

@@ -0,0 +1,21 @@
program nimlaz;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms
{ you can add units after this }, Unit1, LResources;
{$IFDEF WINDOWS}{$R nimlaz.rc}{$ENDIF}
begin
{$I nimlaz.lrs}
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

5222
examples/lazarus/nimlaz.lrs Executable file

File diff suppressed because it is too large Load Diff

8
examples/lazarus/readme.txt Executable file
View File

@@ -0,0 +1,8 @@
This example demonstrates how to use Nimrod with Lazarus. The GUI is generated
with Lazarus, while the "backend" is written in Nimrod. To compile the example,
use this command:
nimrod c --app:gui --no_main --no_linking backend.nim
Open the ``nimlaz.lpi`` file in Lazarus and run the program.

46
examples/lazarus/unit1.lfm Executable file
View File

@@ -0,0 +1,46 @@
object Form1: TForm1
Left = 553
Height = 111
Top = 464
Width = 448
ActiveControl = SpinEdit1
Caption = 'Sum'
ClientHeight = 111
ClientWidth = 448
OnCreate = FormCreate
LCLVersion = '0.9.28.2'
object Label1: TLabel
Left = 8
Height = 18
Top = 72
Width = 34
Caption = 'Sum:'
ParentColor = False
end
object SpinEdit1: TSpinEdit
Left = 8
Height = 27
Top = 8
Width = 436
Anchors = [akTop, akLeft, akRight]
OnChange = SpinEdit1Change
TabOrder = 0
end
object SpinEdit2: TSpinEdit
Left = 8
Height = 27
Top = 40
Width = 436
Anchors = [akTop, akLeft, akRight]
OnChange = SpinEdit1Change
TabOrder = 1
end
object Edit1: TEdit
Left = 48
Height = 27
Top = 72
Width = 396
Anchors = [akTop, akLeft, akRight]
TabOrder = 2
end
end

58
examples/lazarus/unit1.pas Executable file
View File

@@ -0,0 +1,58 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
Spin, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
procedure FormCreate(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
{$link nimcache/lib/system.o}
{$link nimcache/backend.o}
{$link nimcache/nim__dat.o}
{$linklib c}
procedure NimMain; cdecl; external;
function myAdd(x, y: longint): longint; cdecl; external;
procedure TForm1.FormCreate(Sender: TObject);
begin
// we initialize the Nimrod data structures here:
NimMain();
end;
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
Edit1.text := IntToStr(myAdd(SpinEdit1.Value, SpinEdit2.Value));
end;
initialization
{$I unit1.lrs}
end.

View File

@@ -1,41 +1,6 @@
Installation
============
Bootstrapping from github
-------------------------
To get the source code you need either of these:
* A working web browser + tar(or equivalent):
https://github.com/Araq/Nimrod/tarball/master
* wget + tar:
``wget --no-check-certificate "https://github.com/Araq/Nimrod/tarball/master"``
* git: ``git clone git://github.com/Araq/Nimrod.git``
After downloading the source (and extracting it), you need to
extract ``build/csources.zip``:
* ``cd build``
* ``unzip csources.zip``
* ``cd ..``
and then you can bootstrap with:
On Windows
~~~~~~~~~~
* ``build.bat``
* ``bin\nimrod c koch``
* ``koch boot -d:release``
On UNIX
~~~~~~~
* ``./build.sh``
* ``bin/nimrod c koch``
* ``./koch boot -d:release``
Installation on Linux/UNIX
--------------------------
@@ -97,3 +62,41 @@ Currently, the following C compilers are supported under Windows:
| http://www.digitalmars.com/download/freecompiler.html
However, most testing is done with GCC.
Bootstrapping from github
-------------------------
To get the source code you need either of these:
* A working web browser + tar(or equivalent):
https://github.com/Araq/Nimrod/tarball/master
* wget + tar:
``wget --no-check-certificate "https://github.com/Araq/Nimrod/tarball/master"``
* git: ``git clone git://github.com/Araq/Nimrod.git``
After downloading the source (and extracting it), you need to
extract ``build/csources.zip``:
* ``cd build``
* ``unzip csources.zip``
* ``cd ..``
and then you can bootstrap with:
On Windows
~~~~~~~~~~
* ``build.bat``
* ``bin\nimrod c koch``
* ``koch boot -d:release``
On UNIX
~~~~~~~
* ``./build.sh``
* ``bin/nimrod c koch``
* ``./koch boot -d:release``

View File

@@ -96,13 +96,13 @@ proc peekExitCode*(p: PProcess): int
## return -1 if the process is still running. Otherwise the process' exit code
proc inputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1".}
## returns ``p``'s input stream for writing to
## opens ``p``'s input stream for writing to
proc outputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1".}
## returns ``p``'s output stream for reading from
## opens ``p``'s output stream for reading from
proc errorStream*(p: PProcess): PStream {.rtl, extern: "nosp$1".}
## returns ``p``'s output stream for reading from
## opens ``p``'s output stream for reading from
when defined(macosx) or defined(bsd):
const

View File

@@ -7,7 +7,8 @@ Version 0.8.14
- optional indentation for 'case' statement
- make threadvar efficient again on linux after testing
- test the sort implementation again
- export re-entrant and non-reentrant locks and condition vars
- export re-entrant and non-reentrant locks and condition vars; threads should
not have an inbox per default
version 0.9.0
@@ -34,7 +35,6 @@ Bugs
version 0.9.XX
==============
- distinct types for array/seq indexes
- GC: marker procs for native Nimrod GC and Boehm GC; precise stack marking
- implicit ref/ptr->var conversion; the compiler may store an object
implicitly on the heap for write barrier efficiency; better: