computed goto
Gaucheã®ã½ã¼ã¹ã§ã¯gotoã£ã¦ä½¿ããã¦ãããã ãããã¨æã£ã¦ã®ããã¦ã¿ãããvm.cã«ãããããããªç®æçºè¦ã
/* We take advantage of GCC's `computed goto' feature (see gcc.info, "Labels as Values"). */ #ifdef __GNUC__ #define SWITCH(val) goto *dispatch_table[val]; #define CASE(insn) SCM_CPP_CAT(LABEL_, insn) : #define DEFAULT LABEL_DEFAULT : #define DISPATCH /*empty*/ #define NEXT \ do { \ if (vm->queueNotEmpty) goto process_queue; \ FETCH_INSN(code); \ goto *dispatch_table[SCM_VM_INSN_CODE(code)]; \ } while (0) #else /* !__GNUC__ */ #define SWITCH(val) switch (val) #define CASE(insn) case insn : #define DISPATCH dispatch: #define NEXT goto dispatch #endif
computed gotoã¯Gaucheã ããããªãã¦ãRuby1.9ãPerl6ãPython3.1ãPHP5.2ã§ã使ããã¦ãããããã
DSASéçºè ã®é¨å±:ã¤ã³ã¿ããªã¿åè¨èªãé«éåãã computed goto
http://dsas.blog.klab.org/archives/51393628.html
computed goto ã¨ããååãèãæ £ããªãã£ãã®ã§ããã調ã¹ã¦ã¿ã㨠Ruby 1.9 ã® VM (YARV) ãã Perl6 ã® VM ã¨ãã¦éçºããã¨ãã¨ããªãªã¼ã¹ããã Parrot ã«ãæ¡ç¨ããã¦ããææ³ã§ããã
Python3.1ããã«ãããã¨ãã«ã¯ãå¿ããã« --with-computed-gotos ãä»ãã¾ãããï¼
DSASéçºè ã®é¨å±:phpãé«éåãã computed goto
http://dsas.blog.klab.org/archives/51395944.html
Python 3.1 ã ããããªã㦠php ããã«ãããã¨ãã computed goto ã試ãã¦ã¿ã¦ä¸ããã
å ·ä½çãªä½¿ãæ¹ã
Using and Porting GNU CC - C è¨èªãã¡ããªã«å¯¾ããæ¡å¼µ
å¤ã¨ãã¦ã®ã©ãã«
ã«ã¬ã³ããªé¢æ° ï¼ãããã¯ã ãã®ã©ãã«ãå«ãã§ããé¢æ°ï¼ ã®ä¸ã§å®ç¾©ãããã©ãã«ã®ã¢ãã¬ã¹ãã åé æ¼ç®å `&&' ã§ç²å¾ãããã¨ãã§ãã¾ãã ãã®å¤ã®å㯠void * ã§ãã ãã®å¤ã¯å®æ°ã§ããã void * åã®å®æ°ãæ£å½ã§ããã¨ããã§ã¯ã©ãã§ã使ããã¨ãã§ãã¾ãã 以ä¸ã«ä¾ã示ãã¾ããvoid *ptr; ... ptr = &&foo;ãã®å¤ã使ãããã«ã¯ã ãã®ã©ãã«ã«ã¸ã£ã³ããããã¨ãã§ããå¿ è¦ãããã¾ãã ããã¯è©ä¾¡ gotoï¼computed gotoï¼æ (10) goto *exp; ã§è¡ãã¾ãã 以ä¸ã«ä¾ã示ãã¾ãã
goto *ptr;è©ä¾¡ goto æã§ã¯ void * åã®ä»»æã®å¼ã使ããã¨ãã§ãã¾ãã
ãã®ãããªå®æ°ã®ç¨éã®ï¼ã¤ã«ã ã¸ã£ã³ãã»ãã¼ãã«ã¨ãã¦æ©è½ããéçé åã®åæåãããã¾ããstatic void *array[] = { &&foo, &&bar, &&hack };ããããã¨ã 以ä¸ã®ããã«ã¤ã³ããã¯ã¹ã使ã£ã¦ã©ãã«ãé¸æãããã¨ãã§ãã¾ãã
goto *array[i];http://www.asahi-net.or.jp/~WG5K-ICKW/html/online/gcc-2.8.1/gcc_3.html
é¢æ°ãã¤ã³ã¿ã¨å¯¾æ¯ãããããªãµã³ãã«ãæ¸ãã¦ã¿ãã
#include<stdio.h> void foo(){ puts("foo"); } int main(){ void (*func)(),*label; printf("%d\n",foo); func=foo; (*func)(); printf("%d\n",&&bar); label=&&bar; goto *label; puts("dummy"); bar: puts("bar"); }
å®è¡çµæ
$ gcc --version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465) $ gcc test.c $ ./a.out 8018 foo 8159 bar
é¢æ°ã®ã¢ãã¬ã¹ã¯ãé¢æ°åãã®ã¾ã¾ãã§åãåºãã*ãã¤ãã¦ã³ã¼ã«ãã
ã©ãã«ã®ã¢ãã¬ã¹ã¯ã&&ã©ãã«åãã§åãåºãã*ãã¤ãã¦ã¸ã£ã³ããã