Giter Club home page Giter Club logo

amp_archive's People

Contributors

pzipper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

amp_archive's Issues

`export` modifier

Description

Currently, all functions and struct types are public by default. Instead, they should be private by default, only public if they are following the export keyword.

Use Cases

export func Main() {
    // ...
}

func MyPrivateMethod() {}

Basic math

Addition, subtraction, multiplication and division.

var my_var = 1 + 2;

Implement slice types

Implement a slice type for strings.

The layout for [u8] should be the same as the following C code:

typedef struct {
    char *ptr;
    size_t len;
} U8Slice;

That is, the pointer value followed by the number of items in the slice.

Struct types

struct MyStruct {
    member: i32,
}

func Main() {
    var my_struct = MyStruct .{
        member = 42,
    };
}

Bitwise Operators

Description

Implement the <<, >>, ! (bitwise not for integers), ^, & and | operators

Use Cases

No response

Allow multiple declarations of an external function

Description

Multiple declarations of an external declaration should be allowed, as long as they are the same.

Use Cases

// Module1.amp
func puts(str: ~const u8);
// Module2.amp
import "Module1.amp"; // other declaration not in scope, but still exists

func puts(str: ~const u8);

Prevent variable from being used before it's defined

Currently, a variable can be used like this:

func Print(buffer: []const u8);

func Main() {
    var my_var: []const u8;
    Print(my_var);
}

This is undefined behavior and we want to avoid it. Throw an error when this occurs.

`as` conversion operator

Description

We need an operator to convert between types. The value should stay the same semantically through the conversion, though the memory representation may not (for example my_float as i32 converts the float into an integer by flooring it).

Use Cases

var my_int: int = 42;
var my_i64: i64 = my_int as i64;
var my_i32: i32 = my_int as i32;
var my_str: []const u8 = "Hello, world!";
var my_ptr: ~const u8 = my_str as ~const u8;

Disallow modifiers for nothing

Current Behavior

Currently, just having modifiers followed by the end of the file or invalid syntax is allowed by the compiler:

export etst

Expected Behavior

Throw an error when this situation occurs.

Steps to Reproduce

No response

Host Environment

n/a

Disallow private types to be exposed

Current Behavior

For example,

// Test1.amp
import "Test2";

export func Main() {
    var my_struct = MyFunc();
}
// Test2.amp

// Private struct
struct MyStruct {
    member: i32,
}

// Public function exposes private type to any module that imports it
export func MyFunc() -> MyStruct {
    return MyStruct .{ member = 42 };
}

Expected Behavior

The compiler should throw an error when a situation like this occurs.

Steps to Reproduce

No response

Host Environment

  • OS: n/a
  • Architecture: n/a
  • Amp version: n/a

Keep `const` and `mut` pointer types?

~const T and ~mut T vs ~T for pointer types and values.

  • ~const T and ~mut T better describe whether or not a function is writing data to a pointer.
  • ~const T and ~mut T can provide compile time checks to prevent writing to a const pointer.
  • ~T is simpler to implement
  • ~const T can be explicitly casted to a ~mut T anyway, and ~T never requires a conversion

C/C++ Parity

C and C++ both have const value pointers, for example, const char* in C/C++ would be equivalent to ~const u8 in Amp.

Pointer arithmetic

Description

Implement arithmetic for raw pointer types (~mut T and ~const T).

Use Cases

var nullterm_str: ~const u8 = "Test";
var second_byte = *(nullterm_str + 1);

Dereference assignments

func printf(str: ~mut u8) -> i32;

func Main() {
    var my_str: ~mut u8 = "Hello, world!";
    *my_str = 0x66;
    printf(my_str); // => Bello, world!
}

Return statements

Implement return statements in the compiler. Currently, the test program is returning nothing, when it should be returning an i32.

Get this to compile:

func printf(format: ~const u8) -> i32;

func main() -> i32 {
    printf("Hello, world!");
    return 0;
}

Fix scoping

Current Behavior

if condition {
    var my_var: i32;
}
my_var = 42; // this code compiles

Expected Behavior

The above code should not compile as my_var should fall out of scope.

Steps to Reproduce

No response

Host Environment

  • OS: doesn't matter
  • Architecture: doesn't matter
  • Amp version: doesn't matter

Implement other integer types

Currently, only i32 and u8 are implemented. Let's implement the other integer types:

  • i8 to i64
  • u8 to u64
  • int and uint (pointer sized integers)

Implement other assignment operator syntax

Description

Writing my_var = my_var + 1 seems unnecessary, so the other operators should be implemented soon:

my_var += 8;
my_var -= 8;
my_var *= 8;
my_var /= 8;
my_var %= 8;
my_var &= 8;
my_var |= 8;
my_var ^= 8;
my_var <<= 8;
my_var >>= 8;

...note that first #43 must be implemented to go through with this feature.

Use Cases

No response

Labeled loops

Description

Loops should be possible to label, so they can be broken or continued from an inner loop.

I am unsure of the best syntax for this, we can go for the classic:

label: while true {}

Or we can go for a different syntax:

while:label true {}

Use Cases

