change blang op meanings
This commit is contained in:
		
							parent
							
								
									905a0e9056
								
							
						
					
					
						commit
						da0ec7de01
					
				
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								README.md
									
									
									
									
									
								
							| @ -16,11 +16,10 @@ Public domain. 2022 DTB. | |||||||
| 
 | 
 | ||||||
| ## true(1) | ## true(1) | ||||||
| ``` | ``` | ||||||
| ^ ; initialize state to 0 | ^ ; initialize hand to 0 | ||||||
| % ; store state (0) into *stack | ; set the chart pointer to 0 - this destroys the chart | ||||||
| ; stack is destroyed, state becomes the final value of *stack | ; and the program exits with the value of the hand | ||||||
| ; when the stack is destroyed, the program exits with the value of state | *  | ||||||
| $ |  | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ## Hello world: | ## Hello world: | ||||||
| @ -28,5 +27,5 @@ $ | |||||||
| ; the <.> construct uses '<' to store the next value literally into state, | ; the <.> construct uses '<' to store the next value literally into state, | ||||||
| ; does so, and uses '>' to output state literally | ; does so, and uses '>' to output state literally | ||||||
| <H><e><l><l><o><,>< ><w><o><r><l><d><!>< | <H><e><l><l><o><,>< ><w><o><r><l><d><!>< | ||||||
| >^%$ | >^* | ||||||
| ``` | ``` | ||||||
|  | |||||||
| @ -3,5 +3,5 @@ | |||||||
| struct State{ | struct State{ | ||||||
| 	unsigned char hand; | 	unsigned char hand; | ||||||
| 	char *chart; | 	char *chart; | ||||||
| } | }; | ||||||
| #endif | #endif | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								src/ops.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/ops.c
									
									
									
									
									
								
							| @ -1,5 +1,6 @@ | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <string.h> | ||||||
| 
 | 
 | ||||||
| #include "blang.h" | #include "blang.h" | ||||||
| 
 | 
 | ||||||
| @ -17,11 +18,11 @@ void Ops_carat(struct State *s){ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Ops_ampersand(struct State *s){ | void Ops_ampersand(struct State *s){ | ||||||
| 	s->hand = s->chart; | 	s->hand = (char)s->chart; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Ops_splat(struct State *s){ | void Ops_splat(struct State *s){ | ||||||
| 	s->chart = s->hand; | 	s->chart = (char *)s->hand; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Ops_plus(struct State *s){ | void Ops_plus(struct State *s){ | ||||||
| @ -41,6 +42,8 @@ void Ops_left(struct State *s){ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Ops_semi(struct State *s){ | void Ops_semi(struct State *s){ | ||||||
|  | 	int c; | ||||||
|  | 
 | ||||||
| 	while( | 	while( | ||||||
| 		(c = getc(stdin)) != EOF | 		(c = getc(stdin)) != EOF | ||||||
| 		&& strchr("!\n", c) == NULL | 		&& strchr("!\n", c) == NULL | ||||||
| @ -57,10 +60,9 @@ void Ops_cross(struct State *s){ | |||||||
| const struct { | const struct { | ||||||
| 	unsigned char name; | 	unsigned char name; | ||||||
| 	void (*f)(struct State *); | 	void (*f)(struct State *); | ||||||
| } *OPS[] = { | } OPS[] = { | ||||||
| 	{ '$', Ops_dollar }, |  | ||||||
| 	{ '%', Ops_percent }, | 	{ '%', Ops_percent }, | ||||||
| 	{ '^', Ops_caret }, | 	{ '^', Ops_carat }, | ||||||
| 	{ '&', Ops_ampersand }, | 	{ '&', Ops_ampersand }, | ||||||
| 	{ '*', Ops_splat }, | 	{ '*', Ops_splat }, | ||||||
| 	{ '+', Ops_plus }, | 	{ '+', Ops_plus }, | ||||||
| @ -80,7 +82,7 @@ const struct { | |||||||
| 
 | 
 | ||||||
| /* Slower than a switch but you don't have to update it when you add new
 | /* Slower than a switch but you don't have to update it when you add new
 | ||||||
|  * ops! */ |  * ops! */ | ||||||
| (void(struct State *)) Ops_lookup(char op){ | void (*Ops_lookup(char op))(struct State *){ | ||||||
| 	size_t i; | 	size_t i; | ||||||
| 
 | 
 | ||||||
| 	for(i = 0; i < (sizeof OPS)/(sizeof *OPS); ++i) | 	for(i = 0; i < (sizeof OPS)/(sizeof *OPS); ++i) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user