issue #128 refactor membuff_t to move it from the debugger to a shared location so that we can reuse it in the JIT implementation, some more initial work on the new backend

gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent b2ddc8038e
commit 1443fe9099

@ -165,7 +165,7 @@ endif()
set(LUA_CORE_SRCS src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src/ldump.c
src/lfunc.c src/lgc.c src/llex.c src/lmem.c src/lobject.c src/lopcodes.c
src/lparser.c src/lstate.c src/lstring.c src/ltable.c src/ltm.c src/lundump.c
src/lvm.c src/lzio.c src/ravijit.cpp src/ltests.c src/ravi_profile.c)
src/lvm.c src/lzio.c src/ravijit.cpp src/ltests.c src/ravi_profile.c src/ravi_membuf.c)
# define the lua lib source files
set(LUA_LIB_SRCS src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/ldblib.c src/liolib.c
src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/loadlib.c src/linit.c src/lutf8lib.c)

@ -1,4 +1,4 @@
mkdir nojit64a
cd nojit64a
cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 14 Win64" ..
cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 15 Win64" ..
cd ..

@ -1,4 +1,4 @@
mkdir nojit64
cd nojit64
cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -DCMAKE_BUILD_TYPE=Release -DSTATIC_BUILD=ON -G "Visual Studio 14 Win64" ..
cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -DCMAKE_BUILD_TYPE=Release -DSTATIC_BUILD=ON -G "Visual Studio 15 Win64" ..
cd ..

@ -0,0 +1,27 @@
#ifndef RAVI_MEMBUF_H
#define RAVI_MEMBUF_H
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
typedef struct {
char *buf;
size_t allocated_size;
size_t pos;
} membuff_t;
extern void membuff_init(membuff_t *mb, size_t initial_size);
extern void membuff_rewindpos(membuff_t *mb);
extern void membuff_resize(membuff_t *mb, size_t new_size);
extern void membuff_free(membuff_t *mb);
extern void membuff_add_string(membuff_t *mb, const char *str);
extern void membuff_add_bool(membuff_t *mb, bool value);
extern void membuff_add_int(membuff_t *mb, int value);
extern void membuff_add_longlong(membuff_t *mb, int64_t value);
/* strncpy() with guaranteed 0 termination */
extern void ravi_string_copy(char *buf, const char *src, size_t buflen);
#endif

@ -0,0 +1,65 @@
#include <ravi_membuf.h>
#include <assert.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void ravi_string_copy(char *buf, const char *src, size_t buflen) {
if (buflen == 0) return;
strncpy(buf, src, buflen);
buf[buflen - 1] = 0;
}
void membuff_init(membuff_t *mb, size_t initial_size) {
if (initial_size > 0) {
mb->buf = (char *)calloc(1, initial_size);
if (mb->buf == NULL) {
fprintf(stderr, "out of memory\n");
exit(1);
}
}
else
mb->buf = NULL;
mb->pos = 0;
mb->allocated_size = initial_size;
}
void membuff_rewindpos(membuff_t *mb) { mb->pos = 0; }
void membuff_resize(membuff_t *mb, size_t new_size) {
if (new_size <= mb->allocated_size) return;
char *newmem = (char *)realloc(mb->buf, new_size);
if (newmem == NULL) {
fprintf(stderr, "out of memory\n");
exit(1);
}
mb->buf = newmem;
mb->allocated_size = new_size;
}
void membuff_free(membuff_t *mb) { free(mb->buf); }
void membuff_add_string(membuff_t *mb, const char *str) {
size_t len = strlen(str);
size_t required_size = mb->pos + len + 1; /* extra byte for NULL terminator */
membuff_resize(mb, required_size);
assert(mb->allocated_size - mb->pos > len);
ravi_string_copy(&mb->buf[mb->pos], str, mb->allocated_size - mb->pos);
mb->pos += len;
}
void membuff_add_bool(membuff_t *mb, bool value) {
if (value)
membuff_add_string(mb, "true");
else
membuff_add_string(mb, "false");
}
void membuff_add_int(membuff_t *mb, int value) {
char temp[100];
snprintf(temp, sizeof temp, "%d", value);
membuff_add_string(mb, temp);
}
void membuff_add_longlong(membuff_t *mb, int64_t value) {
char temp[100];
snprintf(temp, sizeof temp, "%" PRId64 "", value);
membuff_add_string(mb, temp);
}

