Skip to content

Commit

Permalink
issue #21 #22 New test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Jun 6, 2020
1 parent 78dbcb8 commit 6b27a0a
Show file tree
Hide file tree
Showing 14 changed files with 671 additions and 172 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@ add_executable(tastwalk tests/tastwalk.c tests/tcommon.c tests/tcommon.h)
target_link_libraries(tastwalk ravicomp)
target_include_directories(tastwalk
PUBLIC "${CMAKE_CURRENT_BINARY_DIR}"
PUBLIC "${RaviCompiler_SOURCE_DIR}/include")

add_executable(trun tests/trun.c tests/tcommon.c tests/tcommon.h)
target_link_libraries(trun ravicomp)
target_include_directories(trun
PUBLIC "${CMAKE_CURRENT_BINARY_DIR}"
PRIVATE "${RaviCompiler_SOURCE_DIR}/src"
PUBLIC "${RaviCompiler_SOURCE_DIR}/include")
1 change: 1 addition & 0 deletions include/ravi_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ static inline void raviX_buffer_reset(membuff_t *mb) { mb->pos = 0; }

/* following convert input to string before adding */
RAVICOMP_EXPORT void raviX_buffer_add_string(membuff_t *mb, const char *str);
RAVICOMP_EXPORT void raviX_buffer_add_bytes(membuff_t *mb, const char *str, size_t len);
RAVICOMP_EXPORT void raviX_buffer_add_fstring(membuff_t *mb, const char *str, ...) FORMAT_ATTR(2);

/* strncpy() replacement with guaranteed 0 termination */
Expand Down
1 change: 1 addition & 0 deletions src/implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ struct function_expression {
struct var_type type;
unsigned int is_vararg : 1;
unsigned int is_method : 1;
uint32_t proc_id; /* Backend allocated id */
struct ast_node *parent_function; /* parent function or NULL if main chunk */
struct block_scope *main_block; /* the function's main block */
struct ast_node_list *function_statement_list; /* statements in this block */
Expand Down
3 changes: 2 additions & 1 deletion src/linearizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ static struct proc *allocate_proc(struct linearizer_state *linearizer, struct as
assert(function_expr->type == EXPR_FUNCTION);
struct proc *proc = raviX_allocator_allocate(&linearizer->proc_allocator, 0);
proc->function_expr = function_expr;
proc->id = ptrlist_size((struct ptr_list *)linearizer->all_procs);
proc->id = ptrlist_size((struct ptr_list *)linearizer->all_procs)+1; // so that 0 is not assigned
function_expr->function_expr.proc_id = proc->id;
ptrlist_add((struct ptr_list **)&linearizer->all_procs, proc, &linearizer->ptrlist_allocator);
if (linearizer->current_proc) {
proc->parent = linearizer->current_proc;
Expand Down
8 changes: 6 additions & 2 deletions src/membuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ void raviX_buffer_reserve(membuff_t *mb, size_t n)
}
}
void raviX_buffer_free(membuff_t *mb) { free(mb->buf); }
void raviX_buffer_add_string(membuff_t *mb, const char *str)
void raviX_buffer_add_bytes(membuff_t *mb, const char *str, size_t len)
{
size_t len = strlen(str);
size_t required_size = mb->pos + len + 1; /* extra byte for NULL terminator */
raviX_buffer_resize(mb, required_size);
assert(mb->allocated_size - mb->pos > len);
raviX_string_copy(&mb->buf[mb->pos], str, mb->allocated_size - mb->pos);
mb->pos += len;
}
void raviX_buffer_add_string(membuff_t *mb, const char *str)
{
size_t len = strlen(str);
raviX_buffer_add_bytes(mb, str, len);
}

void raviX_buffer_add_fstring(membuff_t *mb, const char *fmt, ...)
{
Expand Down
1 change: 1 addition & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ static struct ast_node *new_function(struct parser_state *parser)
set_type(&node->function_expr.type, RAVI_TFUNCTION);
node->function_expr.is_method = false;
node->function_expr.is_vararg = false;
node->function_expr.proc_id = 0;
node->function_expr.args = NULL;
node->function_expr.child_functions = NULL;
node->function_expr.upvalues = NULL;
Expand Down
Loading

0 comments on commit 6b27a0a

Please sign in to comment.