diff --git a/Compiler b/Compiler index be9aba9..8ef578d 100644 Binary files a/Compiler and b/Compiler differ diff --git a/Compiler.exe b/Compiler.exe index a96401f..7a19d20 100644 Binary files a/Compiler.exe and b/Compiler.exe differ diff --git a/LICENSE b/LICENSE index 7f7490c..d921fd2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 2-Clause License -Copyright (c) 2018, Anton Krotov +Copyright (c) 2018-2019, Anton Krotov All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/SamplesMSP430.bat b/SamplesMSP430.bat new file mode 100644 index 0000000..97327de --- /dev/null +++ b/SamplesMSP430.bat @@ -0,0 +1,2 @@ +for %%f in (samples\MSP430\*.ob07) do Compiler.exe %%f msp430 +@pause diff --git a/SamplesWin64.bat b/SamplesWin64.bat new file mode 100644 index 0000000..20d301c --- /dev/null +++ b/SamplesWin64.bat @@ -0,0 +1,2 @@ +for %%f in (samples\Windows\Console\*.ob07) do Compiler.exe %%f console64 +@pause diff --git a/self-kos.cmd b/SelfKolibriOS.cmd similarity index 98% rename from self-kos.cmd rename to SelfKolibriOS.cmd index 08d2661..e3aee71 100644 --- a/self-kos.cmd +++ b/SelfKolibriOS.cmd @@ -1,2 +1,2 @@ -Compiler.exe source\Compiler.ob07 kos -out source\Compiler.kex -stk 2 +Compiler.exe source\Compiler.ob07 kos -out source\Compiler.kex -stk 2 @pause \ No newline at end of file diff --git a/self-win64-linux32.cmd b/SelfLinux32.cmd similarity index 98% rename from self-win64-linux32.cmd rename to SelfLinux32.cmd index 089b1cc..b1f53bf 100644 --- a/self-win64-linux32.cmd +++ b/SelfLinux32.cmd @@ -1,2 +1,2 @@ -Compiler.exe source\Compiler.ob07 elfexe -out source\Compiler32 -stk 2 +Compiler.exe source\Compiler.ob07 elfexe -out source\Compiler32 -stk 2 @pause \ No newline at end of file diff --git a/SelfLinux64.cmd b/SelfLinux64.cmd new file mode 100644 index 0000000..a57e679 --- /dev/null +++ b/SelfLinux64.cmd @@ -0,0 +1,2 @@ +Compiler.exe source\Compiler.ob07 elfexe64 -out source\Compiler -stk 2 +@pause \ No newline at end of file diff --git a/self64-32.cmd b/SelfWin32.cmd similarity index 97% rename from self64-32.cmd rename to SelfWin32.cmd index 1fdd65f..0af8935 100644 --- a/self64-32.cmd +++ b/SelfWin32.cmd @@ -1,2 +1,2 @@ -Compiler.exe source\Compiler.ob07 console -out source\Compiler32.exe -stk 2 -@pause +Compiler.exe source\Compiler.ob07 console -out source\Compiler32.exe -stk 2 +@pause diff --git a/self64.cmd b/SelfWin64.cmd similarity index 97% rename from self64.cmd rename to SelfWin64.cmd index 9ecd8af..1af9484 100644 --- a/self64.cmd +++ b/SelfWin64.cmd @@ -1,2 +1,2 @@ -Compiler.exe source\Compiler.ob07 console64 -out source\Compiler.exe -stk 2 -@pause +Compiler.exe source\Compiler.ob07 console64 -out source\Compiler.exe -stk 2 +@pause diff --git a/lib/KolibriOS/HOST.ob07 b/lib/KolibriOS/HOST.ob07 index 3a43347..523a7f5 100644 --- a/lib/KolibriOS/HOST.ob07 +++ b/lib/KolibriOS/HOST.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/KolibriOS/KOSAPI.ob07 b/lib/KolibriOS/KOSAPI.ob07 index 4cf92fc..84a881b 100644 --- a/lib/KolibriOS/KOSAPI.ob07 +++ b/lib/KolibriOS/KOSAPI.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/KolibriOS/RTL.ob07 b/lib/KolibriOS/RTL.ob07 index bf1516c..bb32817 100644 --- a/lib/KolibriOS/RTL.ob07 +++ b/lib/KolibriOS/RTL.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/UNIXTIME.ob07 b/lib/KolibriOS/UnixTime.ob07 similarity index 89% rename from source/UNIXTIME.ob07 rename to lib/KolibriOS/UnixTime.ob07 index e5f6ce3..0e6ed5b 100644 --- a/source/UNIXTIME.ob07 +++ b/lib/KolibriOS/UnixTime.ob07 @@ -1,64 +1,64 @@ -(* - BSD 2-Clause License - - Copyright (c) 2018, 2019, Anton Krotov - All rights reserved. -*) - -MODULE UNIXTIME; - - -VAR - - days: ARRAY 12, 31, 2 OF INTEGER; - - -PROCEDURE init; -VAR - i, j, k, n0, n1: INTEGER; -BEGIN - - FOR i := 0 TO 11 DO - FOR j := 0 TO 30 DO - days[i, j, 0] := 0; - days[i, j, 1] := 0; - END - END; - - days[ 1, 28, 0] := -1; - - FOR k := 0 TO 1 DO - days[ 1, 29, k] := -1; - days[ 1, 30, k] := -1; - days[ 3, 30, k] := -1; - days[ 5, 30, k] := -1; - days[ 8, 30, k] := -1; - days[10, 30, k] := -1; - END; - - n0 := 0; - n1 := 0; - FOR i := 0 TO 11 DO - FOR j := 0 TO 30 DO - IF days[i, j, 0] = 0 THEN - days[i, j, 0] := n0; - INC(n0) - END; - IF days[i, j, 1] = 0 THEN - days[i, j, 1] := n1; - INC(n1) - END - END - END - -END init; - - -PROCEDURE time* (year, month, day, hour, min, sec: INTEGER): INTEGER; - RETURN ((year - 1970) * 365 + days[month - 1, day - 1, ORD(year DIV 4 = 0)] + (year - 1969) DIV 4) * 86400 + hour * 3600 + min * 60 + sec -END time; - - -BEGIN - init -END UNIXTIME. \ No newline at end of file +(* + BSD 2-Clause License + + Copyright (c) 2018-2019, Anton Krotov + All rights reserved. +*) + +MODULE UnixTime; + + +VAR + + days: ARRAY 12, 31, 2 OF INTEGER; + + +PROCEDURE init; +VAR + i, j, k, n0, n1: INTEGER; +BEGIN + + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + days[i, j, 0] := 0; + days[i, j, 1] := 0; + END + END; + + days[ 1, 28, 0] := -1; + + FOR k := 0 TO 1 DO + days[ 1, 29, k] := -1; + days[ 1, 30, k] := -1; + days[ 3, 30, k] := -1; + days[ 5, 30, k] := -1; + days[ 8, 30, k] := -1; + days[10, 30, k] := -1; + END; + + n0 := 0; + n1 := 0; + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + IF days[i, j, 0] = 0 THEN + days[i, j, 0] := n0; + INC(n0) + END; + IF days[i, j, 1] = 0 THEN + days[i, j, 1] := n1; + INC(n1) + END + END + END + +END init; + + +PROCEDURE time* (year, month, day, hour, min, sec: INTEGER): INTEGER; + RETURN ((year - 1970) * 365 + days[month - 1, day - 1, ORD(year DIV 4 = 0)] + (year - 1969) DIV 4) * 86400 + hour * 3600 + min * 60 + sec +END time; + + +BEGIN + init +END UnixTime. \ No newline at end of file diff --git a/lib/Linux32/RTL.ob07 b/lib/Linux32/RTL.ob07 index bf1516c..bb32817 100644 --- a/lib/Linux32/RTL.ob07 +++ b/lib/Linux32/RTL.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Linux64/RTL.ob07 b/lib/Linux64/RTL.ob07 index 91f92b6..0c3d161 100644 --- a/lib/Linux64/RTL.ob07 +++ b/lib/Linux64/RTL.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Windows32/API.ob07 b/lib/Windows32/API.ob07 index 588669f..00e04fb 100644 --- a/lib/Windows32/API.ob07 +++ b/lib/Windows32/API.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Windows32/HOST.ob07 b/lib/Windows32/HOST.ob07 index a603c37..be51af0 100644 --- a/lib/Windows32/HOST.ob07 +++ b/lib/Windows32/HOST.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Windows32/RTL.ob07 b/lib/Windows32/RTL.ob07 index bf1516c..bb32817 100644 --- a/lib/Windows32/RTL.ob07 +++ b/lib/Windows32/RTL.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Windows32/UnixTime.ob07 b/lib/Windows32/UnixTime.ob07 new file mode 100644 index 0000000..0e6ed5b --- /dev/null +++ b/lib/Windows32/UnixTime.ob07 @@ -0,0 +1,64 @@ +(* + BSD 2-Clause License + + Copyright (c) 2018-2019, Anton Krotov + All rights reserved. +*) + +MODULE UnixTime; + + +VAR + + days: ARRAY 12, 31, 2 OF INTEGER; + + +PROCEDURE init; +VAR + i, j, k, n0, n1: INTEGER; +BEGIN + + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + days[i, j, 0] := 0; + days[i, j, 1] := 0; + END + END; + + days[ 1, 28, 0] := -1; + + FOR k := 0 TO 1 DO + days[ 1, 29, k] := -1; + days[ 1, 30, k] := -1; + days[ 3, 30, k] := -1; + days[ 5, 30, k] := -1; + days[ 8, 30, k] := -1; + days[10, 30, k] := -1; + END; + + n0 := 0; + n1 := 0; + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + IF days[i, j, 0] = 0 THEN + days[i, j, 0] := n0; + INC(n0) + END; + IF days[i, j, 1] = 0 THEN + days[i, j, 1] := n1; + INC(n1) + END + END + END + +END init; + + +PROCEDURE time* (year, month, day, hour, min, sec: INTEGER): INTEGER; + RETURN ((year - 1970) * 365 + days[month - 1, day - 1, ORD(year DIV 4 = 0)] + (year - 1969) DIV 4) * 86400 + hour * 3600 + min * 60 + sec +END time; + + +BEGIN + init +END UnixTime. \ No newline at end of file diff --git a/lib/Windows64/API.ob07 b/lib/Windows64/API.ob07 index 588669f..00e04fb 100644 --- a/lib/Windows64/API.ob07 +++ b/lib/Windows64/API.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Windows64/HOST.ob07 b/lib/Windows64/HOST.ob07 index a603c37..be51af0 100644 --- a/lib/Windows64/HOST.ob07 +++ b/lib/Windows64/HOST.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Windows64/RTL.ob07 b/lib/Windows64/RTL.ob07 index 91f92b6..0c3d161 100644 --- a/lib/Windows64/RTL.ob07 +++ b/lib/Windows64/RTL.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/lib/Windows64/UnixTime.ob07 b/lib/Windows64/UnixTime.ob07 new file mode 100644 index 0000000..0e6ed5b --- /dev/null +++ b/lib/Windows64/UnixTime.ob07 @@ -0,0 +1,64 @@ +(* + BSD 2-Clause License + + Copyright (c) 2018-2019, Anton Krotov + All rights reserved. +*) + +MODULE UnixTime; + + +VAR + + days: ARRAY 12, 31, 2 OF INTEGER; + + +PROCEDURE init; +VAR + i, j, k, n0, n1: INTEGER; +BEGIN + + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + days[i, j, 0] := 0; + days[i, j, 1] := 0; + END + END; + + days[ 1, 28, 0] := -1; + + FOR k := 0 TO 1 DO + days[ 1, 29, k] := -1; + days[ 1, 30, k] := -1; + days[ 3, 30, k] := -1; + days[ 5, 30, k] := -1; + days[ 8, 30, k] := -1; + days[10, 30, k] := -1; + END; + + n0 := 0; + n1 := 0; + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + IF days[i, j, 0] = 0 THEN + days[i, j, 0] := n0; + INC(n0) + END; + IF days[i, j, 1] = 0 THEN + days[i, j, 1] := n1; + INC(n1) + END + END + END + +END init; + + +PROCEDURE time* (year, month, day, hour, min, sec: INTEGER): INTEGER; + RETURN ((year - 1970) * 365 + days[month - 1, day - 1, ORD(year DIV 4 = 0)] + (year - 1969) DIV 4) * 86400 + hour * 3600 + min * 60 + sec +END time; + + +BEGIN + init +END UnixTime. \ No newline at end of file diff --git a/self-win64-linux64.cmd b/self-win64-linux64.cmd deleted file mode 100644 index 59bcdfd..0000000 --- a/self-win64-linux64.cmd +++ /dev/null @@ -1,2 +0,0 @@ -Compiler.exe source\Compiler.ob07 elfexe64 -stk 2 -@pause \ No newline at end of file diff --git a/source/AMD64.ob07 b/source/AMD64.ob07 index 2a58bc3..9d80972 100644 --- a/source/AMD64.ob07 +++ b/source/AMD64.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) @@ -2574,12 +2574,12 @@ BEGIN END translate; -PROCEDURE prolog (code: IL.CODES; modname: ARRAY OF CHAR; target, stack_size: INTEGER); +PROCEDURE prolog (modname: ARRAY OF CHAR; target, stack_size: INTEGER); VAR ModName_Offs, entry, L: INTEGER; BEGIN - ModName_Offs := tcount * 8 + CHL.Length(code.data); + ModName_Offs := tcount * 8 + CHL.Length(IL.codes.data); Numbers_Offs := ModName_Offs + LENGTH(modname) + 1; ASSERT(UTILS.Align(Numbers_Offs, 16)); @@ -2626,7 +2626,7 @@ BEGIN END prolog; -PROCEDURE epilog (code: IL.CODES; modname: ARRAY OF CHAR; target: INTEGER); +PROCEDURE epilog (modname: ARRAY OF CHAR; target: INTEGER); VAR i, n: INTEGER; number: Number; @@ -2673,13 +2673,13 @@ BEGIN i := 0; WHILE i < tcount DO - BIN.PutData64LE(prog, CHL.GetInt(code.types, i)); + BIN.PutData64LE(prog, CHL.GetInt(IL.codes.types, i)); INC(i) END; i := 0; - WHILE i < CHL.Length(code.data) DO - BIN.PutData(prog, CHL.GetByte(code.data, i)); + WHILE i < CHL.Length(IL.codes.data) DO + BIN.PutData(prog, CHL.GetByte(IL.codes.data, i)); INC(i) END; @@ -2698,13 +2698,13 @@ BEGIN number := number.next(Number) END; - exp := code.export.first(IL.EXPORT_PROC); + exp := IL.codes.export.first(IL.EXPORT_PROC); WHILE exp # NIL DO BIN.Export(prog, exp.name, exp.label); exp := exp.next(IL.EXPORT_PROC) END; - import(code.import) + import(IL.codes.import) END epilog; @@ -2732,12 +2732,12 @@ BEGIN END rsave; -PROCEDURE CodeGen* (code: IL.CODES; outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS); +PROCEDURE CodeGen* (outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS); VAR path, modname, ext: PATHS.PATH; BEGIN - tcount := CHL.Length(code.types); + tcount := CHL.Length(IL.codes.types); Win64RegPar[0] := rcx; Win64RegPar[1] := rdx; @@ -2756,7 +2756,7 @@ BEGIN REG.Init(R, push, pop, mov, xchg, rload, rsave, {rax, r10, r11}, {rcx, rdx, r8, r9}); - code.bss := MAX(code.bss, MAX(code.dmin - CHL.Length(code.data), 8)); + IL.set_bss(MAX(IL.codes.bss, MAX(IL.codes.dmin - CHL.Length(IL.codes.data), 8))); Numbers := LISTS.create(NIL); Numbers_Count := 0; @@ -2768,14 +2768,14 @@ BEGIN NewNumber(ORD(-BITS(LSR(ASR(ROR(1, 1), 10), 1)))); (* {0..51, 63} *) NewNumber(LSR(ASR(ROR(1, 1), 9), 2)); (* {52..61} *) - prog := BIN.create(code.lcount); - BIN.SetParams(prog, code.bss, 1, WCHR(1), WCHR(0)); + prog := BIN.create(IL.codes.lcount); + BIN.SetParams(prog, IL.codes.bss, 1, WCHR(1), WCHR(0)); X86.SetProgram(prog); - prolog(code, modname, target, options.stack); - translate(code.commands, tcount * 8); - epilog(code, modname, target); + prolog(modname, target, options.stack); + translate(IL.codes.commands, tcount * 8); + epilog(modname, target); BIN.fixup(prog); IF target IN {mConst.Target_iConsole64, mConst.Target_iGUI64, mConst.Target_iDLL64} THEN diff --git a/source/ARITH.ob07 b/source/ARITH.ob07 index 9d03466..aa54000 100644 --- a/source/ARITH.ob07 +++ b/source/ARITH.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/AVLTREES.ob07 b/source/AVLTREES.ob07 index 84053be..64b1990 100644 --- a/source/AVLTREES.ob07 +++ b/source/AVLTREES.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/BIN.ob07 b/source/BIN.ob07 index a3f7db6..6ab0b48 100644 --- a/source/BIN.ob07 +++ b/source/BIN.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/CHUNKLISTS.ob07 b/source/CHUNKLISTS.ob07 index b604c2d..7df4c1f 100644 --- a/source/CHUNKLISTS.ob07 +++ b/source/CHUNKLISTS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/COLLECTIONS.ob07 b/source/COLLECTIONS.ob07 index 311d6df..f9b713a 100644 --- a/source/COLLECTIONS.ob07 +++ b/source/COLLECTIONS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/CONSOLE.ob07 b/source/CONSOLE.ob07 index 7b4072f..b591683 100644 --- a/source/CONSOLE.ob07 +++ b/source/CONSOLE.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/CONSTANTS.ob07 b/source/CONSTANTS.ob07 index 161e1b3..aaa4f16 100644 --- a/source/CONSTANTS.ob07 +++ b/source/CONSTANTS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/Compiler.ob07 b/source/Compiler.ob07 index 496747a..79a5562 100644 --- a/source/Compiler.ob07 +++ b/source/Compiler.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/ERRORS.ob07 b/source/ERRORS.ob07 index 6738d04..86cc8fb 100644 --- a/source/ERRORS.ob07 +++ b/source/ERRORS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/FILES.ob07 b/source/FILES.ob07 index fc67c1f..067329b 100644 --- a/source/FILES.ob07 +++ b/source/FILES.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/IL.ob07 b/source/IL.ob07 index f243e0a..f0d1dad 100644 --- a/source/IL.ob07 +++ b/source/IL.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) @@ -171,7 +171,7 @@ TYPE END; - CODES* = POINTER TO RECORD + CODES = RECORD last: COMMAND; begcall: CMDSTACK; @@ -204,6 +204,24 @@ VAR commands, variables: C.COLLECTION; +PROCEDURE set_dmin* (value: INTEGER); +BEGIN + codes.dmin := value +END set_dmin; + + +PROCEDURE set_bss* (value: INTEGER); +BEGIN + codes.bss := value +END set_bss; + + +PROCEDURE set_rtl* (idx, label: INTEGER); +BEGIN + codes.rtl[idx] := label +END set_rtl; + + PROCEDURE NewCmd (): COMMAND; VAR cmd: COMMAND; @@ -253,7 +271,7 @@ PROCEDURE getlast* (): COMMAND; END getlast; -PROCEDURE PutByte (codes: CODES; b: BYTE); +PROCEDURE PutByte (b: BYTE); BEGIN CHL.PushByte(codes.data, b) END PutByte; @@ -268,11 +286,11 @@ BEGIN i := 0; n := LENGTH(s); WHILE i < n DO - PutByte(codes, ORD(s[i])); + PutByte(ORD(s[i])); INC(i) END; - PutByte(codes, 0) + PutByte(0) RETURN res END putstr; @@ -285,8 +303,8 @@ VAR BEGIN IF codes.charoffs[c] = -1 THEN res := CHL.Length(codes.data); - PutByte(codes, c); - PutByte(codes, 0); + PutByte(c); + PutByte(0); codes.charoffs[c] := res ELSE res := codes.charoffs[c] @@ -304,7 +322,7 @@ BEGIN res := CHL.Length(codes.data); IF ODD(res) THEN - PutByte(codes, 0); + PutByte(0); INC(res) END; @@ -313,17 +331,17 @@ BEGIN i := 0; WHILE i < n DO IF endianness = little_endian THEN - PutByte(codes, ORD(codes.wstr[i]) MOD 256); - PutByte(codes, ORD(codes.wstr[i]) DIV 256) + PutByte(ORD(codes.wstr[i]) MOD 256); + PutByte(ORD(codes.wstr[i]) DIV 256) ELSIF endianness = big_endian THEN - PutByte(codes, ORD(codes.wstr[i]) DIV 256); - PutByte(codes, ORD(codes.wstr[i]) MOD 256) + PutByte(ORD(codes.wstr[i]) DIV 256); + PutByte(ORD(codes.wstr[i]) MOD 256) END; INC(i) END; - PutByte(codes, 0); - PutByte(codes, 0) + PutByte(0); + PutByte(0) RETURN res END putstrW; @@ -338,20 +356,20 @@ BEGIN res := CHL.Length(codes.data); IF ODD(res) THEN - PutByte(codes, 0); + PutByte(0); INC(res) END; IF endianness = little_endian THEN - PutByte(codes, c MOD 256); - PutByte(codes, c DIV 256) + PutByte(c MOD 256); + PutByte(c DIV 256) ELSIF endianness = big_endian THEN - PutByte(codes, c DIV 256); - PutByte(codes, c MOD 256) + PutByte(c DIV 256); + PutByte(c MOD 256) END; - PutByte(codes, 0); - PutByte(codes, 0); + PutByte(0); + PutByte(0); codes.wcharoffs[c] := res ELSE @@ -931,18 +949,6 @@ BEGIN END flt; -PROCEDURE odd*; -BEGIN - AddCmd0(opODD) -END odd; - - -PROCEDURE ord*; -BEGIN - AddCmd0(opORD) -END ord; - - PROCEDURE shift_minmax* (op: CHAR); BEGIN CASE op OF @@ -1143,7 +1149,6 @@ BEGIN numRegsFloat := pNumRegsFloat; endianness := pEndianness; - NEW(codes); NEW(codes.begcall); codes.begcall.top := -1; NEW(codes.endcall); diff --git a/source/KOS.ob07 b/source/KOS.ob07 index fe44eed..96c6f97 100644 --- a/source/KOS.ob07 +++ b/source/KOS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/LISTS.ob07 b/source/LISTS.ob07 index 59b1342..d9a8bcc 100644 --- a/source/LISTS.ob07 +++ b/source/LISTS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/MSCOFF.ob07 b/source/MSCOFF.ob07 index 5abc831..f27f608 100644 --- a/source/MSCOFF.ob07 +++ b/source/MSCOFF.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/MSP430.ob07 b/source/MSP430.ob07 index 925ab0c..bb1e7ae 100644 --- a/source/MSP430.ob07 +++ b/source/MSP430.ob07 @@ -582,7 +582,7 @@ BEGIN END Neg; -PROCEDURE translate (code: IL.CODES); +PROCEDURE translate; VAR cmd, next: COMMAND; @@ -593,7 +593,7 @@ VAR cc: INTEGER; BEGIN - cmd := code.commands.first(COMMAND); + cmd := IL.codes.commands.first(COMMAND); WHILE cmd # NIL DO @@ -1643,7 +1643,7 @@ BEGIN END WriteHex; -PROCEDURE CodeGen* (code: IL.CODES; outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS); +PROCEDURE CodeGen* (outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS); VAR i, adr, heap, stack, TextSize, TypesSize, bits, n: INTEGER; @@ -1668,12 +1668,12 @@ BEGIN ram := MIN(MAX(ram, minRAM), maxRAM); rom := MIN(MAX(rom, minROM), maxROM); - IF code.bss > ram - minStackSize - RTL.VarSize THEN + IF IL.codes.bss > ram - minStackSize - RTL.VarSize THEN ERRORS.Error(204) END; Labels := CHL.CreateIntList(); - FOR i := 1 TO code.lcount DO + FOR i := 1 TO IL.codes.lcount DO CHL.PushInt(Labels, 0) END; @@ -1681,28 +1681,28 @@ BEGIN mem[i] := 0 END; - TypesSize := CHL.Length(code.types) * 2; + TypesSize := CHL.Length(IL.codes.types) * 2; CodeList := LISTS.create(NIL); RelList := LISTS.create(NIL); REG.Init(R, Push, Pop, mov, xchg, NIL, NIL, {R4, R5, R6, R7}, {}); prolog(ram); - translate(code); + translate; epilog; Code.address := 10000H - rom; Code.size := Fixup(Code.address, IntVectorSize + TypesSize); Data.address := Code.address + Code.size; - Data.size := CHL.Length(code.data); + Data.size := CHL.Length(IL.codes.data); Data.size := Data.size + ORD(ODD(Data.size)); TextSize := Code.size + Data.size; - IF Code.address + TextSize + MAX(code.dmin - Data.size, IntVectorSize + TypesSize) > 10000H THEN + IF Code.address + TextSize + MAX(IL.codes.dmin - Data.size, IntVectorSize + TypesSize) > 10000H THEN ERRORS.Error(203) END; Bss.address := RTL.ram + RTL.VarSize; - Bss.size := code.bss + ORD(ODD(code.bss)); + Bss.size := IL.codes.bss + ORD(ODD(IL.codes.bss)); heap := Bss.address + Bss.size; stack := RTL.ram + ram; ASSERT(stack - heap >= minStackSize); @@ -1724,15 +1724,15 @@ BEGIN adr := Data.address; - FOR i := 0 TO CHL.Length(code.data) - 1 DO - mem[adr] := CHL.GetByte(code.data, i); + FOR i := 0 TO CHL.Length(IL.codes.data) - 1 DO + mem[adr] := CHL.GetByte(IL.codes.data, i); INC(adr) END; adr := 10000H - IntVectorSize - TypesSize; FOR i := TypesSize DIV 2 - 1 TO 0 BY -1 DO - PutWord(CHL.GetInt(code.types, i), adr) + PutWord(CHL.GetInt(IL.codes.types, i), adr) END; FOR i := 0 TO 15 DO diff --git a/source/PARS.ob07 b/source/PARS.ob07 index 3f183a2..e7b91af 100644 --- a/source/PARS.ob07 +++ b/source/PARS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/PATHS.ob07 b/source/PATHS.ob07 index e6ea792..5532b6c 100644 --- a/source/PATHS.ob07 +++ b/source/PATHS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/PE32.ob07 b/source/PE32.ob07 index a21383d..acb13e5 100644 --- a/source/PE32.ob07 +++ b/source/PE32.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/PROG.ob07 b/source/PROG.ob07 index b60f6df..7945b9a 100644 --- a/source/PROG.ob07 +++ b/source/PROG.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/REG.ob07 b/source/REG.ob07 index b77aebf..8014d50 100644 --- a/source/REG.ob07 +++ b/source/REG.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/SCAN.ob07 b/source/SCAN.ob07 index ce26b89..029b2f3 100644 --- a/source/SCAN.ob07 +++ b/source/SCAN.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/STATEMENTS.ob07 b/source/STATEMENTS.ob07 index aa4ecee..9d9027e 100644 --- a/source/STATEMENTS.ob07 +++ b/source/STATEMENTS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) @@ -613,7 +613,7 @@ BEGIN stroffs := StringW(e); IL.StrAdr(stroffs) END; - IL.codes.dmin := stroffs + p.type.size; + IL.set_dmin(stroffs + p.type.size); IL.Param1 ELSE LoadConst(e); @@ -1113,7 +1113,7 @@ BEGIN IF e.obj = eCONST THEN ARITH.odd(e.value) ELSE - IL.odd + IL.AddCmd0(IL.opODD) END |PROG.stORD: @@ -1127,7 +1127,7 @@ BEGIN END ELSE IF isBoolean(e) THEN - IL.ord + IL.AddCmd0(IL.opORD) END END; e.type := tINTEGER @@ -3228,10 +3228,10 @@ VAR id := PROG.getIdent(rtl, SCAN.enterid(name), FALSE); IF (id # NIL) & (id.import # NIL) THEN - IL.codes.rtl[idx] := -id.import(IL.IMPORT_PROC).label; + IL.set_rtl(idx, -id.import(IL.IMPORT_PROC).label); id.proc.used := TRUE ELSIF (id # NIL) & (id.proc # NIL) THEN - IL.codes.rtl[idx] := id.proc.label; + IL.set_rtl(idx, id.proc.label); id.proc.used := TRUE ELSE ERRORS.WrongRTL(name) @@ -3349,12 +3349,12 @@ BEGIN PROG.DelUnused(PARS.program, IL.DelImport); - IL.codes.bss := PARS.program.bss; + IL.set_bss(PARS.program.bss); CASE CPU OF - | cpuAMD64: AMD64.CodeGen(IL.codes, outname, target, options) - | cpuX86: X86.CodeGen(IL.codes, outname, target, options) - |cpuMSP430: MSP430.CodeGen(IL.codes, outname, target, options) + | cpuAMD64: AMD64.CodeGen(outname, target, options) + | cpuX86: X86.CodeGen(outname, target, options) + |cpuMSP430: MSP430.CodeGen(outname, target, options) END END compile; diff --git a/source/STRINGS.ob07 b/source/STRINGS.ob07 index 2905c08..3743320 100644 --- a/source/STRINGS.ob07 +++ b/source/STRINGS.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/TEXTDRV.ob07 b/source/TEXTDRV.ob07 index 92e095d..cfdddba 100644 --- a/source/TEXTDRV.ob07 +++ b/source/TEXTDRV.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/UTILS.ob07 b/source/UTILS.ob07 index c31ac81..459d143 100644 --- a/source/UTILS.ob07 +++ b/source/UTILS.ob07 @@ -1,13 +1,13 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) MODULE UTILS; -IMPORT HOST, UNIXTIME; +IMPORT HOST; CONST @@ -24,6 +24,11 @@ CONST max32* = 2147483647; +TYPE + + DAYS = ARRAY 12, 31, 2 OF INTEGER; + + VAR time*: INTEGER; @@ -48,6 +53,8 @@ VAR bit_diff*: INTEGER; + days: DAYS; + PROCEDURE FileRead* (F: INTEGER; VAR Buffer: ARRAY OF BYTE; bytes: INTEGER): INTEGER; RETURN HOST.FileRead(F, Buffer, bytes) @@ -114,6 +121,11 @@ BEGIN END GetCurrentDirectory; +PROCEDURE GetUnixTime* (year, month, day, hour, min, sec: INTEGER): INTEGER; + RETURN ((year - 1970) * 365 + days[month - 1, day - 1, ORD(year DIV 4 = 0)] + (year - 1969) DIV 4) * 86400 + hour * 3600 + min * 60 + sec +END GetUnixTime; + + PROCEDURE UnixTime* (): INTEGER; VAR year, month, day, hour, min, sec: INTEGER; @@ -124,7 +136,7 @@ BEGIN res := HOST.UnixTime() ELSE HOST.now(year, month, day, hour, min, sec); - res := UNIXTIME.time(year, month, day, hour, min, sec) + res := GetUnixTime(year, month, day, hour, min, sec) END RETURN res @@ -201,9 +213,52 @@ BEGIN END Log2; +PROCEDURE init (VAR days: DAYS); +VAR + i, j, n0, n1: INTEGER; + +BEGIN + + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + days[i, j, 0] := 0; + days[i, j, 1] := 0; + END + END; + + days[ 1, 28, 0] := -1; + + FOR i := 0 TO 1 DO + days[ 1, 29, i] := -1; + days[ 1, 30, i] := -1; + days[ 3, 30, i] := -1; + days[ 5, 30, i] := -1; + days[ 8, 30, i] := -1; + days[10, 30, i] := -1; + END; + + n0 := 0; + n1 := 0; + FOR i := 0 TO 11 DO + FOR j := 0 TO 30 DO + IF days[i, j, 0] = 0 THEN + days[i, j, 0] := n0; + INC(n0) + END; + IF days[i, j, 1] = 0 THEN + days[i, j, 1] := n1; + INC(n1) + END + END + END + +END init; + + BEGIN time := GetTickCount(); COPY(HOST.eol, eol); maxreal := 1.9; - PACK(maxreal, 1023) + PACK(maxreal, 1023); + init(days) END UTILS. \ No newline at end of file diff --git a/source/WRITER.ob07 b/source/WRITER.ob07 index 4781013..5832900 100644 --- a/source/WRITER.ob07 +++ b/source/WRITER.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) diff --git a/source/X86.ob07 b/source/X86.ob07 index c02489c..711f108 100644 --- a/source/X86.ob07 +++ b/source/X86.ob07 @@ -1,7 +1,7 @@ (* BSD 2-Clause License - Copyright (c) 2018, 2019, Anton Krotov + Copyright (c) 2018-2019, Anton Krotov All rights reserved. *) @@ -573,7 +573,7 @@ BEGIN END GetRegA; -PROCEDURE translate (code: IL.CODES; pic: BOOLEAN; stroffs: INTEGER); +PROCEDURE translate (pic: BOOLEAN; stroffs: INTEGER); VAR cmd: COMMAND; @@ -586,7 +586,7 @@ VAR float: REAL; BEGIN - cmd := code.commands.first(COMMAND); + cmd := IL.codes.commands.first(COMMAND); WHILE cmd # NIL DO @@ -2087,7 +2087,7 @@ BEGIN END translate; -PROCEDURE prolog (code: IL.CODES; pic: BOOLEAN; target, stack, dllinit, dllret: INTEGER); +PROCEDURE prolog (pic: BOOLEAN; target, stack, dllinit, dllret: INTEGER); VAR reg1, entry, L, dcount: INTEGER; @@ -2143,7 +2143,7 @@ BEGIN Reloc(BIN.RDATA, 0) END; - dcount := CHL.Length(code.data); + dcount := CHL.Length(IL.codes.data); pushc(tcount); @@ -2176,7 +2176,7 @@ BEGIN END prolog; -PROCEDURE epilog (code: IL.CODES; pic: BOOLEAN; modname: ARRAY OF CHAR; target, stack, ver, dllinit, dllret, sofinit: INTEGER); +PROCEDURE epilog (pic: BOOLEAN; modname: ARRAY OF CHAR; target, stack, ver, dllinit, dllret, sofinit: INTEGER); VAR exp: IL.EXPORT_PROC; path, name, ext: PATHS.PATH; @@ -2227,14 +2227,14 @@ BEGIN fixup; - dcount := CHL.Length(code.data); + dcount := CHL.Length(IL.codes.data); FOR i := 0 TO tcount - 1 DO - BIN.PutData32LE(program, CHL.GetInt(code.types, i)) + BIN.PutData32LE(program, CHL.GetInt(IL.codes.types, i)) END; FOR i := 0 TO dcount - 1 DO - BIN.PutData(program, CHL.GetByte(code.data, i)) + BIN.PutData(program, CHL.GetByte(IL.codes.data, i)) END; program.modname := CHL.Length(program.data); @@ -2248,33 +2248,33 @@ BEGIN BIN.Export(program, "lib_init", dllinit); END; - exp := code.export.first(IL.EXPORT_PROC); + exp := IL.codes.export.first(IL.EXPORT_PROC); WHILE exp # NIL DO BIN.Export(program, exp.name, exp.label); exp := exp.next(IL.EXPORT_PROC) END; - import(code.import); + import(IL.codes.import); - code.bss := MAX(code.bss, MAX(code.dmin - CHL.Length(code.data), 4)); + IL.set_bss(MAX(IL.codes.bss, MAX(IL.codes.dmin - CHL.Length(IL.codes.data), 4))); - BIN.SetParams(program, code.bss, stack * (1024 * 1024), WCHR(ver DIV 65536), WCHR(ver MOD 65536)); + BIN.SetParams(program, IL.codes.bss, stack * (1024 * 1024), WCHR(ver DIV 65536), WCHR(ver MOD 65536)); END epilog; -PROCEDURE CodeGen* (code: IL.CODES; outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS); +PROCEDURE CodeGen* (outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS); VAR dllret, dllinit, sofinit: INTEGER; opt: PROG.OPTIONS; BEGIN - tcount := CHL.Length(code.types); + tcount := CHL.Length(IL.codes.types); opt := options; CodeList := LISTS.create(NIL); - program := BIN.create(code.lcount); + program := BIN.create(IL.codes.lcount); dllinit := NewLabel(); dllret := NewLabel(); @@ -2290,9 +2290,9 @@ BEGIN REG.Init(R, push, pop, mov, xchg, NIL, NIL, {eax, ecx, edx}, {}); - prolog(code, opt.pic, target, opt.stack, dllinit, dllret); - translate(code, opt.pic, tcount * 4); - epilog(code, opt.pic, outname, target, opt.stack, opt.version, dllinit, dllret, sofinit); + prolog(opt.pic, target, opt.stack, dllinit, dllret); + translate(opt.pic, tcount * 4); + epilog(opt.pic, outname, target, opt.stack, opt.version, dllinit, dllret, sofinit); BIN.fixup(program);