mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Add underscore to repl
This commit is contained in:
		| @@ -73,10 +73,18 @@ static void bshift(DstBuffer *buf, int32_t delta) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| /* Wrap a value to add to the env */ | ||||
| static void set_underscore(Dst val) { | ||||
|     DstTable *t = dst_table(0); | ||||
|     dst_table_put(t, dst_csymbolv("value"), val); | ||||
|     dst_put(env, dst_csymbolv("_"), dst_wrap_table(t)); | ||||
| } | ||||
|  | ||||
| /* simple repl */ | ||||
| static int repl() { | ||||
|     DstBuffer b; | ||||
|     dst_buffer_init(&b, 256); | ||||
|     set_underscore(dst_wrap_nil()); | ||||
|     for (;;) { | ||||
|         int c; | ||||
|         DstParseResult res; | ||||
| @@ -120,6 +128,7 @@ static int repl() { | ||||
|                             dst_puts(dst_formatc("runtime error: %S\n", dst_to_string(ret)));  | ||||
|                         } else { | ||||
|                             dst_puts(dst_formatc("%v\n", ret));  | ||||
|                             set_underscore(ret); | ||||
|                         } | ||||
|                     } else { | ||||
|                         dst_puts(dst_formatc("compile error: %S\n", cres.error));  | ||||
|   | ||||
| @@ -378,7 +378,7 @@ Dst dst_loadstl(int flags) { | ||||
|     if (dst_checktype(ret, DST_TABLE)) { | ||||
|         DstTable *v = dst_table(1); | ||||
|         dst_table_put(v, dst_csymbolv("value"), ret); | ||||
|         dst_put(ret, dst_csymbolv("-env-"), dst_wrap_table(v)); | ||||
|         dst_put(ret, dst_csymbolv("_env"), dst_wrap_table(v)); | ||||
|     } | ||||
|     return ret; | ||||
| } | ||||
|   | ||||
| @@ -72,7 +72,7 @@ | ||||
| (assert (= 7 (| 3 4)) "bit or") | ||||
| (assert (= 0 (& 3 4)) "bit and") | ||||
|  | ||||
| # Set global variables to prevent some compiler optimizations that defeat point of the test | ||||
| # Set global variables to prevent some possible compiler optimizations that defeat point of the test | ||||
| (var zero 0) | ||||
| (var one 1) | ||||
| (var two 2) | ||||
| @@ -84,6 +84,9 @@ | ||||
| (var f91 nil) | ||||
| (varset! f91 (fn [n] (if (> n 100) (- n 10) (f91 (f91 (+ n 11)))))) | ||||
| (assert (= 91 (f91 10)), "f91(10) = 91") | ||||
| (assert (= 91 (f91 11)), "f91(11) = 91") | ||||
| (assert (= 91 (f91 20)), "f91(20) = 91") | ||||
| (assert (= 91 (f91 31)), "f91(31) = 91") | ||||
| (assert (= 91 (f91 100)), "f91(100) = 91") | ||||
| (assert (= 91 (f91 101)), "f91(101) = 91") | ||||
| (assert (= 92 (f91 102)), "f91(102) = 92") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 bakpakin
					bakpakin