jdillenkofer / klong Goto Github PK
View Code? Open in Web Editor NEWCompiler for klong, a small procedural language.
License: MIT License
Compiler for klong, a small procedural language.
License: MIT License
Currently only external c functions can be declared as variadic.
Add support for klong functions that are variadic.
; ModuleID = 'for.kg'
source_filename = "for.kg"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-win32"
define i64 @main() {
entry:
%0 = alloca i64
store i64 0, i64* %0
br label %forCond
forCond: ; preds = %mergeBranch, %entry
%1 = load i64, i64* %0
%2 = icmp slt i64 %1, 5
br i1 %2, label %forBody, label %mergeFor
forBody: ; preds = %forCond
%3 = load i64, i64* %0
%4 = icmp sgt i64 %3, 5
br i1 %4, label %thenBranch, label %mergeBranch
mergeFor: ; preds = %forCond
ret i64 0
thenBranch: ; preds = %forBody
ret i64 1
br label %mergeBranch
mergeBranch: ; preds = %forBody, %thenBranch
unreachable
%5 = load i64, i64* %0
%6 = add i64 %5, 1
store i64 %6, i64* %0
br label %forCond
}
; ModuleID = 'for.kg'
source_filename = "for.kg"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-win32"
define i64 @main() {
entry:
%0 = alloca i64
store i64 0, i64* %0
br label %forCond
forCond: ; preds = %mergeBranch, %entry
%1 = load i64, i64* %0
%2 = icmp slt i64 %1, 5
br i1 %2, label %forBody, label %mergeFor
forBody: ; preds = %forCond
%3 = load i64, i64* %0
%4 = icmp sgt i64 %3, 5
br i1 %4, label %thenBranch, label %mergeBranch
mergeFor: ; preds = %forCond
ret i64 0
thenBranch: ; preds = %forBody
ret i64 1
br label %mergeBranch
mergeBranch: ; preds = %forBody, %thenBranch
%5 = load i64, i64* %0
%6 = add i64 %5, 1
store i64 %6, i64* %0
br label %forCond
}
import "somepath/to/klongfile.kg";
Note: the import path can be relative to the current filepath the import stmt is in
If we hit a import stmt during parsing we have to parse the imported file first.
Maybe use std::future. Create a job system, that uses the dependency graph to run the parsing on multiple threads. Merge the errors, if there are any, otherwise go ahead and add external declarations to the module trees. Generate objectfiles and call linker on all generated objectfiles.
The generated executable from this klong program segfaults.
It has something to do with returning twice and calling a function before.
pub fun main() -> i64 {
return test();
return 2;
}
fun test() -> i64 {
return 1;
}
pub fun main() -> i64 {
return 1;
}
terminate called after throwing an instance of 'klong::LexerException'
what(): Illegal char sequence encountered.
Syntax:
cast<>
Path:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64
Command:
link.exe /NOLOGO /MANIFEST /SUBSYSTEM:CONSOLE /MACHINE:x64 /DEFAULTLIB:libcmt simple.o /OUT:out.exe /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\lib\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\ucrt\x64"
gcc simple.o
Option -no-pie
is required if the target doesn't use position independet code as its relocation-model
Maybe something like this:
const i:[i64, 5] = [12, 5, 3, 0, 1];
void LLVMEmitter::destroy() {
if (_initialized) {
// TODO: this segfaults sometimes!
// llvm::llvm_shutdown();
_initialized = false;
}
}
Syntax
pub struct Node {
value: ptr<void>,
next: ptr<Node>
}
fun next(n: Node) -> Node {
return *(n.next);
}
The travis-ci build is failing on ubuntu:
perhaps std::filesystem::parent_path() is not supported (c++17)
A packed struct should emit a type without padding between members.
Example:
pub packed struct Packed {
v1: i8,
v2: i32
}
pub struct NotPacked {
v1: i8,
v2: i32
}
sizeof(Packed) == 5
sizeof(NotPacked) == 8
Use the SourceLocations structs in the ast nodes to improve the error messages.
$./klong -h
No input file!
Relative imports seem to not work
// FIX THIS >>> CANT DIRECTLY ACCESS CALL RESULT <<<
if (testPassByPtr(&node).value != 0) {
return 1;
}
Fails with both unions and structs passed byVal or byPtr.
pub enum Result {
SUCCESS,
ERROR
}
pub fun test() -> Result {
return Result::SUCCESS;
}
struct Test {
a: i32,
b: i32
}
named:
{
a: 2,
b: 3
}
unnamed:
{
2, 3
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.