Merge branch 'master' into ravi-distro

ravi-distro
Dibyendu Majumdar 4 years ago
commit e9774b3e96

@ -33,8 +33,10 @@ Features
* Optional static typing - for details `see the reference manual <https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-reference.html>`_.
* Type specific bytecodes to improve performance
* Compatibility with Lua 5.3 (see Compatibility section below)
* New! JIT backend `MIR <https://github.com/vnmakarov/mir>`_; only Linux and x86-64 supported for now.
* `LLVM <http://www.llvm.org/>`_ powered JIT compiler
* Generational GC from Lua 5.4
* ``defer`` statement added
* Compact JIT backend `MIR <https://github.com/vnmakarov/mir>`_; only Linux and x86-64 supported for now.
* `LLVM <http://www.llvm.org/>`_ supported as alternative JIT backend.
* A `distribution with batteries <https://github.com/dibyendumajumdar/Suravi>`_.
Documentation
@ -55,14 +57,15 @@ Lua 5.4 Position Statement
==========================
Lua 5.4 relationship to Ravi is as follows:
* Generational GC - This has been back-ported to Ravi.
* Generational GC - back-ported to Ravi.
* New random number generator - back-ported to Ravi.
* Multiple user values can be associated with userdata - under consideration.
* ``<const>`` variables - no plan to include this.
* ``<const>`` variables - not planned.
* ``<close>`` variables - Ravi has ``'defer'`` statement which is better option in my opinion, hence no plans to support ``<close>`` variables.
* Interpreter performance improvements - these are beneficial to Lua interpreter but not to the JIT backends, hence not much point in back-porting.
* Table implementation changes - under consideration.
* String to number coertion is now part of string library metamethods - back-ported to Ravi.
* String to number coercion is now part of string library metamethods - back-ported to Ravi.
* utf8 library accepts codepoints up to 2^31 - back-ported to Ravi.
* Removal of compatibility layers for 5.1, and 5.2 - not implemented as Ravi continues to provide these layers as per Lua 5.3.
Compatibility with Lua 5.3
@ -74,6 +77,7 @@ Ravi should be able to run all Lua 5.3 programs in interpreted mode, but followi
* Upvalues cannot subvert the static typing of local variables (issue #26) when types are annotated.
* Certain Lua limits are reduced due to changed byte code structure. These are described below.
* Ravi uses an extended bytecode which means it is not compatible with Lua 5.3 bytecode.
* Ravi incorporates the new Generational GC from Lua 5.4, hence the GC interface has changed.
+-----------------+-------------+-------------+
| Limit name | Lua value | Ravi value |

@ -294,10 +294,6 @@ LUALIB_API void (luaL_setmetatable)(lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata)(lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata)(lua_State *L, int ud, const char *tname);
LUALIB_API int (raviL_build_ast_from_buffer) (lua_State *L, const char *buff, size_t size,
const char *name, const char *mode);
LUALIB_API int (raviL_dumpast) (lua_State *L);
LUALIB_API void *ravi_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize);
#endif

@ -102,7 +102,7 @@ typedef LUAI_UACINT l_uacInt;
#if defined(lua_assert)
/** RAVI changes */
#if !defined(RAVI_OPTION_STRING1)
#define RAVI_OPTION_STRING1 " assertions"
#define RAVI_OPTION_STRING1 "assertions "
#endif
#if !defined(RAVI_OPTION_STRING2)
#define RAVI_OPTION_STRING2
@ -114,7 +114,7 @@ typedef LUAI_UACINT l_uacInt;
#define lua_assert(c) ((void)0)
#define check_exp(c,e) (e)
#define lua_longassert(c) ((void)0)
/** RVAI changes */
/** RAVI changes */
#define RAVI_OPTION_STRING1
#define RAVI_OPTION_STRING2
#endif

@ -140,10 +140,10 @@ typedef void(*ravi_Writestringerror)(const char *fmt, const char *p);
#define lua_assert(c) assert(c)
#if !defined(RAVI_OPTION_STRING1)
#define RAVI_OPTION_STRING1 " assertions"
#define RAVI_OPTION_STRING1 "assertions "
#endif
#define RAVI_OPTION_STRING2 " ltests"
#define RAVI_OPTION_STRING2 "ltests "
/* to avoid warnings, and to make sure value is really unused */
#define UNUSED(x) (x=0, (void)(x))