var x = 0;
outer: while x < 100 {
    var y = 0;
    while y < 100 {
        if my_condition {
            break outer;
        }
        y = y + 1;
    }
    x = x + 1;
}

Slice and pointer indexing

Description

Implement the ptr[idx] operator for slices and pointers.

Use Cases

var slice = "Hello, world!";
var h = slice[0];
var e = slice[1];
// ...

You can also create a "sub-slice" of a slice or pointer by indexing with the .. operator:

var slice = ptr[0..len]; // converts a pointer into a slice
var hello = slice[0..5]; // gets the value of "Hello" from the above string slice

`export` struct fields

Description

Struct fields should be private by default, currently they are public and cannot be made private.

Structs with private members can only be constructed in the module they're declared in.

Use Cases

export struct MyStruct {
    export member1: i32,
    member2: i32,
}

Namespaces

Description

A namespace would allow different modules and libraries to separate code.

Use Cases

namespace Space;

func Space.Test() {
    // ...
}

func Main() {
    Space.Test();
}

`import` statements

Syntax

import "Std";

The compiler searches the following paths for the module with the given name, in order:

  • Std
  • Std.amp
  • Std/Main.amp

Local modules can be imported using the following syntax:

import "./MyModule";

The compiler searches the following paths for the module with the given name, in order:

  • ./MyModule
  • ./MyModule.amp
  • ./MyModule/Main.amp

Command Line

This would also introduce the -I compiler flag, which would add a path to search for modules in:

amp test.amp -I runtime

Given the above example, the compiler would search the following paths for the Std module (in order):

  • runtime/Std
  • runtime/Std.amp
  • runtime/Std/Main.amp

`while` loop statements

A standard while statement:

var i = 0;
while i < 10 {
    i = i + 1;
}
printf("%d", i); // => 10

With an optional condition:

while {
    Print("Going on forever...");
}

Assign field of struct reference

This currently doesn't compile when it should:

struct MyStruct {
    member: i32,
}

func MyStruct(self: ~mut MyStruct) {
    self.member = 42;
}

func Main() {
    var s = MyStruct .{ member = 0 };
    MyStruct(~mut s);
}

Link multiple Amp modules together through command line

It would be useful for the command line to allow multiple Amp files to be linked together, like so:

// test1.amp
func Print(str: []const u8);
func Test() {
    Print("Hello, world!");
}
// test2.amp
func Test();

func Main() {
    Test();
}

And then link them together with the command line:

amp test1.amp test2.amp -o test
./test

Comparison operators

The ==, !=, <, >, <= and >= operators.

var i = 0;
while i < 10 {
    i = i + 1;
}

Allow multiple private functions to have the same name

Currently, if two private functions exist with the same name, the following error message shows:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: DuplicateDefinition("__f_4Test")', src\codegen\func.rs:196:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This should be fixed by making private functions "anonymous" behind the scenes.

Code:

// Test.amp
import "Test2";

func Test() {}
// Test2.amp
func Test() {}

First-class functions

Essentially, functions should be possible to pass around as values:

func MyFunction() -> i32 {
    return 42;
}

export func Main() {
    var my_func: func() -> i32 = MyFunction;
}

Variables

var my_variable = "Hello, world!";
var my_variable: []const u8 = "Hello, world!";
var my_variable: []const u8;

Function calls as values

Allow function calls as values:

func GetStr() -> []const u8 {
    return "Hello, world!";
}

func Print(str: []const u8);

func Main() {
    Print(GetStr());
}

Integer values & types

Implement integer values and types.

Currently, we need i32 types and decimal integers. Already implemented in the scanner, the rest should be relatively simple.

Implement returning big values

Big values, such as slices, do not fit in registers and must be implemented differently than primitive values such as integers.

func GetStr() -> []const u8 {
    return "Hello, world!";
}

This should follow the C ABI for returning struct values.

Struct field accessing

let my_struct = MyStruct .{ member = 42 };
my_struct.member = 64;
printf("%d", my_struct.member);

Remove support for null-terminated strings

Inbuilt language support for null-terminated strings should no longer be supported.

Null-terminated strings should be implemented like so:

var my_str: ~const u8 = "Hello, world!\0" as ~const u8;

There should be a standard library type for null-terminated strings in the future.

Type aliases

Description

A user should be able to declare types under a specific name.

Use Cases

type MyBoolean = bool;

Support for external variadic arguments

Description

Though Amp will likely never support variadic arguments in Amp functions, C does. To provide more support for C interop, we should allow externally defined functions to use variadic arguments.

Use Cases

func printf(format: ~const u8, ...) -> i32;

String escapes

Currently, Amp does not parse escapes in strings, for example:

func printf(format: ~const u8) -> i32;

func main() {
    printf("Hello, world!\n");
}

Prints Hello, world!\n literally to the console.

Reference struct field

struct MyStruct {
    member: i32,
}

func InitMember(member: ~mut i32) {
    *member = 0;
}

func Main() {
    var my_struct = MyStruct .{};
    InitMember(~mut my_struct.member);
}

`if` statements

if true {
    // do something
} else if true {
    // do something
} else {
    // do something
}

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.