Commit Diff


commit - 85a1cbdde59060f8f0ee56a7785f938734510ac1
commit + 6019438afeeb073278dec3b2a194b3529d9efe33
blob - 030e267f4e05f8993782575e6af0cf6ec79e6cad
blob + 66bbecb8e5aeeb790093e8dc7cb7cb3099cefd2c
--- script.c
+++ script.c
@@ -43,6 +43,8 @@ static struct envs envs = TAILQ_HEAD_INITIALIZER(envs)
 
 static struct value v_false = {.type = V_NUM, .v = {.num = 0}};
 static struct value v_true  = {.type = V_NUM, .v = {.num = 1}};
+
+static uint8_t lasttag;
 
 static inline void
 peekn(int depth, struct value *v)
@@ -847,6 +849,19 @@ static int
 builtin_skip(int argc)
 {
 	return EVAL_SKIP;
+}
+
+static int
+builtin_iota(int argc)
+{
+	struct value v;
+
+	v.type = V_U8;
+	if ((v.v.u8 = ++lasttag) == 255)
+		v.v.u8 = ++lasttag;
+
+	pushv(&v);
+	return EVAL_OK;
 }
 
 static int
@@ -876,6 +891,7 @@ main(int argc, char **argv)
 
 	add_builtin_proc("print", builtin_print, 1, 1);
 	add_builtin_proc("skip", builtin_skip, 0, 0);
+	add_builtin_proc("iota", builtin_iota, 0, 0);
 
 	for (i = 1; i < argc; ++i)
 		loadfile(argv[i]);