Commit 5c17e4da authored by Kunshan Wang's avatar Kunshan Wang

C client seems to work

parent c91c84c7
......@@ -16,7 +16,6 @@ licenses := Seq("CC BY-SA 4.0" -> url("https://creativecommons.org/licenses/by-s
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % "2.11.8",
"org.antlr" % "antlr4" % "4.5.2-1",
"com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",
"ch.qos.logback" % "logback-classic" % "1.1.3",
......
......@@ -366,7 +366,7 @@ struct MuCtx {
MuID (*cur_func )(MuCtx *ctx, MuFCRefValue cursor);
MuID (*cur_func_ver )(MuCtx *ctx, MuFCRefValue cursor);
MuID (*cur_inst )(MuCtx *ctx, MuFCRefValue cursor);
void (*dump_keepalives)(MuCtx *ctx, MuFCRefValue cursor, MuValue *results); /// MUAPIPARSER: results:out
void (*dump_keepalives)(MuCtx *ctx, MuFCRefValue cursor, MuValue *results); /// MUAPIPARSER results:out
// On-stack replacement
void (*pop_frames_to)(MuCtx *ctx, MuFCRefValue cursor);
......@@ -558,7 +558,7 @@ struct MuCtx {
MuInstNode (*new_swapstack_ret )(MuCtx *ctx, MuBBNode bb, MuVarNode swappee, MuTypeNode *ret_tys, int nret_tys); /// MUAPIPARSER ret_tys:array:nret_tys
MuInstNode (*new_swapstack_kill)(MuCtx *ctx, MuBBNode bb, MuVarNode swappee);
void (*set_newstack_pass_values)(MuCtx *ctx, MuInstNode inst, MuTypeNode *tys, MuVarNode *vars, int nvars); /// MUAPIPARSER tys:array:nvars;ret_tys:array:nret_tys
void (*set_newstack_pass_values)(MuCtx *ctx, MuInstNode inst, MuTypeNode *tys, MuVarNode *vars, int nvars); /// MUAPIPARSER tys:array:nvars;vars:array:nvars
void (*set_newstack_throw_exc )(MuCtx *ctx, MuInstNode inst, MuVarNode exc);
MuInstNode (*new_comminst )(MuCtx *ctx, MuBBNode bb, MuCommInst opcode,
......
......@@ -63,8 +63,7 @@ int main() {
MuFuncRefValue func = ctx->handle_from_func(ctx, ctx->id_of(ctx, "@hw"));
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, NULL, 0, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, NULL, 0);
mvm->execute(mvm);
......@@ -96,8 +95,7 @@ int main() {
printf("Object populated. Create thread with threadlocal and execute...\n");
MuFuncRefValue func2 = ctx->handle_from_func(ctx, ctx->id_of(ctx, "@hw2"));
MuStackRefValue stack2 = ctx->new_stack(ctx, func2);
MuThreadRefValue thread2 = ctx->new_thread(ctx, stack2, hobj,
MU_REBIND_PASS_VALUES, NULL, 0, NULL);
MuThreadRefValue thread2 = ctx->new_thread_nor(ctx, stack2, hobj, NULL, 0);
mvm->execute(mvm);
......
......@@ -12,7 +12,6 @@ r_commpragma = re.compile(r'///\s*MUAPIPARSER:(.*)$')
r_comment = re.compile(r'//.*$', re.MULTILINE)
r_decl = re.compile(r'(?P<ret>\w+\s*\*?)\s*\(\s*\*\s*(?P<name>\w+)\s*\)\s*\((?P<params>[^)]*)\)\s*;\s*(?:///\s*MUAPIPARSER\s+(?P<pragma>.*)$)?', re.MULTILINE)
r_param = re.compile(r'\s*(?P<type>\w+\s*\*?)\s*(?P<name>\w+)')
r_value_ty = re.compile(r'Mu\w*(Value|Node)')
r_define = re.compile(r'^\s*#define\s+(?P<name>\w+)\s*\(\((?P<type>\w+)\)(?P<value>\w+)\)\s*$', re.MULTILINE)
......
......@@ -52,7 +52,7 @@ _self_getters = {
def type_is_explicit_ptr(ty):
return ty.endswith("*")
r_handle_ty = re.compile(r'Mu\w*(Value|Node)')
r_handle_ty = re.compile(r'^Mu\w*(Value|Node)$')
def type_is_handle(ty):
return r_handle_ty.match(ty) is not None
......@@ -212,9 +212,9 @@ def param_converter(pn, pt, rn, rt, is_optional, array_sz, is_bool, is_out):
if type_is_handle(pt):
if is_optional:
return "getMuValueNullable({})".format(rn)
return "getMuValueNullable({}).asInstanceOf[Option[{}]]".format(rn, pt)
else:
return "getMuValueNotNull({})".format(rn)
return "getMuValueNotNull({}).asInstanceOf[{}]".format(rn, pt)
if pt in _special_converters:
return "{}({})".format(_special_converters[pt], rn)
......@@ -233,8 +233,10 @@ def generate_method(typedefs, strname, meth) -> Tuple[str, str]:
jffi_retty = to_jffi_ty(to_basic_type(typedefs, ret_ty))
jffi_paramtys = [to_jffi_ty(to_basic_type(typedefs, p["type"])) for p in params]
header = "val {} = exposedMethod({}, Array({})) {{ _jffiBuffer =>".format(
valname, jffi_retty, ", ".join(jffi_paramtys))
pretty_name = "{}.{}".format(strname, name)
header = 'val {} = exposedMethod("{}", {}, Array({})) {{ _jffiBuffer =>'.format(
valname, pretty_name, jffi_retty, ", ".join(jffi_paramtys))
stmts = []
......@@ -346,7 +348,7 @@ def generate_stubs_for_struct(typedefs, st) -> str:
ptrs.append(ptrname)
results.append(code)
results.append("val stubsOf{} = Array[Word]({})".format(name, len(ptrs)))
results.append("val stubsOf{} = new Array[Word]({})".format(name, len(ptrs)))
for i,ptr in enumerate(ptrs):
results.append("stubsOf{}({}) = {}.address".format(name, i, ptr))
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -15,21 +15,29 @@ import uvm.refimpl.MicroVM
import uvm.ssavariables.Flag
import java.nio.charset.StandardCharsets
class ExposedMethod(jRetTy: JType, jParamTys: Array[JType], invokeFunc: Buffer => Unit) {
val closure = new SimpleClosure(invokeFunc)
class ExposedMethod(name: String, jRetTy: JType, jParamTys: Array[JType], invokeFunc: Buffer => Unit) {
val closure = new SimpleClosure(name, invokeFunc)
val handle = jffiClosureManager.newClosure(closure, jRetTy, jParamTys, CallingConvention.DEFAULT)
def address = handle.getAddress()
}
class SimpleClosure(f: Buffer => Unit) extends Closure {
def invoke(buffer: Buffer): Unit = f(buffer)
class SimpleClosure(name: String, f: Buffer => Unit) extends Closure {
def invoke(buffer: Buffer): Unit = try {
f(buffer)
} catch {
case t: Throwable => {
MuErrorNumber.setMuError(MuErrorNumber.MU_NATIVE_ERRNO)
NativeClientSupport.logger.error(
"Error thrown in Mu while native is calling %s. This is fatal.".format(name), t)
}
}
}
private object CDefsHelperFunctions {
import NativeClientSupport._
def exposedMethod(jRetTy: JType, jParamTys: Array[JType])(invokeFunc: Buffer => Unit) = {
new ExposedMethod(jRetTy, jParamTys, invokeFunc)
def exposedMethod(name: String, jRetTy: JType, jParamTys: Array[JType])(invokeFunc: Buffer => Unit) = {
new ExposedMethod(name: String, jRetTy, jParamTys, invokeFunc)
}
def readIntArray(base: Long, len: Long): IndexedSeq[Int] = {
......@@ -94,7 +102,7 @@ private object CDefsHelperFunctions {
mvm.setTrapHandler(new NativeTrapHandler(trap_handler, userdata))
}
def getMuErrorPtr(): MuCPtr = ClientAccessibleClassExposer.muErrorPtr.address()
def getMuErrorPtr(): MuCPtr = MuErrorNumber.muErrorPtr.address()
}
implicit class RichMuCtx(val ctx: MuCtx) extends AnyVal {
......@@ -155,5 +163,6 @@ private object CDefsHelperFunctions {
}
implicit def makeMuValueSeqCovariant[T <: MuValue, U <: T](seq: Seq[T]): Seq[U] = seq.asInstanceOf[Seq[U]]
implicit def muValueAutoCast[T <: MuValue, U <: T](v: T): U = v.asInstanceOf[U]
}
\ No newline at end of file
......@@ -330,8 +330,7 @@ bool test_traps(MuVM *mvm) {
MuFuncRefValue func = ctx->handle_from_func(ctx, ID("@trapper"));
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, args, 1, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, args, 1);
mvm->execute(mvm);
......@@ -411,8 +410,7 @@ bool test_load_bundle(MuVM *mvm) {
MuFuncRefValue func = ctx->handle_from_func(ctx, ID("@made_in_c"));
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, args, 1, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, args, 1);
mvm->execute(mvm);
......@@ -670,8 +668,7 @@ bool test_osr(MuVM *mvm) {
MuFuncRefValue func = ctx->handle_from_func(ctx, ID("@osr_test_base"));
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, args, 1, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, args, 1);
mvm->execute(mvm);
......@@ -787,8 +784,7 @@ bool test_wp(MuVM *mvm) {
{
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, NULL, 0, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, NULL, 0);
mvm->execute(mvm);
}
......@@ -798,8 +794,7 @@ bool test_wp(MuVM *mvm) {
{
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, NULL, 0, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, NULL, 0);
mvm->execute(mvm);
}
......@@ -809,8 +804,7 @@ bool test_wp(MuVM *mvm) {
{
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, NULL, 0, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, NULL, 0);
mvm->execute(mvm);
}
......@@ -900,8 +894,7 @@ bool test_native(MuVM *mvm) {
MuFuncRefValue func = ctx->handle_from_func(ctx, ID("@native_test"));
MuStackRefValue stack = ctx->new_stack(ctx, func);
MuThreadRefValue thread = ctx->new_thread(ctx, stack, NULL,
MU_REBIND_PASS_VALUES, args, 1, NULL);
MuThreadRefValue thread = ctx->new_thread_nor(ctx, stack, NULL, args, 1);
mvm->execute(mvm);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment