mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 13:22:26 +00:00
PO 2013 compiler for Wirth's RISC processor now can be compiled with voc
Former-commit-id: edf0df4cbf
This commit is contained in:
parent
0e5d1c3ca8
commit
bc8c90fb84
6 changed files with 253 additions and 71 deletions
|
|
@ -1,5 +1,5 @@
|
|||
MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07*)
|
||||
IMPORT Texts, Oberon, ORS, ORB, ORG;
|
||||
IMPORT Args, Out := Console, Texts := CmdlnTexts, (*Oberon,*) ORS, ORB, ORG;
|
||||
(*Author: Niklaus Wirth, 2011.
|
||||
Parser of Oberon-RISC compiler. Uses Scanner ORS to obtain symbols (tokens),
|
||||
ORB for definition of data structures and for handling import and export, and
|
||||
|
|
@ -21,7 +21,7 @@ MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07
|
|||
modid: ORS.Ident;
|
||||
pbsList: PtrBase; (*list of names of pointer base types*)
|
||||
dummy: ORB.Object;
|
||||
W: Texts.Writer;
|
||||
(*W: Texts.Writer;*)
|
||||
|
||||
PROCEDURE Check(s: INTEGER; msg: ARRAY OF CHAR);
|
||||
BEGIN
|
||||
|
|
@ -166,7 +166,8 @@ MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07
|
|||
IF (t0.base = t1.base) & (t0.nofpar = t1.nofpar) THEN
|
||||
p0 := t0.dsc; p1 := t1.dsc;
|
||||
WHILE p0 # NIL DO
|
||||
IF (p0.class = p1.class) & CompTypes(p0.type, p1.type, TRUE) & (ORD(p0.rdo) = ORD(p1.rdo)) THEN
|
||||
(*IF (p0.class = p1.class) & CompTypes(p0.type, p1.type, TRUE) & (ORD(p0.rdo) = ORD(p1.rdo)) THEN*)
|
||||
IF (p0.class = p1.class) & CompTypes(p0.type, p1.type, TRUE) & (p0.rdo = p1.rdo) THEN
|
||||
IF p0.type.form >= ORB.Array THEN com := CompTypes(p0.type, p1.type, (p0.class = ORB.Par)) END ;
|
||||
p0 := p0.next; p1 := p1.next
|
||||
ELSE p0 := NIL; com := FALSE
|
||||
|
|
@ -767,7 +768,11 @@ MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07
|
|||
expression(x);
|
||||
IF (x.type.form = ORB.String) & (x.b = 2) THEN ORG.StrToChar(x) END ;
|
||||
ORB.NewObj(obj, id, ORB.Const); obj.expo := expo;
|
||||
IF x.mode = ORB.Const THEN obj.val := x.a; obj.lev := x.b; obj.type := x.type
|
||||
IF x.mode = ORB.Const THEN
|
||||
obj.val := x.a;
|
||||
(*obj.lev := x.b;*)
|
||||
obj.lev := SHORT(x.b);
|
||||
obj.type := x.type
|
||||
ELSE ORS.Mark("expression not constant"); obj.type := ORB.intType
|
||||
END;
|
||||
Check(ORS.semicolon, "; missing")
|
||||
|
|
@ -870,14 +875,25 @@ MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07
|
|||
VAR key: LONGINT;
|
||||
obj: ORB.Object;
|
||||
impid, impid1: ORS.Ident;
|
||||
BEGIN Texts.WriteString(W, " compiling "); ORS.Get(sym);
|
||||
BEGIN
|
||||
(*Texts.WriteString(W, " compiling "); *)
|
||||
Out.String(" compiling ");
|
||||
ORS.Get(sym);
|
||||
IF sym = ORS.module THEN
|
||||
ORS.Get(sym);
|
||||
IF sym = ORS.times THEN version := 0; Texts.Write(W, "*"); ORS.Get(sym) ELSE version := 1 END ;
|
||||
IF sym = ORS.times THEN
|
||||
version := 0;
|
||||
(*Texts.Write(W, "*"); *)
|
||||
Out.Char("*");
|
||||
ORS.Get(sym)
|
||||
ELSE
|
||||
version := 1
|
||||
END ;
|
||||
ORB.Init; ORB.OpenScope;
|
||||
IF sym = ORS.ident THEN
|
||||
ORS.CopyId(modid); ORS.Get(sym);
|
||||
Texts.WriteString(W, modid); Texts.Append(Oberon.Log, W.buf)
|
||||
(*Texts.WriteString(W, modid); Texts.Append(Oberon.Log, W.buf)*)
|
||||
Out.String(modid); Out.Ln
|
||||
ELSE ORS.Mark("identifier expected")
|
||||
END ;
|
||||
Check(ORS.semicolon, "no ;"); level := 0; dc := 0; exno := 1; key := 0;
|
||||
|
|
@ -913,19 +929,28 @@ MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07
|
|||
IF sym # ORS.period THEN ORS.Mark("period missing") END ;
|
||||
IF ORS.errcnt = 0 THEN
|
||||
ORB.Export(modid, newSF, key);
|
||||
IF newSF THEN Texts.WriteLn(W); Texts.WriteString(W, "new symbol file ") END
|
||||
IF newSF THEN
|
||||
(*Texts.WriteLn(W); Texts.WriteString(W, "new symbol file ") *)
|
||||
Out.Ln; Out.String("new symbol file ")
|
||||
END
|
||||
END ;
|
||||
IF ORS.errcnt = 0 THEN
|
||||
ORG.Close(modid, key, exno); Texts.WriteLn(W); Texts.WriteString(W, "compilation done ");
|
||||
Texts.WriteInt(W, ORG.pc, 6); Texts.WriteInt(W, dc, 6)
|
||||
ELSE Texts.WriteLn(W); Texts.WriteString(W, "compilation FAILED")
|
||||
ORG.Close(modid, key, exno);
|
||||
(*Texts.WriteLn(W); Texts.WriteString(W, "compilation done ");*)
|
||||
Out.Ln; Out.String("compilation done ");
|
||||
(*Texts.WriteInt(W, ORG.pc, 6); Texts.WriteInt(W, dc, 6)*)
|
||||
Out.Int(ORG.pc, 6); Out.Int(dc, 6)
|
||||
ELSE
|
||||
(*Texts.WriteLn(W); Texts.WriteString(W, "compilation FAILED")*)
|
||||
Out.Ln; Out.String("compilation FAILED")
|
||||
END ;
|
||||
Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
|
||||
(*Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);*)
|
||||
Out.Ln;
|
||||
ORB.CloseScope; pbsList := NIL
|
||||
ELSE ORS.Mark("must start with MODULE")
|
||||
END
|
||||
END Module;
|
||||
|
||||
(*
|
||||
PROCEDURE Option(VAR S: Texts.Scanner);
|
||||
BEGIN newSF := FALSE;
|
||||
IF S.nextCh = "/" THEN
|
||||
|
|
@ -933,12 +958,23 @@ MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07
|
|||
IF (S.class = Texts.Name) & (S.s[0] = "s") THEN newSF := TRUE END
|
||||
END
|
||||
END Option;
|
||||
*)
|
||||
PROCEDURE Option(VAR s: ARRAY OF CHAR);
|
||||
BEGIN
|
||||
newSF := FALSE;
|
||||
IF s[0] = "-" THEN
|
||||
IF s[1] = "s" THEN newSF := TRUE END
|
||||
END
|
||||
END Option;
|
||||
|
||||
PROCEDURE Compile*;
|
||||
VAR beg, end, time: LONGINT;
|
||||
T: Texts.Text;
|
||||
S: Texts.Scanner;
|
||||
BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
|
||||
(*T: Texts.Text;
|
||||
S: Texts.Scanner;*)
|
||||
s, name : ARRAY 32 OF CHAR;
|
||||
T : Texts.Text;
|
||||
BEGIN
|
||||
(*Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
|
||||
Texts.Scan(S);
|
||||
IF S.class = Texts.Char THEN
|
||||
IF S.c = "@" THEN
|
||||
|
|
@ -965,10 +1001,29 @@ MODULE ORP; (*N. Wirth 1.7.97 / 5.11.2013 Oberon compiler for RISC in Oberon-07
|
|||
END
|
||||
END ;
|
||||
Oberon.Collect(0)
|
||||
*)
|
||||
IF Args.argc <= 1 THEN HALT(1) END;
|
||||
Args.Get (1, s);
|
||||
Option(s);
|
||||
IF s[0] = "-" THEN
|
||||
IF Args.argc < 3 THEN Out.String ("module name expected"); Out.Ln; HALT(1) END;
|
||||
Args.Get(2, name);
|
||||
ELSE
|
||||
COPY(s, name);
|
||||
END;
|
||||
NEW(T);
|
||||
Texts.Open(T, name);
|
||||
IF T.len > 0 THEN
|
||||
ORS.Init(T, 0); Module
|
||||
ELSE
|
||||
Out.String ("module not found"); Out.Ln
|
||||
END;
|
||||
END Compile;
|
||||
|
||||
BEGIN Texts.OpenWriter(W); Texts.WriteString(W, "OR Compiler 5.11.2013");
|
||||
Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
|
||||
BEGIN (*Texts.OpenWriter(W); Texts.WriteString(W, "OR Compiler 5.11.2013");*)
|
||||
Out.String("OR Compiler 5.11.2013"); Out.Ln;
|
||||
(*Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);*)
|
||||
NEW(dummy); dummy.class := ORB.Var; dummy.type := ORB.intType;
|
||||
expression := expression0; Type := Type0; FormalType := FormalType0
|
||||
expression := expression0; Type := Type0; FormalType := FormalType0;
|
||||
Compile;
|
||||
END ORP.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue