Compare commits
5 Commits
add3346ce9
...
2e9cd20761
Author | SHA1 | Date | |
---|---|---|---|
2e9cd20761 | |||
193254fb1f | |||
6a90901f81 | |||
6c659ee621 | |||
35a3fb0d62 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
bin
|
bin/blang
|
||||||
bin/*
|
build
|
||||||
|
build/*
|
||||||
|
4
Makefile
4
Makefile
@ -7,8 +7,6 @@ all: $(TARGETS)
|
|||||||
clean:
|
clean:
|
||||||
$(RM) $(TARGETS)
|
$(RM) $(TARGETS)
|
||||||
|
|
||||||
bin:
|
|
||||||
mkdir -p bin
|
|
||||||
build:
|
build:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
|
|
||||||
@ -18,7 +16,7 @@ build/blang.o: build src/blang.c src/blang.h
|
|||||||
build/ops.o: build src/blang.h src/ops.c src/ops.h
|
build/ops.o: build src/blang.h src/ops.c src/ops.h
|
||||||
$(CC) -c -o $@ src/ops.c
|
$(CC) -c -o $@ src/ops.c
|
||||||
|
|
||||||
bin/blang: bin build/blang.o build/ops.o
|
bin/blang: build/blang.o build/ops.o
|
||||||
$(CC) $(CFLAGS) -o $@ build/*.o
|
$(CC) $(CFLAGS) -o $@ build/*.o
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
14
README.md
14
README.md
@ -12,20 +12,22 @@ the bang language
|
|||||||
|
|
||||||
Public domain. 2022 DTB.
|
Public domain. 2022 DTB.
|
||||||
|
|
||||||
# Examples
|
## Examples
|
||||||
|
|
||||||
## true(1)
|
### true(1)
|
||||||
```
|
```
|
||||||
^ ; initialize hand to 0
|
; initialize hand to 0
|
||||||
|
^
|
||||||
|
|
||||||
; set the chart pointer to 0 - this destroys the chart
|
; set the chart pointer to 0 - this destroys the chart
|
||||||
; and the program exits with the value of the hand
|
; and the program exits with the value of the hand
|
||||||
*
|
*
|
||||||
```
|
```
|
||||||
|
|
||||||
## Hello world:
|
### Hello world:
|
||||||
```
|
```
|
||||||
; the <.> construct uses '<' to store the next value literally into state,
|
; the <.> construct uses '<' to literally 'palm' the next value
|
||||||
; does so, and uses '>' to output state literally
|
; (store into hand), does so, and uses '>' to 'toss' (output hand's value)
|
||||||
<H><e><l><l><o><,>< ><w><o><r><l><d><!><
|
<H><e><l><l><o><,>< ><w><o><r><l><d><!><
|
||||||
>^*
|
>^*
|
||||||
```
|
```
|
||||||
|
3
bin/blangfile
Executable file
3
bin/blangfile
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
blang "$(cat "$@")"
|
2
example/hello_world.blang
Normal file
2
example/hello_world.blang
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<H><e><l><l><o><,>< ><w><o><r><l><d><!><
|
||||||
|
>^*
|
2
example/true.blang
Normal file
2
example/true.blang
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env blangfile
|
||||||
|
^*
|
@ -11,12 +11,12 @@ int main(int argc, char **argv){
|
|||||||
void (*op)(struct State *);
|
void (*op)(struct State *);
|
||||||
|
|
||||||
s.chart = *(argv+1);
|
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)
|
if(s.chart == (char *)0)
|
||||||
return (int)s.hand;
|
return (int)s.hand;
|
||||||
if((op = Ops_lookup(s.chart[s.counter])) == NULL)
|
if((op = Ops_lookup(*s.counter)) == NULL)
|
||||||
return 127;
|
return 127;
|
||||||
else
|
else
|
||||||
op(&s);
|
op(&s);
|
||||||
|
@ -5,15 +5,13 @@
|
|||||||
* Adjust to architecture/system/environment/etc. */
|
* Adjust to architecture/system/environment/etc. */
|
||||||
typedef uint64_t hand_t;
|
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. */
|
/* Holds *argv; will not change between environments. */
|
||||||
typedef char * chart_t;
|
typedef char * chart_t;
|
||||||
|
|
||||||
struct State{
|
struct State{
|
||||||
chart_t chart;
|
chart_t chart;
|
||||||
counter_t counter;
|
chart_t point;
|
||||||
|
chart_t counter;
|
||||||
hand_t hand;
|
hand_t hand;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
36
src/ops.c
36
src/ops.c
@ -18,7 +18,7 @@ void Ops_carat(struct State *s){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Ops_ampersand(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){
|
void Ops_splat(struct State *s){
|
||||||
@ -33,42 +33,62 @@ void Ops_dash(struct State *s){
|
|||||||
--(s->hand);
|
--(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){
|
void Ops_right(struct State *s){
|
||||||
putc((char)s->hand, stdout);
|
putc((char)s->hand, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ops_left(struct State *s){
|
void Ops_what(struct State *s){
|
||||||
s->hand = getc(stdin);
|
if(!s->hand)
|
||||||
|
++(s->counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ops_semi(struct State *s){
|
void Ops_semi(struct State *s){
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while(
|
while(strchr("!\n", *++s->counter) == NULL);
|
||||||
(c = getc(stdin)) != EOF
|
}
|
||||||
&& strchr("!\n", c) == NULL
|
|
||||||
);
|
void Ops_mirror(struct State *s){
|
||||||
|
s->hand = !s->hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ops_cross(struct State *s){
|
void Ops_cross(struct State *s){
|
||||||
char *i;
|
char *i;
|
||||||
i = s->chart;
|
i = s->chart;
|
||||||
s->chart = (char *)s->hand;
|
s->chart = (char *)s->hand;
|
||||||
s->hand = (unsigned char)i;
|
s->hand = (uint64_t)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
unsigned char name;
|
unsigned char name;
|
||||||
void (*f)(struct State *);
|
void (*f)(struct State *);
|
||||||
} OPS[] = {
|
} OPS[] = {
|
||||||
|
{ '#', Ops_semi },
|
||||||
{ '%', Ops_percent },
|
{ '%', Ops_percent },
|
||||||
{ '^', Ops_carat },
|
{ '^', Ops_carat },
|
||||||
{ '&', Ops_ampersand },
|
{ '&', Ops_ampersand },
|
||||||
{ '*', Ops_splat },
|
{ '*', Ops_splat },
|
||||||
{ '+', Ops_plus },
|
{ '+', Ops_plus },
|
||||||
{ '-', Ops_dash },
|
{ '-', Ops_dash },
|
||||||
|
{ '{', Ops_lbrack },
|
||||||
|
{ '}', Ops_rbrack },
|
||||||
|
{ ';', Ops_semi },
|
||||||
{ '>', Ops_right },
|
{ '>', Ops_right },
|
||||||
{ '<', Ops_left },
|
{ '<', Ops_left },
|
||||||
|
{ '?', Ops_what },
|
||||||
|
{ 'v', Ops_mirror },
|
||||||
{ 'x', Ops_cross },
|
{ 'x', Ops_cross },
|
||||||
|
|
||||||
/* no-ops */
|
/* no-ops */
|
||||||
|
Loading…
Reference in New Issue
Block a user