Skip to content

Commit

Permalink
update libetl
Browse files Browse the repository at this point in the history
update libetl
  • Loading branch information
lostjared authored Oct 21, 2024
1 parent f8e3587 commit b0af11c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
38 changes: 1 addition & 37 deletions compiler/ETL/libetl/shared/etl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,9 @@
#include<iostream>
#include<sstream>

namespace ast {
enum class VarType { NUMBER, STRING, POINTER, TYPE_NULL };
}
namespace interp {
struct Var {
Var() = default;
Var(const std::string &n, ast::VarType v) : name{n}, numeric_value{0}, ptr_value{nullptr}, type{v} {}
Var(const std::string &n, const std::string &value) : name{n}, string_value{value}, type{ast::VarType::STRING} {}
Var(const std::string &n, long value) : name{n}, numeric_value{value}, type{ast::VarType::NUMBER} {}
Var(const std::string &n, void *ptr) : name{n}, ptr_value{ptr}, type {ast::VarType::POINTER} {}
Var(const Var &v) : name{v.name}, numeric_value{v.numeric_value}, string_value{v.string_value}, ptr_value{v.ptr_value}, type{v.type} {}
Var(Var &&v) : name{std::move(v.name)}, numeric_value{v.numeric_value}, string_value{std::move(v.string_value)}, ptr_value{v.ptr_value}, type{v.type} {}

Var &operator=(const Var &v) {
name = v.name;
numeric_value = v.numeric_value;
string_value = v.string_value;
ptr_value = v.ptr_value;
type = v.type;
return *this;
}

Var &operator=(Var &&v) {
name = std::move(v.name);
numeric_value = v.numeric_value;
string_value = std::move(v.string_value);
ptr_value = v.ptr_value;
type = v.type;
return *this;
}

std::string name;
long numeric_value = 0;
std::string string_value;
void *ptr_value = nullptr;
ast::VarType type;
};

void check_args(const std::string &n, const std::vector<interp::Var> &v, std::initializer_list<ast::VarType> args) {
inline void check_args(const std::string &n, const std::vector<interp::Var> &v, std::initializer_list<ast::VarType> args) {
if(v.size() != args.size()) {
std::ostringstream stream;
stream << "In function: " << n << " argument count mismatch.\n";
Expand Down
4 changes: 3 additions & 1 deletion compiler/ETL/libetl/shared/io/io.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "../../../interp.hpp"
#include "../../../ast.hpp"
#include "../etl.hpp"
#include<cstdio>

Expand Down Expand Up @@ -46,7 +48,7 @@ interp::Var func_file_size(const std::vector<interp::Var> &v) {
return interp::Var("return", (long)file_size(v.at(0).ptr_value));
}

extern "C" void initTable(addFunction func) {
extern "C" void libio_rt_initTable(addFunction func) {
func("file_open", (void*)func_file_open);
func("file_print", (void*)func_file_print);
func("file_write", (void*)func_file_write);
Expand Down
7 changes: 4 additions & 3 deletions compiler/ETL/libetl/shared/sdl/sdl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* ETL: SDL2 Module */
#include"SDL.h"
#include "../../../interp.hpp"
#include "../../../ast.hpp"
#include "../etl.hpp"

extern "C" void sdl_init();
Expand Down Expand Up @@ -200,8 +202,7 @@ interp::Var func_sdl_draw_gradient(const std::vector<interp::Var> &v) {
return interp::Var("return", (long)0);
}


extern "C" void initTable(addFunction func) {
extern "C" void libsdl_rt_initTable(addFunction func) {
func("sdl_init", (void*)func_sdl_init);
func("sdl_init_size", (void*)func_sdl_init_size);
func("sdl_quit", (void*)func_sdl_quit);
Expand Down Expand Up @@ -231,4 +232,4 @@ extern "C" void initTable(addFunction func) {
func("sdl_setstartcolor", (void*)func_sdl_setstartcolor);
func("sdl_setendcolor", (void*)func_sdl_setendcolor);
func("sdl_draw_gradient", (void*)func_sdl_draw_gradient);
}
}

0 comments on commit b0af11c

Please sign in to comment.