@ -21,7 +21,8 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#include "ravi_nanojit.h"
#include <ravi_nanojit.h>
#include <ravi_membuf.h>
#include <ravijit.h>
#include <stddef.h>
@ -725,6 +726,191 @@ static const char Lua_header[] = ""
static int showparsetree(const char *buffer);
// We can only compile a subset of op codes
// and not all features are supported
static bool can_compile(Proto *p) {
if (p->ravi_jit.jit_status == 1)
return false;
const Instruction *code = p->code;
int pc, n = p->sizecode;
// Loop over the byte codes; as Lua compiler inserts
// an extra RETURN op we need to ignore the last op
for (pc = 0; pc < n; pc++) {
Instruction i = code[pc];
OpCode o = GET_OPCODE(i);
switch (o) {
case OP_RETURN:
case OP_LOADK:
#if 0
case OP_LOADKX:
case OP_RAVI_FORLOOP_IP:
case OP_RAVI_FORLOOP_I1:
case OP_RAVI_FORPREP_IP:
case OP_RAVI_FORPREP_I1:
case OP_MOVE:
case OP_LOADNIL:
case OP_RAVI_LOADIZ:
case OP_RAVI_LOADFZ:
case OP_CALL:
case OP_TAILCALL:
case OP_JMP:
case OP_EQ:
case OP_RAVI_EQ_II:
case OP_RAVI_EQ_FF:
case OP_LT:
case OP_RAVI_LT_II:
case OP_RAVI_LT_FF:
case OP_LE:
case OP_RAVI_LE_II:
case OP_RAVI_LE_FF:
case OP_GETTABUP:
case OP_LOADBOOL:
case OP_NOT:
case OP_TEST:
case OP_TESTSET:
case OP_RAVI_MOVEI:
case OP_RAVI_MOVEF:
case OP_RAVI_TOINT:
case OP_RAVI_TOFLT:
case OP_VARARG:
case OP_CONCAT:
case OP_CLOSURE:
case OP_RAVI_ADDFF:
case OP_RAVI_ADDFI:
case OP_RAVI_ADDII:
case OP_RAVI_SUBFF:
case OP_RAVI_SUBFI:
case OP_RAVI_SUBIF:
case OP_RAVI_SUBII:
case OP_RAVI_MULFF:
case OP_RAVI_MULFI:
case OP_RAVI_MULII:
case OP_RAVI_DIVFF:
case OP_RAVI_DIVFI:
case OP_RAVI_DIVIF:
case OP_RAVI_DIVII:
case OP_SELF:
case OP_LEN:
case OP_SETTABLE:
case OP_GETTABLE:
case OP_NEWTABLE:
case OP_SETLIST:
case OP_TFORCALL:
case OP_TFORLOOP:
case OP_RAVI_NEWARRAYI:
case OP_RAVI_NEWARRAYF:
case OP_RAVI_GETTABLE_AI:
case OP_RAVI_GETTABLE_AF:
case OP_RAVI_TOARRAYI:
case OP_RAVI_TOARRAYF:
case OP_RAVI_MOVEAI:
case OP_RAVI_MOVEAF:
case OP_RAVI_SETTABLE_AI:
case OP_RAVI_SETTABLE_AII:
case OP_RAVI_SETTABLE_AF:
case OP_RAVI_SETTABLE_AFF:
case OP_SETTABUP:
case OP_ADD:
case OP_SUB:
case OP_MUL:
case OP_DIV:
case OP_GETUPVAL:
case OP_SETUPVAL:
break;
case OP_FORPREP:
case OP_FORLOOP:
case OP_MOD:
case OP_IDIV:
case OP_UNM:
case OP_POW:
#endif
default: {
p->ravi_jit.jit_status = 1;
return false;
}
}
}
return true;
}
struct function {
struct lua_State *L;
struct Proto *p;
// should be bitmap
// flags to mark instructions
unsigned char *jmps;
membuff_t prologue;
membuff_t body;
};
// Identify Ravi bytecode instructions that are jump
// targets - we need this so that when generating code
// we can emit labels for gotos
static void scan_jump_targets(struct function *fn)
{
const Instruction *code = fn->p->code;
int pc, n = fn->p->sizecode;
lua_assert(fn->jmps != NULL);
for (pc = 0; pc < n; pc++) {
Instruction i = code[pc];
OpCode op = GET_OPCODE(i);
switch (op) {
case OP_LOADBOOL: {
int C = GETARG_C(i);
int j = pc + 2; // jump target
fn->jmps[j] = 1;
} break;
case OP_JMP:
case OP_RAVI_FORPREP_IP:
case OP_RAVI_FORPREP_I1:
case OP_RAVI_FORLOOP_IP:
case OP_RAVI_FORLOOP_I1:
case OP_FORLOOP:
case OP_FORPREP:
case OP_TFORLOOP: {
int sbx = GETARG_sBx(i);
int j = sbx + pc + 1;
fn->jmps[j] = true;
} break;
default: break;
}
}
}
static void initfn(struct function *fn, struct lua_State *L, struct Proto *p)
{
fn->L = L;
fn->p = p;
fn->jmps = calloc(p->sizecode, sizeof fn->jmps[0]);
membuff_init(&fn->prologue, strlen(Lua_header) + 4096);
membuff_init(&fn->body, 4096);
}
static void cleanup(struct function *fn)
{
free(fn->jmps);
membuff_free(&fn->prologue);
membuff_free(&fn->body);
}
#define RA(i) (base + GETARG_A(i))
/* to be used after possible stack reallocation */
#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base + GETARG_B(i))
#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base + GETARG_C(i))
#define RKB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_B(i)) ? k + INDEXK(GETARG_B(i)) : base + GETARG_B(i))
#define RKC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_C(i)) ? k + INDEXK(GETARG_C(i)) : base + GETARG_C(i))
#define KBx(i) \
(k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
/* RAVI */
#define KB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_B(i)))
#define KC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_C(i)))
// Compile a Lua function
// If JIT is turned off then compilation is skipped
// Compilation occurs if either auto compilation is ON (subject to some
@ -733,7 +919,16 @@ static int showparsetree(const char *buffer);
// Returns true if compilation was successful
int raviV_compile(struct lua_State *L, struct Proto *p,
ravi_compile_options_t *options) {
if (!can_compile(p)) return false;
struct function fn;
initfn(&fn, L, p);
scan_jump_targets(&fn);
showparsetree(Lua_header);
cleanup(&fn);
return false;
}

@ -12,55 +12,6 @@
#include <stdlib.h>
#include <inttypes.h>
void membuff_init(membuff_t *mb, size_t initial_size) {
if (initial_size > 0) {
mb->buf = (char *)calloc(1, initial_size);
if (mb->buf == NULL) {
fprintf(stderr, "out of memory\n");
exit(1);
}
}
else
mb->buf = NULL;
mb->pos = 0;
mb->allocated_size = initial_size;
}
void membuff_rewindpos(membuff_t *mb) { mb->pos = 0; }
void membuff_resize(membuff_t *mb, size_t new_size) {
if (new_size <= mb->allocated_size) return;
char *newmem = (char *)realloc(mb->buf, new_size);
if (newmem == NULL) {
fprintf(stderr, "out of memory\n");
exit(1);
}
mb->buf = newmem;
mb->allocated_size = new_size;
}
void membuff_free(membuff_t *mb) { free(mb->buf); }
void membuff_add_string(membuff_t *mb, const char *str) {
size_t len = strlen(str);
size_t required_size = mb->pos + len + 1; /* extra byte for NULL terminator */
membuff_resize(mb, required_size);
assert(mb->allocated_size - mb->pos > len);
vscode_string_copy(&mb->buf[mb->pos], str, mb->allocated_size - mb->pos);
mb->pos += len;
}
void membuff_add_bool(membuff_t *mb, bool value) {
if (value)
membuff_add_string(mb, "true");
else
membuff_add_string(mb, "false");
}
void membuff_add_int(membuff_t *mb, int value) {
char temp[100];
snprintf(temp, sizeof temp, "%d", value);
membuff_add_string(mb, temp);
}
void membuff_add_longlong(membuff_t *mb, int64_t value) {
char temp[100];
snprintf(temp, sizeof temp, "%" PRId64 "", value);
membuff_add_string(mb, temp);
}
/* Parse a VSCode JSON message type
*/
@ -281,7 +232,7 @@ static int vscode_parse_initialize_request(json_value *js, ProtocolMessage *msg,
adapterID != NULL ? adapterID : "null");
return VSCODE_UNKNOWN_REQUEST;
}
vscode_string_copy(msg->u.Request.u.InitializeRequest.adapterID, adapterID,
ravi_string_copy(msg->u.Request.u.InitializeRequest.adapterID, adapterID,
sizeof msg->u.Request.u.InitializeRequest.adapterID);
const char *pathFormat = get_string_value(args, "pathFormat", log);
if (pathFormat != NULL && strcmp(pathFormat, "path") != 0) {
@ -290,7 +241,7 @@ static int vscode_parse_initialize_request(json_value *js, ProtocolMessage *msg,
return VSCODE_UNKNOWN_REQUEST;
}
if (pathFormat)
vscode_string_copy(msg->u.Request.u.InitializeRequest.pathFormat, pathFormat,
ravi_string_copy(msg->u.Request.u.InitializeRequest.pathFormat, pathFormat,
sizeof msg->u.Request.u.InitializeRequest.pathFormat);
int found = 0;
msg->u.Request.u.InitializeRequest.columnsStartAt1 =
@ -349,23 +300,23 @@ static int vscode_parse_launch_request(json_value *js, ProtocolMessage *msg,
get_boolean_value(args, "stopOnEntry", log, &found);
const char *prog = get_string_value(args, "program", log);
if (prog == NULL) return VSCODE_UNKNOWN_REQUEST;
vscode_string_copy(msg->u.Request.u.LaunchRequest.program, prog,
ravi_string_copy(msg->u.Request.u.LaunchRequest.program, prog,
sizeof msg->u.Request.u.LaunchRequest.program);
fix_path(msg->u.Request.u.LaunchRequest.program);
fprintf(log, "LAUNCH %s\n", prog);
const char *lua_path = get_string_value(args, "LUA_PATH", log);
if (lua_path != NULL)
vscode_string_copy(msg->u.Request.u.LaunchRequest.lua_path, lua_path,
ravi_string_copy(msg->u.Request.u.LaunchRequest.lua_path, lua_path,
sizeof msg->u.Request.u.LaunchRequest.lua_path);
fix_path(msg->u.Request.u.LaunchRequest.lua_path);
const char *lua_cpath = get_string_value(args, "LUA_CPATH", log);
if (lua_cpath != NULL)
vscode_string_copy(msg->u.Request.u.LaunchRequest.lua_cpath, lua_cpath,
ravi_string_copy(msg->u.Request.u.LaunchRequest.lua_cpath, lua_cpath,
sizeof msg->u.Request.u.LaunchRequest.lua_cpath);
fix_path(msg->u.Request.u.LaunchRequest.lua_cpath);
const char *cwd = get_string_value(args, "cwd", log);
if (cwd != NULL)
vscode_string_copy(msg->u.Request.u.LaunchRequest.cwd, cwd,
ravi_string_copy(msg->u.Request.u.LaunchRequest.cwd, cwd,
sizeof msg->u.Request.u.LaunchRequest.cwd);
fix_path(msg->u.Request.u.LaunchRequest.cwd);
msg->u.Request.request_type = msgtype;
@ -382,7 +333,7 @@ static int vscode_parse_set_breakpoints_request(json_value *js,
if (source == NULL) return VSCODE_UNKNOWN_REQUEST;
const char *prog = get_string_value(source, "path", log);
if (prog == NULL) return VSCODE_UNKNOWN_REQUEST;
vscode_string_copy(msg->u.Request.u.SetBreakpointsRequest.source.path, prog,
ravi_string_copy(msg->u.Request.u.SetBreakpointsRequest.source.path, prog,
sizeof msg->u.Request.u.SetBreakpointsRequest.source.path);
fix_path(msg->u.Request.u.SetBreakpointsRequest.source.path);
json_value *breakpoints = get_array_value(args, "breakpoints", log);
@ -424,7 +375,7 @@ static int vscode_parse_request(json_value *js, ProtocolMessage *msg,
if (cmd == NULL) return VSCODE_UNKNOWN_REQUEST;
msg->type = VSCODE_REQUEST;
msg->seq = get_int_value(js, "seq", log, &found);
vscode_string_copy(msg->u.Request.command, cmd, sizeof msg->u.Request.command);
ravi_string_copy(msg->u.Request.command, cmd, sizeof msg->u.Request.command);
fprintf(log, "\nRequest --> '%s'\n", cmd);
int cmdtype = get_cmdtype(msg->u.Request.command);
switch (cmdtype) {
@ -482,11 +433,11 @@ void vscode_make_error_response(ProtocolMessage *req, ProtocolMessage *res,
memset(res, 0, sizeof(ProtocolMessage));
res->seq = seq++;
res->type = VSCODE_RESPONSE;
vscode_string_copy(res->u.Response.command, req->u.Request.command,
ravi_string_copy(res->u.Response.command, req->u.Request.command,
sizeof res->u.Response.command);
res->u.Response.request_seq = req->seq;
res->u.Response.response_type = restype;
vscode_string_copy(res->u.Response.message, errormsg,
ravi_string_copy(res->u.Response.message, errormsg,
sizeof res->u.Response.message);
res->u.Response.success = 0;
}
@ -496,7 +447,7 @@ void vscode_make_success_response(ProtocolMessage *req, ProtocolMessage *res,
memset(res, 0, sizeof(ProtocolMessage));
res->seq = seq++;
res->type = VSCODE_RESPONSE;
vscode_string_copy(res->u.Response.command, req->u.Request.command,
ravi_string_copy(res->u.Response.command, req->u.Request.command,
sizeof res->u.Response.command);
res->u.Response.request_seq = req->seq;
res->u.Response.response_type = restype;
@ -507,7 +458,7 @@ void vscode_make_initialized_event(ProtocolMessage *res) {
memset(res, 0, sizeof(ProtocolMessage));
res->seq = seq++;
res->type = VSCODE_EVENT;
vscode_string_copy(res->u.Event.event, "initialized",
ravi_string_copy(res->u.Event.event, "initialized",
sizeof res->u.Event.event);
res->u.Event.event_type = VSCODE_INITIALIZED_EVENT;
}
@ -517,8 +468,8 @@ static void vscode_make_output_event(ProtocolMessage *res, const char *category,
memset(res, 0, sizeof(ProtocolMessage));
res->seq = seq++;
res->type = VSCODE_EVENT;
vscode_string_copy(res->u.Event.event, "output", sizeof res->u.Event.event);
vscode_string_copy(res->u.Event.u.OutputEvent.category, category,
ravi_string_copy(res->u.Event.event, "output", sizeof res->u.Event.event);
ravi_string_copy(res->u.Event.u.OutputEvent.category, category,
sizeof res->u.Event.u.OutputEvent.category);
vscode_json_stringify(msg, res->u.Event.u.OutputEvent.output,
sizeof res->u.Event.u.OutputEvent.output);
@ -533,9 +484,9 @@ void vscode_make_stopped_event(ProtocolMessage *res, const char *reason) {
res->seq = seq++;
res->type = VSCODE_EVENT;
res->u.Event.event_type = VSCODE_STOPPED_EVENT;
vscode_string_copy(res->u.Event.event, "stopped", sizeof res->u.Event.event);
ravi_string_copy(res->u.Event.event, "stopped", sizeof res->u.Event.event);
res->u.Event.u.StoppedEvent.threadId = 1; /* dummy thread id - always 1 */
vscode_string_copy(res->u.Event.u.StoppedEvent.reason, reason,
ravi_string_copy(res->u.Event.u.StoppedEvent.reason, reason,
sizeof res->u.Event.u.StoppedEvent.reason);
}
@ -547,7 +498,7 @@ void vscode_make_terminated_event(ProtocolMessage *res) {
res->seq = seq++;
res->type = VSCODE_EVENT;
res->u.Event.event_type = VSCODE_TERMINATED_EVENT;
vscode_string_copy(res->u.Event.event, "terminated", sizeof res->u.Event.event);
ravi_string_copy(res->u.Event.event, "terminated", sizeof res->u.Event.event);
res->u.Event.u.TerminatedEvent.restart = 0;
}
@ -559,9 +510,9 @@ void vscode_make_thread_event(ProtocolMessage *res, bool started) {
res->seq = seq++;
res->type = VSCODE_EVENT;
res->u.Event.event_type = VSCODE_THREAD_EVENT;
vscode_string_copy(res->u.Event.event, "thread", sizeof res->u.Event.event);
ravi_string_copy(res->u.Event.event, "thread", sizeof res->u.Event.event);
res->u.Event.u.ThreadEvent.threadId = 1; /* dummy thread id - always 1 */
vscode_string_copy(res->u.Event.u.ThreadEvent.reason,
ravi_string_copy(res->u.Event.u.ThreadEvent.reason,
started ? "started" : "exited",
sizeof res->u.Event.u.ThreadEvent.reason);
}
@ -898,11 +849,6 @@ int vscode_get_request(FILE *in, membuff_t *mb, ProtocolMessage *req, FILE *log)
}
}
void vscode_string_copy(char *buf, const char *src, size_t buflen) {
strncpy(buf, src, buflen);
buf[buflen - 1] = 0;
}
int64_t vscode_pack(PackedInteger *pi) {
int64_t i = 0;
assert(pi->x8[0] <= 0xFF);

@ -5,6 +5,7 @@
#ifndef RAVI_VSCODE_PROTOCOL_H
#define RAVI_VSCODE_PROTOCOL_H
#include <ravi_membuf.h>
#include "json.h"
#include <stdbool.h>
@ -362,21 +363,6 @@ typedef struct {
} ProtocolMessage;
typedef struct {
char *buf;
size_t allocated_size;
size_t pos;
} membuff_t;
extern void membuff_init(membuff_t *mb, size_t initial_size);
extern void membuff_rewindpos(membuff_t *mb);
extern void membuff_resize(membuff_t *mb, size_t new_size);
extern void membuff_free(membuff_t *mb);
extern void membuff_add_string(membuff_t *mb, const char *str);
extern void membuff_add_bool(membuff_t *mb, bool value);
extern void membuff_add_int(membuff_t *mb, int value);
extern void membuff_add_longlong(membuff_t *mb, int64_t value);
extern int vscode_parse_message(char *buf, size_t len, ProtocolMessage *msg,
FILE *log);
extern void vscode_make_error_response(ProtocolMessage *req,
@ -408,8 +394,6 @@ extern void vscode_send_success_response(ProtocolMessage *req,
extern int vscode_get_request(FILE *in, membuff_t *mb, ProtocolMessage *req, FILE *log);
extern void vscode_json_stringify(const char *src, char *dest, size_t len);
/* guaranteed null termination */
extern void vscode_string_copy(char *buf, const char *src, size_t buflen);
extern int64_t vscode_pack(PackedInteger *pi);
extern void vscode_unpack(int64_t i, PackedInteger *pi);

@ -173,11 +173,11 @@ static void get_path_and_name(char *path, size_t pathlen, char *name,
const char *last_path_delim = strrchr(input_name, '/');
if (last_path_delim) {
/* source includes a path */
vscode_string_copy(name, last_path_delim + 1, namelen);
vscode_string_copy(path, input_name, pathlen);
ravi_string_copy(name, last_path_delim + 1, namelen);
ravi_string_copy(path, input_name, pathlen);
} else {
/* prepend the working directory to the name */
vscode_string_copy(name, input_name, namelen);
ravi_string_copy(name, input_name, namelen);
if (workingdir[0]) {
size_t n = strlen(workingdir);
if (workingdir[n - 1] == '/')
@ -186,7 +186,7 @@ static void get_path_and_name(char *path, size_t pathlen, char *name,
snprintf(path, pathlen, "%s/%s", workingdir, input_name);
} else {
/* no working directory */
vscode_string_copy(path, input_name, pathlen);
ravi_string_copy(path, input_name, pathlen);
}
}
}
@ -216,11 +216,11 @@ static void handle_stack_trace_request(ProtocolMessage *req,
char path[1024];
char name[256];
get_path_and_name(path, sizeof path, name, sizeof name, src, workingdir);
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.StackTraceResponse.stackFrames[depth].source.path,
path, sizeof res->u.Response.u.StackTraceResponse.stackFrames[depth]
.source.path);
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.StackTraceResponse.stackFrames[depth].source.name,
name, sizeof res->u.Response.u.StackTraceResponse.stackFrames[depth]
.source.name);
@ -228,7 +228,7 @@ static void handle_stack_trace_request(ProtocolMessage *req,
/* C Function so source is not available */
res->u.Response.u.StackTraceResponse.stackFrames[depth]
.source.sourceReference = -1;
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.StackTraceResponse.stackFrames[depth].source.name,
"<C function>",
sizeof res->u.Response.u.StackTraceResponse.stackFrames[depth]
@ -264,7 +264,7 @@ static void handle_stack_trace_request(ProtocolMessage *req,
res->u.Response.u.StackTraceResponse.stackFrames[depth].line =
entry.currentline;
const char *funcname = entry.name ? entry.name : "?";
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.StackTraceResponse.stackFrames[depth].name, funcname,
sizeof res->u.Response.u.StackTraceResponse.stackFrames[depth].name);
depth++;
@ -304,7 +304,7 @@ static void handle_source_request(ProtocolMessage *req, ProtocolMessage *res,
const char *src = entry.source;
if (*src != '@' && *src != '=') {
/* Source is a string */
vscode_string_copy(res->u.Response.u.SourceResponse.content, src,
ravi_string_copy(res->u.Response.u.SourceResponse.content, src,
sizeof res->u.Response.u.SourceResponse.content);
} else
goto l_nosource;
@ -312,7 +312,7 @@ static void handle_source_request(ProtocolMessage *req, ProtocolMessage *res,
goto l_nosource;
} else {
l_nosource:
vscode_string_copy(res->u.Response.u.SourceResponse.content,
ravi_string_copy(res->u.Response.u.SourceResponse.content,
"Source not available",
sizeof res->u.Response.u.SourceResponse.content);
}
@ -345,7 +345,7 @@ static void handle_set_breakpoints_request(ProtocolMessage *req,
if (breakpoints[y].source.path[0] == 0 ||
strcmp(breakpoints[y].source.path,
req->u.Request.u.SetBreakpointsRequest.source.path) == 0) {
vscode_string_copy(breakpoints[y].source.path,
ravi_string_copy(breakpoints[y].source.path,
req->u.Request.u.SetBreakpointsRequest.source.path,
sizeof breakpoints[0].source.path);
breakpoints[y].line =
@ -357,7 +357,7 @@ static void handle_set_breakpoints_request(ProtocolMessage *req,
req->u.Request.u.SetBreakpointsRequest.breakpoints[i].line;
res->u.Response.u.SetBreakpointsResponse.breakpoints[k].verified =
false;
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.SetBreakpointsResponse.breakpoints[k]
.source.path,
breakpoints[y].source.path,
@ -398,7 +398,7 @@ static void handle_scopes_request(ProtocolMessage *req, ProtocolMessage *res,
int status = lua_getinfo(L, "u", &entry);
assert(status);
int i = 0;
vscode_string_copy(res->u.Response.u.ScopesResponse.scopes[i].name,
ravi_string_copy(res->u.Response.u.ScopesResponse.scopes[i].name,
"Locals",
sizeof res->u.Response.u.ScopesResponse.scopes[0].name);
PackedInteger varRef;
@ -410,7 +410,7 @@ static void handle_scopes_request(ProtocolMessage *req, ProtocolMessage *res,
res->u.Response.u.ScopesResponse.scopes[i].expensive = 0;
i++;
if (entry.isvararg) {
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.ScopesResponse.scopes[i].name, "Var Args",
sizeof res->u.Response.u.ScopesResponse.scopes[0].name);
memset(&varRef, 0, sizeof(PackedInteger));
@ -421,7 +421,7 @@ static void handle_scopes_request(ProtocolMessage *req, ProtocolMessage *res,
res->u.Response.u.ScopesResponse.scopes[i].expensive = 0;
i++;
}
vscode_string_copy(res->u.Response.u.ScopesResponse.scopes[i].name,
ravi_string_copy(res->u.Response.u.ScopesResponse.scopes[i].name,
"Globals",
sizeof res->u.Response.u.ScopesResponse.scopes[0].name);
memset(&varRef, 0, sizeof(PackedInteger));
@ -431,7 +431,7 @@ static void handle_scopes_request(ProtocolMessage *req, ProtocolMessage *res,
vscode_pack(&varRef);
res->u.Response.u.ScopesResponse.scopes[i].expensive = 0;
i++;
vscode_string_copy(res->u.Response.u.ScopesResponse.scopes[i].name,
ravi_string_copy(res->u.Response.u.ScopesResponse.scopes[i].name,
"Lua Globals",
sizeof res->u.Response.u.ScopesResponse.scopes[0].name);
memset(&varRef, 0, sizeof(PackedInteger));
@ -596,10 +596,10 @@ static void get_table_values(ProtocolMessage *res, lua_State *L, int stack_idx,
}
lua_pop(L, 1);
} else if (j + 1 == MAX_VARIABLES) {
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[j].name, "...",
sizeof res->u.Response.u.VariablesResponse.variables[0].name);
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[j].value, "",
sizeof res->u.Response.u.VariablesResponse.variables[0].value);
lua_pop(L, 1); /* pop value */
@ -612,10 +612,10 @@ static void get_table_values(ProtocolMessage *res, lua_State *L, int stack_idx,
char key[sizeof res->u.Response.u.VariablesResponse.variables[0].name];
get_value(L, -1, key, sizeof key);
if (!search_for_name(key, filter)) {
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[j].name, key,
sizeof res->u.Response.u.VariablesResponse.variables[0].name);
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[j].type,
ravi_typename(L, -2),
sizeof res->u.Response.u.VariablesResponse.variables[0].type);
@ -739,10 +739,10 @@ static void handle_variables_request(ProtocolMessage *req, ProtocolMessage *res,
for (int n = 1, v = 0; v < MAX_VARIABLES; n++) {
if (v + 1 == MAX_VARIABLES) {
/* Let the user know that we are not displaying all the variables */
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[v].name, "...",
sizeof res->u.Response.u.VariablesResponse.variables[0].name);
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[v].value, "",
sizeof res->u.Response.u.VariablesResponse.variables[0].value);
break;
@ -756,12 +756,12 @@ static void handle_variables_request(ProtocolMessage *req, ProtocolMessage *res,
if (*name == '(') {
char temp[80];
snprintf(temp, sizeof temp, "[%d]", n);
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[v].name, temp,
sizeof res->u.Response.u.VariablesResponse.variables[0]
.name);
} else {
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[v].name, name,
sizeof res->u.Response.u.VariablesResponse.variables[0]
.name);
@ -771,7 +771,7 @@ static void handle_variables_request(ProtocolMessage *req, ProtocolMessage *res,
res->u.Response.u.VariablesResponse.variables[v].value,
sizeof res->u.Response.u.VariablesResponse.variables[0]
.value);
vscode_string_copy(
ravi_string_copy(
res->u.Response.u.VariablesResponse.variables[v].type,
ravi_typename(L, -1),
sizeof res->u.Response.u.VariablesResponse.variables[0].type);
@ -862,7 +862,7 @@ static void handle_launch_request(ProtocolMessage *req, ProtocolMessage *res,
} else {
/* Make a note of the working directory so that we can work out the
path name of any source files */
vscode_string_copy(workingdir, req->u.Request.u.LaunchRequest.cwd,
ravi_string_copy(workingdir, req->u.Request.u.LaunchRequest.cwd,
sizeof workingdir);
}
}
@ -1096,7 +1096,7 @@ void ravi_debug_writestring(const char *s, size_t l) {
l = buflen - 1;
overflow = 1;
}
vscode_string_copy(buf, s, l + 1);
ravi_string_copy(buf, s, l + 1);
if (overflow || *s == '\n') {
vscode_send_output_event(&output_response, "stdout", output_buffer, stdout,
my_logger);

Loading…
Cancel
Save