0
42
3.14
+.314e+1
.314e1
-31.4e-1
0x7E
-0X7e
0x0.1E
0xA23p-4
"text"
"tab\t"
"quote\""
"\x3A" ; hexadecimal 8-bits character
"\u20AC" ; unicode char UTF-8 encoded (4 hexadecimals)
"\U000020AC"; unicode char UTF-8 encoded (8 hexadecimals)
"
multiline
string
"
(1 4 9 16)
(-100: "min" 100: "max")
(0: "zero" "one")
("zero": 0 "one": 1)
Foo
Foo-Bar
Foo\:Bar
Foo\(Bar\)
Foo\ Bar
!Foo$Bar?
assignment (could be used as expression, not like in Lua)
addition
logical and
break statement
function call
function call; if function returns multiple results, only first is retained
in expression with operator (for example (!neg (!call f))
),
!call
is automatically replaced by !call1
tail call optimization is disabled with (!return (!call1 ...))
method call
method call; if method returns multiple results, only first is retained
concatenation
cond statement
define local variables
division
block (could be used as expression, not like in Lua)
relational equal
for statement
relational great or equal
goto statement
relational great than
if statement
relational less or equal
length
define local variables which could not be re-assigned
define a local variable which could used in recursive call
annotation
loop statement
relational less then
multiple assignment
concatenation
modulo
multiplication
relational not equal
negation
logical not
logical or
exponentiation
repeat statement
return statement
subtraction
while statement
In addition to the Lua standard libraries.
like table.concat
but using tostring
to convert each element.
like dofile
but for TP chunk.
returns a escaped string ((
, )
, :
, and space) suitable to be safely read back by the TP interpreter.
like load
(5.2) but for TP chunk
(includes 5.1 loadstring
).
like loadfile
(5.2) but for TP chunk.
constructor of op
representation.
parses a TP chunk from a string and returns a op
tree.
parses a TP chunk from a file and returns a op
tree.
returns a quoted string (not printable character are escaped) suitable to be safely read back by the TP interpreter.
like unpack
but accept nil
as parameter,
so tvm.unpack(t)
is equivalent to unpack(t or {})
.
like string.char
but returns a string which is the concatenation of the UTF-8 representation of each integer.
backported from Lua 5.3.0.
In addition to the C/Lua API and the Auxiliary Library.
like lua_load
but for TP chunk.
like luaL_loadbuffer
but for TP chunk.
int (tvm_loadbufferx) (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode);
like luaL_loadbufferx
(5.2) but for TP chunk
like luaL_loadfile
but for TP chunk.
like luaL_loadfilex
(5.2) but for TP chunk
like luaL_loadstring
but for TP chunk.
Here, an example with the code generation library :
$ cat ost.t
(!let concat (!index tvm "concat"))
(!let op (!index (!index tvm "op") "new"))
(!let quote (!index tvm "quote"))
(!let insert (!index table "insert"))
(!let o (
(!call1 op ("!line" 1))
(!call1 op ("!call" "print" (!call1 quote "hello")))
(!call1 op ("!line" 2))
(!call1 op ("!let" "h" (!call1 op ((!call1 quote "no"): 0 (!call1 quote "yes"): 1))))
(!call1 op ("!line" 3))
(!call1 op ("!let" "a" (!call1 op (0: (!call1 quote "zero") (!call1 quote "one") (!call1 quote "two")))))
(!callmeth1 (!call1 op ("!line"))
push 4)
(!call1 op ("!let" "h" (!callmeth1 (!call1 op ())
addkv (!call1 quote "key") (!call1 quote "value"))))
))
(!call insert o (!call1 op ("!line" 5)))
(!call insert o (!call1 op ("!call" "print" (!call1 op ("!index" "h" (!call1 quote "key"))))))
(!call print (!call1 concat o))
$ ./tvmjit ost.t
(!line 1)(!call print "hello")
(!line 2)(!let h ("no": 0 "yes": 1))
(!line 3)(!let a (0: "zero" "one" "two"))
(!line 4)(!let h ("key": "value"))
(!line 5)(!call print (!index h "key"))
$ ./tvmjit ost.t | ./tvmjit
hello
value