Beispiel #1
0
/* (fopen path mode) Open a file and return fh, where fh is the open file
handle or void on failure. */
value type_fopen(value f)
	{
	if (!f->L || !f->L->L) return 0;
	{
	value x = arg(f->L->R);
	value y = arg(f->R);
	if (x->T == type_str && y->T == type_str)
		{
		string path = get_str(x);
		string mode = get_str(y);
		FILE *fh = fopen(path->data,mode->data);
		f = fh ? Qfile(fh) : hold(&Qvoid);
		}
	else
		f = reduce_void(f);
	drop(x);
	drop(y);
	return f;
	}
	}
Beispiel #2
0
/* Resolve standard names. */
static value standard(value name)
	{
	cur_name = str_data(name);

	/* Resolve numeric literals. */
	{
	value def = Qnum_str0(cur_name);
	if (def) return def;
	}

	/* Resolve other names. */
	if (match("put")) return hold(Qput);
	if (match("nl")) return hold(Qnl);
	if (match("say")) return Q(type_say);
	if (match("fput")) return hold(Qfput);
	if (match("fnl")) return hold(Qfnl);
	if (match("fsay")) return Q(type_fsay);
	if (match("fflush")) return Q(type_fflush);

	if (match("+")) return Q(type_add);
	if (match("-")) return Q(type_sub);
	if (match("*")) return Q(type_mul);
	if (match("/")) return Q(type_div);
	if (match("^")) return Q(type_pow);
	if (match("xor")) return Q(type_xor);
	if (match("round")) return Q(type_round);
	if (match("trunc")) return Q(type_trunc);
	if (match("abs")) return Q(type_abs);
	if (match("sqrt")) return Q(type_sqrt);
	if (match("exp")) return Q(type_exp);
	if (match("log")) return Q(type_log);
	if (match("sin")) return Q(type_sin);
	if (match("cos")) return Q(type_cos);
	if (match("pi")) return Qnum(num_pi());

	if (match("lt")) return Q(type_lt);
	if (match("le")) return Q(type_le);
	if (match("eq")) return Q(type_eq);
	if (match("ne")) return Q(type_ne);
	if (match("ge")) return Q(type_ge);
	if (match("gt")) return Q(type_gt);

	if (match("I")) return hold(QI);
	if (match("T")) return hold(QT);
	if (match("F")) return hold(QF);
	if (match("@")) return hold(QY);
	if (match("void")) return hold(Qvoid);
	if (match("cons")) return hold(Qcons);
	if (match("null")) return hold(Qnull);
	if (match("eval")) return hold(Qeval);
	if (match("once")) return Q(type_once);
	if (match("later")) return hold(Qlater);
	if (match("is_defined")) return Q(type_is_defined);
	if (match("is_void")) return Q(type_is_void);
	if (match("is_good")) return Q(type_is_good);
	if (match("is_bool")) return Q(type_is_bool);
	if (match("is_list")) return Q(type_is_list);

	if (match(".")) return Q(type_concat);
	if (match("length")) return Q(type_length);
	if (match("slice")) return Q(type_slice);
	if (match("search")) return Q(type_search);
	if (match("str_num")) return Q(type_str_num);
	if (match("ord")) return Q(type_ord);
	if (match("chr")) return Q(type_chr);
	if (match("char_width")) return Q(type_char_width);
	if (match("dirname")) return Q(type_dirname);
	if (match("basename")) return Q(type_basename);
	if (match("length_common")) return Q(type_length_common);
	if (match("is_str")) return Q(type_is_str);

	if (match("num_str")) return Q(type_num_str);
	if (match("is_num")) return Q(type_is_num);

	if (match("is_tuple")) return Q(type_is_tuple);
	if (match("arity")) return Q(type_arity);
	if (match("split_tuple")) return Q(type_split_tuple);
	if (match("join_tuple")) return Q(type_join_tuple);

	if (match("stdin")) return Qfile(stdin);
	if (match("stdout")) return Qfile(stdout);
	if (match("stderr")) return Qfile(stderr);
	if (match("fopen")) return Q(type_fopen);
	if (match("fclose")) return Q(type_fclose);
	if (match("fgetc")) return Q(type_fgetc);
	if (match("fget")) return Q(type_fget);
	if (match("flook")) return Q(type_flook);
	if (match("remove")) return Q(type_remove);
	if (match("is_newer")) return Q(type_is_newer);
	if (match("is_file")) return Q(type_is_file);
	if (match("is_dir")) return Q(type_is_dir);
	if (match("flock_ex")) return Q(type_flock_ex);
	if (match("flock_sh")) return Q(type_flock_sh);
	if (match("flock_un")) return Q(type_flock_un);
	if (match("readlink")) return Q(type_readlink);
	if (match("mkdir")) return Q(type_mkdir);
	if (match("rmdir")) return Q(type_rmdir);
	if (match("ftruncate")) return Q(type_ftruncate);
	if (match("fseek_set")) return Q(type_fseek_set);
	if (match("fseek_cur")) return Q(type_fseek_cur);
	if (match("fseek_end")) return Q(type_fseek_end);
	if (match("ftell")) return Q(type_ftell);
	if (match("fread")) return Q(type_fread);
	if (match("mkfile")) return Q(type_mkfile);
	if (match("dir_names")) return Q(type_dir_names);
	if (match("mod_time")) return Q(type_mod_time);
	if (match("file_size")) return Q(type_file_size);
	if (match("symlink")) return Q(type_symlink);
	if (match("rename")) return Q(type_rename);

	if (match("time")) return Q(type_time);
	if (match("localtime")) return Q(type_localtime);

	if (match("die")) return Q(type_die);
	if (match("argv")) return Q(type_argv);
	if (match("sleep")) return Q(type_sleep);
	if (match("usleep")) return Q(type_usleep);
	if (match("run_process")) return Q(type_run_process);
	if (match("spawn")) return Q(type_spawn);
	if (match("exec")) return Q(type_exec);
	if (match("fexl_benchmark")) return Q(type_fexl_benchmark);

	if (match("seed_rand")) return Q(type_seed_rand);
	if (match("rand")) return Q(type_rand);

	if (match("parse")) return Q(type_parse);
	if (match("parse_file")) return hold(Qparse_file);

	if (match("evaluate")) return hold(Qevaluate);
	if (match("resolve")) return Q(type_resolve);

	if (match("buf_new")) return Q(type_buf_new);
	if (match("buf_put")) return Q(type_buf_put);
	if (match("buf_get")) return Q(type_buf_get);

	if (match("readstr")) return Q(type_readstr);
	if (match("sgetc")) return Q(type_sgetc);
	if (match("sget")) return Q(type_sget);
	if (match("slook")) return Q(type_slook);

	if (match("var_new")) return Q(type_var_new);
	if (match("var_get")) return Q(type_var_get);
	if (match("var_put")) return Q(type_var_put);
	if (match("is_var")) return Q(type_is_var);

	if (match("limit_time")) return Q(type_limit_time);
	if (match("limit_memory")) return Q(type_limit_memory);
	if (match("limit_stack")) return Q(type_limit_stack);

	if (match("unpack")) return Q(type_unpack);
	if (match("pack")) return Q(type_pack);

	if (match("random_bytes")) return Q(type_random_bytes);
	if (match("random_nonce")) return Q(type_random_nonce);
	if (match("random_secret_key")) return Q(type_random_secret_key);
	if (match("crypto_box_public")) return Q(type_crypto_box_public);
	if (match("crypto_box_prepare")) return Q(type_crypto_box_prepare);
	if (match("crypto_box_seal")) return Q(type_crypto_box_seal);
	if (match("crypto_box_open")) return Q(type_crypto_box_open);
	if (match("crypto_sign_public")) return Q(type_crypto_sign_public);
	if (match("crypto_sign_seal")) return Q(type_crypto_sign_seal);
	if (match("crypto_sign_open")) return Q(type_crypto_sign_open);
	if (match("crypto_hash")) return Q(type_crypto_hash);

	if (match("set_alarm")) return Q(type_set_alarm);
	if (match("start_server")) return Q(type_start_server);
	if (match("kill")) return Q(type_kill);
	if (match("connect")) return Q(type_connect);
	if (match("receive_keystrokes")) return Q(type_receive_keystrokes);

	return 0;
	}