-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathProgram.fs
40 lines (34 loc) · 1.04 KB
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
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
namespace Examples.DotNetBinding
open System
open ES.SacaraVm
open ES.Sacara.Ir.Assembler
module Program =
(*
This example use the SacaraVm .NET binding and the Sacara assembler in order to execute the code
*)
let generateBytecode() =
let assembler = new SacaraAssembler()
let irInstruction =
[
proc "main"
push 12
push 44
add
pop "result" // save the result in a local var to access it
halt
endp
]
|> List.map(fun f -> Action<Ctx>(f))
|> List.toArray
|> assembler.Assemble
irInstruction.GetBuffer()
let runCode(code: Byte array) =
use vm = new SacaraVm()
vm.Run(code)
vm.LocalVarGet(0)
[<EntryPoint>]
let main argv =
let code = generateBytecode()
let result = runCode(code)
Console.WriteLine(String.Format("Code execution result: {0}", result))
0