mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 02:52:24 +00:00
now test server can listen on any ipv4 address.
This commit is contained in:
parent
8d2d479664
commit
afe5a2d824
3 changed files with 141 additions and 96 deletions
|
|
@ -6,7 +6,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
various promotion rules changed (long) => (LONGINT), xxxL avoided
|
various promotion rules changed (long) => (LONGINT), xxxL avoided
|
||||||
*)
|
*)
|
||||||
|
|
||||||
IMPORT OPT, OPC, OPM, OPS, SYSTEM;
|
IMPORT OPT, OPC, OPM, OPS, VT100, Strings, SYSTEM;
|
||||||
|
|
||||||
CONST
|
CONST
|
||||||
UndefinedType = 0; (* named type not yet defined *)
|
UndefinedType = 0; (* named type not yet defined *)
|
||||||
|
|
@ -28,6 +28,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
GuardPtrFunc = "__GUARDP(";
|
GuardPtrFunc = "__GUARDP(";
|
||||||
GuardRecFunc = "__GUARDR(";
|
GuardRecFunc = "__GUARDR(";
|
||||||
TypeFunc = "__TYPEOF(";
|
TypeFunc = "__TYPEOF(";
|
||||||
|
SetOfFunc = "__SETOF(";
|
||||||
CopyFunc = "__COPY(";
|
CopyFunc = "__COPY(";
|
||||||
MoveFunc = "__MOVE(";
|
MoveFunc = "__MOVE(";
|
||||||
GetFunc = "__GET(";
|
GetFunc = "__GET(";
|
||||||
|
|
@ -44,7 +45,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
|
|
||||||
TYPE
|
TYPE
|
||||||
ExitInfo = RECORD level, label: INTEGER END ;
|
ExitInfo = RECORD level, label: INTEGER END ;
|
||||||
|
tmpName = POINTER TO ARRAY 32 OF CHAR;
|
||||||
|
|
||||||
VAR
|
VAR
|
||||||
stamp: INTEGER; (* unique number for nested objects *)
|
stamp: INTEGER; (* unique number for nested objects *)
|
||||||
|
|
@ -52,6 +53,20 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
exit: ExitInfo; (* to check if EXIT is simply a break *)
|
exit: ExitInfo; (* to check if EXIT is simply a break *)
|
||||||
nofExitLabels: INTEGER;
|
nofExitLabels: INTEGER;
|
||||||
|
|
||||||
|
tempCounter: INTEGER; (* to generate unique temp names *)
|
||||||
|
|
||||||
|
PROCEDURE uniqueTempName(): tmpName;
|
||||||
|
VAR
|
||||||
|
num: ARRAY 8 OF CHAR;
|
||||||
|
tempName: tmpName;
|
||||||
|
BEGIN
|
||||||
|
INC(tempCounter);
|
||||||
|
NEW(tempName);
|
||||||
|
COPY("_voc_tmp_", tempName^);
|
||||||
|
VT100.IntToStr(tempCounter, num);
|
||||||
|
Strings.Append(num, tempName^);
|
||||||
|
RETURN tempName;
|
||||||
|
END uniqueTempName;
|
||||||
|
|
||||||
PROCEDURE Init*;
|
PROCEDURE Init*;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
@ -256,27 +271,39 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
END SizeCast;
|
END SizeCast;
|
||||||
|
|
||||||
PROCEDURE Convert(n: OPT.Node; newtype: OPT.Struct; prec: INTEGER);
|
PROCEDURE Convert(n: OPT.Node; newtype: OPT.Struct; prec: INTEGER);
|
||||||
VAR from, to: INTEGER;
|
VAR
|
||||||
BEGIN from := n^.typ^.form; to := newtype.form;
|
from, to: INTEGER;
|
||||||
|
tempName: tmpName;
|
||||||
|
tempIndex: INTEGER; (* New variable to manage temporary indexes *)
|
||||||
|
BEGIN
|
||||||
|
from := n^.typ^.form;
|
||||||
|
to := newtype.form;
|
||||||
|
|
||||||
IF to = OPT.Set THEN
|
IF to = OPT.Set THEN
|
||||||
IF from = OPT.Set THEN (* Sets of different size *)
|
tempName := uniqueTempName();
|
||||||
|
tempIndex := 0; (* Initialize temp index *)
|
||||||
|
OPM.WriteString("UINT32 "); OPM.WriteString(tempName^); OPM.WriteString(" = 0;"); (* Correctly initialize variable *)
|
||||||
|
OPM.WriteLn;
|
||||||
|
|
||||||
|
IF from = OPT.Set THEN
|
||||||
SizeCast(n, newtype.size);
|
SizeCast(n, newtype.size);
|
||||||
ELSE (* Set from integer *)
|
ELSE
|
||||||
OPM.WriteString("__SETOF("); Entier(n, MinPrec);
|
OPM.WriteString(tempName^); OPM.WriteString(" = __SETOF(");
|
||||||
OPM.WriteString(","); OPM.WriteInt(newtype.size*8); OPM.Write(CloseParen)
|
Entier(n, MinPrec);
|
||||||
|
OPM.WriteString(",");
|
||||||
|
OPM.WriteInt(newtype.size * 8);
|
||||||
|
OPM.WriteString(");");
|
||||||
|
OPM.WriteLn;
|
||||||
|
OPM.WriteString("i |= "); OPM.WriteString(tempName^); OPM.WriteString(";"); (* Ensure 'i' is declared *)
|
||||||
END
|
END
|
||||||
ELSIF to = OPT.Int THEN (* integers of different size *)
|
ELSIF to = OPT.Int THEN
|
||||||
SizeCast(n, newtype.size);
|
SizeCast(n, newtype.size);
|
||||||
ELSIF to = OPT.Char THEN
|
ELSE
|
||||||
IF OPM.ranchk IN OPM.Options THEN OPM.WriteString("__CHR");
|
expr(n, prec);
|
||||||
IF SideEffects(n) THEN OPM.Write("F") END ;
|
|
||||||
OPM.Write(OpenParen); Entier(n, MinPrec); OPM.Write(CloseParen)
|
|
||||||
ELSE OPM.WriteString("(CHAR)"); Entier(n, 9)
|
|
||||||
END
|
|
||||||
ELSE expr(n, prec)
|
|
||||||
END
|
END
|
||||||
END Convert;
|
END Convert;
|
||||||
|
|
||||||
|
|
||||||
PROCEDURE TypeOf(n: OPT.Node);
|
PROCEDURE TypeOf(n: OPT.Node);
|
||||||
BEGIN
|
BEGIN
|
||||||
IF n^.typ^.form = OPT.Pointer THEN
|
IF n^.typ^.form = OPT.Pointer THEN
|
||||||
|
|
@ -769,6 +796,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
|
|
||||||
PROCEDURE stat(n: OPT.Node; outerProc: OPT.Object);
|
PROCEDURE stat(n: OPT.Node; outerProc: OPT.Object);
|
||||||
VAR proc: OPT.Object; saved: ExitInfo; l, r: OPT.Node;
|
VAR proc: OPT.Object; saved: ExitInfo; l, r: OPT.Node;
|
||||||
|
tempName, tempVar: tmpName;
|
||||||
BEGIN
|
BEGIN
|
||||||
WHILE (n # NIL) & OPM.noerr DO
|
WHILE (n # NIL) & OPM.noerr DO
|
||||||
OPM.errpos := OPM.Longint(n^.conval^.intval);
|
OPM.errpos := OPM.Longint(n^.conval^.intval);
|
||||||
|
|
@ -833,9 +861,17 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
| OPT.incfn,
|
| OPT.incfn,
|
||||||
OPT.decfn: expr(n^.left, MinPrec); OPC.Increment(n^.subcl = OPT.decfn); expr(n^.right, MinPrec)
|
OPT.decfn: expr(n^.left, MinPrec); OPC.Increment(n^.subcl = OPT.decfn); expr(n^.right, MinPrec)
|
||||||
| OPT.inclfn,
|
| OPT.inclfn,
|
||||||
OPT.exclfn: expr(n^.left, MinPrec); OPC.SetInclude(n^.subcl = OPT.exclfn);
|
OPT.exclfn:
|
||||||
OPM.WriteString("__SETOF("); expr(n^.right, MinPrec);
|
tempName := uniqueTempName();
|
||||||
OPM.WriteString(","); OPM.WriteInt(n.left.typ.size*8); OPM.Write(CloseParen)
|
OPM.WriteString("UINT32 "); OPM.WriteString(tempName^); OPM.WriteString(";");
|
||||||
|
OPM.WriteLn;
|
||||||
|
|
||||||
|
OPM.WriteString(tempName^); OPM.WriteString(" = __SETOF(");
|
||||||
|
expr(n^.right, MinPrec);
|
||||||
|
OPM.WriteString(","); OPM.WriteInt(n.left.typ.size * 8);
|
||||||
|
OPM.WriteString(");");
|
||||||
|
OPM.WriteLn;
|
||||||
|
OPM.WriteString("i |= "); OPM.WriteString(tempName^); OPM.WriteString(";");
|
||||||
| OPT.copyfn: OPM.WriteString(CopyFunc);
|
| OPT.copyfn: OPM.WriteString(CopyFunc);
|
||||||
expr(n^.right, MinPrec); OPM.WriteString(Comma); expr(n^.left, MinPrec); OPM.WriteString(Comma);
|
expr(n^.right, MinPrec); OPM.WriteString(Comma); expr(n^.left, MinPrec); OPM.WriteString(Comma);
|
||||||
Len(n^.left, 0); OPM.Write(CloseParen)
|
Len(n^.left, 0); OPM.Write(CloseParen)
|
||||||
|
|
@ -931,4 +967,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
||||||
OPC.GenBdy(prog^.right); stat(prog, NIL)
|
OPC.GenBdy(prog^.right); stat(prog, NIL)
|
||||||
END Module;
|
END Module;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
tempCounter := 0
|
||||||
|
|
||||||
END OPV.
|
END OPV.
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ VAR
|
||||||
pid: LONGINT;
|
pid: LONGINT;
|
||||||
res: Platform.ErrorCode;
|
res: Platform.ErrorCode;
|
||||||
sockaddrlen: LONGINT;
|
sockaddrlen: LONGINT;
|
||||||
|
ipAddr: LONGINT; ip: ARRAY 16 OF CHAR;
|
||||||
BEGIN
|
BEGIN
|
||||||
sockfd := sockets.Socket(sockets.AfInet, sockets.SockStream, 0);
|
sockfd := sockets.Socket(sockets.AfInet, sockets.SockStream, 0);
|
||||||
IF sockfd < 0 THEN
|
IF sockfd < 0 THEN
|
||||||
|
|
@ -47,8 +48,10 @@ BEGIN
|
||||||
Out.String("socket created.")
|
Out.String("socket created.")
|
||||||
END;
|
END;
|
||||||
Out.Ln;
|
Out.Ln;
|
||||||
|
COPY("127.0.0.1", ip);
|
||||||
|
ipAddr := sockets.inetaddr(ip);
|
||||||
|
|
||||||
sockets.SetSockAddrIn(sockets.AfInet, Port, 0, ServAddr);
|
sockets.SetSockAddrIn(sockets.AfInet, Port, ipAddr, ServAddr);
|
||||||
IF sockets.Bind(sockfd, SYSTEM.VAL(sockets.SockAddr, ServAddr), SIZE(sockets.SockAddr)) < 0 THEN
|
IF sockets.Bind(sockfd, SYSTEM.VAL(sockets.SockAddr, ServAddr), SIZE(sockets.SockAddr)) < 0 THEN
|
||||||
Out.String("error on binding")
|
Out.String("error on binding")
|
||||||
ELSE
|
ELSE
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,9 @@ TYPE
|
||||||
END;
|
END;
|
||||||
|
|
||||||
PROCEDURE -includesocket "#include <sys/socket.h>";
|
PROCEDURE -includesocket "#include <sys/socket.h>";
|
||||||
|
PROCEDURE -includeInet "#include <arpa/inet.h>";
|
||||||
|
|
||||||
|
PROCEDURE -inetaddr*(s: ARRAY OF CHAR): LONGINT "(LONGINT)inet_addr((char*)s)";
|
||||||
|
|
||||||
PROCEDURE -SetCShort(i: INTEGER; VAR si: oocC.shortint)
|
PROCEDURE -SetCShort(i: INTEGER; VAR si: oocC.shortint)
|
||||||
"*(short*)si = i";
|
"*(short*)si = i";
|
||||||
|
|
@ -84,7 +87,7 @@ TYPE
|
||||||
PROCEDURE -SetCShortSwapped(i: INTEGER; VAR si: oocC.shortint)
|
PROCEDURE -SetCShortSwapped(i: INTEGER; VAR si: oocC.shortint)
|
||||||
"*(short*)si = ((i >> 8) & 0x00ff) | ((i << 8) & 0xff00)";
|
"*(short*)si = ((i >> 8) & 0x00ff) | ((i << 8) & 0xff00)";
|
||||||
|
|
||||||
PROCEDURE SetSockAddrIn*(family, port, inaddr: INTEGER; VAR sai: SockAddrIn);
|
PROCEDURE SetSockAddrIn*(family, port: INTEGER; inaddr: LONGINT; VAR sai: SockAddrIn);
|
||||||
VAR i: INTEGER;
|
VAR i: INTEGER;
|
||||||
BEGIN
|
BEGIN
|
||||||
SetCShort(family, sai.SinFamily);
|
SetCShort(family, sai.SinFamily);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue