Skip to content

Commit

Permalink
Merge pull request #33 from AbdelrahmanKhaledd/fix-linux-build
Browse files Browse the repository at this point in the history
Fix: headers including, undefined `readline<-RETURN` macro from CodeGen.cpp
  • Loading branch information
alexdovzhanyn authored Sep 29, 2024
2 parents 0b91cf5 + b49c20c commit cf40af7
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 27 deletions.
168 changes: 168 additions & 0 deletions .github/workflows/cmake-single-platform-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: CMake on a single platform on Linux

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Initialize submodules
run: git submodule update --init --recursive

- name: Install Wasmer
run: curl https://get.wasmer.io -sSfL | WASMER_DIR=lib/wasmer sh

- name: Upload Wasmer as artifact
uses: actions/upload-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Cache CMake build
uses: actions/cache@v3
with:
path: build
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-
- name: Cache CMake dependencies
uses: actions/cache@v3
with:
path: |
.cache
key: ${{ runner.os }}-cmake-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cmake-
- name: Install libreadline-dev
run: sudo apt-get install -y libreadline-dev

- name: Build project
working-directory: ${{ github.workspace }}
run: ./build.sh

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

lexer-test:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make LexerTest Executable
run: chmod +x ${{ github.workspace }}/build/LexerTest

- name: Output Wasmer directory
run: ls -laR ${{ github.workspace }}/lib/wasmer

- name: Run Lexer Test
working-directory: ${{ github.workspace }}/build
run: ./LexerTest

parser-test:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make ParserTest Executable
run: chmod +x ${{ github.workspace }}/build/ParserTest

- name: Run Parser Test
working-directory: ${{ github.workspace }}/build
run: ./ParserTest

typechecker-test:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make TypeCheckerTest Executable
run: chmod +x ${{ github.workspace }}/build/TypeCheckerTest

- name: Run TypeChecker Test
working-directory: ${{ github.workspace }}/build
run: ./TypeCheckerTest

codegen-test:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make CodegenTest Executable
run: chmod +x ${{ github.workspace }}/build/CodegenTest

- name: Run Codegen Test
working-directory: ${{ github.workspace }}/build
run: ./CodegenTest

20 changes: 10 additions & 10 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: curl https://get.wasmer.io -sSfL | WASMER_DIR=lib/wasmer sh

- name: Upload Wasmer as artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer
Expand All @@ -51,7 +51,7 @@ jobs:
run: ./build.sh

- name: Upload build artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build
Expand All @@ -64,13 +64,13 @@ jobs:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer
Expand All @@ -93,13 +93,13 @@ jobs:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer
Expand All @@ -119,13 +119,13 @@ jobs:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer
Expand All @@ -145,13 +145,13 @@ jobs:
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if [ ! -d "build" ]; then
mkdir build
fi
cd build
g++ --version
cmake ..
make
cd ..
35 changes: 23 additions & 12 deletions src/compiler/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
#pragma push_macro("RETURN")
#undef RETURN

