Skip to content

Commit

Permalink
refs #352: added an example of jit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kray-G committed Dec 24, 2021
1 parent e4e8c1d commit 4de3cbd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/jitclib.kx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Jit;

function jit1() {
var c = new Jit.Compiler();
c.enter();
var cx = c.makeConst(Jit.VAR(0));
c.mov(Jit.R0, Jit.VAR(0));
c.icall(Jit.IMM(Jit.Clib.print));
c.ret(Jit.R0);

var code = c.generate();
cx.setValue("Help me!\n");
code.dump();

var r = code.run();
System.println(" ... ret:%x" % r);
}

function jit2() {
var printf = Jit.Clib.load("printf");
var c = new Jit.Compiler();
c.enter();
c.mov(Jit.R1, Jit.IMM(100));
c.mov(Jit.R0, "Don't help me! %d\n");
c.icall(Jit.IMM(printf));
c.ret(Jit.R0);

var code = c.generate();
code.dump();

var r = code.run();
System.println(" ... ret:%x" % r);
}

jit1();
jit2();

0 comments on commit 4de3cbd

Please sign in to comment.