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

FactorialFromRPython.scala 1.29 KB
Newer Older
1
2
3
4
5
6
7
8
package junks

import uvm.refimpl._

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

  val ca = microVM.newClientAgent()
9
10

  val r = new java.io.FileReader("tests/extra-progs/factorial.uir")
11
  ca.loadBundle(r)
12
  r.close()
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

  // Magical trick. Theoretically the client would publish bundles as binary and knows all the IDs. But in this version
  // only the text form is supported and IDs are automatically generated. So we look into the globalBundle itself.
  val m = ca.putFunction(microVM.globalBundle.funcNs("@main").id)

  microVM.trapManager.trapHandler = new TrapHandler {
    override def handleTrap(ca: ClientAgent, thread: Handle, stack: Handle, watchPointID: Int): TrapHandlerResult = {
      val curInst = ca.currentInstruction(stack, 0)
      val trapName = microVM.globalBundle.varNs(curInst).name.get

      if (trapName == "@main_v1.main_trap") {
        val kas = ca.dumpKeepalives(stack, 0)
        val Seq(rv) = kas

        val i = ca.toInt(rv, signExt = true)

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

      TrapRebindPassVoid(stack) // continue
    }
  }

  val sta = ca.newStack(m, Seq())
  val thr = ca.newThread(sta)

  microVM.threadStackManager.joinAll() // run until all threads stop

  ca.close()
}