Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 282 additions & 79 deletions src/cowbe/archpdp11.cow.ng

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions src/cowbe/regcache.coh
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,38 @@ sub RegCacheFindValue(sym: [Symbol], off: Size): (reg: RegId) is
end loop;
end sub;

sub RegCacheCopy(src: RegId, dst: RegId) is
var p := &register_cache[0];
while p != &register_cache[@sizeof register_cache] loop
if (p.state != CACHE_SLOT_EMPTY) and ((src & p.reg) != 0) then
p.reg := p.reg | dst;
end if;
p := @next p;
end loop;
end sub;

sub RegCacheGet(src: RegId): (q: [CacheSlot]) is
var p := &register_cache[0];
q := nil;
while p != &register_cache[@sizeof register_cache] loop
if (p.state != CACHE_SLOT_EMPTY) and ((src & p.reg) != 0) then
q := p;
return;
end if;
p := @next p;
end loop;
end sub;

sub RegCacheFind(state: uint8, subr: [Subroutine], wsid: uint8, off: Size): (reg: RegId) is
var p := &register_cache[0];
reg := 0;
while p != &register_cache[@sizeof register_cache] loop
if (p.state == state) and (p.subr == subr)
and (p.wsid == wsid) and (p.number == (off as Word)) then
reg := p.reg;
return;
end if;
p := @next p;
end loop;
end sub;

1 change: 1 addition & 0 deletions tests/pointers.good
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
p.byte==4: yes
direct: yes
indirect: yes
minus1: yes
3 changes: 3 additions & 0 deletions tests/pointers.test.cow
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ sub IndexTest() is

var p := &b;
print("indirect"); if p.buffer[p.offset] == 42 then yes(); else no(); end if;

var pb := &b.buffer[3];
print("minus1"); if [pb - 1] == 42 then yes(); else no(); end if;
end sub;
IndexTest();

3 changes: 3 additions & 0 deletions tests/regcache.good
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ regcache1 sub: yes
regcache1 or: yes
regcache1 xor: yes
regcache1 and: yes
regcache1 shl: yes
regcache1 shr: yes
regcache2: yes
23 changes: 23 additions & 0 deletions tests/regcache.test.cow
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,28 @@ sub cache1() is
c := a & b;
d := a;
print("regcache1 and"); if c == 0 and d == 2 then yes(); else no(); end if;

c := a << b;
d := a;
print("regcache1 shl"); if c == 4 and d == 2 then yes(); else no(); end if;

c := a >> b;
d := a;
print("regcache1 shr"); if c == 1 and d == 2 then yes(); else no(); end if;
end sub;
cache1();

# STORE should flush cached pointer value
sub cache2() is
var c: uint8;
var d: uint8;
var p: [uint8] := "ab";

c := [p];
p := p + 1;
d := [p];

print("regcache2"); if c == 'a' and d == 'b' then yes(); else no(); end if;
end sub;
cache2();

1 change: 1 addition & 0 deletions tests/shifts-16bit.good
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bug1<<8 == 0x8800: yes
big>>zero == 0x8000: yes
big>>one == 0x4000: yes
big>>two == 0x2000: yes
bug1>>14 == 0x3: yes
bug1>>10 == 0x30: yes
bug1>>8 == 0xc3: yes
mbig>>zero == 0x8000: yes
Expand Down
1 change: 1 addition & 0 deletions tests/shifts-16bit.test.cow
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sub rshiftu() is
print("big>>zero == 0x8000"); if big>>zero == 0x8000 then yes(); else no(); end if;
print("big>>one == 0x4000"); if big>>one == 0x4000 then yes(); else no(); end if;
print("big>>two == 0x2000"); if big>>two == 0x2000 then yes(); else no(); end if;
print("bug1>>14 == 0x3") ; if bug1>>14 == 0x3 then yes(); else no(); end if;
print("bug1>>10 == 0x30"); if bug1>>10 == 0x30 then yes(); else no(); end if;
print("bug1>>8 == 0xc3"); if bug1>>8 == 0xc3 then yes(); else no(); end if;
end sub;
Expand Down
8 changes: 8 additions & 0 deletions tests/shifts-8bit.good
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
one<<zero == 1: yes
one<<one == 2: yes
one<<two == 4: yes
one<<ONE == 2: yes
one<<TWO == 4: yes
onetwoeight<<one == 0: yes
onetwoeight<<ONE == 0: yes
onetwoeight<<NINE == 0: yes
onetwoeight>>zero == 128: yes
onetwoeight>>one == 64: yes
onetwoeight>>two == 32: yes
onetwoeight>>ONE == 64: yes
onetwoeight>>TWO == 32: yes
mbig>>zero == 0x80: yes
mbig>>one == 0xc0: yes
mbig>>two == 0xe0: yes
mbig>>ONE == 0xc0: yes
mbig>>TWO == 0xe0: yes
12 changes: 12 additions & 0 deletions tests/shifts-8bit.test.cow
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,37 @@ var one: uint8 := 1;
var two: uint8 := 2;
var onetwoeight: uint8 := 0x80;

const ONE := 1;
const TWO := 2;
const NINE := 9;

sub lshift() is
print("one<<zero == 1"); if one<<zero == 1 then yes(); else no(); end if;
print("one<<one == 2"); if one<<one == 2 then yes(); else no(); end if;
print("one<<two == 4"); if one<<two == 4 then yes(); else no(); end if;
print("one<<ONE == 2"); if one<<ONE == 2 then yes(); else no(); end if;
print("one<<TWO == 4"); if one<<TWO == 4 then yes(); else no(); end if;
print("onetwoeight<<one == 0"); if onetwoeight<<one == 0 then yes(); else no(); end if;
print("onetwoeight<<ONE == 0"); if onetwoeight<<ONE == 0 then yes(); else no(); end if;
print("onetwoeight<<NINE == 0"); if onetwoeight<<NINE == 0 then yes(); else no(); end if;
end sub;
lshift();

sub rshiftu() is
print("onetwoeight>>zero == 128"); if onetwoeight>>zero == 128 then yes(); else no(); end if;
print("onetwoeight>>one == 64"); if onetwoeight>>one == 64 then yes(); else no(); end if;
print("onetwoeight>>two == 32"); if onetwoeight>>two == 32 then yes(); else no(); end if;
print("onetwoeight>>ONE == 64"); if onetwoeight>>ONE == 64 then yes(); else no(); end if;
print("onetwoeight>>TWO == 32"); if onetwoeight>>TWO == 32 then yes(); else no(); end if;
end sub;
rshiftu();

sub rshifts() is
print("mbig>>zero == 0x80"); if mbig>>zero == 0x80 then yes(); else no(); end if;
print("mbig>>one == 0xc0"); if mbig>>one == 0xc0 then yes(); else no(); end if;
print("mbig>>two == 0xe0"); if mbig>>two == 0xe0 then yes(); else no(); end if;
print("mbig>>ONE == 0xc0"); if mbig>>ONE == 0xc0 then yes(); else no(); end if;
print("mbig>>TWO == 0xe0"); if mbig>>TWO == 0xe0 then yes(); else no(); end if;
end sub;
rshifts();