Răsfoiți Sursa

tripl: now starting beta test ...

rain 4 ani în urmă
părinte
comite
87611791d0
4 a modificat fișierele cu 76 adăugiri și 21 ștergeri
  1. 28 12
      arch/interp/interp.c
  2. 20 7
      arch/x86_64/asm.c
  3. 4 1
      sample.trp
  4. 24 1
      tripl.c

+ 28 - 12
arch/interp/interp.c

@@ -61,7 +61,7 @@ int interp_do_keyword(char *p, char c) {
 	int type, out, i, attrs;
 
 	char *np;
-	char *name = NULL;
+	char *name = NULL, *save;
 	void *dlib;
 
 	lbsave = p;
@@ -94,8 +94,12 @@ int interp_do_keyword(char *p, char c) {
 			getword(p, &type, &out);
 		}
 
-		if (type != WORDTYPE_NR) 
-			exit(generic_error("'$' requires a number", lbsave, lno));
+		if (type != WORDTYPE_NR) {
+			if (type) 
+				exit(generic_error("'$' requires a number", lbsave, lno));
+
+			out = 0;
+		}
 
 		p++;
 		_skip_word(p);
@@ -171,13 +175,18 @@ int interp_do_keyword(char *p, char c) {
 		break;
 
 	case '@':
+		++p;
+		_skip_spaces(p);
+
 		/* function call. the real funny thing is going on :-) */
 		do_funcall(p);
 
 		break;
 
 	default:
-		/* setting 'i = 0' */
+		save = p;
+
+		/* setting 'i = 0', or function call */
 		getword(p, &type, &out);
 
 		if (type != WORDTYPE_NAME) 
@@ -188,6 +197,16 @@ int interp_do_keyword(char *p, char c) {
 		if (name[0] == '&') 
 			name++;
 
+		_skip_word(p);
+		_skip_spaces(p);
+
+		if (*p == '(') {
+			/* function calling */
+			do_funcall(save);
+
+			break;
+		}
+
 		if (!(n = find_name(name))) 
 			exit(generic_error("name not found", lbsave, lno));
 
@@ -198,9 +217,6 @@ int interp_do_keyword(char *p, char c) {
 		if (n->xmask & 1 && np == name) 
 			exit(generic_error("no '&' found before global variable", lbsave, lno));
 
-		_skip_word(p);
-		_skip_spaces(p);
-
 		if (!getword(p, &type, &out)) 
 			exit(generic_error("no equal", lbsave, lno));
 
@@ -233,9 +249,6 @@ static int do_funcall(char *p) {
 
 	/* get function name */
 
-	p++;
-	_skip_spaces(p);
-
 	p = getword(p, &type, &out);
 
 	if (type != WORDTYPE_NAME) 
@@ -257,6 +270,7 @@ static int do_funcall(char *p) {
 		}
 	}
 
+	error(name);
 	exit(generic_error("function not found", lbsave, lno));
 
 	return 0;
@@ -299,7 +313,9 @@ static int do_dl_funcall(void *f, char *p) {
 			name = strndup(p, out);
 
 			if (!(node = find_name(name))) {
+				error(name);
 				generic_error("name not found", lbsave, lno);
+
 				free(name);
 
 				exit(1);
@@ -321,7 +337,7 @@ static int do_dl_funcall(void *f, char *p) {
 			break;
 
 		case WORDTYPE_STR:
-			name = strndup(p + 2, out - 1);
+			name = strndup(p + 1, out);
 			dest = malloc(out - 1);
 
 			next_arg->arg_s = dest;
@@ -343,7 +359,7 @@ static int do_dl_funcall(void *f, char *p) {
 
 			if (out == ')') {
 				p++;
-				_skip_spaces(p);;
+				_skip_spaces(p);
 
 				/* ; */
 

+ 20 - 7
arch/x86_64/asm.c

@@ -107,8 +107,9 @@ int x86_64_asm_fin(void) {
 
 
 int x86_64_do_asm(char *p, char c) {
-	char *name = NULL;
+	char *name = NULL, *save;
 	int out, type, attr;
+
 	lbsave = p;
 
 	switch (c) {
@@ -138,8 +139,12 @@ int x86_64_do_asm(char *p, char c) {
 			getword(p, &type, &out);
 		}
 
-		if (type != WORDTYPE_NR) 
-			exit(generic_error("'$' requires a number", lbsave, lno));
+		if (type != WORDTYPE_NR) {
+			if (type) 
+				exit(generic_error("'$' requires a number", lbsave, lno));
+
+			out = 0;
+		}
 
 		_skip_spaces(p);
 		_skip_word(p);
@@ -173,7 +178,9 @@ int x86_64_do_asm(char *p, char c) {
 		break;
 
 	default:
-		/* setting */
+		save = p;
+		/* setting or function calling */
+
 		getword(p, &type, &out);
 
 		if (type != WORDTYPE_NAME) 
@@ -181,6 +188,15 @@ int x86_64_do_asm(char *p, char c) {
 
 		name = strndup(p, out);
 
+		_skip_word(p);
+		_skip_spaces(p);
+
+		if (*p == '(') {
+			do_funcall(save);
+
+			break;
+		}
+
 		set_name(p, name);
 
 		free(name);
@@ -226,9 +242,6 @@ static int set_name(char *p, char *name) {
 		if (n->xmask & 4) 
 			exit(generic_error("variable sets attribute 'read-only'", lbsave, lno));
 
-		_skip_word(p);
-		_skip_spaces(p);
-
 		if (!getword(p, &type, &out)) 
 			exit(generic_error("no equal", lbsave, lno));
 

+ 4 - 1
sample.trp

@@ -1,4 +1,7 @@
 #! /usr/bin/tripl
 
-@ main ();
+$ a;
+a = 1;
+
+abort ();
 

+ 24 - 1
tripl.c

@@ -205,6 +205,14 @@ static int getnumber(char *p) {
 
 
 
+
+/* NEVER MODIFY THIS! MAGIC! 
+ * THIS IS REALLY THE UGLY CODE, MOST UGLY CODE ALL OVER THE WORLD. 
+ *
+ * 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. 
+ * */
+
 #define isfirstchr() 	(!i)
 #define notfirstchr() 	i
 
@@ -245,7 +253,6 @@ char *getword(char *fbuffer, int *type, int *out) {
 				return p;
 			}
 
-			/* eg. "# " */
 			if (i == 1 && isspace(*p)) {
 				if (ischr(p[-1])) {
 					/* name */
@@ -271,6 +278,22 @@ char *getword(char *fbuffer, int *type, int *out) {
 
 				return fbuffer;
 			}
+
+			if (!ischr(*p)) {
+				if (!i) {
+					*type = WORDTYPE_KWORD;
+					*out = *p;
+
+					return fbuffer;
+				}
+
+				if (ischr(p[-1])) {
+					*type = WORDTYPE_NAME;
+					*out = 1;
+
+					return --p;
+				}
+			}
 		}
 	}