示例#1
0
文件: solid.c 项目: atupal/Solid
int main(int argc, char *argv[])
{
	if (argc > 1) {
		solid_object *mainfunc = solid_parse_tree(solid_parse_file(argv[1]));
		solid_vm *vm = solid_make_vm();
		solid_set_namespace(solid_get_current_namespace(vm), solid_str("compile"), solid_define_c_function(solid_compile));
		solid_set_namespace(solid_get_current_namespace(vm), solid_str("import"), solid_define_c_function(solid_import));
		solid_call_func(vm, mainfunc);
	} else {
		solid_repl();
	}

	return 0;
}
示例#2
0
文件: solid.c 项目: atupal/Solid
void solid_repl()
{
	size_t n = 256;
	char *buffer = (char *) malloc(sizeof(char) * n);
	solid_vm *vm = solid_make_vm();
	solid_set_namespace(solid_get_current_namespace(vm), solid_str("compile"), solid_define_c_function(solid_compile));
	solid_set_namespace(solid_get_current_namespace(vm), solid_str("import"), solid_define_c_function(solid_import));
	while (printf("%s", "solid> "), getline(&buffer, &n, stdin) != -1) {
		solid_object *curexpr = solid_parse_tree(solid_parse_expr(buffer));
		solid_call_func(vm, curexpr);
		solid_push_stack(vm, vm->regs[255]);
		solid_print(vm);
	}
}
示例#3
0
文件: solid.c 项目: AngelFishy/Solid
void d_type(solid_vm *vm, char *name)
{
	debug("%s: type of %d", name, get_namespace(get_current_namespace(vm), solid_str(name))->type);
}
示例#4
0
文件: solid.c 项目: AngelFishy/Solid
void d_int(solid_vm *vm, char *name)
{
	debug("%s: %d, type of %d", name, get_int_value(get_namespace(get_current_namespace(vm), solid_str(name))), get_namespace(get_current_namespace(vm), solid_str(name))->type);
}
示例#5
0
文件: vm.c 项目: chameco/Solid
solid_vm *solid_make_vm()
{
	solid_vm *ret = (solid_vm *) malloc(sizeof(solid_vm));
	ret->stack = make_list();
	ret->all_objects = make_list();
	memset(ret->regs, 0, 256);
	memset(ret->namespace_stack, 0, 256);
	ret->namespace_stack[0] = solid_instance(ret);
	ret->namespace_stack_pointer = 0;
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "!!"), solid_define_c_function(ret, solid_nth_list));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "print"), solid_define_c_function(ret, solid_print));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "clone"), solid_define_c_function(ret, solid_clone));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, ":"), solid_define_c_function(ret, solid_cons));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "+"), solid_define_c_function(ret, solid_add));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "-"), solid_define_c_function(ret, solid_sub));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "*"), solid_define_c_function(ret, solid_mul));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "/"), solid_define_c_function(ret, solid_div));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "=="), solid_define_c_function(ret, solid_eq));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "<"), solid_define_c_function(ret, solid_lt));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "<="), solid_define_c_function(ret, solid_lte));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, ">"), solid_define_c_function(ret, solid_gt));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, ">="), solid_define_c_function(ret, solid_gte));
	solid_set_namespace(solid_get_current_namespace(ret), solid_str(ret, "gc"), solid_define_c_function(ret, solid_gc));
	return ret;
}