Skip to content

Commit

Permalink
Updated to 1.7.
Browse files Browse the repository at this point in the history
Added AND function.
  • Loading branch information
Laksen committed Apr 27, 2012
1 parent f06042f commit 4224a94
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 59 deletions.
94 changes: 45 additions & 49 deletions doc.lpi
Expand Up @@ -44,9 +44,9 @@
<IsVisibleTab Value="True"/>
<EditorIndex Value="0"/>
<WindowIndex Value="0"/>
<TopLine Value="890"/>
<CursorPos X="33" Y="914"/>
<UsageCount Value="24"/>
<TopLine Value="1779"/>
<CursorPos X="63" Y="1793"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
Expand All @@ -55,16 +55,16 @@
<UnitName Value="symtab"/>
<EditorIndex Value="1"/>
<WindowIndex Value="0"/>
<TopLine Value="67"/>
<CursorPos X="36" Y="86"/>
<UsageCount Value="24"/>
<TopLine Value="1"/>
<CursorPos X="29" Y="10"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="ntypes.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ntypes"/>
<UsageCount Value="24"/>
<UsageCount Value="29"/>
</Unit2>
<Unit3>
<Filename Value="instr.pas"/>
Expand All @@ -73,8 +73,8 @@
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="1"/>
<CursorPos X="29" Y="12"/>
<UsageCount Value="24"/>
<CursorPos X="57" Y="9"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
Expand All @@ -83,139 +83,135 @@
<UnitName Value="ninbuilt"/>
<EditorIndex Value="2"/>
<WindowIndex Value="0"/>
<TopLine Value="44"/>
<CursorPos X="24" Y="70"/>
<UsageCount Value="24"/>
<TopLine Value="31"/>
<CursorPos X="24" Y="48"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="nsystem.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="nsystem"/>
<UsageCount Value="24"/>
<UsageCount Value="29"/>
</Unit5>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<JumpHistory Count="29" HistoryIndex="28">
<Position1>
<Filename Value="doc.lpr"/>
<Caret Line="978" Column="34" TopLine="963"/>
<Caret Line="3823" Column="66" TopLine="3802"/>
</Position1>
<Position2>
<Filename Value="doc.lpr"/>
<Caret Line="3206" Column="1" TopLine="3189"/>
<Filename Value="ninbuilt.pas"/>
<Caret Line="65" Column="32" TopLine="49"/>
</Position2>
<Position3>
<Filename Value="doc.lpr"/>
<Caret Line="3207" Column="1" TopLine="3189"/>
<Caret Line="3824" Column="68" TopLine="3802"/>
</Position3>
<Position4>
<Filename Value="doc.lpr"/>
<Caret Line="982" Column="1" TopLine="965"/>
<Caret Line="3200" Column="52" TopLine="3195"/>
</Position4>
<Position5>
<Filename Value="doc.lpr"/>
<Caret Line="983" Column="1" TopLine="965"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position5>
<Position6>
<Filename Value="doc.lpr"/>
<Caret Line="985" Column="1" TopLine="965"/>
<Caret Line="3" Column="6" TopLine="1"/>
</Position6>
<Position7>
<Filename Value="doc.lpr"/>
<Caret Line="987" Column="1" TopLine="968"/>
<Caret Line="20" Column="8" TopLine="1"/>
</Position7>
<Position8>
<Filename Value="doc.lpr"/>
<Caret Line="989" Column="46" TopLine="968"/>
<Caret Line="142" Column="17" TopLine="114"/>
</Position8>
<Position9>
<Filename Value="doc.lpr"/>
<Caret Line="61" Column="70" TopLine="55"/>
<Caret Line="146" Column="10" TopLine="118"/>
</Position9>
<Position10>
<Filename Value="doc.lpr"/>
<Caret Line="3827" Column="28" TopLine="3809"/>
<Caret Line="379" Column="29" TopLine="351"/>
</Position10>
<Position11>
<Filename Value="doc.lpr"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Caret Line="967" Column="29" TopLine="939"/>
</Position11>
<Position12>
<Filename Value="doc.lpr"/>
<Caret Line="334" Column="33" TopLine="302"/>
<Caret Line="1079" Column="48" TopLine="1051"/>
</Position12>
<Position13>
<Filename Value="instr.pas"/>
<Caret Line="39" Column="3" TopLine="20"/>
<Filename Value="doc.lpr"/>
<Caret Line="1123" Column="32" TopLine="1096"/>
</Position13>
<Position14>
<Filename Value="doc.lpr"/>
<Caret Line="3831" Column="18" TopLine="3814"/>
<Caret Line="1449" Column="38" TopLine="1421"/>
</Position14>
<Position15>
<Filename Value="doc.lpr"/>
<Caret Line="319" Column="33" TopLine="304"/>
<Caret Line="2033" Column="48" TopLine="2005"/>
</Position15>
<Position16>
<Filename Value="doc.lpr"/>
<Caret Line="338" Column="44" TopLine="316"/>
<Caret Line="2071" Column="21" TopLine="2043"/>
</Position16>
<Position17>
<Filename Value="doc.lpr"/>
<Caret Line="318" Column="61" TopLine="313"/>
<Caret Line="2073" Column="58" TopLine="2045"/>
</Position17>
<Position18>
<Filename Value="doc.lpr"/>
<Caret Line="3840" Column="50" TopLine="3829"/>
<Caret Line="2135" Column="21" TopLine="2107"/>
</Position18>
<Position19>
<Filename Value="doc.lpr"/>
<Caret Line="309" Column="11" TopLine="292"/>
<Caret Line="2137" Column="39" TopLine="2109"/>
</Position19>
<Position20>
<Filename Value="doc.lpr"/>
<Caret Line="157" Column="41" TopLine="140"/>
<Caret Line="3825" Column="36" TopLine="3815"/>
</Position20>
<Position21>
<Filename Value="doc.lpr"/>
<Caret Line="3868" Column="11" TopLine="3850"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position21>
<Position22>
<Filename Value="doc.lpr"/>
<Caret Line="431" Column="1" TopLine="414"/>
<Caret Line="1468" Column="34" TopLine="1440"/>
</Position22>
<Position23>
<Filename Value="doc.lpr"/>
<Caret Line="927" Column="1" TopLine="910"/>
<Caret Line="1470" Column="29" TopLine="1442"/>
</Position23>
<Position24>
<Filename Value="doc.lpr"/>
<Caret Line="2022" Column="1" TopLine="2005"/>
<Caret Line="3674" Column="35" TopLine="3656"/>
</Position24>
<Position25>
<Filename Value="doc.lpr"/>
<Caret Line="2154" Column="1" TopLine="2137"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position25>
<Position26>
<Filename Value="doc.lpr"/>
<Caret Line="2288" Column="1" TopLine="2271"/>
<Caret Line="2137" Column="39" TopLine="2109"/>
</Position26>
<Position27>
<Filename Value="doc.lpr"/>
<Caret Line="2022" Column="1" TopLine="2005"/>
<Caret Line="2124" Column="62" TopLine="2109"/>
</Position27>
<Position28>
<Filename Value="doc.lpr"/>
<Caret Line="2283" Column="49" TopLine="2271"/>
<Caret Line="3881" Column="43" TopLine="3850"/>
</Position28>
<Position29>
<Filename Value="doc.lpr"/>
<Caret Line="3876" Column="70" TopLine="3850"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position29>
<Position30>
<Filename Value="doc.lpr"/>
<Caret Line="425" Column="99" TopLine="414"/>
</Position30>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
Expand Down
104 changes: 96 additions & 8 deletions doc.lpr
Expand Up @@ -909,6 +909,15 @@ function Compile(const AName: string): PSymbol;
Instruction(A_ADD, RegLoc(V_PC), ConstLoc($FEFE));
end;

