rain 4 роки тому
батько
коміт
672253833b
6 змінених файлів з 42 додано та 15 видалено
  1. 4 2
      arch/arch_templ.c
  2. 2 0
      arch/cstyles.c
  3. 2 1
      arch/interp/interp.c
  4. 1 0
      include/tripl/tripl.h
  5. 29 12
      man/tripl.1
  6. 4 0
      sample.trp

+ 4 - 2
arch/arch_templ.c

@@ -422,8 +422,10 @@ skip:	attr = getattrmask(p, declare_attrtab);
 	if (unlikely(!attr && guess != SHARED)) 
 		exit(generic_error("you must give attributes for declares", psave, lno));
 
-	if (attr & 2) 
+	if (attr & 2) {
 		n->value |= DECLARE_FN;
+		n->xmask = XMASK_FN;
+	}
 
 	else if (attr & 4) {
 		if (unlikely(guess == FUNCTION)) 
@@ -453,7 +455,7 @@ skip:	attr = getattrmask(p, declare_attrtab);
 		}
 	
 
-	n->xmask = XMASK_WEAK;
+	n->xmask |= XMASK_WEAK;
 	klist_add(&names_list, n);
 
 	return 0;

+ 2 - 0
arch/cstyles.c

@@ -166,6 +166,8 @@ __arch_templ int cstyle_declare(char *p, struct arch *arch_fn) {
 	else 
 		n->value = DECLARE_FN | nargs;
 
+	n->xmask = XMASK_WEAK | XMASK_FN;
+
 	n->payload = fname;
 
 	if (find_name(n->payload)) {

+ 2 - 1
arch/interp/interp.c

@@ -110,7 +110,8 @@ __arch static int interp_names_dump(int names) {
 	ansi_csi_ed(stdout);
 
 	for (n = names_list.next; n != &names_list; n = n->next) {
-		if ((n->value & DECLARE_FN) && (names & NAMES_FNS)) {
+		if (n->xmask & XMASK_FN && 
+				(n->value & DECLARE_FN) && (names & NAMES_FNS)) {
 			int nargs = n->value & (DECLARE_FN - 1);
 
 			if (nargs == DECLARE_NOARG) 

+ 1 - 0
include/tripl/tripl.h

@@ -135,6 +135,7 @@
 
 /* only declared, so will not raise name-already-defined */
 #define XMASK_WEAK 		0x80000000
+#define XMASK_FN 		0x40000000
 
 
 /* main.c */

+ 29 - 12
man/tripl.1

@@ -15,31 +15,48 @@ to download that from https://gitee.com/pengruiyang-cpu/tripl.git before
 that. 
 
 .SH SYNTAX
-\fB$\fP: uses to push a number into stack. 
+\fB$\fP: uses to push a number into stack. now we also support global variables. 
 
-eg. 	\fB$ name 1048576\fP
+eg. 	\fB$ name 1048576;\fP
 
-	\fB$ name 1048576 @ rdonly global\fP
+	\fB$ name = +1048576;\fP
 
-\fB`\fP: pop a number and free the memory of it. \fBWILL BE ABANDONED\fP
+	\fB$ name = -1048576;\fP
+
+	# or just leave blank. default value is 0
+
+	\fB$ name;$\fP;
+
+	\fB$ name 1048576 @ rdonly global;\fP
+
+	usable variable attributes: global rdonly ptr
 
-eg. 	\fB`;\fP
 
 \fB#\fP: line comment
 
-\fB!\fP: stack dump. This dumps the stack, you can see numbers in the stack, 
-but this won't change anything. \fBIT DOES NOT WORK IN COMPILE MODE\fP
+\fB!\fP: dump. This dumps things you want, e.g. functions, names, libraries 
 
-\fB<\fP: import shared library. 
+	\fBTHIS ONLY WORKS IN INTERPRETER MODE\fP
+
+eg. 	\fB!		@ var;
+
+	usable attributes: var (aka variables) fn (aka functions) names libs (aka libraries) 
+	all 
+
+\fB<\fP: import shared library and declares. 
 
 eg. 	\fB< "foobar.so"\fP
+	
+	\fB< fn 	@ fn;\fP
+
+	\fB< name 	@ var;\fP
 
-\fB@\fP: calling function. \fBWARNING: MAX 6 ARGUMENTS SUPPORT\fP
+	\fB< fn 2 	@ fn;\fP
 
-eg. 	\fB@ printf "hello, world %d %s" 0 "hello"
+	\fB< fn (a, b) 	@ fn;\fP
 
-	\fB@ printf ("hello, world");
+	\fB< age 	@ var;\fP
 
-	\fB@ printf("a: %d\n", a);
+	usable attributes: shared (aka dynalib), fn (aka function), var (aka variable)
 
 

+ 4 - 0
sample.trp

@@ -11,8 +11,12 @@ char *functio2n(void);
 
 < function3 ( a, b, c ) @ fn;
 
+< function4 4 		@ fn;
+
 $ a = +10;
 
 -10 -> a;
 
+!;
+