From 4f34eb13d06cdfa7b526f7e0aced9955808ee0d3 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 8 Aug 2017 18:25:28 +0200 Subject: Add faster interpreter, and some stuff --- test/Makefile | 4 ++++ test/brace16 | Bin 0 -> 12984 bytes test/brace16.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/notes.txt | 6 ++++++ test/test | Bin 0 -> 8632 bytes test/test.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+) create mode 100644 test/Makefile create mode 100755 test/brace16 create mode 100644 test/brace16.c create mode 100644 test/notes.txt create mode 100755 test/test create mode 100644 test/test.c (limited to 'test') diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..224fc85 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,4 @@ +CC = gcc +CFLAGS = -Wall -Wextra -std=c11 -O2 -fwrapv + +all: test brace16 diff --git a/test/brace16 b/test/brace16 new file mode 100755 index 0000000..fb36801 Binary files /dev/null and b/test/brace16 differ diff --git a/test/brace16.c b/test/brace16.c new file mode 100644 index 0000000..58273d3 --- /dev/null +++ b/test/brace16.c @@ -0,0 +1,58 @@ +#include +#include +#include + +int expand(char *dst,char ch,int amount){ +#define WRITE(s__) {int l__=strlen(s__); if(dst){memcpy(dst,s__,l__+1); dst+=l__;} written+=l__;} +#define WGOTO(i__) {while(curpos"); curpos++;} while(curpos>i__){WRITE("<"); curpos--;}} +#define WMOVE(i1__,i2__) {int p__=curpos; WGOTO(i1__); WRITE("[-"); WGOTO(i2__); WRITE("+"); WGOTO(i1__); WRITE("]"); WGOTO(p__);} + int written=0,curpos=0; + switch(str[i]){ + case '+': //strcpy(p,"+>+[->+<]>[<<->>[-<+>]]<<"); p+=25; break; + case '+': //strcpy(p,"+>+[<->[->+<]]>[-<+>]<<"); p+=23; break; + case '+': + WRITE("+"); + for(int i=1;i"); + } + case '-': strcpy(p,"->[->+<]>[<<+>>[-<+>]]<-<"); p+=25; break; + case '[': strcpy(p,"[->>+>>>+<<<<<]>>>>>[<<<[-<<+>>]+>>>[-]]<<<<[->+>>>+<<<<]>>>>[[-<<<-<+>>>>]<<<+>>>]<<<[[-]<<"); p+=92; break; + case ']': strcpy(p,"[->>+>>>+<<<<<]>>>>>[<<<[-<<+>>]+>>>[-]]<<<<[->+>>>+<<<<]>>>>[[-<<<-<+>>>>]<<<+>>>]<<<]<<"); p+=89; break; + case '>': strcpy(p,">>>"); p+=3; break; + case '<': strcpy(p,"<<<"); p+=3; break; + case ',': strcpy(p,"[-]>,<"); p+=6; break; + case '.': strcpy(p,">.<"); p+=3; break; + default: *(p++)=str[i]; break; + } + return res; +#undef WRITE +#undef WGOTO +#undef WMOVE +} + +int main(void){ + int amount=1; + char c; + while((c=getchar())!=EOF){ + if(c=='{'){ + amount++; + } else if(c=='}'){ + amount--; + if(amount<=0){ + fprintf(stderr,"More '}' than '{'\n"); + return 1; + } + } else if(amount==1){ + putchar(c); + } else { + int len=expand(NULL,c,amount); + char *str=malloc(len+1); + expand(str,c,amount); + printf("%s",str); + free(str); + } + } +} diff --git a/test/notes.txt b/test/notes.txt new file mode 100644 index 0000000..defedd4 --- /dev/null +++ b/test/notes.txt @@ -0,0 +1,6 @@ ++: +>+[->+<]>[<<->>[-<+>]]<< +-: ->[->+<]>[<<+>>[-<+>]]<-< +[: [->>+>>>+<<<<<]>>>>>[<<<[-<<+>>]+>>>[-]]<<<<[->+>>>+<<<<]>>>>[[-<<<-<+>>>>]<<<+>>>]<<<[[-]<< +]: [->>+>>>+<<<<<]>>>>>[<<<[-<<+>>]+>>>[-]]<<<<[->+>>>+<<<<]>>>>[[-<<<-<+>>>>]<<<+>>>]<<<]<< +>: >>> +<: <<< diff --git a/test/test b/test/test new file mode 100755 index 0000000..2ea9788 Binary files /dev/null and b/test/test differ diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..bdc11fc --- /dev/null +++ b/test/test.c @@ -0,0 +1,45 @@ +#include +#include + +// typedef uint32_t SF; +// const int ush=24,ssh=31; +typedef uint16_t SF; +const int ush=11,ssh=15; + +SF mul(SF a,SF b){ + SF sg=1; + if(a>=(1<=(1<>ush); +} + +SF mk(int i){ + return i<=(1<>4);y-=mk(1)>>4){ + for(SF x=L;x!=R;x+=mk(1)>>5){ + int n=0; + SF a=x,b=y,a2=mul(a,a),b2=mul(b,b); + while(n<26&&a2+b2