procedure ShortJump(ToAddr: word);
var ofs: word;
begin
ofs := codeCounter-ToAddr+1;
if ofs >= 29 then
inc(ofs);
Instruction(A_SUB, RegLoc(V_PC), ConstLoc(ofs));
end;

procedure FixJmp(l: word);
begin
code[l-1] := codeCounter-l;
Expand Down Expand Up @@ -1109,9 +1118,9 @@ function Compile(const AName: string): PSymbol;
tkMod:
begin
if same(result, @TypeInteger) then
val := val div v2
val := val mod v2
else
error('DIV operator does not apply to types');
error('MOD operator does not apply to types');
end;
tkAnd:
begin
Expand Down Expand Up @@ -1779,6 +1788,21 @@ function Compile(const AName: string): PSymbol;
Instruction(A_SHR, result, tmp);
Instruction(A_BOR, result, RegLoc(V_EX));

Unuse(tmp);
end;
inbAnd:
begin
result := Expression;
if not same(result.Typ, @TypeInteger) then Error('AND can only be applied to integers');

Consume(tkComma);
tmp := Expression;
if not same(tmp.Typ, @TypeInteger) then Error('AND can only be applied to integers');

MakeWritable(result);

Instruction(A_AND, result, tmp);

Unuse(tmp);
end;
inbFloor:
Expand Down Expand Up @@ -2125,7 +2149,7 @@ function Compile(const AName: string): PSymbol;
error('Syntax error');
tkMod:
if same(result.Typ, @TypeInteger) then
Instruction(A_MOD, result, r2)
Instruction(A_MDI, result, r2)
else
error('Syntax error');
tkAnd:
Expand Down Expand Up @@ -2953,10 +2977,10 @@ function Compile(const AName: string): PSymbol;
end;

