WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

FactorialFromRPython.scala 1.14 KB
Newer Older
1
2
3
package junks

import uvm.refimpl._
4
5
import uvm.refimpl.TrapHandlerResult.Rebind
import uvm.refimpl.HowToResume.PassValues
6
7
8
9

object FactorialFromRPython extends App {
  val microVM = new MicroVM()

10
  val ctx = microVM.newContext()
11
12

  val r = new java.io.FileReader("tests/extra-progs/factorial.uir")
13
  ctx.loadBundle(r)
14
  r.close()
15

16
  val m = ctx.handleFromFunc(microVM.idOf("@main"))
17

18
19
20
  microVM.setTrapHandler(new TrapHandler {
    override def handleTrap(ctx: MuCtx, thread: MuThreadRefValue, stack: MuStackRefValue, watchPointID: Int): TrapHandlerResult = {
      val curInst = ctx.curInst(stack, 0)
21
      val trapName = microVM.nameOf(curInst)
22

23
24
      if (trapName == "@main_v1.entry.main_trap") {
        val kas = ctx.dumpKeepalives(stack, 0)
25
26
        val Seq(rv) = kas

27
        val i = ctx.handleToSInt(rv.asInstanceOf[MuIntValue])
28
29
30
31
32
33

        println(i)
      } else {
        throw new RuntimeException("Hit the wrong trap: " + trapName)
      }

34
      Rebind(stack, PassValues(Seq())) // continue
35
    }
36
  })
37

38
39
  val sta = ctx.newStack(m)
  val thr = ctx.newThread(sta, PassValues(Seq()))
40

Kunshan Wang's avatar
Kunshan Wang committed
41
  microVM.execute() // run until all threads stop
42

43
  ctx.closeContext()
44
}