Add isptest (active) and In.Mod (not yet used).

This commit is contained in:
David Brown 2016-10-20 19:20:25 +01:00
parent a4c372253b
commit 1e7d3ca4fd
6 changed files with 1317 additions and 18 deletions

View file

@ -0,0 +1,128 @@
MODULE In;
IMPORT Platform, SYSTEM, Out;
VAR
nextch: CHAR;
ready: BOOLEAN;
initialized: BOOLEAN;
Done-: BOOLEAN;
PROCEDURE ReadChar;
VAR error: Platform.ErrorCode; n: LONGINT; ch: CHAR;
BEGIN
error := Platform.ReadBuf(Platform.StdIn, ch, n);
ready := (error = 0) & (n = 1);
IF ready & (nextch = 0DX) & (ch = 0AX) THEN
ready := (error = 0) & (n = 1)
END;
IF ready THEN nextch := ch ELSE nextch := 0X END
END ReadChar;
PROCEDURE Flush;
BEGIN Out.Flush; IF ~initialized THEN ReadChar END; initialized := TRUE
END Flush;
PROCEDURE Open*;
VAR error: Platform.ErrorCode;
BEGIN
error := Platform.Seek(Platform.StdIn, 0, Platform.SeekSet); (* Rewind STDIN to beginning of file. *)
ready := TRUE; initialized := FALSE;
END Open;
PROCEDURE Char*(VAR ch: CHAR);
BEGIN Flush;
Done := ready;
IF ready THEN ch := nextch; ReadChar ELSE ch := 0X END
END Char;
PROCEDURE Skip;
BEGIN
WHILE ready & (nextch <= " ") DO ReadChar END; (* Skip leading blanks, CR, LF, tab etc. *)
END Skip;
PROCEDURE HugeInt*(VAR h: HUGEINT);
VAR
neg, hex, decdigit, hexdigit: BOOLEAN;
decacc, hexacc, digit: HUGEINT;
BEGIN
Flush; Skip;
neg := nextch = '-'; IF neg THEN ReadChar END;
hex := FALSE;
endofnum := FALSE;
decacc := 0;
hexacc := 0;
Done := FALSE;
WHILE ready & ~endofnum DO
decdigit := (nextch >= "0") & (nextch <= "9");
IF decdigit THEN digit := ORD(nextch) MOD 16 END;
hexdigit := (nextch >= "f") & (nextch <= "f") OR (nextch >= "A") & (nextch <= "F");
IF hexdigit THEN ORD(nextch) MOD 16 + 9; hex := TRUE END;
IF decdigit OR hexdigit THEN
Done := TRUE;
decacc := decacc * 10 + digit;
hexacc := hexacc * 16 + digit;
ReadChar
ELSIF nextch = "H" THEN
hex := TRUE; endofnum := TRUE; ReadChar
ELSE
endofnum := TRUE
END
END;
IF Done THEN
IF hex THEN h := hexacc ELSE h := decacc END;
IF neg THEN h := -h END
ELSE
h := 0
END
END HugeInt;
PROCEDURE Int*(VAR i: INTEGER);
VAR h: HUGEINT;
BEGIN HugeInt(h); i := SYSTEM.VAL(INTEGER, h)
END Int;
PROCEDURE LongInt*(VAR i: LONGINT);
VAR h: HUGEINT;
BEGIN HugeInt(h); i := SYSTEM.VAL(LONGINT, h)
END LongInt;
PROCEDURE Real*(VAR x: REAL);
BEGIN ASSERT(FALSE) (* Not implemented *)
END Real;
PROCEDURE LongReal*(VAR y: LONGREAL);
BEGIN ASSERT(FALSE) (* Not implemented *)
END LongReal;
PROCEDURE String*(VAR str: ARRAY OF CHAR);
VAR i: INTEGER;
BEGIN Flush; Skip; i := 0;
IF ready AND nextch = '"' THEN (* " *)
ReadChar;
WHILE ready & (i < LEN(str)-1) & (nextch >= " ") & (nextch # '"') DO (* " *)
str[i] := nextch; INC(i)
END
END;
Done := ready & (i < LEN(str)-1) & (nextch = '"'); (* " *)
IF Done THEN
ReadChar; str[i] := 0X
ELSE
str[0] := 0X
END
END String;
PROCEDURE Name*(VAR name: ARRAY OF CHAR); (* Read filename. Presumably using shell semantics. *)
BEGIN ASSERT(FALSE) (* Not implemented *)
END Name;
BEGIN
nextch := 0X;
ready := FALSE;
initialized := FALSE;
END In.

View file

@ -8,23 +8,6 @@
#define __o_64
#endif
// // Temporary while bootstrapping and clearing up SYSTEM.c.
//
// #ifndef LONGINT
// #if defined (__o_64)
// #define INTEGER int32
// #define LONGINT int64
// #define SET uint64
// #else
// #define INTEGER int16
// #define LONGINT int32
// #define SET uint32
// #endif
// #endif
// Declare memcpy in a way compatible with C compilers intrinsic
// built in implementations.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,27 @@
MODULE isptest;
IMPORT Files, Texts, Out, Platform;
CONST path="isptest.mod";
VAR
T: Texts.Text;
R: Texts.Reader;
ch: CHAR;
i, j, k : LONGINT;
BEGIN
NEW(T);
IF Files.Old(path) # NIL THEN
Texts.Open(T, path);
Texts.OpenReader(R, T, 0); Texts.Read(R, ch);
WHILE ~R.eot DO
Texts.Read(R, ch);
i := Texts.Pos(R);
Out.String("pos="); Out.Int(i,0); Out.String(" char="); Out.Char(ch); Out.Ln;
IF i = 21906 THEN
Out.String("21906"); Out.Ln;
(*Platform.Delay(10000);*)
END;
END;
END
END isptest.

View file

@ -0,0 +1,13 @@
#!/bin/sh
. ../testenv.sh
$OBECOMP isptest.mod -m -O2
./isptest >result-O2
$OBECOMP isptest.mod -m -OC
./isptest >result-OC
echo --- Testing with Oberon 2 variable model --- >result
cat result-O2 >>result
echo "" >>result
echo "" >>result
echo --- Testing with Component Pascal variable model --- >>result
cat result-OC >>result
. ../testresult.sh

View file

@ -382,12 +382,12 @@ RUNTEST = COMPILER=$(COMPILER) OBECOMP="$(OBECOMP) -O$(MODEL)" FLAVOUR=$(FLAVOUR
confidence:
@printf "\n\n--- Confidence tests ---\n\n"
cd src/test/confidence/hello; $(RUNTEST)
cd src/test/confidence/isptest; $(RUNTEST)
cd src/test/confidence/out; $(RUNTEST)
cd src/test/confidence/math; $(RUNTEST)
cd src/test/confidence/intsyntax; $(RUNTEST)
cd src/test/confidence/language; $(RUNTEST)
cd src/test/confidence/texts; $(RUNTEST)
cd src/test/confidence/math; $(RUNTEST)
cd src/test/confidence/library; $(RUNTEST)
cd src/test/confidence/lola; $(RUNTEST)
cd src/test/confidence/arrayassignment; $(RUNTEST)