To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 5d383563 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Fixed the factorial result from RPython.

parent d1171fa4
......@@ -3,6 +3,7 @@ if [ x$SED == x ]; then
SED=sed
fi
$SED -i 's/newClientAgent/newContext/g' $FN
$SED -i 's/ClientAgent/MuCtx/g' $FN
$SED -i 's/deleteHandle/deleteValue/g' $FN
$SED -i 's/\bca\b/ctx/g' $FN
$SED -i 's/ctx\.close()/ctx.closeContext()/g' $FN
......
......@@ -8,7 +8,7 @@ $SED -i 's/COMMINST\s*@uvm\.new_thread\s*(\([@%]\w\+\))/NEWTHREAD \1 PASS_VALUES
$SED -i 's/TRAP\s*<@void>/TRAP <>/g' $FN
$SED -i 's/noparamsnoret/v_v/g' $FN
$SED -i 's/@funcdumb/@frv_v/g' $FN
$SED -i '/\.funcsig/ {s/@void\s*(\([^)]*\))/(\1) -> ()}/g' $FN
$SED -i '/\.funcsig/ {s/@void\s*(\([^)]*\))/(\1) -> ()/g}' $FN
$SED -i '/\.funcsig/ {s/=\s*\(@\w\+\)\s*(\([^)]*\))/= (\2) -> (\1)/}' $FN
$SED -i 's/@i_ii/@ii_i/g' $FN
$SED -i 's/RET @VOID/RET ()/g' $FN
......
package junks
import uvm.refimpl._
import uvm.refimpl.TrapHandlerResult.Rebind
import uvm.refimpl.HowToResume.PassValues
object FactorialFromRPython extends App {
val microVM = new MicroVM()
val ca = microVM.newClientAgent()
val ctx = microVM.newContext()
val r = new java.io.FileReader("tests/extra-progs/factorial.uir")
ca.loadBundle(r)
ctx.loadBundle(r)
r.close()
val m = ca.putFunction(microVM.idOf("@main"))
val m = ctx.handleFromFunc(microVM.idOf("@main"))
microVM.trapManager.trapHandler = new TrapHandler {
override def handleTrap(ca: ClientAgent, thread: Handle, stack: Handle, watchPointID: Int): TrapHandlerResult = {
val curInst = ca.currentInstruction(stack, 0)
microVM.setTrapHandler(new TrapHandler {
override def handleTrap(ctx: MuCtx, thread: MuThreadRefValue, stack: MuStackRefValue, watchPointID: Int): TrapHandlerResult = {
val curInst = ctx.curInst(stack, 0)
val trapName = microVM.nameOf(curInst)
if (trapName == "@main_v1.main_trap") {
val kas = ca.dumpKeepalives(stack, 0)
if (trapName == "@main_v1.entry.main_trap") {
val kas = ctx.dumpKeepalives(stack, 0)
val Seq(rv) = kas
val i = ca.toInt(rv, signExt = true)
val i = ctx.handleToSInt(rv.asInstanceOf[MuIntValue])
println(i)
} else {
throw new RuntimeException("Hit the wrong trap: " + trapName)
}
TrapRebindPassVoid(stack) // continue
Rebind(stack, PassValues(Seq())) // continue
}
}
})
val sta = ca.newStack(m, Seq())
val thr = ca.newThread(sta)
val sta = ctx.newStack(m)
val thr = ctx.newThread(sta, PassValues(Seq()))
microVM.execute() // run until all threads stop
ca.close()
ctx.closeContext()
}
\ No newline at end of file
......@@ -6,34 +6,30 @@
.typedef @int_8 = int<8>
.typedef @int_32 = int<32>
.const @int_64_1 <@int_64> = 1
.funcsig @fac_sig = @int_64 (@int_64)
.funcdef @fac VERSION @fac_v1 <@fac_sig> (%n_3)
.funcsig @fac_sig = (@int_64) -> (@int_64)
.funcdef @fac VERSION @fac_v1 <@fac_sig>
{
%blk_0:
%blk_0(<@int_64> %n_3):
%v48 = EQ <@int_64> %n_3 @int_64_1
BRANCH2 %v48 %blk_2 %blk_1
BRANCH2 %v48 %blk_2(@int_64_1) %blk_1(%n_3)
%blk_2:
%v53 = PHI <@int_64> {
%blk_1: %v52;
%blk_0: @int_64_1;
}
RET <@int_64> %v53
%blk_2(<@int_64> %v53):
RET %v53
%blk_1:
%blk_1(<@int_64> %n_3):
%v50 = SUB <@int_64> %n_3 @int_64_1
%v51 = CALL <@fac_sig> @fac (%v50)
%v52 = MUL <@int_64> %n_3 %v51
BRANCH %blk_2
BRANCH %blk_2(%v52)
}
.const @int_64_10 <@int_32> = 10
.funcsig @main_sig = @void ()
.funcdef @main VERSION @main_v1 <@main_sig> () {
%entry:
.funcsig @main_sig = () -> ()
.funcdef @main VERSION @main_v1 <@main_sig> {
%entry():
%rv = CALL <@fac_sig> @fac (@int_64_10)
%main_trap = TRAP <@void> KEEPALIVE (%rv)
[%main_trap] TRAP <> KEEPALIVE (%rv)
COMMINST @uvm.thread_exit
}
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