Browse Source

tripl: BIGCHANGE: new getword(), declares and c-style declares

rain 4 năm trước cách đây
mục cha
commit
40d937fb9d
13 tập tin đã thay đổi với 454 bổ sung và 151 xóa
  1. 3 2
      arch/Makefile
  2. 42 19
      arch/arch_templ.c
  3. 172 0
      arch/cstyles.c
  4. 97 5
      arch/interp/interp.c
  5. 2 2
      arch/x86_64/asm.c
  6. 1 1
      arch/x86_64/x86_64.c
  7. 5 3
      include/klist.h
  8. 1 1
      include/tripl/arch.h
  9. 9 1
      include/tripl/tripl.h
  10. 1 0
      klist.c
  11. 3 3
      main.c
  12. 8 0
      sample.trp
  13. 110 114
      tripl.c

+ 3 - 2
arch/Makefile

@@ -1,6 +1,6 @@
 arch 	= interp x86_64 
 CFLAGS 	= -Wall -Werror -I../include -g 
-templ 	= arch_templ.o 
+templ 	= arch_templ.o cstyles.o 
 targ 	= libarch.a 
 
 
@@ -13,7 +13,8 @@ all : 	$(templ)
 
 
 %.o : %.c 
-	$(CC) $(CFLAGS) -c $*.c 
+	@$(CC) $(CFLAGS) -c $*.c 
+	@echo "\tCC\t\t\t$*.c"
 
 
 .PHONY clean : 

+ 42 - 19
arch/arch_templ.c

@@ -45,12 +45,14 @@ __arch_templ static int set_name(char *p, struct arch *);
 __arch_templ static int math_set_name(char *p, struct arch *);
 __arch_templ static int declare_object(char *p, struct arch *);
 
+__arch_templ int cstyle_declare(char *p, struct arch *);
+
 
 
 __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
 	psave = p;
 
