Giter VIP home page Giter VIP logo

klong's People

Contributors

jdillenkofer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gmh5225

klong's Issues

variadic functions

Currently only external c functions can be declared as variadic.
Add support for klong functions that are variadic.

Windows test for.kg sometimes generates unreachable

; 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 system

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.

Generated executable segfaults

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;
}

Linking object files

Windows

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"

Unix

gcc simple.o

Option -no-pie is required if the target doesn't use position independet code as its relocation-model

arrays

Maybe something like this:

const i:[i64, 5] = [12, 5, 3, 0, 1];

structs

Syntax

pub struct Node {
    value: ptr<void>,
    next: ptr<Node>
}

fun next(n: Node) -> Node {
    return *(n.next);
}

Packed structs

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

Improve diagnostics

Use the SourceLocations structs in the ast nodes to improve the error messages.

enums

pub enum Result {
    SUCCESS,
    ERROR
}

pub fun test() -> Result {
    return Result::SUCCESS;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.