@ -93,6 +93,12 @@ void raviV_dumpIR(struct lua_State *L, struct Proto *p);
/* Dump the compiled assembly code if available */
void raviV_dumpASM(struct lua_State *L, struct Proto *p);
/* Return JIT backend identifier */
const char *raviV_jit_id(struct lua_State *L);
/* Options */
const char *raviV_options(struct lua_State *L);
#ifdef __cplusplus
}
#endif

@ -33,8 +33,10 @@ Features
* Optional static typing - for details `see the reference manual <https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-reference.html>`_.
* Type specific bytecodes to improve performance
* Compatibility with Lua 5.3 (see Compatibility section below)
* New! JIT backend `MIR <https://github.com/vnmakarov/mir>`_; only Linux and x86-64 supported for now.
* `LLVM <http://www.llvm.org/>`_ powered JIT compiler
* Generational GC from Lua 5.4
* ``defer`` statement for releasing resources
* Compact JIT backend `MIR <https://github.com/vnmakarov/mir>`_; only Linux and x86-64 supported for now.
* `LLVM <http://www.llvm.org/>`_ supported as alternative JIT backend.
* A `distribution with batteries <https://github.com/dibyendumajumdar/Suravi>`_.
Documentation
@ -55,14 +57,15 @@ Lua 5.4 Position Statement
==========================
Lua 5.4 relationship to Ravi is as follows:
* Generational GC - This has been back-ported to Ravi.
* Generational GC - back-ported to Ravi.
* New random number generator - back-ported to Ravi.
* Multiple user values can be associated with userdata - under consideration.
* ``<const>`` variables - no plan to include this.
* ``<const>`` variables - not planned.
* ``<close>`` variables - Ravi has ``'defer'`` statement which is better option in my opinion, hence no plans to support ``<close>`` variables.
* Interpreter performance improvements - these are beneficial to Lua interpreter but not to the JIT backends, hence not much point in back-porting.
* Table implementation changes - under consideration.
* String to number coertion is now part of string library metamethods - back-ported to Ravi.
* String to number coercion is now part of string library metamethods - back-ported to Ravi.
* utf8 library accepts codepoints up to 2^31 - back-ported to Ravi.
* Removal of compatibility layers for 5.1, and 5.2 - not implemented as Ravi continues to provide these layers as per Lua 5.3.
Compatibility with Lua 5.3
@ -74,6 +77,7 @@ Ravi should be able to run all Lua 5.3 programs in interpreted mode, but followi
* Upvalues cannot subvert the static typing of local variables (issue #26) when types are annotated.
* Certain Lua limits are reduced due to changed byte code structure. These are described below.
* Ravi uses an extended bytecode which means it is not compatible with Lua 5.3 bytecode.
* Ravi incorporates the new Generational GC from Lua 5.4, hence the GC interface has changed.
+-----------------+-------------+-------------+
| Limit name | Lua value | Ravi value |

@ -5,6 +5,18 @@ Ravi Extensions to Lua 5.3
:depth: 2
:backlinks: top
------------
Introduction
------------
Ravi is based on Lua 5.3. Additionally some features of Lua 5.4 have been back-ported to Ravi.
This document describes the enhancements available in Ravi compared to the Lua 5.3 baseline.
* Optional static typing
* ``defer`` statement
* Generational Garbage Collector
* New random number generator
----------------------
Optional Static Typing
----------------------
@ -277,8 +289,9 @@ Another example using arrays. Here the function receives a parameter ``arr`` of
The ``table.numarray(n, initial_value)`` creates a ``number[]`` of specified size and initializes the array with the given initial value.
``defer`` statement
-------------------
-----------------------
The ``defer`` statement
-----------------------
A new addition to Ravi is the ``defer`` statement. The statement has the form::
@ -327,6 +340,10 @@ A JIT api is available with following functions:
``ravi.jit([b])``
returns enabled setting of JIT compiler; also enables/disables the JIT compiler; defaults to true
``ravi.jitname()``
returns an identifier for the JIT
``ravi.options()``
returns a string with compiled options
``ravi.auto([b [, min_size [, min_executions]]])``
returns setting of auto compilation and compilation thresholds; also sets the new settings if values are supplied; defaults are false, 150, 50.
``ravi.compile(func_or_table[, options])``
@ -350,7 +367,29 @@ A JIT api is available with following functions:
Enables support for line hooks via the debug api. Note that enabling this option will result in inefficient JIT as a call to a C function will be inserted at beginning of every Lua bytecode boundary; use this option only when you want to use the debug api to step through code line by line. Currently only supported by LLVM backend.
``ravi.verbosity([b])``
Controls the amount of verbose messages generated during compilation.
-------------------------------
Generational Garbage Collection
-------------------------------
Ravi incorporates the generational garbage collector from Lua 5.4.
Please refer to the Lua 5.4 manual regarding the api changes to support generational collection.
Note that by default, Ravi now enables generational garbage collector.
To switch to incremental GC::
collectgarbage("incremental")
To switch to generational GC::
collectgarbage("generational")
-----------------------
Random Number Generator
-----------------------
Ravi incorporates the new random number generator from Lua 5.4.
Please refer to the Lua 5.4 manual for api changes in this area.
----------------
C API Extensions
----------------

@ -1081,9 +1081,3 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {
luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
(LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);
}
LUALIB_API int (raviL_dumpast) (lua_State *L) {
(void) L;
return 0;
}

@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ravi_jit.h>
#include "lua.h"
@ -44,20 +45,6 @@
#define LUA_INITVARVERSION LUA_INIT_VAR LUA_VERSUFFIX
#ifdef USE_LLVM
#define ravi_xstringify(s) ravi_stringify(s)
#define ravi_stringify(s) #s
#define RAVI_OPTION_STRING3 " LLVM-" LLVM_VERSION_STRING " ORC=" ravi_xstringify(USE_ORC_JIT) " v2=" ravi_xstringify(USE_ORCv2_JIT)
#elif USE_OMRJIT
#define RAVI_OPTION_STRING3 " omrjit"
#elif USE_MIRJIT
#define RAVI_OPTION_STRING3 " mirjit"
#else
#define RAVI_OPTION_STRING3 " nojit"
#endif
#define RAVI_OPTIONS "\nOptions" RAVI_OPTION_STRING1 RAVI_OPTION_STRING2 RAVI_OPTION_STRING3
/*
** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
** is, whether we're running lua interactively).
@ -228,7 +215,12 @@ static int docall (lua_State *L, int narg, int nres) {
static void print_version (lua_State *L) {
lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
lua_writestring(RAVI_OPTIONS, strlen(RAVI_OPTIONS));
const char *options = raviV_options(L);
lua_writeline();
#define OPTSTR "Options "
lua_writestring(OPTSTR, strlen(OPTSTR));
#undef OPTSTR
lua_writestring(options, strlen(options));
lua_writeline();
}

@ -1809,8 +1809,10 @@ int luaV_execute (lua_State *L) {
vmcase(OP_RETURN) {
int b = GETARG_B(i);
#ifdef RAVI_DEFER_STATEMENT
if (cl->p->sizep > 0)
if (cl->p->sizep > 0) {
Protect_base(luaF_close(L, base, LUA_OK));
ra = RA(i);
}
#else
if (cl->p->sizep > 0) luaF_close(L, base);
#endif

@ -238,6 +238,18 @@ static int ravi_listcode(lua_State *L) {
return ravi_list_code(L);
}
static int ravi_get_jit_id(lua_State *L) {
const char *id = raviV_jit_id(L);
lua_pushstring(L, id);
return 1;
}
static int ravi_get_options(lua_State *L) {
const char *options = raviV_options(L);
lua_pushstring(L, options);
return 1;
}
static const luaL_Reg ravilib[] = {{"iscompiled", ravi_is_compiled},
{"compile", ravi_compile_n},
{"dumplua", ravi_dump_luacode},
@ -254,6 +266,8 @@ static const luaL_Reg ravilib[] = {{"iscompiled", ravi_is_compiled},
{"tracehook", ravi_traceenable},
{"listcode", ravi_listcode},
{"limits", ravi_get_limits},
{"jitname", ravi_get_jit_id},
{"options", ravi_get_options},
{NULL, NULL}};
#include <math.h>

@ -1062,7 +1062,6 @@ static void emit_op_loadk(struct function *fn, int A, int Bx, int pc) {
static void emit_op_return(struct function *fn, int A, int B, int pc) {
(void)pc;
emit_reg(fn, "ra", A);
#ifdef RAVI_DEFER_STATEMENT
membuff_add_string(&fn->body, "if (cl->p->sizep > 0) {\n luaF_close(L, base, LUA_OK);\n");
membuff_add_string(&fn->body, " base = ci->u.l.base;\n");
@ -1070,6 +1069,7 @@ static void emit_op_return(struct function *fn, int A, int B, int pc) {
#else
membuff_add_string(&fn->body, "if (cl->p->sizep > 0) luaF_close(L, base);\n");
#endif
emit_reg(fn, "ra", A);
membuff_add_fstring(&fn->body, "result = (%d != 0 ? %d - 1 : cast_int(L->top - ra));\n", B, B);
membuff_add_string(&fn->body, "return luaD_poscall(L, ci, ra, result);\n");
}

@ -1080,3 +1080,17 @@ int raviV_gettraceenabled(lua_State *L) {
}
extern "C" int ravi_compile_C(lua_State *L) { return 0; }
const char *raviV_jit_id(struct lua_State *L) {
return "llvm";
}
#define ravi_xstringify(s) ravi_stringify(s)
#define ravi_stringify(s) #s
#define RAVI_OPTION_STRING3 "LLVM-" LLVM_VERSION_STRING " ORC=" ravi_xstringify(USE_ORC_JIT) " v2=" ravi_xstringify(USE_ORCv2_JIT)
#define RAVI_OPTIONS RAVI_OPTION_STRING1 RAVI_OPTION_STRING2 RAVI_OPTION_STRING3
const char *raviV_options(struct lua_State *L) {
return RAVI_OPTIONS;
}

@ -494,4 +494,15 @@ void raviV_freeproto(struct lua_State *L, struct Proto *p) {
int ravi_compile_C(lua_State *L) {
(void)L;
return 0;
}
}
const char *raviV_jit_id(struct lua_State *L) {
return "mir";
}
#define RAVI_OPTION_STRING3 "mirjit"
#define RAVI_OPTIONS RAVI_OPTION_STRING1 RAVI_OPTION_STRING2 RAVI_OPTION_STRING3
const char *raviV_options(struct lua_State *L) {
return RAVI_OPTIONS;
}

@ -166,4 +166,16 @@ int raviV_gettraceenabled(struct lua_State *L) {
int ravi_compile_C(lua_State *L) {
(void)L;
return 0;
}
}
const char *raviV_jit_id(struct lua_State *L) {
return "nojit";
}
#define RAVI_OPTION_STRING3 "nojit"
#define RAVI_OPTIONS RAVI_OPTION_STRING1 RAVI_OPTION_STRING2 RAVI_OPTION_STRING3
const char *raviV_options(struct lua_State *L) {
return RAVI_OPTIONS;
}

@ -1891,6 +1891,24 @@ compile(x)
x()
print 'Test 83 OK'
--- Test stack reallocation in defer statement
function x(a) if a <= 0 then return else x(a-1) end end
y = ravi.jit and 100 or 1000
function z(...)
-- recursive call to make stack
defer x(y) end
return ...
end
do
local a,b,c = z(1,2,3)
assert(a == 1 and b == 2 and c == 3)
compile(x)
compile(z)
a,b,c = z(3,2,1)
assert(a == 3 and b == 2 and c == 1)
end
print 'Test 84 OK'
for k,v in pairs(opcodes_coverage)
do
print(k, v)

Loading…
Cancel
Save