-	if (p == line_eof) 
+	if (unlikely(p == line_eof)) 
 		return 0;
 
 	switch (*p) {
@@ -68,10 +70,13 @@ __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
 		break;
 
 	case '!':
-		if (!arch_fn->arch_stack_dump) 
-			exit(generic_error("unsupported 'stack-dump' in current mode", psave, lno));
+		p++;
+		_skip_spaces(p);
 
-		arch_fn->arch_stack_dump();
+		if (likely(!arch_fn->arch_dump)) 
+			exit(generic_error("unsupported dumping in current mode", psave, lno));
+
+		arch_fn->arch_dump(getattrmask(p, dump_attrtab));
 
 		break;
 
@@ -81,7 +86,9 @@ __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
 		break;
 
 	default:
-		if (set_name(p, arch_fn) + math_set_name(p, arch_fn) == 0) 
+		if (unlikely(!set_name(p, arch_fn) && 
+					!math_set_name(p, arch_fn) && 
+					!cstyle_declare(p, arch_fn))) 
 			exit(generic_error("unknow keyword", psave, lno));
 
 		break;
@@ -97,7 +104,7 @@ __arch_templ static int new_var(char *p, struct arch *arch_fn) {
 	
 	getword(p, &type, &out);
 
-	if (type != WORDTYPE_NAME) 
+	if (unlikely(type != WORDTYPE_NAME)) 
 		exit(generic_error("a name for variable required", psave, lno));
 
 	name = strndup(p, out);
@@ -109,7 +116,7 @@ __arch_templ static int new_var(char *p, struct arch *arch_fn) {
 
 	switch (type) {
 	case WORDTYPE_KWORD:
-		if (out != '=') 
+		if (unlikely(out != '=')) 
 			exit(generic_error("keyword but it's not a '='", psave, lno));
 		
 		++p;
@@ -117,7 +124,7 @@ __arch_templ static int new_var(char *p, struct arch *arch_fn) {
 
 		getword(p, &type, &out);
 
-		if (type != WORDTYPE_NR) 
+		if (unlikely(type != WORDTYPE_NR)) 
 			exit(generic_error("a number required", psave, lno));
 
 		_skip_word(p);
@@ -174,7 +181,7 @@ static int set_name(char *p, struct arch *arch_fn) {
 
 	getword(p, &type, &out);
 
-	if (type != WORDTYPE_NR) 
+	if (unlikely(type != WORDTYPE_NR)) 
 		exit(generic_error("a number required", psave, lno));
 
 
@@ -205,13 +212,13 @@ static int math_set_name(char *p, struct arch *arch_fn) {
 	_skip_word(p);
 	getword(p, &type, &out);
 
-	if (type != WORDTYPE_KWORD || out != '-') 
+	if (unlikely(type != WORDTYPE_KWORD || out != '-')) 
 		exit(generic_error("a '->' required", psave, lno));
 
 	p++;
 	getword(p, &type, &out);
 
-	if (type != WORDTYPE_KWORD || out != '>') 
+	if (unlikely(type != WORDTYPE_KWORD || out != '>')) 
 		exit(generic_error("a '->' required", psave, lno));
 
 	p++;
@@ -219,7 +226,7 @@ static int math_set_name(char *p, struct arch *arch_fn) {
 
 	getword(p, &type, &out);
 
-	if (type != WORDTYPE_NAME) 
+	if (unlikely(type != WORDTYPE_NAME)) 
 		exit(generic_error("a name required", psave, lno));
 
 	name = strndup(p, out);
@@ -232,6 +239,17 @@ static int math_set_name(char *p, struct arch *arch_fn) {
 }
 
 
+static int name_defined(char *name) {
+	struct klist_node *n;
+
+	for (n = names_list.next; n != &names_list; n = n->next) 
+		if (!strcmp(n->payload, name)) 
+			return 1;
+
+	return 0;
+}
+
+
 /*  
  *  1. 	
  *  	< "libfoo.a" 	@ dynalib;
@@ -261,7 +279,7 @@ static int declare_object(char *p, struct arch *arch_fn) {
 	_skip_spaces(p);
 
 	
-	if (!getword(p, &type, &out)) 
+	if (unlikely(!getword(p, &type, &out))) 
 		exit(generic_error("a module name or object name required", psave, lno));
 
 
@@ -277,7 +295,7 @@ static int declare_object(char *p, struct arch *arch_fn) {
 
 		p += out + 2;
 
-		free(name);
+		/* we will not free the name because interp_libs_dump uses it */
 
 		break;
 
@@ -292,6 +310,7 @@ static int declare_object(char *p, struct arch *arch_fn) {
 		klist_init(n);
 
 		n->payload = name;
+
 		klist_add(&names_list, n);
 
 		guess = NAMES;
@@ -344,14 +363,14 @@ static int declare_object(char *p, struct arch *arch_fn) {
 		_skip_spaces(p);
 
 		for (;;) {
-			if (!getword(p, &type, &out)) 
+			if (unlikely(!getword(p, &type, &out))) 
 				/* end but no ')' */
 				exit(generic_error("argument list terminated with no ')'", psave, lno));
 
 
 			switch (type) {
 			case WORDTYPE_KWORD:
-				if (out != ')' && out != ',') 
+				if (unlikely(out != ')' && out != ',')) 
 					exit(generic_error("invalid operators between arguments", psave, lno));
 
 				if (out == ')') {
@@ -390,7 +409,7 @@ static int declare_object(char *p, struct arch *arch_fn) {
 
 skip:	attr = getattrmask(p, declare_attrtab);
 
-	if (!attr && guess != SHARED) 
+	if (unlikely(!attr && guess != SHARED)) 
 		exit(generic_error("you must give attributes for declares", psave, lno));
 
 	if (guess != SHARED) {
@@ -398,7 +417,7 @@ skip:	attr = getattrmask(p, declare_attrtab);
 			n->value |= DECLARE_FN;
 
 		else if (attr & 4) {
-			if (guess == FUNCTION) 
+			if (unlikely(guess == FUNCTION)) 
 				exit(generic_error("you gave us a function declare but told us this is a variable declare? ", 
 							psave, lno));
 
@@ -410,10 +429,14 @@ skip:	attr = getattrmask(p, declare_attrtab);
 			exit(generic_error("one of 'fn' or 'var' must be gave", psave, lno));
 	}
 
+	if (unlikely(name_defined(n->payload))) {
+		error((char *) n->payload);
+
+		exit(generic_error("name already defined", psave, lno));
+	}
 
 	return 0;
 }
 
 
 
-

+ 172 - 0
arch/cstyles.c

@@ -0,0 +1,172 @@
+/* tripl/arch/cstyles.c 
+ * 
+ * This file is part of tripl. 
+ * 
+ * tripl is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * tripl is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with tripl. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+
+#include <errno.h>
+
+#include <klist.h>
+#include <tripl/tripl.h>
+#include <tripl/limits.h>
+#include <tripl/arch.h>
+
+
+
+/* compatible of c-style function defines */
+
+
+extern struct klist_node names_list;
+extern char *psave;
+
+
+const static char *c_keywords[] = {
+	"char", 	"double", 	"enum", 	"float", 
+	"int", 		"long", 	"short", 	"signed", 
+	"struct", 	"union", 	"unsigned", 	"void", 
+
+	"for", 		"do", 		"while", 	"break", 
+	"continue", 
+
+	"if", 		"else", 	"goto", 
+
+	"switch", 	"case", 	"default", 
+
+	"return", 
+
+	"auto", 	"extern", 	"register", 	"static", 
+
+	"const", 	"sizeof", 	"typedef", 	"volatile", 
+
+	"inline", 	"restrict", 	"_Bool", 	"_Complex", 
+	"_Imaginary"
+};
+
+
+static int iskeyword(char *p, int l) {
+	int i;
+
+	for (i = 0; i < arrlen(c_keywords); i++) 
+		if (!strncmp(c_keywords[i], p, l)) 
+			return 1;
+
+	return 0;
+}
+
+
+__arch_templ int cstyle_declare(char *p, struct arch *arch_fn) {
+	/* return-type function-name ( argument-type-1 argument-name, ...) 
+	 *
+	 * and the preprocess is MUST done, so only keywords are before functions.
+	 * and an important thing is, we will do some check with the c-style declares. */
+
+	struct klist_node *n;
+	int type, out, nargs = 0;
+	char *fname;
+
+
+	/* get function name */
+
+	_skip_spaces(p);
+
+	for (;;) {
+		getword(p, &type, &out);
+
+		if (type == WORDTYPE_NAME) {
+			if (iskeyword(p, out)) {
+				p += out;
+				_skip_spaces(p);
+
+				continue;
+			}
+		}
+
+		else if (type == WORDTYPE_KWORD) 
+			if (out == '*') {
+				p++;
+				_skip_spaces(p);
+
+				continue;
+			}
+
+		/* now we found the name */
+
+		break;
+	}
+
+	fname = strndup(p, out);
+
+	p += out;
+	_skip_spaces(p);
+
+	getword(p, &type, &out);
+
+	if (unlikely(type != WORDTYPE_KWORD || out != '(')) 
+		/* not a c-style declare */
+		return 0;
+
+	p++;
+	_skip_spaces(p);
+
+	while (getword(p, &type, &out)) {
+		switch (type) {
+		case WORDTYPE_NAME:
+			if (!iskeyword(p, out)) 
+				nargs++;
+			
+			p += out;
+			_skip_spaces(p);
+
+			break;
+
+		case WORDTYPE_KWORD:
+			p++;
+			_skip_spaces(p);
+
+			break;
+
+		case WORDTYPE_NR:
+		default:
+			exit(generic_error("invalid c-style declare: are you kidding me? ", psave, lno));
+		}
+	}
+
+	/* join to the function-list */
+
+	n = malloc(sizeof(struct klist_node));
+	klist_init(n);
+
+
+	if (!nargs) 
+		n->value = DECLARE_FN | DECLARE_NOARG;
+
+	else 
+		n->value = DECLARE_FN | nargs;
+
+	n->payload = fname;
+	klist_add(&names_list, n);
+
+	return 1;
+}
+
+

+ 97 - 5
arch/interp/interp.c

@@ -37,7 +37,7 @@
 int interp_init(void);
 
 __arch int interp_new_var(char *name, long value, int attr);
-__arch int interp_stack_dump(void);
+__arch int interp_dump(int);
 __arch int interp_set_var(char *name, long value, int attr);
 __arch int interp_import_shared(char *name);
 
@@ -46,13 +46,14 @@ extern char *psave;
 
 struct klist_node stack = KLIST_NODE_INIT(&stack), 
 		  libs = KLIST_NODE_INIT(&libs);
+extern struct klist_node names_list;
 
 
 
 struct arch interp_arch_fn = {
 	.arch_init = interp_init, 
 	.arch_new_var = interp_new_var, 
-	.arch_stack_dump = interp_stack_dump,  
+	.arch_dump = interp_dump,  
 	.arch_import_shared = interp_import_shared, 
 	.arch_funcall = NULL, 
 	.arch_set_var = interp_set_var
@@ -87,10 +88,10 @@ __arch int interp_set_var(char *name, long value, int attr) {
 
 	/* find the name */
 
-	if (!(n = find_name(name))) 
+	if (unlikely(!(n = find_name(name)))) 
 		exit(generic_error("name not found", psave, lno));
 
-	if (n->xmask & 4) 
+	if (unlikely(n->xmask & 4)) 
 		exit(generic_error("variable sets to be read-only", psave, lno));
 
 	n->value = value;
@@ -99,7 +100,7 @@ __arch int interp_set_var(char *name, long value, int attr) {
 }
 
 
-__arch int interp_stack_dump(void) {
+__arch static int interp_stack_dump(void) {
 	struct klist_node *n;
 	int i;
 
@@ -112,6 +113,96 @@ __arch int interp_stack_dump(void) {
 	for (i = 0, n = stack.next; n != &stack; n = n->next, i++) 
 		printf("\t%3d: 	%s \t%ld @ %08x\n", i, (char *) n->payload, n->value, n->xmask);
 
+	printf("\n");
+
+	return 0;
+}
+
+#define NAMES_VARS 	1
+#define NAMES_FNS 	2
+#define NAMES_ANY 	3
+
+__arch static int interp_names_dump(int names) {
+	struct klist_node *n;
+
+	ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_LIGHTBLUE, BG_BLACK);
+
+	if (names == NAMES_VARS) 
+		printf("dump variables: \n");
+
+	else if (names == NAMES_FNS) 
+		printf("dump functions: \n");
+
+	else 
+		printf("names dump: \n");
+
+	ansi_csi_ed(stdout);
+
+	for (n = names_list.next; n != &names_list; n = n->next) {
+		if ((n->value & DECLARE_FN) && (names & NAMES_FNS)) {
+			int nargs = n->value & (DECLARE_FN - 1);
+
+			if (nargs == DECLARE_NOARG) 
+				nargs = 0;
+
+			printf("\tfn %s: \t%d arguments\n", (char *) n->payload, nargs);
+		}
+
+		
+		if (!(n->value & DECLARE_FN) && (names & NAMES_VARS)) 
+			/* variables */
+			printf("\t var %s\n", (char *)n->payload);
+	}
+
+	printf("\n");
+
+	return 0;
+}
+
+
+__arch static int interp_libs_dump(void) {
+	struct klist_node *n;
+
+	ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_LIGHTBLUE, BG_BLACK);
+
+	printf("dump libraries: \n");
+
+	ansi_csi_ed(stdout);
+
+	for (n = libs.next; n != &libs; n = n->next) 
+		printf("\tlib %s: handle %p\n", (char *) n->data, n->payload);
+
+	printf("\n");
+
+	return 0;
+}
+
+
+__arch int interp_dump(int attr) {
+	if (!attr || attr == 32) {
+		/* dump all */
+		interp_stack_dump();
+		interp_names_dump(NAMES_ANY);
+		interp_libs_dump();
+
+		return 0;
+	}
+
+	if (attr & 1) 
+		interp_stack_dump();
+
+	if (attr & 2) 
+		interp_names_dump(NAMES_VARS);
+
+	if (attr & 4) 
+		interp_names_dump(NAMES_FNS);
+
+	if (attr & 8) 
+		interp_names_dump(NAMES_ANY);
+
+	if (attr & 16) 
+		interp_libs_dump();
+
 	return 0;
 }
 
@@ -127,6 +218,7 @@ __arch int interp_import_shared(char *name) {
 	klist_init(n);
 
 	n->payload = dl;
+	n->data = name;
 
 	klist_add(&libs, n);
 

+ 2 - 2
arch/x86_64/asm.c

@@ -160,10 +160,10 @@ __arch int x86_64_new_var(char *name, long value, int attr) {
 __arch int x86_64_set_var(char *name, long value, int attr) {
 	struct klist_node *n;
 
-	if (!(n = find_name(name))) 
+	if (unlikely(!(n = find_name(name)))) 
 		exit(generic_error("name not found", psave, lno));
 
-	if (n->xmask & 4) 
+	if (unlikely(n->xmask & 4)) 
 		exit(generic_error("variable sets to be 'read-only'", psave, lno));
 
 	if (n->xmask & 1) 

+ 1 - 1
arch/x86_64/x86_64.c

@@ -40,7 +40,7 @@ struct arch x86_64_arch_fn = {
 	.arch_init = x86_64_init, 
 	.arch_fin = x86_64_fin, 
 	.arch_new_var = x86_64_new_var, 
-	.arch_stack_dump = NULL, 
+	.arch_dump = NULL, 
 	.arch_import_shared = NULL, 
 	.arch_funcall = NULL, 
 	.arch_set_var = x86_64_set_var

+ 5 - 3
include/klist.h

@@ -26,9 +26,10 @@
 
 
 struct klist_node {
-	long value;
-	int xmask;
-	void *payload;
+	long 		value;
+	int 		xmask;
+	void 		*payload;
+	void 		*data;
 
 	struct klist_node *next, *prev;
 };
@@ -48,6 +49,7 @@ void klist_del(struct klist_node *head, struct klist_node *will_del);
 	.value = 0, \
 	.xmask = 0, \
 	.payload = NULL, \
+	.data = NULL, \
 	.next = __x, \
 	.prev = __x, \
 }

+ 1 - 1
include/tripl/arch.h

@@ -32,7 +32,7 @@ struct arch {
 	int (* arch_new_var) (char *name, long value, int attr);
 
 	/* interpreter only */
-	int (* arch_stack_dump) (void);
+	int (* arch_dump) (int attr);
 
 	int (* arch_import_shared) (char *name);
 

+ 9 - 1
include/tripl/tripl.h

@@ -30,7 +30,7 @@
 
 #define panic(msg, ...) 	error(msg, ##__VA_ARGS__); exit(1)
 
-#define BUG_ON(cond) 		({if (cond) panic(__FUNCTION__ ": " #cond)})
+#define BUG_ON(cond) 		({if (unlikely(cond)) panic(__FUNCTION__ ": " #cond)})
 
 /* macros to let you know, what does it do */
 
@@ -61,6 +61,8 @@
 #define MODE_HIGHLIGHT 		1
 #define MODE_LINE 		4
 
+#define MAKECOMPILERHAPPY 	114514
+
 
 #define ansi_csi_st(strm, m, fg, bg) \
 	fprintf(strm, "\033[%d;%d;%dm", m, fg, bg)
@@ -89,6 +91,11 @@
 #define atox(c) 	((c) >= 'a' ? (c) - 'a' + 10 : (c) - '0')
 #define atoX(c) 	((c) >= 'A' ? (c) - 'A' + 10 : (c) - '0')
 
+#define arrlen(arr) 	(sizeof(arr) / sizeof(arr[0]))
+#define boolean(__c) 	(!!(__c))
+#define likely(__c) 	__builtin_expect(boolean(__c), 1)
+#define unlikely(__c) 	__builtin_expect(boolean(__c), 0)
+
 
 #define __push_nr(__stack, nr, np, mask) ({ \
 	struct klist_node *p = malloc(sizeof(struct klist_node)); \
@@ -156,6 +163,7 @@ struct attr_table {
 
 extern const struct attr_table vardef_attrtab[];
 extern const struct attr_table declare_attrtab[];
+extern const struct attr_table dump_attrtab[];
 
 
 int do_tripl_compile(char *, off_t);

+ 1 - 0
klist.c

@@ -41,6 +41,7 @@ void klist_init(struct klist_node *head) {
 	head->prev = head;
 	head->value = 0;
 	head->payload = NULL;
+	head->data = NULL;
 
 	return;
 }

+ 3 - 3
main.c

@@ -45,10 +45,10 @@ int main(int argc, const char **argv) {
 		return usage();
 
 
-	if (!(fname = (char *) argv[1])) 
+	if (unlikely(!(fname = (char *) argv[1]))) 
 		return usage();
 
-	if ((fd = open(fname, O_RDONLY)) < 0) {
+	if (unlikely((fd = open(fname, O_RDONLY)) < 0)) {
 		perror(basename);
 
 		return usage();
@@ -58,7 +58,7 @@ int main(int argc, const char **argv) {
 	lseek(fd, 0, SEEK_SET);
 
 
-	if ((fbuffer = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) {
+	if (unlikely((fbuffer = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)) {
 		perror(basename);
 
 		return usage();

+ 8 - 0
sample.trp

@@ -3,8 +3,16 @@
 < "libc-2.33.so" 	@ shared;
 < "libc-2.33.so";
 
+
+extern int *function(int arg, const asdf);
+int function2();
+
+
+# buggy
+#
 < function 		@ fn;
 < function2 2 		@ fn;
 < function3 ( a, b, c ) @ fn;
 
+!  			@ fn var;
 

+ 110 - 114
tripl.c

@@ -73,6 +73,7 @@ const struct attr_table vardef_attrtab[] = {
 	{ NULL, 0 }
 };
 
+
 const struct attr_table declare_attrtab[] = {
 	{ "shared", 1 }, 
 	{ "fn", 2 }, 
@@ -86,6 +87,22 @@ const struct attr_table declare_attrtab[] = {
 };
 
 
+const struct attr_table dump_attrtab[] = {
+	{ "stack", 1 }, 
+	{ "var", 2 }, 
+	{ "fn", 4 }, 
+	{ "names", 8 }, 
+	{ "libs", 16 }, 
+	{ "all", 32 }, 
+
+	{ "variables", 2 }, 
+	{ "functions", 4 }, 
+	{ "libraries", 16 }, 
+
+	{ NULL, 0 }
+};
+
+
 
 int do_tripl_compile(char *fbuffer, off_t fsize) {
 	char *archname = getenv("TRIPL_ARCH");
@@ -128,7 +145,7 @@ ok:	klist_init(&stack);
 /* skip the comment, from '# asdf\nasdf2' to 'asdf2' */
 
 static char *__skip_comment(char *fbuffer) {
-	if (*fbuffer != '#') 
+	if (likely(*fbuffer != '#')) 
 		return fbuffer;
 
 	while (*fbuffer != '\n') 
@@ -145,24 +162,43 @@ static char *__skip_comment(char *fbuffer) {
 }
 
 
-static int next_line(char *fbuffer) {
-	char *p;
+/* skip to the ';' */
+
+static char *to_eol(char *p, char *eof) {
+	int in = 0;
+
+	while (p < eof) {
+		if (*p == '\"') {
+			if (in) 
+				in = 0;
+
+			else 
+				in = 1;
+		}
 	
+		if (!in && *p == ';') 
+			return p;
+
+		p++;
+	}
+
+	return NULL;
+}
+
+
+static int next_line(char *fbuffer) {
 	++lno;
 
 	/* first time we call this, initial */
 
-	if (!line_buffer) {
-		p = line_eof = line_buffer = fbuffer = __skip_comment(fbuffer);
+	if (unlikely(!line_buffer)) {
+		line_eof = line_buffer = fbuffer = __skip_comment(fbuffer);
 
-		if (fbuffer >= eof) 
+		if (unlikely(fbuffer >= eof)) 
 			/* only comment in this file */
 			return 0;
 
-		/* got line_eof */
-
-		while (*p != ';' && p < eof) 
-			p++, line_eof++;
+		line_eof = to_eol(line_eof, eof);
 
 		linebuffer_save = line_buffer;
 
@@ -173,28 +209,24 @@ static int next_line(char *fbuffer) {
 
 	line_buffer = fbuffer = __skip_comment(line_buffer);
 
-	if (fbuffer >= eof) 
+	if (unlikely(fbuffer >= eof)) 
 		return 0;
 
-	while (*line_buffer != ';' && line_buffer < eof) 
-		line_buffer++;
+	/* skip current line */
 
+	line_buffer = to_eol(line_buffer, eof);
 
 	line_buffer++;
-
-	/* \n */
 	_skip_spaces(line_buffer)
 
 	line_buffer = __skip_comment(line_buffer);
 
 	line_eof = line_buffer;
 
-	while (*line_eof != ';' && line_eof < eof) 
-		line_eof++;
-
+	line_eof = to_eol(line_eof, eof);
 	linebuffer_save = line_buffer;
 
-	if (line_buffer >= eof) 
+	if (unlikely(line_buffer >= eof)) 
 		return 0;
 
 	return 1;
@@ -218,7 +250,7 @@ static int getnumber(char *p) {
 		p++;
 	}
 
-	if (*p == '0' && isnr(p[1])) 
+	if (unlikely(*p == '0' && isnr(p[1]))) 
 		exit(generic_error("number starting with '0'", linebuffer_save, lno));
 
 
@@ -243,6 +275,19 @@ static int getnumber(char *p) {
 }
 
 
+static inline int getwordtype(char c) {
+	if (isnr(c)) 
+		return WORDTYPE_NR;
+
+	else if (ischr(c)) 
+		return WORDTYPE_NAME;
+
+	else if (isspace(c)) 
+		return 0;
+
+	return WORDTYPE_KWORD;
+}
+
 
 
 /* NEVER MODIFY THIS! MAGIC! 
@@ -250,133 +295,84 @@ static int getnumber(char *p) {
  *
  * BUT IT WORKS NOW, SO WE DO NOT TO CHANGE THIS AND WE WILL CHANGE 
  * A LOT BECAUSE ALL OF THE TRIPL REQUIRES THIS FUNCTION. 
+ *
+ * f**k up. i will fix this up. --- 2021.1.29 rain
  * */
 
-#define isfirstchr() 	(!i)
-#define notfirstchr() 	i
 
+#define isfirstchr() 		!len
+#define notfirstchr() 		len
 
-char *getword(char *fbuffer, int *type, int *out) {
-	*type = WORDTYPE_INVAL;
-	char *p;
-	int i, in = 0;
 
-	_skip_spaces(fbuffer);
+char *getword(char *p, int *type, int *out) {
+	int last_word_type, curr_word_type;
+	int len, in = 0;
 
-	for (i = 0, p = fbuffer; p < line_eof; i++, p++) {
-		if (*p == '\"') {
-			if (in) {
-				/* end */
+	char *back = p;
 
-				*out = i - 1;
-				return fbuffer;
-			}
+	last_word_type = 0;
 
-			in = 1;
-			*type = WORDTYPE_STR;
-		}
-
-		if (!in) {
-			if (isnr(*p) || *p == '-' || *p == '+') {
-				if (notfirstchr()) 
-					/* name, but not a number */
-					continue;
-
-				if ((*p == '-' || *p == '+') && !isnr(p[1])) 
-					continue;
-
-				/* get the number, and save to *out */
+	if (p >= line_eof) 
+		return NULL;
 
-				*out = getnumber(p);
+	for (len = 0; p < line_eof; p++, len++) {
+		if (*p == '\"') {
+			if (in) {
+				in = 0;
 
-				/* line finished. */
-				*type = WORDTYPE_NR;
+				*type = WORDTYPE_STR;
+				*out = len - 1;
 
 				return p;
 			}
 
-			if (i == 1 && isspace(*p)) {
-				if (ischr(p[-1])) {
-					/* name */
-					*type = WORDTYPE_NAME;
-					*out = 1;
+			if (!in) 
+				in = 1;
+		}
 
-					return --p;
-				}
+		if (!in) {
+			curr_word_type = getwordtype(*p);
 
-				/* keyword */
+			if (!curr_word_type) 
+				break;
 
+			if (isfirstchr() && curr_word_type == WORDTYPE_KWORD) {
 				*type = WORDTYPE_KWORD;
-				*out = *--p;
+				*out = *p;
 
 				return p;
 			}
 
-			/* it can only be a name */
-			if (isspace(*p)) {
-				/* end */
-				*type = WORDTYPE_NAME;
-				*out = i;
+			if (notfirstchr() && curr_word_type != last_word_type) {
+				if (curr_word_type == WORDTYPE_NR && !isnr(p[-1])) 
+					continue;
 
-				return fbuffer;
+				break;
 			}
 
-			if (!ischr(*p)) {
-				if (!i) {
-					*type = WORDTYPE_KWORD;
-					*out = *p;
-
-					return fbuffer;
-				}
-
-				if (i == 1 && (p[-1] == '-' || p[-1] == '+')) {
-					*type = WORDTYPE_KWORD;
-					*out = p[-1];
-
-					return fbuffer;
-				}
-
-				if (ischr(p[-1])) {
-					*type = WORDTYPE_NAME;
-					*out = i;
-
-					return p - i;
-				}
-			}
+			last_word_type = curr_word_type;
 		}
 	}
 
-	/* there isn't a space at end of the line */
-
-	if (in) 
-		exit(generic_error("no '\"' found", linebuffer_save, lno));
+ 	*type = last_word_type;
 
-	if (i == 1) {
-		if (ischr(p[-1])) {
-			*type = WORDTYPE_NAME;
-			*out = 1;
+	switch (last_word_type) {
+	case WORDTYPE_NR:
+		*out = getnumber(back);
 
-			return p;
-		}
+		break;
 
-		*type = WORDTYPE_KWORD;
-		*out = *--p;
+	case WORDTYPE_NAME:
+		*out = len;
 
-		return p;
+		break;
 	}
 
-	if (!i) 
-		return NULL;
-
-	/* only can be a name */
-
-	*type = WORDTYPE_NAME;
-	*out = i;
-
-	return fbuffer;
+	return back;
 }
 
 
+
 static inline int find_attr(char *attrname, const struct attr_table *tab) {
 	int i;
 
@@ -395,22 +391,22 @@ int getattrmask(char *p, const struct attr_table *tab) {
 	if (!getword(p, &type, &out)) 
 		return 0;
 
-	if (type != WORDTYPE_KWORD) 
+	if (unlikely(type != WORDTYPE_KWORD)) 
 		exit(generic_error("non-attribute ('@') character after that", linebuffer_save, lno));
 
-	if (out != '@') 
+	if (unlikely(out != '@')) 
 		exit(generic_error("not a '@' after string", linebuffer_save, lno));
 
 	++p;
 	_skip_spaces(p);
 
 	while (getword(p, &type, &out)) {
-		if (type != WORDTYPE_NAME) 
+		if (unlikely(type != WORDTYPE_NAME)) 
 			exit(generic_error("an attribute name required", linebuffer_save, lno));
 
 		attrname = strndup(p, out);
 
-		if (!(t = find_attr(attrname, tab))) 
+		if (unlikely(!(t = find_attr(attrname, tab)))) 
 			exit(generic_error("unknow attribute", linebuffer_save, lno));
 
 		mask |= t;