Esempio n. 1
0
	ObjectPtr<Array> get_load_paths() {
		static Value* root = NULL;
		if (!root) {
			ObjectPtr<Array> load_paths = create_array_with_size(10);
			array_push(load_paths, create_string_constant("./"));
			array_push(load_paths, create_string_constant("./lib"));
			root = gc_create_root(load_paths);
		}
		return *root;
	}
Esempio n. 2
0
		VALUE array_inspect(const CallFrame* here, VALUE self, VALUE it) {
			ObjectPtr<Array> array = self;
			if (array == NULL) {
				throw_exception_with_description("Array#inspect called for object that doesn't derive from Array.");
			}

			ObjectPtr<String> result = create_string_constant("@(");

			for (size_t i = 0; i < array->size(); ++i) {
				Value val = (*array)[i];
				string_append(result, value_inspect(val));
				if (i != array->size() - 1) {
					string_append_cstr(result, ", ");
				}
			}

			string_append_cstr(result, ")");

			return result;
		}
Esempio n. 3
0
int main(int argc, char* const* argv) {
	static int debug_mode = false;
	static int verbose_mode = false;
	static int interactive_mode = false;
	
	ObjectPtr<Array> require_files = create_array();
	
	while (true)
	{
		int c;
		
		static struct option long_options[] = {
			{"debug",       no_argument,       &debug_mode,       'd'},
			{"version",     no_argument,       NULL,              'v'},
			{"require",     required_argument, NULL,              'r'},
			{"interactive", no_argument,       &interactive_mode,  1 },
			{"verbose",     no_argument,       &verbose_mode,      1 },
			{0,0,0,0}
		};
		
		int option_index = -1;
		
		c = getopt_long(argc, argv, "dvir:", long_options, &option_index);
		if (c < 0)
			break;
		
		switch (c)
		{
			case 'v':
			{
				print_version_info();
				return 0;
			}
			case 'r':
			{
				ObjectPtr<String> filename = create_string_constant(optarg);
				array_push(require_files, filename);
				break;
			}
			case 'i':
			{
				interactive_mode = true;
				break;
			}
			case '?':
				TRAP(); // unknown argument
			default:
				break;
		}
	}
	
	// require first loose argument, unless -- was used
	if (optind < argc && strcmp("--", argv[optind-1]) != 0) {
		ObjectPtr<String> filename = create_string_constant(argv[optind++]);
		array_push(require_files, filename);
	}
	
	// stuff the rest in ARGV
	ObjectPtr<Array> ARGV = create_array_with_size(argc);
	while (optind < argc) {
		ObjectPtr<String> argument = create_string_constant(argv[optind++]);
		array_push(ARGV, argument);
	}
	set_global(snow::sym("ARGV"), ARGV);
	
	for (size_t i = 0; i < array_size(require_files); ++i) {
		ObjectPtr<String> str = array_get(require_files, i);
		ASSERT(str != NULL);
		load(str);
	}
	
	if (interactive_mode) {
		interactive_prompt();
	}
	
	return 0;
}
Esempio n. 4
0
	inline ObjectPtr<String> create_empty_string() { return create_string_constant(""); }