procedure Statement;
var d, expr: TExpr;
var d, expr, len: TExpr;
i, cnt, adj: longint;
r: longword;
l,l2: word;
l,l2,l3: word;
sym, sym2: PSymbol;
begin
if token = tkIdent then
Expand Down Expand Up @@ -3151,9 +3175,66 @@ function Compile(const AName: string): PSymbol;
else
Error('Type error');
end;
inbChunkMove:
inbMoveForward:
begin
Error('Proper procedure called');
expr := Expression;
Consume(tkComma);
d := Expression;
Consume(tkComma);
len := Expression;

if not Same(expr.Typ, @TypeInteger) then error('Source address must be integer');
if not Same(d.Typ, @TypeInteger) then error('Destination address must be integer');
if not Same(len.Typ, @TypeInteger) then error('Length must be integer');

Instruction(A_SET, PushLoc, RegLoc(7));
if regs[6] then Instruction(A_SET, PushLoc, RegLoc(6));
if regs[5] then Instruction(A_SET, PushLoc, RegLoc(5));

Instruction(A_SET, RegLoc(7), expr);
Instruction(A_SET, RegLoc(6), d);
Instruction(A_SET, RegLoc(5), len);

Instruction(A_ADD, RegLoc(5), RegLoc(6));

Instruction(A_IFE, regloc(5), RegLoc(6)); // 1 words
Instruction(A_ADD, RegLoc(V_PC), ConstLoc(2)); // 1 words
Instruction(A_STI, MakeAddr(RegLoc(6)), MakeAddr(RegLoc(7))); // 1 words
Instruction(A_SUB, RegLoc(V_PC), ConstLoc(4)); // 1 words

if regs[5] then Instruction(A_SET, RegLoc(5), PushLoc);
if regs[6] then Instruction(A_SET, RegLoc(6), PushLoc);
Instruction(A_SET, RegLoc(7), PopLoc);
end;
inbMoveBackward:
begin
expr := Expression;
Consume(tkComma);
d := Expression;
Consume(tkComma);
len := Expression;

if not Same(expr.Typ, @TypeInteger) then error('Source address must be integer');
if not Same(d.Typ, @TypeInteger) then error('Destination address must be integer');
if not Same(len.Typ, @TypeInteger) then error('Length must be integer');

Instruction(A_SET, PushLoc, RegLoc(7));
if regs[6] then Instruction(A_SET, PushLoc, RegLoc(6));
if regs[5] then Instruction(A_SET, PushLoc, RegLoc(5));

Instruction(A_SET, RegLoc(7), expr);
Instruction(A_SET, RegLoc(6), d);
Instruction(A_STD, RegLoc(5), RegLoc(6));
Instruction(A_SUB, RegLoc(5), len);

Instruction(A_IFL, regloc(6), RegLoc(5)); // 1 words
Instruction(A_ADD, RegLoc(V_PC), ConstLoc(2)); // 1 words
Instruction(A_STD, MakeAddr(RegLoc(6)), MakeAddr(RegLoc(7))); // 1 words
Instruction(A_SUB, RegLoc(V_PC), ConstLoc(4)); // 1 words

if regs[5] then Instruction(A_SET, RegLoc(5), PushLoc);
if regs[6] then Instruction(A_SET, RegLoc(6), PushLoc);
Instruction(A_SET, RegLoc(7), PopLoc);
end;
inbPut:
begin
Expand Down Expand Up @@ -3572,6 +3653,11 @@ function Compile(const AName: string): PSymbol;
id^.symType := FormalParameters
else
begin
if token = tkNot then
begin
consume(tkNot);
id^.typ := stInterruptFunc;
end;
new(id^.symType);
id^.symType^.TypeKind := typFunc;
id^.symType^.FuncRet := nil;
Expand Down Expand Up @@ -3766,7 +3852,8 @@ function GetSystemModule: PSymbol;

result^.symtab.AddSymbol(InbFunc('HWN', inbHWN));

result^.symtab.AddSymbol(InbFunc('MOVE', inbChunkMove));
result^.symtab.AddSymbol(InbFunc('MOVEFORWARD', inbMoveForward));
result^.symtab.AddSymbol(InbFunc('MOVEBACKWARD', inbMoveBackward));
result^.symtab.AddSymbol(InbFunc('GET', inbGet));
result^.symtab.AddSymbol(InbFunc('PUT', inbPut));

Expand Down Expand Up @@ -3806,6 +3893,7 @@ function GetSystemModule: PSymbol;
globals.AddSymbol(InbFunc('LSR', inbLsr));
globals.AddSymbol(InbFunc('ASR', inbAsr));
globals.AddSymbol(InbFunc('ROR', inbRor));
globals.AddSymbol(InbFunc('AND', inbAnd));

globals.AddSymbol(InbFunc('FLOOR', inbFloor));
globals.AddSymbol(InbFunc('FLT', inbFlt));
Expand Down

0 comments on commit 4224a94

Please sign in to comment.