mirror and brackets

This commit is contained in:
dtb 2022-12-09 21:59:48 -05:00
parent 193254fb1f
commit 2e9cd20761
3 changed files with 33 additions and 15 deletions

View File

@ -11,12 +11,12 @@ int main(int argc, char **argv){
void (*op)(struct State *);
s.chart = *(argv+1);
s.counter = 0;
s.counter = s.chart;
for(s.counter = 0; ; ++s.counter){
for(s.counter = s.chart; ; ++s.counter){
if(s.chart == (char *)0)
return (int)s.hand;
if((op = Ops_lookup(s.chart[s.counter])) == NULL)
if((op = Ops_lookup(*s.counter)) == NULL)
return 127;
else
op(&s);

View File

@ -5,15 +5,13 @@
* Adjust to architecture/system/environment/etc. */
typedef uint64_t hand_t;
/* Just has to be fairly big. (TODO specify) */
typedef uint64_t counter_t;
/* Holds *argv; will not change between environments. */
typedef char * chart_t;
struct State{
chart_t chart;
counter_t counter;
chart_t point;
chart_t counter;
hand_t hand;
};
#endif

View File

@ -18,7 +18,7 @@ void Ops_carat(struct State *s){
}
void Ops_ampersand(struct State *s){
s->hand = (char)s->chart;
s->hand = (uint64_t)s->chart;
}
void Ops_splat(struct State *s){
@ -33,42 +33,62 @@ void Ops_dash(struct State *s){
--(s->hand);
}
void Ops_lbrack(struct State *s){
s->point = s->counter;
}
void Ops_rbrack(struct State *s){
s->counter = s->point;
}
void Ops_left(struct State *s){
s->hand = *++s->counter;
}
void Ops_right(struct State *s){
putc((char)s->hand, stdout);
}
void Ops_left(struct State *s){
s->hand = getc(stdin);
void Ops_what(struct State *s){
if(!s->hand)
++(s->counter);
}
void Ops_semi(struct State *s){
int c;
while(
(c = getc(stdin)) != EOF
&& strchr("!\n", c) == NULL
);
while(strchr("!\n", *++s->counter) == NULL);
}
void Ops_mirror(struct State *s){
s->hand = !s->hand;
}
void Ops_cross(struct State *s){
char *i;
i = s->chart;
s->chart = (char *)s->hand;
s->hand = (unsigned char)i;
s->hand = (uint64_t)i;
}
const struct {
unsigned char name;
void (*f)(struct State *);
} OPS[] = {
{ '#', Ops_semi },
{ '%', Ops_percent },
{ '^', Ops_carat },
{ '&', Ops_ampersand },
{ '*', Ops_splat },
{ '+', Ops_plus },
{ '-', Ops_dash },
{ '{', Ops_lbrack },
{ '}', Ops_rbrack },
{ ';', Ops_semi },
{ '>', Ops_right },
{ '<', Ops_left },
{ '?', Ops_what },
{ 'v', Ops_mirror },
{ 'x', Ops_cross },
/* no-ops */