Skip to content

Commit

Permalink
feat: added release script
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdelahunt committed Dec 16, 2022
1 parent 81f8d76 commit fdbc3fe
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 84 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ liamc/src/Makefile
liamc/tests/out.cpp
liamc/out.cpp
**/build-debug/
*.exe
*.exe
liamc/release
**/Makefile
9 changes: 0 additions & 9 deletions liamc/Makefile

This file was deleted.

30 changes: 30 additions & 0 deletions liamc/liamc.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
release:
./vendor/premake5-mac gmake
mkdir release

mkdir release/win_64
make config=release_win64
mv bin/liamc/liamc release/win_64

mkdir release/macos
make config=release_macos
mv bin/liamc/liamc release/macos

mkdir release/linux_64
make config=release_linux64
mv bin/liamc/liamc release/linux_64

cp -r stdlib release/win_64
cp -r stdlib release/macos
cp -r stdlib release/linux_64

format:
@find . -type f \( -name "*.h" -or -name "*.cpp" \) | xargs clang-format -i --style=file:".clang-format"

build:
@./bin/liamc/liamc --stdlib="stdlib" --in="main.liam" -t

run: build
@clang++ -I "stdlib/include" -std=c++20 -o out.exe out.cpp
@./out.exe

22 changes: 7 additions & 15 deletions liamc/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ distpath = "%{wks.location}/" .. "/%{prj.name}"

workspace "Liam"
architecture "x64"
startproject "liamc" -- this isnt working for some reason
startproject "liamc"

configurations {
"Debug",
"Release",
"Dist"
}

platforms {
"win64",
"macos",
"linux64",
}

project "liamc"
location "src"
kind "ConsoleApp"
Expand Down Expand Up @@ -52,19 +57,6 @@ workspace "Liam"
optimize "on"
}

filter "configurations:Dist"
defines {
"DIST",
optimize "on"
}

postbuildcommands {
"{MKDIR} %{distpath}",
"{COPYFILE} %{cfg.buildtarget.abspath} %{distpath}/",
"{COPYDIR} %{wks.location}/runtime %{distpath}/runtime",
"{COPYDIR} %{wks.location}/stdlib %{distpath}/stdlib",
}

-- windows specific stuffy
filter "system:windows"
systemversion "latest"
Expand Down
10 changes: 4 additions & 6 deletions liamc/src/backends/cpp_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,10 @@ std::string CppBackend::emit_call_expression(CallExpression *expression) {

// because we can call members of a type T on ^T sometimes we do not need to add
// a & as it is already a pointer, if it is not a pointer then add the &
if(get_expression->lhs->type_info->type != TypeInfoType::POINTER) {
source.append("&");
}
if (get_expression->lhs->type_info->type != TypeInfoType::POINTER)
{ source.append("&"); }

source.append( emit_expression(get_expression->lhs));
source.append(emit_expression(get_expression->lhs));
if (expression->args.size() > 0)
{ source.append(", "); }
}
Expand Down Expand Up @@ -773,8 +772,7 @@ std::string CppBackend::emit_type_expression(TypeExpression *type_expression) {
);
break;
case TypeExpressionType::TYPE_FN:
return emit_fn_type_expression(dynamic_cast<FnTypeExpression *>(type_expression)
);
return emit_fn_type_expression(dynamic_cast<FnTypeExpression *>(type_expression));
break;
default:
panic("Cpp back end does not support this type expression");
Expand Down
17 changes: 8 additions & 9 deletions liamc/src/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ ZeroLiteralExpression::ZeroLiteralExpression(Token token) {
this->span = token.span;
}

