amp-lang / amp_archive Goto Github PK
View Code? Open in Web Editor NEWThe Amp programming language: a language designed for building high performance systems.
License: MIT License
The Amp programming language: a language designed for building high performance systems.
License: MIT License
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.
let my_struct = MyStruct .{ member = 42 };
my_struct.member = 64;
printf("%d", my_struct.member);
A user should be able to declare types under a specific name.
type MyBoolean = bool;
Multiple declarations of an external declaration should be allowed, as long as they are the same.
// 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);
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.
export struct MyStruct {
export member1: i32,
member2: i32,
}
if condition {
var my_var: i32;
}
my_var = 42; // this code compiles
The above code should not compile as my_var
should fall out of scope.
No response
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);
}
Implement skipping comments:
// Hello, world!
// ...
func printf(str: ~const u8) -> i32
Implement return value syntax for functions, with syntax like -> TYPE
The ==
, !=
, <
, >
, <=
and >=
operators.
var i = 0;
while i < 10 {
i = i + 1;
}
Currently, Amp doesn't support the ||
, &&
or !
operators when it should.
No response
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 MyStruct {
member: i32,
}
func Main() {
var my_struct = MyStruct .{
member = 42,
};
}
var my_var = 42;
my_var = 64;
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.
// Test.amp
import "Test2";
func Test() {}
// Test2.amp
func Test() {}
Implement arithmetic for raw pointer types (~mut T
and ~const T
).
var nullterm_str: ~const u8 = "Test";
var second_byte = *(nullterm_str + 1);
func printf(str: ~mut u8) -> i32;
func Main() {
var my_str: ~mut u8 = "Hello, world!";
*my_str = 0x66;
printf(my_str); // => Bello, world!
}
Addition, subtraction, multiplication and division.
var my_var = 1 + 2;
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 };
}
The compiler should throw an error when a situation like this occurs.
No response
func Print(str: []const u8);
func PrintRef(str: ~const []const u8) {
Print(*str);
}
func TestPrint(str: []const u8) {
Print(str);
}
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.
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
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
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.
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...");
}
Currently, just having modifiers followed by the end of the file or invalid syntax is allowed by the compiler:
export etst
Throw an error when this situation occurs.
No response
n/a
Implement the <<
, >>
, !
(bitwise not for integers), ^
, &
and |
operators
No response
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;
}
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).
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;
if true {
// do something
} else if true {
// do something
} else {
// do something
}
Implement the ptr[idx]
operator for slices and pointers.
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
Allow function calls as values:
func GetStr() -> []const u8 {
return "Hello, world!";
}
func Print(str: []const u8);
func Main() {
Print(GetStr());
}
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)struct MyStruct {
member: i32,
}
func InitMember(member: ~mut i32) {
*member = 0;
}
func Main() {
var my_struct = MyStruct .{};
InitMember(~mut my_struct.member);
}
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 {}
var x = 0;
outer: while x < 100 {
var y = 0;
while y < 100 {
if my_condition {
break outer;
}
y = y + 1;
}
x = x + 1;
}
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.
export func Main() {
// ...
}
func MyPrivateMethod() {}
export func Main() {}
... this invalid syntax is ignored by the compiler
Throw an error when invalid syntax is found.
No response
n/a
Implement integer values and types.
Currently, we need i32
types and decimal integers. Already implemented in the scanner, the rest should be relatively simple.
Essentially, functions should be possible to pass around as values:
func MyFunction() -> i32 {
return 42;
}
export func Main() {
var my_func: func() -> i32 = MyFunction;
}
func UseReference(ptr: ~const u8) {
// ...
}
let my_value: u8 = 0;
UseReference(~const my_value);
var my_variable = "Hello, world!";
var my_variable: []const u8 = "Hello, world!";
var my_variable: []const u8;
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.
No response
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
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.
func printf(format: ~const u8, ...) -> i32;
A namespace would allow different modules and libraries to separate code.
namespace Space;
func Space.Test() {
// ...
}
func Main() {
Space.Test();
}
Implement parsing 0xabcdef
, 0b10101010
and 0o01234567
literals.
~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 conversionC and C++ both have const value pointers, for example, const char*
in C/C++ would be equivalent to ~const u8
in Amp.
var my_bool_1: bool = true;
var my_bool_2: bool = false;
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.
Currently, the compile reads the path of the input file to the command line and panics if the file can't be read. This behavior should instead be replaced with displaying a diagnostic message.
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.