# HG changeset patch # User Shinji KONO # Date 1397212884 -32400 # Node ID 3cdc3c1d83bdfa31342863a2243af429ee43c6c4 # Parent 35b339b36c88bd03aa2f092f8b5d0cdef9c32b5f macro try ... diff -r 35b339b36c88 -r 3cdc3c1d83bd Changes --- a/Changes Fri Apr 11 14:04:11 2014 +0900 +++ b/Changes Fri Apr 11 19:41:24 2014 +0900 @@ -10057,7 +10057,41 @@ table jump は32bit相対jmpに - - - - +Fri Apr 11 17:36:12 JST 2014 + + +macro の ## は、おそらく、 + + その場でつなげて、その場で置き換える + +方法なはず。 + + + #define names(a,b) name_ ## b(a) + #define names1(x,y) names(x,y) + #define hoge 79 + #define names2(x) names(x,hoge) + +printf("#0104:%d\n",names(3,hoge)); は、 +name_hoge(3) になる。 + #define a 3 + #define b hoge + +printf("#0106:%d\n",names1(4,aho)); は、 +names(4,aho) になって、name_aho(4) になる。 + #define b 79 +にはならない。 + + #define x 4 + #define y aho + + #define a 4 + #define b aho + +にならないとだめ。 + +local_define の時には macro_eval しない。body の macro_eval の時に置き換える。 + + + + diff -r 35b339b36c88 -r 3cdc3c1d83bd Makefile --- a/Makefile Fri Apr 11 14:04:11 2014 +0900 +++ b/Makefile Fri Apr 11 19:41:24 2014 +0900 @@ -1,4 +1,4 @@ -GCC = gcc +GCC = clang CC = $(GCC) -std=c99 $(CCEXT) $(M) -fgnu89-inline # -O3 # MCFLAG = -DUSE_CODE_KEYWORD @@ -162,8 +162,8 @@ # -./$(MC) -Itest/ $(TARGET).c -ifeq ($(CC),clang) - NOWARN = -Wno-literal-conversion -Wno-implicit-function-declaration -Wno-implicit-int \ +ifeq ($(GCC),clang) +NOWARN = -Wno-literal-conversion -Wno-implicit-function-declaration -Wno-implicit-int \ -Wno-incompatible-pointer-types -Wno-int-conversion -Wno-return-type -Wno-bitfield-constant-conversion -Wno-tautological-compare -Wno-shift-overflow \ -Wno-unused-value endif diff -r 35b339b36c88 -r 3cdc3c1d83bd mc-code-i64.c --- a/mc-code-i64.c Fri Apr 11 14:04:11 2014 +0900 +++ b/mc-code-i64.c Fri Apr 11 19:41:24 2014 +0900 @@ -90,131 +90,183 @@ " #ifdef __llvm__ + +#ifdef __APPLE__ "\ -#define __DBL_MIN_EXP__ (-1021)\n\ -#define __FLT_MIN__ 1.17549435e-38F\n\ -#define __DEC64_DEN__ 0.000000000000001E-383DD\n\ +#define OBJC_NEW_PROPERTIES 1\n\ +#define _LP64 1\n\ +#define __APPLE_CC__ 6000\n\ +#define __APPLE__ 1\n\ +#define __ATOMIC_ACQUIRE 2\n\ +#define __ATOMIC_ACQ_REL 4\n\ +#define __ATOMIC_CONSUME 1\n\ +#define __ATOMIC_RELAXED 0\n\ +#define __ATOMIC_RELEASE 3\n\ +#define __ATOMIC_SEQ_CST 5\n\ +// #define __BLOCKS__ 1\n\ +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__\n\ +#define __CHAR16_TYPE__ unsigned short\n\ +#define __CHAR32_TYPE__ unsigned int\n\ #define __CHAR_BIT__ 8\n\ -#define __WCHAR_MAX__ 2147483647\n\ -#define __NO_MATH_INLINES 1\n\ +#define __CONSTANT_CFSTRINGS__ 1\n\ #define __DBL_DENORM_MIN__ 4.9406564584124654e-324\n\ -#define __FLT_EVAL_METHOD__ 0\n\ +#define __DBL_DIG__ 15\n\ +#define __DBL_EPSILON__ 2.2204460492503131e-16\n\ +#define __DBL_HAS_DENORM__ 1\n\ +#define __DBL_HAS_INFINITY__ 1\n\ +#define __DBL_HAS_QUIET_NAN__ 1\n\ +#define __DBL_MANT_DIG__ 53\n\ +#define __DBL_MAX_10_EXP__ 308\n\ +#define __DBL_MAX_EXP__ 1024\n\ +#define __DBL_MAX__ 1.7976931348623157e+308\n\ #define __DBL_MIN_10_EXP__ (-307)\n\ +#define __DBL_MIN_EXP__ (-1021)\n\ +#define __DBL_MIN__ 2.2250738585072014e-308\n\ +#define __DECIMAL_DIG__ 21\n\ +#define __DYNAMIC__ 1\n\ +#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 1090\n\ #define __FINITE_MATH_ONLY__ 0\n\ -#define __DEC64_MAX_EXP__ 384\n\ -#define __SHRT_MAX__ 32767\n\ +#define __FLT_DENORM_MIN__ 1.40129846e-45F\n\ +#define __FLT_DIG__ 6\n\ +#define __FLT_EPSILON__ 1.19209290e-7F\n\ +#define __FLT_EVAL_METHOD__ 0\n\ +#define __FLT_HAS_DENORM__ 1\n\ +#define __FLT_HAS_INFINITY__ 1\n\ +#define __FLT_HAS_QUIET_NAN__ 1\n\ +#define __FLT_MANT_DIG__ 24\n\ +#define __FLT_MAX_10_EXP__ 38\n\ +#define __FLT_MAX_EXP__ 128\n\ +#define __FLT_MAX__ 3.40282347e+38F\n\ +#define __FLT_MIN_10_EXP__ (-37)\n\ +#define __FLT_MIN_EXP__ (-125)\n\ +#define __FLT_MIN__ 1.17549435e-38F\n\ +#define __FLT_RADIX__ 2\n\ +#define __GCC_ATOMIC_BOOL_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_CHAR_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_INT_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_LLONG_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_LONG_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_POINTER_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_SHORT_LOCK_FREE 2\n\ +#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1\n\ +#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2\n\ +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1\n\ +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1\n\ +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1\n\ +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1\n\ +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1\n\ +#define __GNUC_GNU_INLINE__ 1\n\ +#define __GNUC_MINOR__ 2\n\ +#define __GNUC_PATCHLEVEL__ 1\n\ +#define __GNUC__ 4\n\ +#define __GXX_ABI_VERSION 1002\n\ +#define __GXX_RTTI 1\n\ +#define __INT16_TYPE__ short\n\ +#define __INT32_TYPE__ int\n\ +#define __INT64_C_SUFFIX__ LL\n\ +#define __INT64_TYPE__ long long int\n\ +#define __INT8_TYPE__ char\n\ +#define __INTMAX_MAX__ 9223372036854775807L\n\ +#define __INTMAX_TYPE__ long int\n\ +#define __INTMAX_WIDTH__ 64\n\ +#define __INTPTR_TYPE__ long int\n\ +#define __INTPTR_WIDTH__ 64\n\ +#define __INT_MAX__ 2147483647\n\ +#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L\n\ +#define __LDBL_DIG__ 18\n\ +#define __LDBL_EPSILON__ 1.08420217248550443401e-19L\n\ +#define __LDBL_HAS_DENORM__ 1\n\ +#define __LDBL_HAS_INFINITY__ 1\n\ +#define __LDBL_HAS_QUIET_NAN__ 1\n\ +#define __LDBL_MANT_DIG__ 64\n\ +#define __LDBL_MAX_10_EXP__ 4932\n\ +#define __LDBL_MAX_EXP__ 16384\n\ #define __LDBL_MAX__ 1.18973149535723176502e+4932L\n\ -#define __APPLE_CC__ 5658\n\ -#define __UINTMAX_TYPE__ long unsigned int\n\ -#define __DEC32_EPSILON__ 1E-6DF\n\ -#define __SCHAR_MAX__ 127\n\ -#define __USER_LABEL_PREFIX__ _\n\ -#define __STDC_HOSTED__ 1\n\ -#define __DEC64_MIN_EXP__ (-383)\n\ -#define __DBL_DIG__ 15\n\ -#define __FLT_EPSILON__ 1.19209290e-7F\n\ +#define __LDBL_MIN_10_EXP__ (-4931)\n\ +#define __LDBL_MIN_EXP__ (-16381)\n\ #define __LDBL_MIN__ 3.36210314311209350626e-4932L\n\ -#define __DEC32_MAX__ 9.999999E96DF\n\ -#define __strong \n\ -#define __DECIMAL_DIG__ 21\n\ -#define __LDBL_HAS_QUIET_NAN__ 1\n\ -#define __DYNAMIC__ 1\n\ -#define __GNUC__ 4\n\ +#define __LITTLE_ENDIAN__ 1\n\ +#define __LONG_LONG_MAX__ 9223372036854775807LL\n\ +#define __LONG_MAX__ 9223372036854775807L\n\ +#define __LP64__ 1\n\ +#define __MACH__ 1\n\ #define __MMX__ 1\n\ -#define __FLT_HAS_DENORM__ 1\n\ -#define __DBL_MAX__ 1.7976931348623157e+308\n\ -#define __DBL_HAS_INFINITY__ 1\n\ -#define __DEC32_MIN_EXP__ (-95)\n\ -#define OBJC_NEW_PROPERTIES 1\n\ +#define __NO_INLINE__ 1\n\ +#define __NO_MATH_INLINES 1\n\ +#define __ORDER_BIG_ENDIAN__ 4321\n\ +#define __ORDER_LITTLE_ENDIAN__ 1234\n\ +#define __ORDER_PDP_ENDIAN__ 3412\n\ +#define __PIC__ 2\n\ +#define __POINTER_WIDTH__ 64\n\ +#define __PRAGMA_REDEFINE_EXTNAME 1\n\ +#define __PTRDIFF_TYPE__ long int\n\ +#define __PTRDIFF_WIDTH__ 64\n\ +#define __REGISTER_PREFIX__ \n\ +#define __SCHAR_MAX__ 127\n\ +#define __SHRT_MAX__ 32767\n\ +#define __SIG_ATOMIC_WIDTH__ 32\n\ +#define __SIZEOF_DOUBLE__ 8\n\ +#define __SIZEOF_FLOAT__ 4\n\ +#define __SIZEOF_INT128__ 16\n\ +#define __SIZEOF_INT__ 4\n\ +#define __SIZEOF_LONG_DOUBLE__ 16\n\ +#define __SIZEOF_LONG_LONG__ 8\n\ +#define __SIZEOF_LONG__ 8\n\ +#define __SIZEOF_POINTER__ 8\n\ +#define __SIZEOF_PTRDIFF_T__ 8\n\ +#define __SIZEOF_SHORT__ 2\n\ +#define __SIZEOF_SIZE_T__ 8\n\ +#define __SIZEOF_WCHAR_T__ 4\n\ +#define __SIZEOF_WINT_T__ 4\n\ +#define __SIZE_MAX__ 18446744073709551615UL\n\ +#define __SIZE_TYPE__ long unsigned int\n\ +#define __SIZE_WIDTH__ 64\n\ +#define __SSE2_MATH__ 1\n\ +#define __SSE2__ 1\n\ +#define __SSE3__ 1\n\ +#define __SSE_MATH__ 1\n\ +#define __SSE__ 1\n\ +#define __SSP__ 1\n\ +#define __SSSE3__ 1\n\ +#define __STDC_HOSTED__ 1\n\ +#define __STDC_UTF_16__ 1\n\ +#define __STDC_UTF_32__ 1\n\ +#define __STDC_VERSION__ 199901L\n\ +#define __STDC__ 1\n\ #define __STRICT_ANSI__ 1\n\ -#define __LDBL_HAS_DENORM__ 1\n\ -#define __DEC32_MIN__ 1E-95DF\n\ +#define __UINTMAX_TYPE__ long unsigned int\n\ +#define __USER_LABEL_PREFIX__ _\n\ +#define __VERSION__ \"4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)\"\n\ +#define __WCHAR_MAX__ 2147483647\n\ +#define __WCHAR_TYPE__ int\n\ +#define __WCHAR_WIDTH__ 32\n\ +#define __WINT_TYPE__ int\n\ +#define __WINT_WIDTH__ 32\n\ +#define __amd64 1\n\ +#define __amd64__ 1\n\ +#define __apple_build_version__ 5030038\n\ +#define __block __attribute__((__blocks__(byref)))\n\ +#define __clang__ 1\n\ +#define __clang_major__ 5\n\ +#define __clang_minor__ 1\n\ +#define __clang_patchlevel__ 0\n\ +#define __clang_version__ \"5.1 (clang-503.0.38)\"\n\ +#define __core2 1\n\ +#define __core2__ 1\n\ +#define __llvm__ 1\n\ +#define __pic__ 2\n\ +#define __strong \n\ +#define __tune_core2__ 1\n\ +#define __unsafe_unretained \n\ #define __weak __attribute__((objc_gc(weak)))\n\ -#define __DBL_MAX_EXP__ 1024\n\ -#define __DEC128_EPSILON__ 1E-33DL\n\ -#define __SSE2_MATH__ 1\n\ -#define __amd64 1\n\ -#define __tune_core2__ 1\n\ -#define __LONG_LONG_MAX__ 9223372036854775807LL\n\ -#define __GXX_ABI_VERSION 1002\n\ -#define __FLT_MIN_EXP__ (-125)\n\ #define __x86_64 1\n\ #define __x86_64__ 1\n\ -#define __DBL_MIN__ 2.2250738585072014e-308\n\ -#define __LP64__ 1\n\ -#define __DBL_HAS_QUIET_NAN__ 1\n\ -#define __DEC128_MIN__ 1E-6143DL\n\ -#define __REGISTER_PREFIX__ \n\ -#define __DBL_HAS_DENORM__ 1\n\ -#define __NO_INLINE__ 1\n\ -#define __DEC_EVAL_METHOD__ 2\n\ -#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL\n\ -#define __FLT_MANT_DIG__ 24\n\ -#define __VERSION__ \"4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)\"\n\ -#define __DEC64_EPSILON__ 1E-15DD\n\ -#define __DEC128_MIN_EXP__ (-6143)\n\ -#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 1072\n\ -#define __SIZE_TYPE__ long unsigned int\n\ -#define __DEC32_DEN__ 0.000001E-95DF\n\ -#define __FLT_RADIX__ 2\n\ -#define __LDBL_EPSILON__ 1.08420217248550443401e-19L\n\ -#define __SSE_MATH__ 1\n\ -#define __k8 1\n\ -#define __LDBL_DIG__ 18\n\ -#define __FLT_HAS_QUIET_NAN__ 1\n\ -#define __FLT_MAX_10_EXP__ 38\n\ -#define __LONG_MAX__ 9223372036854775807L\n\ -#define __FLT_HAS_INFINITY__ 1\n\ -#define __DEC64_MAX__ 9.999999999999999E384DD\n\ -#define __DEC64_MANT_DIG__ 16\n\ -#define __STDC_VERSION__ 199901L\n\ -#define __DEC32_MAX_EXP__ 96\n\ -#define __DEC128_DEN__ 0.000000000000000000000000000000001E-6143DL\n\ -#define __LITTLE_ENDIAN__ 1\n\ -#define __LDBL_MANT_DIG__ 64\n\ -#define __CONSTANT_CFSTRINGS__ 1\n\ -#define __DEC32_MANT_DIG__ 7\n\ -#define __k8__ 1\n\ -#define __WCHAR_TYPE__ int\n\ -#define __pic__ 2\n\ -#define __FLT_DIG__ 6\n\ -#define __INT_MAX__ 2147483647\n\ -#define __FLT_MAX_EXP__ 128\n\ -#define __DBL_MANT_DIG__ 53\n\ -#define __DEC64_MIN__ 1E-383DD\n\ -#define __WINT_TYPE__ int\n\ -#define __SSE__ 1\n\ -#define __LDBL_MIN_EXP__ (-16381)\n\ -#define __MACH__ 1\n\ -#define __amd64__ 1\n\ -#define __LDBL_MAX_EXP__ 16384\n\ -#define __SSP__ 1\n\ -#define __LDBL_MAX_10_EXP__ 4932\n\ -#define __DBL_EPSILON__ 2.2204460492503131e-16\n\ -#define _LP64 1\n\ -#define __GNUC_PATCHLEVEL__ 1\n\ -#define __LDBL_HAS_INFINITY__ 1\n\ -#define __INTMAX_MAX__ 9223372036854775807L\n\ -#define __FLT_DENORM_MIN__ 1.40129846e-45F\n\ -#define __PIC__ 2\n\ -#define __FLT_MAX__ 3.40282347e+38F\n\ -#define __SSE2__ 1\n\ -#define __FLT_MIN_10_EXP__ (-37)\n\ -#define __INTMAX_TYPE__ long int\n\ -#define __DEC128_MAX_EXP__ 6144\n\ -#define __GNUC_MINOR__ 2\n\ -#define __DBL_MAX_10_EXP__ 308\n\ -#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L\n\ -#define __STDC__ 1\n\ -#define __PTRDIFF_TYPE__ long int\n\ -#define __DEC128_MANT_DIG__ 34\n\ -#define __LDBL_MIN_10_EXP__ (-4931)\n\ -#define __llvm__ 1\n\ -#define __GNUC_GNU_INLINE__ 1\n\ -#define __SSE3__ 1\n\ -#define __extension__\n\ " +#endif + #else #ifdef __APPLE__ @@ -341,7 +393,6 @@ #define __DEC128_MANT_DIG__ 34 \n\ #define __LDBL_MIN_10_EXP__ (-4931) \n\ #define __SSE3__ 1 \n\ -#define __extension__\n\ #define __x86_64__ 1\n\ " #else @@ -480,7 +531,6 @@ #define __SIZEOF_LONG_LONG__ 8\n\ #define __LDBL_DIG__ 18\n\ #define __GNUC_GNU_INLINE__ 1\n\ -#define __extension__\n\ " #endif // extension is certainly wrong @@ -509,7 +559,6 @@ #define __i386__ 1\n\ #define __LITTLE_ENDIAN__ 1\n\ #define __STDC__ 1\n\ -#define __extension__\n\ // #define __restrict\n\ #define __flexarr\n\ //#define __const const\n\ @@ -543,7 +592,6 @@ #define __i386__ 1\n\ #define __LITTLE_ENDIAN__ 1\n\ #define __STDC__ 1\n\ -#define __extension__\n\ // #define __restrict\n\ #define __flexarr\n\ //#define __const const\n\ @@ -3539,9 +3587,10 @@ extern void ascii(char *s,int len) { - if (s[len-1] == 0) + if (s[len-1] == 0) { printf("\t.string \""); - else + len--; + } else printf("\t.ascii \""); while(len-- > 0) { if (*s=='\n') diff -r 35b339b36c88 -r 3cdc3c1d83bd mc-macro.c --- a/mc-macro.c Fri Apr 11 14:04:11 2014 +0900 +++ b/mc-macro.c Fri Apr 11 19:41:24 2014 +0900 @@ -41,7 +41,7 @@ static int macro_args(char **pchptr); static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history); static void local_define(char *macro,char *value, char *name); -static int macro_eval(int macrop,char *body0,int history); +static int macro_eval(int macrop,char *body0,int history,int local_only); static char * mappend0(int lists,char **result); static int macro_processing(); @@ -87,7 +87,7 @@ if (nptrm->sc == FMACRO) { macrop=macro_function(macrop,&chptr,nptrm,macro_history); } else { - macrop=macro_eval(macrop,scaddr(nptrm->dsp),macro_history); + macrop=macro_eval(macrop,scaddr(nptrm->dsp),macro_history,0); } // copy output from resulted listed string @@ -132,7 +132,7 @@ } #endif // evaluate generated result again - macrop=macro_eval(macrop,macropp,macro_history); + macrop=macro_eval(macrop,macropp,macro_history,0); cheap = reset_cheap(&scheap); macropp = cheap->ptr; // will not override evaled list @@ -844,7 +844,8 @@ } if (plevel==0) { if (c==',') { int rev = -1; - while((c = cheap->ptr[--rev])==' '|| c=='\t') ; + while((c = cheap->ptr[--rev])==' '|| c=='\t') + ; cheap->ptr[++rev] = 0; chptr = skip_space(chptr, pchptr); args = list3s(STRING,args,cheap->ptr); @@ -904,7 +905,7 @@ int evalues = 0; int values0 = values; while(values) { - evalues = list2(macro_eval(0,scaddr(values),history),evalues); + evalues = list2(macro_eval(0,scaddr(values),history,1),evalues); values = cadr(values); } evalues = reverse0(evalues); @@ -922,7 +923,7 @@ } // process body replacement macro = scaddr(nptr->dsp); - macrop = macro_eval(macrop,macro,glist3s(STRING,history,nptr->nm)); + macrop = macro_eval(macrop,macro,glist3s(STRING,history,nptr->nm),1); args = sargs; // unbind arguments leave_scope(); @@ -940,6 +941,7 @@ while(*macro==' '||*macro=='\t') macro++; nptr0 = name_space_search(nlist=get_name(macro,0,DEF),MACRO); nptr0 = make_local_scope(nlist,nptr0,MACRO); + nptr0->ty = 1; //mark for local define (else 0 ) nptr0->nm = value; nptr0->u.nm = name; // shallow value for concatenation } @@ -973,7 +975,7 @@ */ static int -macro_eval(int macrop,char *body0,int history) +macro_eval(int macrop,char *body0,int history, int local_only) { int c,len; int in_quote = 0; @@ -1067,10 +1069,10 @@ default: if (prev_concat) { prev_concat = 0; - macro = nptrm->nm; + macro = nptrm->u.nm; } else if (next_concat(c,body)) { prev_concat = 1; - macro = nptrm->nm; + macro = nptrm->u.nm; } if (macro==0 || !macro[0]) macro = nptrm->nm; @@ -1086,7 +1088,7 @@ } *cheap->ptr = 0; cheap = increment_cheap(cheap,expand); - macrop=macro_eval(macrop,macro,glist3s(STRING,history,nptrm->nm)); + macrop=macro_eval(macrop,macro,glist3s(STRING,history,nptrm->nm),local_only); macrop = list3s(STRING,macrop,cheap->ptr); expand = (char **)&(scaddr(macrop)); break; diff -r 35b339b36c88 -r 3cdc3c1d83bd mc-parse.c --- a/mc-parse.c Fri Apr 11 14:04:11 2014 +0900 +++ b/mc-parse.c Fri Apr 11 19:41:24 2014 +0900 @@ -335,9 +335,9 @@ while(--i>0) { c=*s++; if(c=='\n') printf("\\n"); - else if(c=='\r') printf("\\r"); + else if(c=='\r') printf("\\r\\n"); else if(c=='\t') printf("\\t"); - else if(c=='\e') printf("\\e"); + else if(c==033) printf("\\033"); else if(c=='"') printf("\\\""); else if(c=='\\') printf("\\\\"); else if(!(' '<=c&&c<=0x7f)) printf("\\%03o",c); @@ -4347,7 +4347,7 @@ case C_FILE: // return current file name nptr=name_space_search(get_name(filep->name0,0,0),STRING); - nptr->dsp = strlen1(nptr->nm); + nptr->dsp = strlen1(nptr->nm)+1; type=list3(ARRAY,CHAR,nptr->dsp); e1=list3n(STRING,nptr->dsp,nptr); getsym(0); @@ -4356,7 +4356,7 @@ // return current function name nptr=get_name(fnptr->nm,0,0); nptr=name_space_search(nptr,STRING); - nptr->dsp = strlen1(nptr->nm); + nptr->dsp = strlen1(nptr->nm)+1; type=list3(ARRAY,CHAR,nptr->dsp); e1=list3n(STRING,nptr->dsp,nptr); getsym(0); @@ -4928,7 +4928,7 @@ // call this right after '/' static void -skip_comment() +skip_comment(int space) { for(;;getch()) { if (ch=='/') { @@ -4936,7 +4936,8 @@ conv->comment_('/'); conv->comment_('/'); while(ch!='\n') { getch(); conv->comment_(ch); } in_comment = 0; - skipspc(); + if (space) skipspc(); + else return; if (ch!='/') break; continue; } @@ -4952,7 +4953,8 @@ } while(!(c=='*'&&ch=='/')); in_comment = 0; getch(); - skipspc(); + if (space) skipspc(); + else return; if (ch!='/') break; } } @@ -5002,7 +5004,7 @@ char *s = cheap->ptr; skipspc(); if (ch=='/') - skip_comment(); + skip_comment(1); if (ch=='"') { // concatenated string does not terminated by 0 if (s != cheap->ptr) { @@ -5333,7 +5335,7 @@ return sym=SM; case '/': if(ch!='*'&&ch!='/') return postequ(DIV,DIV+AS); - skip_comment(); sc=0; + skip_comment(1); sc=0; goto retry; case 0: case '\n': diff -r 35b339b36c88 -r 3cdc3c1d83bd test/macro.c --- a/test/macro.c Fri Apr 11 14:04:11 2014 +0900 +++ b/test/macro.c Fri Apr 11 19:41:24 2014 +0900 @@ -53,20 +53,6 @@ return 1 ; } -// name concateneation - -#define name(a,b) name_##b(a) - -#define names(a,b) name_ ## b(a) -#define names1(x,y) names(x,y) - -#define name_hoge(c) (c+a) -#define name_aho(c) (c*a) -#define hoge000(a) (a+a) -#define aho000(a) (a*a) /* hoge - comment -*/ -#define stringify(x) (#x) char *init_str = "\ test1\n\ @@ -94,6 +80,23 @@ #endif ; +// name concateneation + +#define name(a,b) name_##b(a) + +#define names(a,b) name_ ## b(a) +#define names1(x,y) names(x,y) +#define hoge 79 +#define names2(x) names(x,hoge) + +#define name_hoge(c) (c+a) +#define name_aho(c) (c*a) +#define hoge000(a) (a+a) +#define aho000(a) (a*a) /* hoge + comment +*/ +#define stringify(x) (#x) + int main() { int a,b,e; @@ -135,6 +138,16 @@ printf("#0106:%d\n",names1(4,aho)); printf("#0107:%s\n",stringify(aho)); printf("#0108:%s\n",init_str); + printf("#0109:%d\n",names2(4)); +/* + printf("#0103:%d\n",(3 +a)); + printf("#0104:%d\n",(3 +a)); + printf("#0105:%d\n",(3 +3)); + printf("#0106:%d\n",(4*a)); + printf("#0107:%s\n",("aho")); + printf("#0108:%s\n",init_str); + printf("#0109:%d\n",(4 +a)); + */ f(); return 0; }