From: Alex Smith Date: Mon, 31 Mar 2008 08:28:04 +0000 (-0400) Subject: Pre-0.28 'd' snapshot. X-Git-Tag: 0.28~4 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=6b4774f6cfe9be2eb497993a2c56a36202b2a96e;p=intercal.git Pre-0.28 'd' snapshot. (This is a retrospective comment.) --- diff --git a/Makefile b/Makefile index 50da8ca..7a4ec62 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ SOURCES = $(CSOURCES) $(ISOURCES) $(YSOURCES) $(HEADERS) $(BUILD) $(MISC) $(DOCS all: bin/ick bin/convickt lib/libick.a lib/libickmt.a lib/libyuk.a lib/libickec.a ial -ial: include/ick_ec.h include/fiddle.h include/abcess.h include/ick_lose.h include/yuk.h include/syslib.i include/syslib.3i include/syslib.4i include/syslib.5i include/syslib.6i include/syslib.7i lib/ick-wrap.c lib/pickwrap.c lib/coopt.sh lib/COPYING.txt lib/syslibc.c include/atari.bin include/baudot.bin include/ebcdic.bin include/latin1.bin +ial: include/ick_ec.h include/fiddle.h include/abcess.h include/ick_lose.h include/yuk.h include/syslib.i include/syslib.3i include/syslib.4i include/syslib.5i include/syslib.6i include/syslib.7i lib/ick-wrap.c lib/pickwrap.c lib/coopt.sh lib/COPYING.txt lib/syslibc.c lib/compunex.c include/atari.bin include/baudot.bin include/ebcdic.bin include/latin1.bin include/ick_ec.h: src/ick_ec.h -cp src/ick_ec.h include/ick_ec.h @@ -94,8 +94,10 @@ lib/coopt.sh:temp/coopt.sh lib/COPYING.txt:COPYING.txt -cp COPYING.txt lib/COPYING.txt -lib/syslibc.c:pit/lib/syslibc.c - -cp pit/lib/syslibc.c lib/syslibc.c +lib/syslibc.c:pit/explib/syslibc.c + -cp pit/explib/syslibc.c lib/syslibc.c +lib/compunex.c:pit/explib/compunex.c + -cp pit/explib/compunex.c lib/compunex.c include/atari.bin:src/atari.bin -cp src/atari.bin include/atari.bin diff --git a/Makefile.in b/Makefile.in index 0730029..8856d90 100644 --- a/Makefile.in +++ b/Makefile.in @@ -55,7 +55,7 @@ SOURCES = $(CSOURCES) $(ISOURCES) $(YSOURCES) $(HEADERS) $(BUILD) $(MISC) $(DOCS all: bin/ick@EXEEXT@ bin/convickt@EXEEXT@ lib/libick.a lib/libickmt.a lib/libyuk.a lib/libickec.a ial -ial: include/ick_ec.h include/fiddle.h include/abcess.h include/ick_lose.h include/yuk.h include/syslib.i include/syslib.3i include/syslib.4i include/syslib.5i include/syslib.6i include/syslib.7i lib/ick-wrap.c lib/pickwrap.c lib/coopt.sh lib/COPYING.txt lib/syslibc.c include/atari.bin include/baudot.bin include/ebcdic.bin include/latin1.bin +ial: include/ick_ec.h include/fiddle.h include/abcess.h include/ick_lose.h include/yuk.h include/syslib.i include/syslib.3i include/syslib.4i include/syslib.5i include/syslib.6i include/syslib.7i lib/ick-wrap.c lib/pickwrap.c lib/coopt.sh lib/COPYING.txt lib/syslibc.c lib/compunex.c include/atari.bin include/baudot.bin include/ebcdic.bin include/latin1.bin include/ick_ec.h: src/ick_ec.h -cp src/ick_ec.h include/ick_ec.h @@ -93,8 +93,10 @@ lib/coopt.sh:temp/coopt.sh lib/COPYING.txt:COPYING.txt -cp COPYING.txt lib/COPYING.txt -lib/syslibc.c:pit/lib/syslibc.c - -cp pit/lib/syslibc.c lib/syslibc.c +lib/syslibc.c:pit/explib/syslibc.c + -cp pit/explib/syslibc.c lib/syslibc.c +lib/compunex.c:pit/explib/compunex.c + -cp pit/explib/compunex.c lib/compunex.c include/atari.bin:src/atari.bin -cp src/atari.bin include/atari.bin diff --git a/NEWS.txt b/NEWS.txt index 6b7cac0..06a4908 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -140,9 +140,12 @@ Changes by Alex Smith also edited unlambda.i in the pit, which was taking advantage of this error (and erroring out if optimisation was turned off). +23. Fixed a bug with the ON THE WAY TO line number displayed when COME FROMs + are involved that I accidentally introduced in 0.25. + Changes from elsewhere -23. Added yet another nontrivial INTERCAL program to the pit; interfunge.i +24. Added yet another nontrivial INTERCAL program to the pit; interfunge.i (written by Jeffrey Lee) is a Befunge-93 interpreter written in INTERCAL. (It appears to conform to the standard (I actually ran it against a testsuite, and it passed); its only pecularities, apart from the language diff --git a/doc/ick.txi b/doc/ick.txi index 0ec1082..ed07fc1 100644 --- a/doc/ick.txi +++ b/doc/ick.txi @@ -1636,6 +1636,13 @@ legal if you specifically specified that it was legal by using the (including a situation in which operand overloading causes a reverse assignment to happen), this error happens at runtime. +This error can also come up when a scalar variable is overloaded to an +array (which doesn't make sense, but could happen if someone exploited +bugs in the CREATE statement (@pxref{CREATE})), and an attempt is made +to read or assign to that variable. (Subscripting a scalar variable +is a syntax error, so there is no use for doing such an overload +anyway.) + @ieanchor E281 @cindex spark, nesting limit @cindex ears, nesting limit @@ -2822,7 +2829,7 @@ time, so has to guess a 32-bit result for a select with a 32-bit type as its right operand even when the result might actually turn out to be of a 16-bit type, and so this behaviour prevents an error when a select operation returns a value with a 16-bit data type and is used as an -argument to amingle.) The result is a 32-bit value (that is, it is of a +argument to a mingle.) The result is a 32-bit value (that is, it is of a 32-bit data type, even if its value fits into the onespot range), which consists of bits alternated from the two arguments; to be precise, its most significant bit is the most significant bit of its first argument, @@ -4171,7 +4178,7 @@ created by @code{COME FROM}; ordinary threads share only share variables and stashes. (They still have separate instruction pointers, separate instruction pointer stacks, such as the NEXT stack, and separate choicepoint lists. Overloading information is shared, -though. Being woven is a relationship between two or more threads, +though.) Being woven is a relationship between two or more threads, rather than an attribute of a thread, although a thread can be referred to as being unwoven if it is not woven to any other thread. @@ -4222,7 +4229,7 @@ case you're wondering: dormant threads are always unwoven.) To create a choicepoint, the statement identifier @code{MAYBE} is used, rather than the more usual @code{DO} or @code{PLEASE}. (Combination statement identifiers are still allowed, but must be in -the order @code{MAYBE DO PLEASE NOT} with optionally some parts +the order @code{MAYBE PLEASE DO NOT} with optionally some parts omitted, or different versions of @code{NOT} used, or both.) Here's an example: @@ -4471,7 +4478,7 @@ DO PIN :2 @end example The twospot variable is conceptually divided into 4 blocks of 8 bits. -The highet two blocks control the directions of the pins in +The highest two blocks control the directions of the pins in @code{PORTB} (most significant block) and @code{PORTA} (second most significant block); a 1 on any bit means that the corresponding I/O pin should be set to send data, and a 0 means that it should be set to @@ -4557,7 +4564,9 @@ the stashes for the 1600-range variables yourself.) So what syntax is available in created statements@? All the capital letters except @samp{V} (which is an operator in @ical{}) are available and can be used freely and as many times as desired; they -match themselves literally. Whitespace is allowed, but is ignored +match themselves literally. However, they are not allowed to spell an +@ical{} keyword at any point (so watch out for @code{DO} and +@code{FROM}, for instance). Whitespace is allowed, but is ignored (both in the @code{CREATE} template statement, and in the code being created; so @code{DO SW ITCH :8 WITH :50} will also have been created). Then, there are three groups of matchable data: scalar @@ -4914,7 +4923,7 @@ wrapper function for it). It can be used within any function regardless of how it was declared, and never returns; instead, it pops the specified number of @code{NEXT} stack entries and resumes execution at the last one popped, just as the @ical{} statement does. This causes the same errors -as the @ical{} statement if the amount of entries popped is zero or +as the @ical{} statement if the number of entries popped is zero or larger than the @code{NEXT} stack. @findex ick_return_or_resume @@ -5004,10 +5013,16 @@ The signature defines the syntax that you are defining; whenever that syntax is encountered within the @ical{} program, it will @code{NEXT} to the line number you specify, which can do various clever things and then @code{RESUME} back to the @ical{} program (or if you're defining -a flow-control operation, you might want to @code{FORGET} or even -leave the @code{NEXT} stack entry there and do other things). This -allows the external calls system to define whole new @ical{} commands, -with the same power as any other programming language. +a flow-control operation, you might want to leave the @code{NEXT} +stack entry there and do other things). However, note that the +overloading of @code{:1601}, etc.@:, will still take place as in the +@ical{} version of @code{CREATE} if the @option{-a} option is used +(@pxref{-a}), so care is needed when writing flow control statements +that they work both with and without the option and don't cause +@code{STASH} leaks (which means no @code{FORGET}ting the relevant +@code{NEXT} stack entry, and no looking at 1600-range variables). +This allows the external calls system to define whole new @ical{} +commands, with the same power as any other programming language. There are various restrictions on what syntax you can @code{CREATE} with this method, which are best explained by an explanation of the @@ -5274,6 +5289,8 @@ completely different way. @subheading syslibc @findex syslibc +@cindex system library, in C +@cindex C, system library @option{syslibc} is an implementation of the base-2 @ical{} system library in C (@pxref{System Library}); using it in programs running in @@ -5290,6 +5307,25 @@ note that the speed gains in arithmetic will be accompanied by the performance penalty of using the external calls infrastructure, unless you were already using it. +@subheading compunex +@findex compunex +@cindex computed NEXT +@cindex NEXT, computed + +As an example of using @code{ick_create}, a very simple expansion +library is provided to enable a computed NEXT capability, by defining +a new command @code{COMPUNEX}. It is used as @code{DO .1 COMPUNEX} +(allowing any expression in place of the .1), and is similar to an +ordinary @code{NEXT}, but has two limitations: it takes up two +@code{NEXT} stack entries, and the top one should not be +@code{RESUMEd} past or forgotten (thus it isn't a particularly useful +command, except maybe to produce the equivalent of something like +function pointers). By the way, note that @cic{} avoids computed +@code{NEXT} mainstream for much the same way that @clcic{} avoids +@code{NEXT} altogether; it makes things too easy. This example is +provided mostly just to demonstrate the syntax, and the care that +needs to be taken with implementing flow control operators. + @node Differences to Other Compilers @chapter Differences to Other Compilers @cindex INTERCAL compilers @@ -6372,7 +6408,9 @@ copyright conditions as the original @ical{} source. (Note that the libraries @file{libick.a} and @file{libickmt.a} are GPL, though, so you cannot redistribute an executable produced by @command{ick} or by linking a C file to either of those libraries unless the original -@ical{} source was GPL.) Also, this manual, and the files that are +@ical{} source was GPL.) For similar reasons, the expansion library +@file{syslibc.c} (currently the only one in the distribution) is +explicitly public domain. Also, this manual, and the files that are the source code for creating it, are licensed under the GNU Free Documentation License rather than the GPL, and the licenses themselves (@file{fdl-1-2.txi} and @file{COPYING.txt}) are licensed under a diff --git a/etc/intercal.el b/etc/intercal.el index 82ecf27..4f14969 100644 --- a/etc/intercal.el +++ b/etc/intercal.el @@ -94,6 +94,7 @@ (define-abbrev intercal-mode-abbrev-table "wh" "" 'intercal-wh-abbrev) ;AIS (define-abbrev intercal-mode-abbrev-table "goa" "" 'intercal-goa-abbrev) ;AIS (define-abbrev intercal-mode-abbrev-table "gob" "" 'intercal-gob-abbrev) ;AIS + (define-abbrev intercal-mode-abbrev-table "cr" "" 'intercal-cr-abbrev) ;AIS (define-abbrev intercal-mode-abbrev-table "ma" "MAYBE" nil) ;AIS (define-abbrev intercal-mode-abbrev-table "tr" "" 'intercal-tr-abbrev) ;AIS (define-abbrev intercal-mode-abbrev-table "cal" "" 'intercal-cal-abbrev) ;AIS @@ -125,6 +126,7 @@ (make-intercal-abbrev intercal-wh-abbrev "WHILING" "WHILE") ;AIS (make-intercal-abbrev intercal-goa-abbrev "GOING AHEAD" "GO AHEAD") ;AIS (make-intercal-abbrev intercal-gob-abbrev "GOING BACK" "GO BACK") ;AIS +(make-intercal-abbrev intercal-cr-abbrev "CREATION" "CREATE") ;AIS (defun intercal-do-abbrev () "Emit a DO (usually). Occasionally, emit PLEASE DO." @@ -192,7 +194,7 @@ res RESUME ret RETRIEVE st STASH wr WRITE IN pl PLEASE tr TRY AGAIN on ONCE ag AGAIN ma MAYBE goa GO AHEAD gob GO BACK do DO, or sometimes PLEASE DO -cal CALCULATING (gerund only) wh WHILE +cal CALCULATE cr CREATE wh WHILE Carriage return takes you to the first tab stop (code indent level). Certain other single keys are bound to things which may or may not be useful. diff --git a/include/abcess.h b/include/abcess.h index e027d12..ba24091 100644 --- a/include/abcess.h +++ b/include/abcess.h @@ -117,6 +117,10 @@ extern void ick_retrieve(void *to, unsigned int type, unsigned int index, ick_bool forget, ick_overop* oo); extern unsigned int ick_roll(unsigned int n); +/* AIS: Lose with IE277 */ +extern ick_type32 ick_ieg277(ick_type32); +extern void ick_ies277(ick_type32, void(*)()); + /* defined in arrgghh.c */ extern void ick_parseargs(int argc, char **argv); extern int ick_printflow; diff --git a/pit/CATALOG b/pit/CATALOG index cdb4a29..79bbb73 100644 --- a/pit/CATALOG +++ b/pit/CATALOG @@ -130,7 +130,8 @@ by Alex Smith tests/ignorret.doc What ignorret does on several compilers tests/normaldist.i Checking the standard deviation of (1910) tests/testcreate.i A test for the CREATE statement - lib/syslibc.c The INTERCAL base 2 syslib, optimised version in C + explib/syslibc.c The INTERCAL base 2 syslib, optimised version in C + explib/compunex.c An example flow-control routine (computed NEXT) sort.i An insertion-sort program testing computed ABSTAIN by Malcom Ryan diff --git a/pit/explib/compunex.c b/pit/explib/compunex.c new file mode 100644 index 0000000..a9d0683 --- /dev/null +++ b/pit/explib/compunex.c @@ -0,0 +1,29 @@ +/* Public domain, by Alex Smith. + An example of CREATing statements from C, in this case an example COMPUNEX + statement that does a computed NEXT. (Note that newly CREATEd statements + can't contain consecutive characters that spell an INTERCAL keyword; also, + I wanted a name that was 8 chars or shorter to serve as a DOS filename.) + + Note that as a CREATEd command, COMPUNEX uses one NEXT stack entry itself, + meaning the COMPUNEX will take up two NEXT stack entries total. Programs + that do large RESUMEs will need to take this into account. (Tail call + optimisation would require some sort of GOTO, but ick_goto isn't documented + and therefore shouldn't be used, right? */ +#include + +/* This name starts ick_, but isn't used; in general, the prefix ick_my_ is + reserved for expansion libraries (as are the line numbers 1600-1699) because + it doesn't conflict either with the compiler or with any linked-in C + programs. */ +ICK_EC_FUNC_START(ick_my_compunex) +{ + ick_startup( { + ick_create(".COMPUNEX",1600); + ick_create(";COMPUNEX",1600); + ick_create("~COMPUNEX",1600); + }); + ick_linelabel(1600); + ick_next(ick_c_value(0)); + ick_resume(1); +} +ICK_EC_FUNC_END diff --git a/pit/explib/syslibc.c b/pit/explib/syslibc.c new file mode 100644 index 0000000..4155fe1 --- /dev/null +++ b/pit/explib/syslibc.c @@ -0,0 +1,197 @@ +/* + * The INTERCAL system library, optimised version in C. + * + * This is provided as an example of how to write a C program + * that links to INTERCAL programs, to demonstrate the external + * call code. + * + * Written originally by Alex Smith, and released to the public + * domain. This library comes with NO WARRANTY. + */ + +#include +#include +#include +#include + +/* This identifier name breaches the namespace rule that ick_ must be + avoided, but this library has to work with both other people's + INTERCAL programs and other people's C programs. So I've chosen an + identifier name which breaches the rules (so that it doesn't clash + with other people's C programs) but isn't used anywhere in the + compiler, and so doesn't clash with it either. +*/ + +static void errout(int routine, char* msg) +{ + fprintf(stderr,"C-INTERCAL system library: (%d): %s\n", routine, msg); + exit(EXIT_FAILURE); +} + +ICK_EC_FUNC_START(ick_my_custom_syslib) +{ + register uint16_t os1, os2; + register uint32_t ts1, ts2; + static int seededyet = 0; + + ick_linelabel(1000); + os1=ick_getonespot(1); + os2=ick_getonespot(2); + if(0xffff-os10xffffLU) errout(1050, "onespot overflow"); + ick_setonespot(2,(uint16_t)ts1); + ick_resume(1); + return; + + ick_linelabel(1500); + ts1=ick_gettwospot(1); + ts2=ick_gettwospot(2); + if(0xffffffffLU-ts1 -#include -#include -#include - -/* This identifier name breaches the namespace rule that ick_ must be - avoided, but this library has to work with both other people's - INTERCAL programs and other people's C programs. So I've chosen an - identifier name which breaches the rules (so that it doesn't clash - with other people's C programs) but isn't used anywhere in the - compiler, and so doesn't clash with it either. -*/ - -static void errout(int routine, char* msg) -{ - fprintf(stderr,"C-INTERCAL system library: (%d): %s\n", routine, msg); - exit(EXIT_FAILURE); -} - -ICK_EC_FUNC_START(ick_my_custom_syslib) -{ - register uint16_t os1, os2; - register uint32_t ts1, ts2; - static int seededyet = 0; - - ick_linelabel(1000); - os1=ick_getonespot(1); - os2=ick_getonespot(2); - if(0xffff-os10xffffLU) errout(1050, "onespot overflow"); - ick_setonespot(2,(uint16_t)ts1); - ick_resume(1); - return; - - ick_linelabel(1500); - ts1=ick_gettwospot(1); - ts2=ick_gettwospot(2); - if(0xffffffffLU-ts1exechance < 100) (void) fprintf(fp, "ick_roll(%d) && ", tn->exechance); if ((tn->type != NEXT && tn->type != GO_BACK && tn->type != COME_FROM - && /* AIS */ tn->type != NEXTFROMLABEL) + && /* AIS */ tn->type != NEXTFROMLABEL && tn->type != UNKNOWN) || tn->onceagainflag == onceagain_NORMAL) (void) fprintf(fp, "!ICKABSTAINED(%d))%s {\n", (int)(tn - tuples), /* AIS */ tn->maybe?")":""); @@ -1762,9 +1762,14 @@ void emit(tuple *tn, FILE *fp) emitlineno = up->ick_lineno; break; } - } else if (tn->ncomefrom) - emitlineno = comefromsearch(tn,1); /* AIS: For multithreading. - Return the 1st if we're forking. */ + } + else if (tn->ncomefrom) + { + /* AIS: For multithreading. Return the 1st if we're forking. */ + emitlineno = comefromsearch(tn,1); + if(emitlineno != -1) + emitlineno = tuples[emitlineno-1].ick_lineno; + } else if (tn < tuples + ick_lineno - 1) emitlineno = tn[1].ick_lineno; else @@ -1809,8 +1814,9 @@ void emit(tuple *tn, FILE *fp) the command has finished, and some, like NEXT, need it before the command has started. At the moment, only NEXT and GO_BACK have a ONCE/AGAIN before it, rather than after (because neither of them - continue in the normal fashion). */ - if ((tn->type == NEXT || tn->type == GO_BACK) && + continue in the normal fashion). UNKNOWN is also handled this way, + because CREATEd statements can be NEXT-like but not COME FROM-like. */ + if ((tn->type == NEXT || tn->type == GO_BACK || tn->type == UNKNOWN) && tn->onceagainflag != onceagain_NORMAL) { /* ONCE/AGAIN has already been swapped by perpet.c in the case @@ -2551,8 +2557,8 @@ void emit(tuple *tn, FILE *fp) COME FROM is also excluded because it acts at the suckpoint, not at the place it's written in the program. */ if (tn->onceagainflag != onceagain_NORMAL && - (tn->type != NEXT && tn->type != GO_BACK && - (tn->type != COME_FROM || useickec) && tn->type != NEXTFROMLABEL)) + tn->type != NEXT && tn->type != GO_BACK && tn->type != UNKNOWN && + ((tn->type != COME_FROM && tn->type != NEXTFROMLABEL) || useickec)) { /* See my comments against the NEXT code for more information. This code is placed here so COME FROM ... ONCE constructs work @@ -2606,7 +2612,7 @@ void emit(tuple *tn, FILE *fp) (int)(cf - tuples), cf->onceagainflag==onceagain_ONCE ? "ick_oldabstain ? ick_oldabstain : 1" : "0"); - } + } emit_guard(cf, fp); if(multithread || compucomesused) (void) fprintf(fp,