namespace Theta {
BinaryenModuleRef CodeGen::generateWasmFromAST(shared_ptr<ASTNode> ast) {
Expand Down Expand Up @@ -86,7 +88,7 @@ namespace Theta {
if (node->getNodeType() == ASTNode::SOURCE) {
generateSource(dynamic_pointer_cast<SourceNode>(node), module);
} else if (node->getNodeType() == ASTNode::CAPSULE) {
return generateCapsule(dynamic_pointer_cast<CapsuleNode>(node), module);
generateCapsule(dynamic_pointer_cast<CapsuleNode>(node), module);
} else if (node->getNodeType() == ASTNode::ASSIGNMENT) {
return generateAssignment(dynamic_pointer_cast<AssignmentNode>(node), module);
} else if (node->getNodeType() == ASTNode::BLOCK) {
Expand Down Expand Up @@ -123,7 +125,7 @@ namespace Theta {
return nullptr;
}

BinaryenExpressionRef CodeGen::generateCapsule(shared_ptr<CapsuleNode> capsuleNode, BinaryenModuleRef &module) {
void CodeGen::generateCapsule(shared_ptr<CapsuleNode> capsuleNode, BinaryenModuleRef &module) {
vector<shared_ptr<ASTNode>> capsuleElements = dynamic_pointer_cast<ASTNodeList>(capsuleNode->getValue())->getElements();

hoistCapsuleElements(capsuleElements);
Expand Down Expand Up @@ -513,7 +515,7 @@ namespace Theta {
collectClosureScope(node->getParent(), identifiersToFind, parameters, bodyExpressions);
}

BinaryenExpressionRef CodeGen::generateFunctionDeclaration(
void CodeGen::generateFunctionDeclaration(
string identifier,
shared_ptr<FunctionDeclarationNode> fnDeclNode,
BinaryenModuleRef &module,
Expand Down Expand Up @@ -690,18 +692,20 @@ namespace Theta {
// If a refIdentifier was passed, that means we have an existing closure
// in memory that we want to populate.
if (refIdentifier != "") {
BinaryenExpressionRef closureArgs[2] = {
BinaryenLocalGet(
module,
scope.lookup(refIdentifier).value()->getMappedBinaryenIndex(),
BinaryenTypeInt32()
),
BinaryenConst(module, BinaryenLiteralInt32(addressToPopulate.getAddress()))
};

expressions.push_back(
BinaryenCall(
module,
"Theta.Function.populateClosure",
(BinaryenExpressionRef[]){
BinaryenLocalGet(
module,
scope.lookup(refIdentifier).value()->getMappedBinaryenIndex(),
BinaryenTypeInt32()
),
BinaryenConst(module, BinaryenLiteralInt32(addressToPopulate.getAddress()))
},
closureArgs,
2,
BinaryenTypeNone()
)
Expand Down Expand Up @@ -1061,10 +1065,12 @@ namespace Theta {
throw runtime_error("Invalid operand types for binary operation");
}

BinaryenExpressionRef args[2] = { binaryenLeft, binaryenRight };

return BinaryenCall(
module,
"Theta.Math.pow",
(BinaryenExpressionRef[]){ binaryenLeft, binaryenRight },
args,
2,
BinaryenTypeInt64()
);
Expand Down Expand Up @@ -1153,6 +1159,8 @@ namespace Theta {
if (op == Lexemes::GT && dataType == DataTypes::NUMBER) return BinaryenGtSInt64();
if (op == Lexemes::LTEQ && dataType == DataTypes::NUMBER) return BinaryenLeSInt64();
if (op == Lexemes::GTEQ && dataType == DataTypes::NUMBER) return BinaryenGeSInt64();

throw runtime_error("No matching WASM opcode for binary operation: " + binOpNode->getOperator());
}

BinaryenType CodeGen::getBinaryenTypeFromTypeDeclaration(shared_ptr<TypeDeclarationNode> typeDeclaration) {
Expand All @@ -1162,6 +1170,8 @@ namespace Theta {

// Function references are returned as i32 pointers to a closure in the function table
if (typeDeclaration->getType() == DataTypes::FUNCTION) return BinaryenTypeInt32();

throw runtime_error("No matching WASM type for TypeDeclaration: " + typeDeclaration->getType());
}

BinaryenType CodeGen::getBinaryenStorageTypeFromTypeDeclaration(shared_ptr<TypeDeclarationNode> typeDeclaration) {
Expand Down Expand Up @@ -1397,3 +1407,4 @@ namespace Theta {
return stream.str();
}
}
#pragma pop_macro("RETURN")
6 changes: 3 additions & 3 deletions src/compiler/CodeGen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
#include <binaryen-c.h>
#include <set>
#include <unordered_map>

#include <functional>
using namespace std;

namespace Theta {
class CodeGen {
public:
BinaryenModuleRef generateWasmFromAST(shared_ptr<ASTNode> ast);
BinaryenExpressionRef generate(shared_ptr<ASTNode> node, BinaryenModuleRef &module);
BinaryenExpressionRef generateCapsule(shared_ptr<CapsuleNode> node, BinaryenModuleRef &module);
void generateCapsule(shared_ptr<CapsuleNode> node, BinaryenModuleRef &module);
BinaryenExpressionRef generateAssignment(shared_ptr<AssignmentNode> node, BinaryenModuleRef &module);
BinaryenExpressionRef generateBlock(shared_ptr<ASTNodeList> node, BinaryenModuleRef &module);
BinaryenExpressionRef generateReturn(shared_ptr<ReturnNode> node, BinaryenModuleRef &module);
BinaryenExpressionRef generateFunctionDeclaration(
void generateFunctionDeclaration(
string identifier,
shared_ptr<FunctionDeclarationNode> node,
BinaryenModuleRef &module,
Expand Down
Loading

0 comments on commit cf40af7

Please sign in to comment.