Ejemplo n.º 1
0
int main(int argc, const char * argv[]) {
	char code[1000] = "";

	FILE *fp = fopen(argv[1], "r");
	int i = 0;
	char c;
	while((c = fgetc(fp)) != EOF){
		code[i++] = c;
	}
	fclose(fp);
	code[i] = '\0';

	VM* vm = newVM();
	Context* global = newContext();
	Contexts* contexts = newContexts();
	pushContext(contexts, global);

	Method* methods[MAX_METHOD_NUM] = {
		defineMethod("+", method_add),
		defineMethod("add", method_add),
		defineMethod("-", method_minus),
		defineMethod("minus", method_minus),
		defineMethod("*", method_multiply),
		defineMethod("multiply", method_multiply),
		defineMethod("/", method_divide),
		defineMethod("divide", method_divide),
		defineMethod("\\", method_last),
		defineMethod("last", method_last)
	};

	return execute(code, vm, contexts, methods);
}
Ejemplo n.º 2
0
void Dot::init() {
    global_scope = new Scope();

    null_type = new DotType(this, "null");
    string_type = new DotString(this);
    number_type = new DotNumber(this);

    null_value = new DotValue(this, null_type);

    operators.push_back(new AssignOperator(this)); //0
    operators.push_back((operatorMethod = new MethodOperator(this))); //1
    operators.push_back(new AddOperator(this)); //2
    operators.push_back(new SubOperator(this)); //3
    operators.push_back(new MulOperator(this)); //4
    operators.push_back(new DivOperator(this)); //5

    defineMethod("print", new DotPrintMethod(this));
    defineMethod("type", new DotTypeMethod(this));
}
Ejemplo n.º 3
0
void ListModel::defineUtilMethods()
{
    auto klass = RubyClass(RubyModule(RubyModule("QML"), "Data"), "ListModel");
    klass.defineMethod("create_wrapper", RUBYQML_FUNCTION_INFO(&createWrapper));
}
Ejemplo n.º 4
0
void wrenDefineStaticMethod(WrenVM* vm, const char* className,
                            const char* methodName, int numParams,
                            WrenForeignMethodFn methodFn)
{
  defineMethod(vm, className, methodName, numParams, methodFn, true);
}