Skip to content

Commit

Permalink
Добавлен генератор кода на Обероне
Browse files Browse the repository at this point in the history
  • Loading branch information
ComdivByZero authored and ComdivByZero committed Dec 22, 2019
1 parent 835f2e4 commit 536fd4d
Show file tree
Hide file tree
Showing 9 changed files with 1,267 additions and 17 deletions.
1 change: 1 addition & 0 deletions README-RU.md
Expand Up @@ -12,6 +12,7 @@
* Общем подмножестве С и С++, совместимом с gcc, clang, tcc, CompCert, MS VS.
* Java стандарта 1.7
* JavaScript стандарта ECMAScript 5
* Код на Oberon-07 и Active Oberon

Основной код транслятора написан на его входном языке - Обероне.
Привязки к библиотекам - на соответствующих выходных языках.
Expand Down
53 changes: 53 additions & 0 deletions singularity/implementation.ao/O_7.mod
@@ -0,0 +1,53 @@
(* Definitions for support Oberon-O7 code translated into Active Oberon
*
* Copyright 2019 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*)
MODULE O_7;

IMPORT
SYSTEM;

VAR
ch*: ARRAY 100H, 2 OF CHAR;

PROCEDURE Ord*(s: SET32): SIGNED32;
BEGIN RETURN
SYSTEM.VAL(INTEGER, s)
END Ord;

PROCEDURE Bti*(b: BOOLEAN): SIGNED32;
VAR i: SIGNED32;
BEGIN
IF b THEN
i := 1
ELSE
i := 0
END;
RETURN
i
END Bti;

PROCEDURE InitCh;
VAR i: INTEGER;
BEGIN
FOR i := 0 TO LEN(ch) - 1 DO
ch[i, 0] := CHR(i);
ch[i, 1] := 0X
END
END InitCh;

BEGIN
InitCh
END O_7.
9 changes: 5 additions & 4 deletions source/Ast.mod
Expand Up @@ -197,10 +197,11 @@ CONST
Used* = 5;
Dereferenced* = 6;

Integers* = {IdByte, IdInteger, IdLongInt};
Reals* = {IdReal32, IdReal};
Numbers* = Integers + Reals;
Sets* = {IdSet, IdLongSet};
Integers* = {IdByte, IdInteger, IdLongInt};
Reals* = {IdReal32, IdReal};
Numbers* = Integers + Reals;
Sets* = {IdSet, IdLongSet};
Structures* = {IdRecord, IdArray};

(* в RExpression.properties для учёта того, что сравнение с NIL не может
быть константным в clang *)
Expand Down
21 changes: 17 additions & 4 deletions source/CliParser.mod
@@ -1,4 +1,5 @@
(* Command line interface for Oberon-07 translator
*
* Copyright (C) 2016-2019 ComdivByZero
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +17,8 @@
*)
MODULE CliParser;

IMPORT V, CLI, Utf8, Strings := StringStore, Platform, GeneratorC, GenOptions,
IMPORT V, CLI, Utf8, Strings := StringStore, Platform,
GenOptions, GeneratorOberon, GeneratorC,
OsUtil, Chars0X;

CONST
Expand All @@ -34,9 +36,13 @@ CONST
ResultJs* = 8;
ResultRunJs* = 9;

ResultMod* = 10;

ThroughC* = {ResultC, ResultBin, ResultRun};
ThroughJava* = {ResultJava, ResultClass, ResultRunJava};
ThroughJs* = {ResultJs, ResultRunJs};
ThroughMod* = {ResultMod};
ForRun* = {ResultRun, ResultRunJava, ResultRunJs};

CyrillicNo* = 0;
CyrillicDefault* = 1;
Expand Down Expand Up @@ -85,7 +91,7 @@ TYPE
modPath*, cDirs*, cc*, javaDirs*, jsDirs*, javac*: ARRAY 4096 OF CHAR;
modPathLen*: INTEGER;
sing*: SET;
init*, memng*, arg*, cStd*: INTEGER;
init*, memng*, arg*, cStd*, obStd*: INTEGER;
noNilCheck*, noOverflowCheck*, noIndexCheck*: BOOLEAN;
cyrillic*: INTEGER;

Expand Down Expand Up @@ -314,6 +320,10 @@ BEGIN
args.cStd := GeneratorC.IsoC99
ELSIF opt = "-C11" THEN
args.cStd := GeneratorC.IsoC11
ELSIF opt = "-out:O7" THEN
args.obStd := GeneratorOberon.StdO7
ELSIF opt = "-out:AO" THEN
args.obStd := GeneratorOberon.StdAo
ELSIF opt = "-multi-errors" THEN
args.multiErrors := TRUE
ELSE
Expand Down Expand Up @@ -360,6 +370,7 @@ BEGIN
args.init := -1;
args.memng := -1;
args.cStd := -1;
args.obStd := -1;
args.noNilCheck := FALSE;
args.noOverflowCheck := FALSE;
args.noIndexCheck := FALSE;
Expand Down Expand Up @@ -519,7 +530,7 @@ BEGIN
argDest := arg;
INC(args.srcLen);

forRun := ret IN {ResultRun, ResultRunJava, ResultRunJs};
forRun := ret IN ForRun;
arg := arg + ORD(~forRun);
cpRet := Options(args, arg);
IF cpRet # ErrNo THEN
Expand All @@ -546,7 +557,7 @@ END ParseOptions;
PROCEDURE Command(VAR args: Args; ret: INTEGER): INTEGER;
VAR arg: INTEGER;
BEGIN
ASSERT(ret IN {ResultC .. ResultRunJs});
ASSERT(ret IN {ResultC .. ResultMod});

ArgsInit(args);

Expand Down Expand Up @@ -595,6 +606,8 @@ BEGIN
ret := Command(args, ResultJs)
ELSIF cmd = "run-js" THEN
ret := Command(args, ResultRunJs)
ELSIF cmd = "to-mod" THEN
ret := Command(args, ResultMod)
ELSE
ret := ErrUnknownCommand
END
Expand Down

0 comments on commit 536fd4d

Please sign in to comment.