diff --git a/README.md b/README.md index 858a041..69ffb0d 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,10 @@ Public domain. 2022 DTB. ## true(1) ``` -^ ; initialize state to 0 -% ; store state (0) into *stack -; stack is destroyed, state becomes the final value of *stack -; when the stack is destroyed, the program exits with the value of state -$ +^ ; initialize hand to 0 +; set the chart pointer to 0 - this destroys the chart +; and the program exits with the value of the hand +* ``` ## Hello world: @@ -28,5 +27,5 @@ $ ; the <.> construct uses '<' to store the next value literally into state, ; does so, and uses '>' to output state literally <,>< >< ->^%$ +>^* ``` diff --git a/src/blang.h b/src/blang.h index 6a8e94e..703e07c 100644 --- a/src/blang.h +++ b/src/blang.h @@ -3,5 +3,5 @@ struct State{ unsigned char hand; char *chart; -} +}; #endif diff --git a/src/ops.c b/src/ops.c index 03d3643..510c72b 100644 --- a/src/ops.c +++ b/src/ops.c @@ -1,5 +1,6 @@ #include #include +#include #include "blang.h" @@ -17,11 +18,11 @@ void Ops_carat(struct State *s){ } void Ops_ampersand(struct State *s){ - s->hand = s->chart; + s->hand = (char)s->chart; } void Ops_splat(struct State *s){ - s->chart = s->hand; + s->chart = (char *)s->hand; } void Ops_plus(struct State *s){ @@ -41,6 +42,8 @@ void Ops_left(struct State *s){ } void Ops_semi(struct State *s){ + int c; + while( (c = getc(stdin)) != EOF && strchr("!\n", c) == NULL @@ -57,10 +60,9 @@ void Ops_cross(struct State *s){ const struct { unsigned char name; void (*f)(struct State *); -} *OPS[] = { - { '$', Ops_dollar }, +} OPS[] = { { '%', Ops_percent }, - { '^', Ops_caret }, + { '^', Ops_carat }, { '&', Ops_ampersand }, { '*', Ops_splat }, { '+', Ops_plus }, @@ -80,7 +82,7 @@ const struct { /* Slower than a switch but you don't have to update it when you add new * ops! */ -(void(struct State *)) Ops_lookup(char op){ +void (*Ops_lookup(char op))(struct State *){ size_t i; for(i = 0; i < (sizeof OPS)/(sizeof *OPS); ++i) diff --git a/src/ops.h b/src/ops.h index 0afee19..a318965 100644 --- a/src/ops.h +++ b/src/ops.h @@ -1,4 +1,4 @@ #if !defined _BLANG_OPS # define _BLANG_OPS 1 -(void(struct State *)) Ops_lookup(char op); +void (*Ops_lookup(char op))(struct State *); #endif