Skip to content

Commit

Permalink
#198 upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Jan 4, 2022
1 parent 06552bb commit 842b4ff
Show file tree
Hide file tree
Showing 34 changed files with 328 additions and 315 deletions.
19 changes: 10 additions & 9 deletions ravicomp/include/ravi_api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand All @@ -23,28 +23,29 @@
#ifndef ravicomp_RAVIAPI_H
#define ravicomp_RAVIAPI_H

#include "ravicomp_export.h"
#include "ravi_compiler.h"
#include "ravicomp_export.h"

#include <stdlib.h>

typedef struct Ravi_CompilerInterface {
/* ------------------------ Inputs ------------------------------ */
void *context; /* Ravi supplied context */
void *context; /* Ravi supplied context, passed to debug_message/error_message callbacks */

const char *source; /* Source code to be compiled - managed by Ravi */
size_t source_len; /* Size of source code */
const char *source_name; /* Name of the source */
const char *source; /* Source code to be compiled - managed by Ravi */
size_t source_len; /* Size of source code */
const char *source_name; /* Name of the source */
const char *compiler_options; /* flags to be passed to compiler */

char main_func_name[31]; /* Name of the generated function that when called will set up the Lua closure */

C_MemoryAllocator *memory_allocator;
C_MemoryAllocator *memory_allocator; /* Memory allocator to use */

/* ------------------------- Outputs ------------------------------ */
const char* generated_code; /* Output of the compiler. */
const char *generated_code; /* Output of the compiler; call raviX_release() to free this */

/* ------------------------ Debugging and error handling ----------------------------------------- */
/* context will be passed as first parameter */
void (*debug_message)(void *context, const char *filename, long long line, const char *message);
void (*error_message)(void *context, const char *message);
} Ravi_CompilerInterface;
Expand All @@ -56,7 +57,7 @@ typedef struct Ravi_CompilerInterface {
* @return 0 for success, non-zero for failure
*/
RAVICOMP_EXPORT int raviX_compile(Ravi_CompilerInterface *compiler_interface);
/* Releases memory etc held by the compiler context */
/* Releases memory etc. held by the compiler context */
RAVICOMP_EXPORT void raviX_release(Ravi_CompilerInterface *compiler_interface);

#endif
291 changes: 142 additions & 149 deletions ravicomp/include/ravi_compiler.h

Large diffs are not rendered by default.

34 changes: 1 addition & 33 deletions ravicomp/src/allocate.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
/*
* allocate.c - simple space-efficient blob allocator.
*
* Copyright (C) 2003 Transmeta Corp.
* 2003-2004 Linus Torvalds
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Simple allocator for data that doesn't get partially free'd.
* The tokenizer and parser allocate a _lot_ of small data structures
* (often just two-three bytes for things like small integers),
* and since they all depend on each other you can't free them
* individually _anyway_. So do something that is very space-
* efficient: allocate larger "blobs", and give out individual
* small bits and pieces of it with no maintenance overhead.
*/
/*
* This version is part of the Ravi Compiler project.
* Copyright (C) 2017-2021 Dibyendu Majumdar
* Copyright (C) 2017-2022 Dibyendu Majumdar
*/

#include <allocate.h>
Expand Down
57 changes: 20 additions & 37 deletions ravicomp/src/allocate.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
#ifndef ravicomp_ALLOCATOR_H
#define ravicomp_ALLOCATOR_H

/*
* allocate.c - simple space-efficient blob allocator.
*
* Copyright (C) 2003 Transmeta Corp.
* 2003-2004 Linus Torvalds
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
/******************************************************************************
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* Simple allocator for data that doesn't get partially free'd.
* The tokenizer and parser allocate a _lot_ of small data structures
* (often just two-three bytes for things like small integers),
* and since they all depend on each other you can't free them
* individually _anyway_. So do something that is very space-
* efficient: allocate larger "blobs", and give out individual
* small bits and pieces of it with no maintenance overhead.
*/
/*
* Portions Copyright (C) 2017-2021 Dibyendu Majumdar
*/
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#ifndef ravicomp_ALLOCATE_H
#define ravicomp_ALLOCATE_H

Expand All @@ -55,7 +39,7 @@ extern void raviX_free(void *ptr);

#ifndef C_MEMORYALLOCATOR_DEFINED
#define C_MEMORYALLOCATOR_DEFINED
/* Note that this struct below is also defined in ravi_compiler.h and both
/* Note that this struct below is also defined in ravi_compiler.h/chibicc.h and all
* definitions must be kept in sync.
*/
typedef struct C_MemoryAllocator {
Expand Down Expand Up @@ -115,4 +99,3 @@ extern size_t raviX_del_array_element(void *p, size_t element_size, size_t array

#endif

#endif
2 changes: 1 addition & 1 deletion ravicomp/src/ast_lower.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2018-2021 Dibyendu Majumdar
* Copyright (C) 2018-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/ast_printer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2018-2021 Dibyendu Majumdar
* Copyright (C) 2018-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/ast_simplify.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2018-2021 Dibyendu Majumdar
* Copyright (C) 2018-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
18 changes: 15 additions & 3 deletions ravicomp/src/ast_walker.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -107,6 +107,14 @@ const Scope *raviX_variable_symbol_scope(const LuaVariableSymbol *lua_local_symb
{
return lua_local_symbol->block;
}
bool raviX_variable_symbol_is_function_parameter(const LuaVariableSymbol *lua_local_symbol)
{
return lua_local_symbol->function_parameter ? true : false;
}
bool raviX_variable_symbol_has_escaped(const LuaVariableSymbol *lua_local_symbol)
{
return lua_local_symbol->escaped ? true : false;
}

#define n(v) ((AstNode *)v)
const ReturnStatement *raviX_return_statement(const Statement *stmt)
Expand Down Expand Up @@ -164,7 +172,7 @@ const ForStatement *raviX_for_statement(const Statement *stmt)
assert(stmt->type == STMT_FOR_IN || stmt->type == STMT_FOR_NUM);
return &n(stmt)->for_stmt;
}
const EmbeddedCStatement *raviX_embedded_C_statment(const Statement *stmt)
const EmbeddedCStatement *raviX_embedded_C_statement(const Statement *stmt)
{
assert(stmt->type == STMT_EMBEDDED_C);
return &n(stmt)->embedded_C_stmt;
Expand Down Expand Up @@ -348,7 +356,7 @@ void raviX_function_statement_foreach_selector(const FunctionStatement *statemen
AstNode *node;
FOR_EACH_PTR(statement->selectors, AstNode, node)
{
assert(node->type == EXPR_Y_INDEX || node->type == EXPR_FIELD_SELECTOR);
assert(/* node->type == EXPR_Y_INDEX ||*/ node->type == EXPR_FIELD_SELECTOR);
callback(userdata, &node->index_expr);
}
END_FOR_EACH_PTR(node)
Expand Down Expand Up @@ -654,6 +662,10 @@ void raviX_scope_foreach_symbol(const Scope *scope, void *userdata,
FOR_EACH_PTR(scope->symbol_list, LuaSymbol, symbol) { callback(userdata, symbol); }
END_FOR_EACH_PTR(node)
}
bool raviX_scope_needs_closing(const Scope *scope)
{
return scope->need_close ? true: false;
}
enum SymbolType raviX_symbol_type(const LuaSymbol *symbol) { return symbol->symbol_type; }
const LuaVariableSymbol *raviX_symbol_variable(const LuaSymbol *symbol)
{
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright (C) 2018-2020 Vladimir Makarov <[email protected]>.
*/
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright (C) 2018-2020 Vladimir Makarov <[email protected]>.
*/
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/cfg.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/cfg.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
10 changes: 5 additions & 5 deletions ravicomp/src/codegen.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions"
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -850,9 +850,9 @@ static inline unsigned get_num_childprocs(Proc *proc) { return raviX_ptrlist_siz
*/
static void emit_vars(const char *type, const char *prefix, PseudoGenerator *gen, TextBuffer *mb)
{
if (gen->next_reg == 0)
if (gen->max_reg == 0)
return;
for (unsigned i = 0; i < gen->next_reg; i++) {
for (unsigned i = 0; i < gen->max_reg; i++) {
if (i == 0) {
raviX_buffer_add_fstring(mb, "%s ", type);
}
Expand Down Expand Up @@ -944,9 +944,9 @@ static void emit_varname(Function *fn, const Pseudo *pseudo)

static void emit_reload_base(Function *fn) { raviX_buffer_add_string(&fn->body, "base = ci->u.l.base;\n"); }

static inline unsigned num_locals(Proc *proc) { return proc->local_pseudos.next_reg; }
static inline unsigned num_locals(Proc *proc) { return proc->local_pseudos.max_reg; }

static inline unsigned num_temps(Proc *proc) { return proc->temp_pseudos.next_reg; }
static inline unsigned num_temps(Proc *proc) { return proc->temp_pseudos.max_reg; }

/*
* Max stack size is number of Lua vars and any temps that live on Lua stack during execution.
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/codegen.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/dataflow_framework.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/dataflow_framework.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/df_liveness.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/dominator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/dominator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/graph.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/graph.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/lexer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2020-2021 Dibyendu Majumdar
* Copyright (C) 2020-2022 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down
Loading

0 comments on commit 842b4ff

Please sign in to comment.