FnExpression::FnExpression(std::vector<std::tuple<Token, TypeExpression *>> params, TypeExpression *return_type, ScopeStatement *body) {
this->params = std::move(params);
FnExpression::FnExpression(
std::vector<std::tuple<Token, TypeExpression *>> params, TypeExpression *return_type, ScopeStatement *body
) {
this->params = std::move(params);
this->return_type = return_type;
this->body = body;
this->type = ExpressionType::EXPRESSION_FN;
this->span = return_type->span; // FIXME: use a better place to put the span for the fn expression

this->body = body;
this->type = ExpressionType::EXPRESSION_FN;
this->span = return_type->span; // FIXME: use a better place to put the span for the fn expression
}

std::ostream &TypeExpression::format(std::ostream &os) const {
Expand Down Expand Up @@ -152,9 +153,7 @@ SpecifiedGenericsTypeExpression::SpecifiedGenericsTypeExpression(
this->type = TypeExpressionType::TYPE_SPECIFIED_GENERICS;
}

FnTypeExpression::FnTypeExpression(
std::vector<TypeExpression *> params, TypeExpression *return_type
) {
FnTypeExpression::FnTypeExpression(std::vector<TypeExpression *> params, TypeExpression *return_type) {
this->params = std::move(params);
this->return_type = return_type;
this->span = return_type->span; // FIXME: this should be a better span, return type is just used for now
Expand Down
6 changes: 4 additions & 2 deletions liamc/src/expression.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "lexer.h"
#include "type_info.h"
#include "statement.h"
#include "type_info.h"

struct TypeExpression;
struct ScopeStatement;
Expand Down Expand Up @@ -135,7 +135,9 @@ struct FnExpression : Expression {
TypeExpression *return_type;
ScopeStatement *body;

FnExpression(std::vector<std::tuple<Token, TypeExpression *>> params, TypeExpression *return_type, ScopeStatement *body);
FnExpression(
std::vector<std::tuple<Token, TypeExpression *>> params, TypeExpression *return_type, ScopeStatement *body
);
};

enum class TypeExpressionType {
Expand Down
2 changes: 1 addition & 1 deletion liamc/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ Expression *Parser::eval_primary() {
// return has no expression
}

Expression * Parser::eval_fn() {
Expression *Parser::eval_fn() {
TRY_CALL_RET(consume_token_of_type(TokenType::TOKEN_FN), NULL);

TRY_CALL_RET(consume_token_of_type(TokenType::TOKEN_PAREN_OPEN), NULL);
Expand Down
85 changes: 44 additions & 41 deletions liamc/src/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void TypeChecker::type_check_expression(Expression *expression, SymbolTable *sym
return type_check_zero_literal_expression(dynamic_cast<ZeroLiteralExpression *>(expression), symbol_table);
break;
case ExpressionType::EXPRESSION_FN:
return type_check_fn_expression(dynamic_cast<FnExpression*>(expression), symbol_table);
return type_check_fn_expression(dynamic_cast<FnExpression *>(expression), symbol_table);
break;
default:
panic("Expression not implemented in type checker");
Expand Down Expand Up @@ -844,12 +844,14 @@ void TypeChecker::type_check_call_expression(CallExpression *expression, SymbolT
TRY_CALL(type_check_expression(expression->callee, symbol_table));
auto callee_expression = expression->callee;

if(expression->callee->type_info->type == TypeInfoType::FN) {
if (expression->callee->type_info->type == TypeInfoType::FN)
{
TRY_CALL(type_check_fn_call_expression(expression, symbol_table));
return;
}

if(expression->callee->type_info->type == TypeInfoType::FN_EXPRESSION) {
if (expression->callee->type_info->type == TypeInfoType::FN_EXPRESSION)
{
TRY_CALL(type_check_fn_expression_call_expression(expression, symbol_table));
return;
}
Expand All @@ -874,23 +876,23 @@ void TypeChecker::type_check_fn_call_expression(CallExpression *expression, Symb
if (fn_type_info->args.size() != arg_type_infos.size())
{
ErrorReporter::report_type_checker_error(
current_file->path, callee_expression, NULL, NULL, NULL,
fmt::format(
"Incorrect number of arguments in call expression, expected {} got {}", fn_type_info->args.size(),
arg_type_infos.size()
)
current_file->path, callee_expression, NULL, NULL, NULL,
fmt::format(
"Incorrect number of arguments in call expression, expected {} got {}", fn_type_info->args.size(),
arg_type_infos.size()
)
);
return;
}

if (fn_type_info->generic_type_infos.size() != expression->generics.size())
{
ErrorReporter::report_type_checker_error(
current_file->path, callee_expression, NULL, NULL, NULL,
fmt::format(
"Incorrect number of generic arguments in call expression, expected {} got {}",
fn_type_info->generic_type_infos.size(), expression->generics.size()
)
current_file->path, callee_expression, NULL, NULL, NULL,
fmt::format(
"Incorrect number of generic arguments in call expression, expected {} got {}",
fn_type_info->generic_type_infos.size(), expression->generics.size()
)
);
return;
}
Expand All @@ -900,8 +902,8 @@ void TypeChecker::type_check_fn_call_expression(CallExpression *expression, Symb
if (!type_match(fn_type_info->args.at(i), arg_type_infos.at(i)))
{
ErrorReporter::report_type_checker_error(
current_file->path, callee_expression, expression->args.at(i), NULL, NULL,
"Mismatched types function call"
current_file->path, callee_expression, expression->args.at(i), NULL, NULL,
"Mismatched types function call"
);
return;
}
Expand All @@ -927,11 +929,11 @@ void TypeChecker::type_check_fn_expression_call_expression(CallExpression *expre
if (fn_type_info->args.size() != arg_type_infos.size())
{
ErrorReporter::report_type_checker_error(
current_file->path, callee_expression, NULL, NULL, NULL,
fmt::format(
"Incorrect number of arguments in call expression, expected {} got {}", fn_type_info->args.size(),
arg_type_infos.size()
)
current_file->path, callee_expression, NULL, NULL, NULL,
fmt::format(
"Incorrect number of arguments in call expression, expected {} got {}", fn_type_info->args.size(),
arg_type_infos.size()
)
);
return;
}
Expand All @@ -941,17 +943,18 @@ void TypeChecker::type_check_fn_expression_call_expression(CallExpression *expre
if (!type_match(fn_type_info->args.at(i), arg_type_infos.at(i)))
{
ErrorReporter::report_type_checker_error(
current_file->path, callee_expression, expression->args.at(i), NULL, NULL,
"Mismatched types function call"
current_file->path, callee_expression, expression->args.at(i), NULL, NULL,
"Mismatched types function call"
);
return;
}
}

if(expression->generics.size() > 0) {
if (expression->generics.size() > 0)
{
ErrorReporter::report_type_checker_error(
current_file->path, callee_expression, NULL, NULL, NULL,
"Cannot pass generic params to functions created from expressions"
current_file->path, callee_expression, NULL, NULL, NULL,
"Cannot pass generic params to functions created from expressions"
);
return;
}
Expand Down Expand Up @@ -1270,8 +1273,8 @@ void TypeChecker::type_check_fn_expression(FnExpression *expression, SymbolTable
if (rt->expression != NULL)
{
ErrorReporter::report_type_checker_error(
current_file->path, rt->expression, NULL, NULL, NULL,
"found expression in return when return type is void"
current_file->path, rt->expression, NULL, NULL, NULL,
"found expression in return when return type is void"
);
return;
}
Expand All @@ -1281,16 +1284,17 @@ void TypeChecker::type_check_fn_expression(FnExpression *expression, SymbolTable
if (!type_match(expression->return_type->type_info, rt->expression->type_info))
{
ErrorReporter::report_type_checker_error(
current_file->path, rt->expression, NULL, expression->return_type, NULL,
"Mismatch types in function, return types do not match"
current_file->path, rt->expression, NULL, expression->return_type, NULL,
"Mismatch types in function, return types do not match"
);
return;
}
}
}
}

expression->type_info = new FnExpressionTypeInfo{TypeInfoType::FN_EXPRESSION, expression->return_type->type_info, param_type_infos};
expression->type_info =
new FnExpressionTypeInfo{TypeInfoType::FN_EXPRESSION, expression->return_type->type_info, param_type_infos};
}

void TypeChecker::type_check_type_expression(TypeExpression *type_expression, SymbolTable *symbol_table) {
Expand Down Expand Up @@ -1377,7 +1381,8 @@ void TypeChecker::type_check_fn_type_expression(FnTypeExpression *type_expressio

TRY_CALL(type_check_type_expression(type_expression->return_type, symbol_table));

type_expression->type_info = new FnExpressionTypeInfo{TypeInfoType::FN_EXPRESSION, type_expression->return_type->type_info, param_type_infos};
type_expression->type_info = new FnExpressionTypeInfo{
TypeInfoType::FN_EXPRESSION, type_expression->return_type->type_info, param_type_infos};
}

void TypeChecker::type_check_identifier_type_expression(
Expand Down Expand Up @@ -1581,18 +1586,16 @@ bool type_match(TypeInfo *a, TypeInfo *b) {
auto fn_a = static_cast<FnExpressionTypeInfo *>(a);
auto fn_b = static_cast<FnExpressionTypeInfo *>(b);

if(!type_match(fn_a->return_type, fn_b->return_type)) {
return false;
}
if (!type_match(fn_a->return_type, fn_b->return_type))
{ return false; }

if(fn_a->args.size() != fn_b->args.size()) {
return false;
}
if (fn_a->args.size() != fn_b->args.size())
{ return false; }

for(u32 i = 0; i < fn_a->args.size(); i++) {
if(!type_match(fn_a->args[i], fn_b->args[i])) {
return false;
}
for (u32 i = 0; i < fn_a->args.size(); i++)
{
if (!type_match(fn_a->args[i], fn_b->args[i]))
{ return false; }
}

return true;
Expand Down

0 comments on commit fdbc3fe

Please sign in to comment.