issue #2607, enable '\e' character escape for --standard cc65

This commit is contained in:
Gorilla Sapiens
2025-05-02 07:02:07 +00:00
parent 2085646e57
commit f48fb03540
7 changed files with 110 additions and 2 deletions

View File

@@ -1053,6 +1053,16 @@ This cc65 version has some extensions to the ISO C standard.
unsigned char foo = 0b101; // sets it to 5
</verb></tscreen>
<item> The character escape '\e', a GCC C extension, is accepted.
In ASCII this is the escape character 0x1B, which may be
remapped in other character sets via a #pragma charmap.
It can be disabled with the <tt><ref id="option--standard"
name="--standard"></tt> option.
<tscreen><verb>
unsigned char foo = '\e'; // sets it to 0x1B or equivalent
</verb></tscreen>
</itemize>
<p>

View File

@@ -346,6 +346,14 @@ static int ParseChar (void)
case 'b':
C = '\b';
break;
case 'e':
if (IS_Get(&Standard) != STD_CC65) {
goto IllegalEscape;
}
/* we'd like to use \e here, but */
/* not all build systems support it */
C = '\x1B';
break;
case 'f':
C = '\f';
break;
@@ -411,6 +419,7 @@ static int ParseChar (void)
Error ("Octal character constant out of range");
break;
default:
IllegalEscape:
C = CurC;
Error ("Illegal escaped character: 0x%02X", CurC);
break;

View File

@@ -25,6 +25,7 @@ continue:
@$(MAKE) -C ref all
@$(MAKE) -C err all
@$(MAKE) -C standard all
@$(MAKE) -C standard_err all
@$(MAKE) -C misc all
@$(MAKE) -C todo all
@@ -35,6 +36,7 @@ mostlyclean:
@$(MAKE) -C ref clean
@$(MAKE) -C err clean
@$(MAKE) -C standard clean
@$(MAKE) -C standard_err clean
@$(MAKE) -C misc clean
@$(MAKE) -C todo clean

View File

@@ -12,6 +12,8 @@ compiler is working as expected (when the tests behave as described):
/val - The bulk of tests are contained here, individual tests should exit with
an exit code of EXIT_SUCCESS when they pass, or EXIT_FAILURE on error.
/err - contains tests that MUST NOT compile
/standard - like the tests in /val, the tests must exit with EXIT_SUCCESS on
success. Unlike the tests in /val these are not compiled for every
combination of optimizer options, but instead always with -Osir and then
@@ -19,6 +21,10 @@ compiler is working as expected (when the tests behave as described):
to check for regressions in standard conformance of the compiler and the
library.
/standard_err - like the tests in /err, these tests MUST NOT compile, and like
the tests in /standard, these are compiled -Osir and then for each
supported C-Standard.
/ref - These tests produce output that must be compared with reference output.
Normally the reference output is produced by compiling the program on the
host (using gcc mostly) and then running them on the host. Tests should
@@ -43,8 +49,6 @@ compiler is working as expected (when the tests behave as described):
only ever use this as a last resort when something can not be tested by
other means.
/err - contains tests that MUST NOT compile
/todo and /misc generally contain the tests that fail because of known bugs:

View File

@@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
/* this should succeed on all three standards
* yet use only \e on CC65
*/
int main(void) {
#if __CC65_STD__ == __CC65_STD_CC65__
printf("\e");
#endif
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,55 @@
# Makefile for the tests that MUST NOT compile
ifneq ($(shell echo),)
CMD_EXE = 1
endif
ifdef CMD_EXE
S = $(subst /,\,/)
NOT = - # Hack
NULLDEV = nul:
MKDIR = mkdir $(subst /,\,$1)
RMDIR = -rmdir /s /q $(subst /,\,$1)
else
S = /
NOT = !
NULLDEV = /dev/null
MKDIR = mkdir -p $1
RMDIR = $(RM) -r $1
endif
ifdef QUIET
.SILENT:
NULLERR = 2>$(NULLDEV)
endif
CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65)
WORKDIR = ../../testwrk/standard_err
OPTIONS = c89 c99 cc65
.PHONY: all clean
SOURCES := $(wildcard *.c)
TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg))
all: $(TESTS)
$(WORKDIR):
$(call MKDIR,$(WORKDIR))
define PRG_template
$(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR)
$(if $(QUIET),echo standard_err/$$*.$1.$2.prg)
$(NOT) $(CC65) -t sim$2 $$(CC65FLAGS) -Osir --add-source --standard $1 -o $$(@:.prg=.s) $$< $(NULLERR)
endef # PRG_template
$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502)))
#$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02)))
clean:
@$(call RMDIR,$(WORKDIR))

View File

@@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
/* this should fail on all three standards
*/
int main(void) {
#if __CC65_STD__ != __CC65_STD_CC65__
printf("\e");
#else
#error "this needs to error on CC65 to make it through validation"
#endif
return EXIT_SUCCESS;
}