September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,181 @@
* CALENDAR FOR REAL PROGRAMMERS 05/03/2017
CALENDAR CSECT
USING CALENDAR,R13 BASE REGISTER
B 72(R15) SKIP MY SAVEAREA
DC 17F'0' MY SAVEAREA
STM R14,R12,12(R13) SAVE CALLER'S REGISTERS
ST R13,4(R15) LINK BACKWARD
ST R15,8(R13) LINK FORWARD
LR R13,R15 SET ADDRESSABILITY
L R4,YEAR YEAR
SRDA R4,32 .
D R4,=F'4' YEAR//4
LTR R4,R4 IF YEAR//4=0
BNZ LYNOT
L R4,YEAR YEAR
SRDA R4,32 .
D R4,=F'100' YEAR//100
LTR R4,R4 IF YEAR//100=0
BNZ LY
L R4,YEAR YEAR
SRDA R4,32 .
D R4,=F'400' IF YEAR//400
LTR R4,R4 IF YEAR//400=0
BNZ LYNOT
LY MVC ML+2,=H'29' ML(2)=29 LEAPYEAR
LYNOT SR R10,R10 LTD1=0
LA R6,1 I=1
LOOPI1 C R6,=F'31' DO I=1 TO 31
BH ELOOPI1
XDECO R6,XDEC EDIT I
LA R14,TD1 TD1
AR R14,R10 TD1+LTD1
MVC 0(3,R14),XDEC+9 SUB(TD1,LTD1+1,3)=PIC(I,3)
LA R10,3(R10) LTD1+3
LA R6,1(R6) I=I+1
B LOOPI1
ELOOPI1 LA R6,1 I=1
LOOPI2 C R6,=F'12' DO I=1 TO 12
BH ELOOPI2
ST R6,M M=I
MVC D,=F'1' D=1
MVC YY,YEAR YY=YEAR
L R4,M M
C R4,=F'3' IF M<3
BNL GE3
L R2,M M
LA R2,12(R2) M+12
ST R2,M M=M+12
L R2,YY YY
BCTR R2,0 YY-1
ST R2,YY YY=YY-1
GE3 L R2,YY YY
LR R1,R2 YY
SRA R1,2 YY/4
AR R2,R1 YY+(YY/4)
L R4,YY YY
SRDA R4,32 .
D R4,=F'100' YY/100
SR R2,R5 YY+(YY/4)-(YY/100)
L R4,YY YY
SRDA R4,32 .
D R4,=F'400' YY/400
AR R2,R5 YY+(YY/4)-(YY/100)+(YY/400)
A R2,D R2=YY+(YY/4)-(YY/100)+(YY/400)+D
LA R5,153 153
M R4,M 153*M
LA R5,8(R5) 153*M+8
D R4,=F'5' (153*M+8)/5
AR R5,R2 ((153*M+8)/5+R2
LA R4,0 .
D R4,=F'7' R4=MOD(R5,7) 0=SUN 1=MON ... 6=SAT
LTR R4,R4 IF J=0
BNZ JNE0
LA R4,7 J=7
JNE0 BCTR R4,0 J-1
MH R4,=H'3' J*3
LR R10,R4 J1=J*3
LR R1,R6 I
SLA R1,1 *2
LH R11,ML-2(R1) ML(I)
MH R11,=H'3' J2=ML(I)*3
MVC TD2,BLANK TD2=' '
LA R4,TD1 @TD1
LR R5,R11 J2
LA R2,TD2 @TD2
AR R2,R10 @TD2+J1
LR R3,R5 J2
MVCL R2,R4 SUB(TD2,J1+1,J2)=SUB(TD1,1,J2)
LR R1,R6 I
MH R1,=H'144' *144
LA R14,DA-144(R1) @DA(I)
MVC 0(144,R14),TD2 DA(I)=TD2
LA R6,1(R6) I=I+1
B LOOPI2
ELOOPI2 XPRNT SNOOPY,132 PRINT SNOOPY
L R1,YEAR YEAR
XDECO R1,PG+56 EDIT YEAR
XPRNT PG,L'PG PRINT YEAR
MVC WDLINE,BLANK WDLINE=' '
LA R10,1 LWDLINE=1
LA R8,1 K=1
LOOPK3 C R8,=F'6' DO K=1 TO 6
BH ELOOPK3
LA R4,WDLINE @WDLINE
AR R4,R10 +LWDLINE
MVC 0(20,R4),WDNA SUB(WDLINE,LWDLINE+1,20)=WDNA
LA R10,20(R10) LWDLINE=LWDLINE+20
C R8,=F'6' IF K<6
BNL ITERK3
LA R10,2(R10) LWDLINE=LWDLINE+2
ITERK3 LA R8,1(R8) K=K+1
B LOOPK3
ELOOPK3 LA R6,1 I=1
LOOPI4 C R6,=F'12' DO I=1 TO 12 BY 6
BH ELOOPI4
MVC MOLINE,BLANK MOLINE=' '
LA R10,6 LMOLINE=6
LR R8,R6 K=I
LOOPK4 LA R2,5(R6) I+5
CR R8,R2 DO K=I TO I+5
BH ELOOPK4
LR R1,R8 K
MH R1,=H'10' *10
LA R3,MO-10(R1) MO(K)
LA R4,MOLINE @MOLINE
AR R4,R10 +LMOLINE
MVC 0(10,R4),0(R3) SUB(MOLINE,LMOLINE+1,10)=MO(K)
LA R10,22(R10) LMOLINE=LMOLINE+22
LA R8,1(R8) K=K+1
B LOOPK4
ELOOPK4 XPRNT MOLINE,L'MOLINE PRINT MONTHS
XPRNT WDLINE,L'WDLINE PRINT DAYS OF WEEK
LA R7,1 J=1
LOOPJ4 C R7,=F'106' DO J=1 TO 106 BY 21
BH ELOOPJ4
MVC PG,BLANK CLEAR BUFFER
LA R9,PG PGI=0
LR R8,R6 K=I
LOOPK5 LA R2,5(R6) I+5
CR R8,R2 DO K=I TO I+5
BH ELOOPK5
LR R1,R8 K
MH R1,=H'144' *144
LA R4,DA-144(R1) DA(K)
BCTR R4,0 -1
AR R4,R7 +J
MVC 0(21,R9),0(R4) SUBSTR(DA(K),J,21)
LA R9,22(R9) PGI=PGI+22
LA R8,1(R8) K=K+1
B LOOPK5
ELOOPK5 XPRNT PG,L'PG PRINT BUFFER
LA R7,21(R7) J=J+21
B LOOPJ4
ELOOPJ4 LA R6,6(R6) I=I+6
B LOOPI4
ELOOPI4 L R13,4(0,R13) RESTORE PREVIOUS SAVEAREA POINTER
LM R14,R12,12(R13) RESTORE CALLER'S REGISTERS
XR R15,R15 SET RETURN CODE TO 0
BR R14 RETURN TO CALLER
SNOOPY DC CL57' ',CL18'INSERT SNOOPY HERE',CL57' '
YEAR DC F'1969' <== 1969
MO DC CL10' JANUARY ',CL10' FEBRUARY ',CL10' MARCH '
DC CL10' APRIL ',CL10' MAY ',CL10' JUNE '
DC CL10' JULY ',CL10' AUGUST ',CL10'SEPTEMBER '
DC CL10' OCTOBER ',CL10' NOVEMBER ',CL10' DECEMBER '
ML DC H'31',H'28',H'31',H'30',H'31',H'30'
DC H'31',H'31',H'30',H'31',H'30',H'31'
WDNA DC CL20'MO TU WE TH FR SA SU'
M DS F
D DS F
YY DS F
TD1 DS CL93
TD2 DS CL144
MOLINE DS CL132
WDLINE DS CL132
PG DC CL132' ' BUFFER FOR THE LINE PRINTER
XDEC DS CL12
BLANK DC CL144' '
DA DS 12CL144
YREGS
END CALENDAR

View file

@ -1,138 +1,142 @@
#import system.
#import system'text.
#import system'routines.
#import system'calendar.
#import extensions.
#import extensions'math.
#import extensions'routines.
import system'text.
import system'routines.
import system'calendar.
import extensions.
import extensions'routines.
#symbol MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
#symbol DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU").
const MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
const DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU").
#class CalendarMonthPrinter
class CalendarMonthPrinter
{
#field theDate.
#field theLine.
#field theMonth.
#field theYear.
#field theRow.
object theDate.
object theLine.
object theMonth.
object theYear.
object theRow.
#constructor new &year:aYear &month:aMonth
constructor new year:aYear month:aMonth
[
theMonth := aMonth.
theYear := aYear.
theLine := TextBuffer new.
theRow := Integer new &int:0.
theRow := Integer new int:0.
]
#method writeTitle
writeTitle
[
theRow << 0.
theDate := Date new &year:(theYear int) &month:(theMonth int) &day:1.
DayNames run &each: aName
[ theLine writeLiteral:" ":aName ].
theRow set:0.
theDate := Date new year(theYear int) month(theMonth int) day:1.
DayNames forEach(:aName)
[ theLine print(" ",aName) ]
]
#method writeLine
writeLine
[
theLine clear.
(theDate month == theMonth)
? [
theLine write:" " &length:(((theDate dayOfWeek) => 0 ? [ 7 ] ! [ theDate dayOfWeek ]) - 1).
if (theDate month == theMonth)
[
theLine write:" " length((theDate dayOfWeek == 0)iif(7,theDate dayOfWeek) - 1).
control do:
[
theLine write:(theDate day literal) &paddingLeft:3 &with:#32.
theDate := theDate add &days:1.
theLine write:(theDate day; literal) paddingLeft:3 with:$32.
theDate := theDate add days:1.
]
&until:[(theDate month != theMonth)or:[theDate dayOfWeek == 1]].
until:$((theDate month != theMonth)or:$(theDate dayOfWeek == 1)).
].
#var(type:int) aLength := theLine length.
(aLength < 21)
? [ theLine write:" " &length:(21 - aLength). ].
int aLength := theLine length.
if (aLength < 21)
[ theLine write:" " length(21 - aLength). ].
theRow += 1.
theRow append int:1.
]
#method iterator = Iterator
indexer = Indexer::
{
available = theRow < 7.
readIndex &vint:anIndex [ anIndex << theRow int. ]
readIndexTo vint:anIndex [ anIndex int := theRow ]
write &index:anIndex
writeIndex int:anIndex
[
(anIndex <= theRow)
? [ self writeTitle. ].
if (anIndex <= theRow)
[ $owner writeTitle ].
#loop (anIndex > theRow) ?
[ self writeLine. ].
while (anIndex > theRow)
[ $owner writeLine ]
]
get = self.
get = $owner.
}.
#method printTitleTo : anOutput
printTitleTo : anOutput
[
anOutput write:(MonthNames @(theMonth - 1)) &padding:21 &with:#32.
anOutput write(MonthNames[theMonth - 1]) padding:21 with:$32.
]
#method printTo : anOutput
printTo : anOutput
[
anOutput write:(theLine literal).
anOutput write(theLine literal).
]
}
#class Calendar
class Calendar
{
#field(type:int) theYear.
#field(type:int) theRowLength.
int theYear.
int theRowLength.
#constructor new : aYear
constructor new : aYear
[
theYear := aYear int.
theRowLength := 3.
]
#method printTo:anOutput
printTo:anOutput
[
anOutput write:"[SNOOPY]" &padding:(theRowLength * 25) &with:#32.
anOutput write:"[SNOOPY]" padding:(theRowLength * 25) with:$32.
anOutput writeLine.
anOutput write:(theYear literal) &padding:(theRowLength * 25) &with:#32.
anOutput writeLine writeLine.
anOutput write:(theYear literal) padding:(theRowLength * 25) with:$32.
anOutput writeLine; writeLine.
#var aRowCount := 12 / theRowLength.
#var Months := Array new &length:aRowCount set &every:(&index:i)
[ Array new &length:theRowLength set &every:(&index:j)
[ CalendarMonthPrinter new &year:(theYear int) &month:((i * theRowLength + j + 1) int) ]].
var aRowCount := 12 / theRowLength.
var Months := Array new length:aRowCount; populate(:i)
(Array new length:theRowLength;
populate(:j)
( CalendarMonthPrinter new year(theYear int) month(i * theRowLength + j + 1))).
Months run &each: aRow
Months forEach(:aRow)
[
aRow run &each: aMonth
aRow forEach(:aMonth)
[
aMonth printTitleTo:anOutput.
anOutput write:" ".
].
anOutput writeLine.
ParallelEnumerator new:aRow run &each: aLine
ParallelEnumerator new:aRow; forEach(:aLine)
[
aLine run &each: aPrinter
aLine forEach(:aPrinter)
[
aPrinter printTo:anOutput.
anOutput write:" ".
anOutput write:" "
].
anOutput writeLine.
anOutput writeLine
].
].
]
}
#symbol program =
program =
[
#var aCalender := Calendar new:(console write:"ENTER THE YEAR:" readLine:(Integer new)).
var aCalender := Calendar new(console write:"ENTER THE YEAR:"; readLineTo(Integer new)).
aCalender printTo:console.

View file

@ -0,0 +1,52 @@
IMPORT JAVA.TEXT.*
IMPORT JAVA.UTIL.*
IMPORT JAVA.IO.PRINTSTREAM
INTERNAL FUN PRINTSTREAM.PRINTCALENDAR(YEAR: INT, NCOLS: BYTE, LOCALE: LOCALE?) {
IF (NCOLS < 1 || NCOLS > 12)
THROW ILLEGALARGUMENTEXCEPTION("ILLEGAL COLUMN WIDTH.")
VAL W = NCOLS * 24
VAL NROWS = MATH.CEIL(12.0 / NCOLS).TOINT()
VAL DATE = GREGORIANCALENDAR(YEAR, 0, 1)
VAR OFFS = DATE.GET(CALENDAR.DAY_OF_WEEK) - 1
VAL DAYS = DATEFORMATSYMBOLS(LOCALE).SHORTWEEKDAYS.SLICE(1..7).MAP { IT.SLICE(0..1) }.JOINTOSTRING(" ", " ")
VAL MONS = ARRAY(12) { ARRAY(8) { "" } }
DATEFORMATSYMBOLS(LOCALE).MONTHS.SLICE(0..11).FOREACHINDEXED { M, NAME ->
VAL LEN = 11 + NAME.LENGTH / 2
VAL FORMAT = MESSAGEFORMAT.FORMAT("%{0}S%{1}S", LEN, 21 - LEN)
MONS[M][0] = STRING.FORMAT(FORMAT, NAME, "")
MONS[M][1] = DAYS
VAL DIM = DATE.GETACTUALMAXIMUM(CALENDAR.DAY_OF_MONTH)
FOR (D IN 1..42) {
VAL ISDAY = D > OFFS && D <= OFFS + DIM
VAL ENTRY = IF (ISDAY) STRING.FORMAT(" %2S", D - OFFS) ELSE " "
IF (D % 7 == 1)
MONS[M][2 + (D - 1) / 7] = ENTRY
ELSE
MONS[M][2 + (D - 1) / 7] += ENTRY
}
OFFS = (OFFS + DIM) % 7
DATE.ADD(CALENDAR.MONTH, 1)
}
PRINTF("%" + (W / 2 + 10) + "S%N", "[SNOOPY PICTURE]")
PRINTF("%" + (W / 2 + 4) + "S%N%N", YEAR)
FOR (R IN 0..NROWS - 1) {
FOR (I IN 0..7) {
VAR C = R * NCOLS
WHILE (C < (R + 1) * NCOLS && C < 12) {
PRINTF(" %S", MONS[C][I].TOUPPERCASE()) // ORIGINAL CHANGED TO PRINT IN UPPER CASE
C++
}
PRINTLN()
}
PRINTLN()
}
}
FUN MAIN(ARGS: ARRAY<STRING>) {
SYSTEM.OUT.PRINTCALENDAR(1969, 3, LOCALE.US)
}

View file

@ -0,0 +1,84 @@
// version 1.1.3
import java.io.File
import java.io.BufferedReader
import java.io.InputStreamReader
fun main(args: Array<String>) {
val keywords = listOf(
"import", "internal", "fun", "if", "throw", "val", "var", "for", "in", "while"
)
val singleCase = listOf(
"java.text",
"java.util",
"java.io",
"else", // really a keyword but doesn't have a following space here
"ceil",
"it", // really a keyword but doesn't have a following space here
"get(", // also included in GETACTUALMAXIMUM
"slice",
"map",
"months",
"length",
".format", // also variable called FORMAT
"add",
"printf",
"println",
"out",
"main",
"args",
"s%{1}s",
"%2s",
"s%n%n",
"s%n",
"%s"
)
val mixedCase = listOf(
"PRINTSTREAM" to "PrintStream",
"INT," to "Int,", // also included in PRINTCALENDAR
"BYTE" to "Byte",
"LOCALE?" to "Locale?", // also variable called LOCALE
"LOCALE." to "Locale.",
"ILLEGALARGUMENTEXCEPTION" to "IllegalArgumentException",
"MATH" to "Math",
"GREGORIANCALENDAR" to "GregorianCalendar",
"DATEFORMATSYMBOLS" to "DateFormatSymbols",
"ARRAY" to "Array",
"MESSAGEFORMAT" to "MessageFormat",
"JOINTOSTRING" to "joinToString",
"STRING" to "String",
"CALENDAR." to "Calendar.", // also included in PRINTCALENDAR
"SYSTEM" to "System",
"TOINT" to "toInt",
"SHORTWEEKDAYS" to "shortWeekdays",
"FOREACHINDEXED" to "forEachIndexed",
"GETACTUALMAXIMUM" to "getActualMaximum",
"TOUPPERCASE" to "toUpperCase"
)
var text = File("calendar_UC.txt").readText()
for (k in keywords) text = text.replace("${k.toUpperCase()} ", "$k ") // add a following space to be on safe side
for (s in singleCase) text = text.replace(s.toUpperCase(), s)
for (m in mixedCase) text = text.replace(m.first, m.second)
File("calendar_NC.kt").writeText(text)
val commands = listOf("kotlinc", "calendar_NC.kt", "-include-runtime", "-d", "calendar_X.jar")
val pb = ProcessBuilder(commands)
pb.redirectErrorStream(true)
val process = pb.start()
process.waitFor()
val commands2 = listOf("java", "-jar", "calendar_NC.jar")
val pb2 = ProcessBuilder(commands2)
pb2.redirectErrorStream(true)
val process2 = pb2.start()
val out = StringBuilder()
val br = BufferedReader(InputStreamReader(process2.inputStream))
while (true) {
val line = br.readLine()
if (line == null) break
out.append(line).append('\n')
}
br.close()
println(out.toString())
}

View file

@ -0,0 +1,52 @@
import java.text.*
import java.util.*
import java.io.PrintStream
internal fun PrintStream.PRINTCALENDAR(YEAR: Int, NCOLS: Byte, LOCALE: Locale?) {
if (NCOLS < 1 || NCOLS > 12)
throw IllegalArgumentException("ILLEGAL COLUMN WIDTH.")
val W = NCOLS * 24
val NROWS = Math.ceil(12.0 / NCOLS).toInt()
val DATE = GregorianCalendar(YEAR, 0, 1)
var OFFS = DATE.get(Calendar.DAY_OF_WEEK) - 1
val DAYS = DateFormatSymbols(LOCALE).shortWeekdays.slice(1..7).map { it.slice(0..1) }.joinToString(" ", " ")
val MONS = Array(12) { Array(8) { "" } }
DateFormatSymbols(LOCALE).months.slice(0..11).forEachIndexed { M, NAME ->
val LEN = 11 + NAME.length / 2
val FORMAT = MessageFormat.format("%{0}s%{1}s", LEN, 21 - LEN)
MONS[M][0] = String.format(FORMAT, NAME, "")
MONS[M][1] = DAYS
val DIM = DATE.getActualMaximum(Calendar.DAY_OF_MONTH)
for (D in 1..42) {
val ISDAY = D > OFFS && D <= OFFS + DIM
val ENTRY = if (ISDAY) String.format(" %2s", D - OFFS) else " "
if (D % 7 == 1)
MONS[M][2 + (D - 1) / 7] = ENTRY
else
MONS[M][2 + (D - 1) / 7] += ENTRY
}
OFFS = (OFFS + DIM) % 7
DATE.add(Calendar.MONTH, 1)
}
printf("%" + (W / 2 + 10) + "s%n", "[SNOOPY PICTURE]")
printf("%" + (W / 2 + 4) + "s%n%n", YEAR)
for (R in 0..NROWS - 1) {
for (I in 0..7) {
var C = R * NCOLS
while (C < (R + 1) * NCOLS && C < 12) {
printf(" %s", MONS[C][I].toUpperCase()) // ORIGINAL CHANGED TO PRINT in UPPER CASE
C++
}
println()
}
println()
}
}
fun main(args: Array<String>) {
System.out.PRINTCALENDAR(1969, 3, Locale.US)
}

View file

@ -35,14 +35,14 @@
}
-> FMT_YEAR (YEAR, STR="", MONTH_STRS=[]) {
MONTH_STRS = 12.("\LOF")({|I| FMT_MONTH(YEAR, I).("\LLINES") })
MONTH_STRS = 12.("\LOF")({|I| FMT_MONTH(YEAR, I+1).("\LLINES") })
STR += (' '*(MONTHS_PER_COL()*10 + 2) + YEAR + "\12")
(0..11 -> ("\LBY")(MONTHS_PER_COL())).("\LEACH")({ |MONTH|
MONTH_STRS[MONTH] && ->() {
{ |I|
MONTH_STRS[MONTH + I - 1] && (
STR += MONTH_STRS[MONTH + I - 1].("\LSHIFT")
MONTH_STRS[MONTH + I] && (
STR += MONTH_STRS[MONTH + I].("\LSHIFT")
STR += ' '*2
)
} * MONTHS_PER_COL()

View file

@ -0,0 +1,12 @@
VAR [CONST] D=TIME.DATE, DAYS="SU MO TU WE TH FR SA";
FCN CENTER(TEXT,M) { STRING(" "*((M-TEXT.LEN())/2),TEXT) }
FCN ONEMONTH(YEAR,MONTH){
DAY1:=D.ZELLER(YEAR,MONTH,1); //1969-1-1 -->3 (WED, ISO 8601)
DAYZ:=D.DAYSINMONTH(YEAR,MONTH); //1969-1 -->31
LIST(CENTER(D.MONTHNAMES[MONTH],DAYS.LEN()),DAYS).EXTEND(
(1).PUMP(DAYZ,(0).PUMP(DAY1,LIST,T(VOID,""))).APPLY("%2S ".FMT)
.PUMP(LIST,T(VOID.READ,DAYS.LEN()/3,FALSE),STRING.CREATE));
}
...

View file

@ -0,0 +1,11 @@
code:=File(vm.arglist[0]).read();
code=Data(Void,code.text.toLower());
mixed:=T("string","String", "list","List", " t("," T(",",t(",",T(",
".tostring",".toString", "void.read","Void.Read",
"time.date","Time.Date", "utils.","Utils.", "zipwith","zipWith",
"daysinmonth","daysInMonth", "monthnames","monthNames",
"void","Void", "false","False",
"d.october","d.October",
);
mixed.pump(Void,Void.Read,'wrap(up,down){ code.replace(up,down) });
Compiler.Compiler.compileText(code)();