Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-ref2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mu
mu-impl-ref2
Commits
5c17e4da
Commit
5c17e4da
authored
Jun 13, 2016
by
Kunshan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C client seems to work
parent
c91c84c7
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
517 additions
and
1260 deletions
+517
-1260
build.sbt
build.sbt
+0
-1
cbinding/muapi.h
cbinding/muapi.h
+2
-2
cbinding/test_client.c
cbinding/test_client.c
+2
-4
migrate_scripts/muapiparser.py
migrate_scripts/muapiparser.py
+0
-1
migrate_scripts/muapitocstubs.py
migrate_scripts/muapitocstubs.py
+8
-6
src/main/scala/uvm/refimpl/nat/cStubs.scala
src/main/scala/uvm/refimpl/nat/cStubs.scala
+461
-466
src/main/scala/uvm/refimpl/nat/cStucsHelperFunctions.scala
src/main/scala/uvm/refimpl/nat/cStucsHelperFunctions.scala
+16
-7
src/main/scala/uvm/refimpl/nat/nativeClientSupport.scala
src/main/scala/uvm/refimpl/nat/nativeClientSupport.scala
+21
-759
tests/c-snippets/ncs_tests.c
tests/c-snippets/ncs_tests.c
+7
-14
No files found.
build.sbt
View file @
5c17e4da
...
...
@@ -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"
,
...
...
cbinding/muapi.h
View file @
5c17e4da
...
...
@@ -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_ty
s
void
(
*
set_newstack_pass_values
)(
MuCtx
*
ctx
,
MuInstNode
inst
,
MuTypeNode
*
tys
,
MuVarNode
*
vars
,
int
nvars
);
/// MUAPIPARSER tys:array:nvars;
vars:array:nvar
s
void
(
*
set_newstack_throw_exc
)(
MuCtx
*
ctx
,
MuInstNode
inst
,
MuVarNode
exc
);
MuInstNode
(
*
new_comminst
)(
MuCtx
*
ctx
,
MuBBNode
bb
,
MuCommInst
opcode
,
...
...
cbinding/test_client.c
View file @
5c17e4da
...
...
@@ -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
);
...
...
migrate_scripts/muapiparser.py
View file @
5c17e4da
...
...
@@ -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
)
...
...
migrate_scripts/muapitocstubs.py
View file @
5c17e4da
...
...
@@ -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
))
...
...
src/main/scala/uvm/refimpl/nat/cStubs.scala
View file @
5c17e4da
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/main/scala/uvm/refimpl/nat/cStucsHelperFunctions.scala
View file @
5c17e4da
...
...
@@ -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
=
ClientAccessibleClassExpos
er
.
muErrorPtr
.
address
()
def
getMuErrorPtr
()
:
MuCPtr
=
MuErrorNumb
er
.
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
src/main/scala/uvm/refimpl/nat/nativeClientSupport.scala
View file @
5c17e4da
This diff is collapsed.
Click to expand it.
tests/c-snippets/ncs_tests.c
View file @
5c17e4da
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment