-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(git): merged pull request #32 from plume-lang/feat/fun-deps
Added support for functional dependencies
- Loading branch information
Showing
40 changed files
with
1,285 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
fn welcome<A extends to_str>(name: A) { | ||
fn welcome<A extends show>(name: A) { | ||
println("Hello, $name!") | ||
} | ||
|
||
println("test") | ||
welcome("world") | ||
welcome(42) | ||
welcome("user") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mut i = 0 | ||
|
||
while *i < 10000 { | ||
while *i < 100000 { | ||
println("test = $i") | ||
|
||
i += 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Functional dependencies help to normalize a relation between two types in | ||
// an extension. | ||
// For instance, the following code would not work if we tried: | ||
|
||
interface<Container, Elem> Indexable<Container, Elem> { | ||
fn get_index(container: Container, index: int): Option<Elem> | ||
} | ||
|
||
println("Hello, world!"[0]) | ||
|
||
// because the type of "Hello, world!" is str, and there is no way to infer | ||
// the type of the element of a str from the type of the str itself. In certain | ||
// cases, this could be possible but the compiler deterministically refuses to | ||
// do so. | ||
|
||
// Functional dependencies allow us to specify that the type of the element of a | ||
// container can be inferred from the container itself. For instance, we could | ||
// write: | ||
|
||
interface<Container, Elem> Indexable<Container, Elem> with Container { | ||
fn get_index(container: Container, index: int): Option<Elem> | ||
} | ||
|
||
println("Hello, world!"[0]) | ||
|
||
// This would work because the compiler can infer that the element of a str is | ||
// char. This is because the compiler knows that the only type that implements | ||
// Indexable<str, char> is str itself. | ||
|
||
// The syntax for functional dependencies is "with <Type>" where <Type> is the | ||
// type that the compiler can infer from the other types in the extension. The | ||
// type must be a type parameter of the interface, and it must be a type | ||
// parameter that is not used in the function signature of the interface. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from os import system | ||
from shutil import which | ||
import os.path | ||
from glob import glob | ||
import platform | ||
from sys import argv | ||
|
||
PLUME_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')) | ||
|
||
if (not which('clang')) and (not which('clang-cl')): | ||
print('Please install clang, clang-cl') | ||
exit(1) | ||
|
||
args = ['-std=c11', '-Wall', '-Wextra', '-shared'] | ||
ffi_files = glob(PLUME_PATH + '/standard/c-ffi/**/*.c', recursive=True) | ||
runtime_headers = PLUME_PATH + '/runtime/include' | ||
runtime_library = [PLUME_PATH + '/runtime/lib/libplume-library.a', 'curl'] | ||
|
||
output = PLUME_PATH + '/standard/native.plmc' | ||
|
||
compiler = 'clang' if which('clang') else 'clang-cl' | ||
|
||
res = system(f'{compiler} -I{PLUME_PATH}/runtime/include {PLUME_PATH}/standard/c-ffi/*.c {PLUME_PATH}/runtime/lib/libplume-library.a -lcurl -shared -o {output}') | ||
|
||
if res != 0: | ||
print('Failed to compile') | ||
exit(1) | ||
|
||
print('Compiled successfully') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from os import system | ||
from shutil import which | ||
import os.path | ||
from glob import glob | ||
import platform | ||
from sys import argv | ||
|
||
PLUME_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')) | ||
|
||
if (not which('clang')) and (not which('clang-cl')): | ||
print('Please install clang, clang-cl') | ||
exit(1) | ||
|
||
args = ['-std=c11', '-Wall', '-Wextra', '-shared'] | ||
runtime_headers = PLUME_PATH + '/runtime/include' | ||
|
||
output = PLUME_PATH + '/runtime/plume-vm.out' | ||
library_output = PLUME_PATH + '/runtime/lib/libplume-library.o' | ||
static_output = PLUME_PATH + '/runtime/lib/libplume-library.a' | ||
|
||
compiler = 'clang' if which('clang') else 'clang-cl' | ||
|
||
res = system(f'{compiler} -I{PLUME_PATH}/runtime/include {PLUME_PATH}/runtime/src/*.c {PLUME_PATH}/runtime/src/core/*.c -o {output} -g3') | ||
|
||
library = system(f'{compiler} -o {library_output} -I{PLUME_PATH}/runtime/include {PLUME_PATH}/runtime/src/*.c {PLUME_PATH}/runtime/src/core/*.c -fPIC') | ||
# static_library = system(f'ar r {static_output} {library_output}') | ||
|
||
# print(library, static_library, res) | ||
|
||
if res != 0: | ||
print('Failed to compile') | ||
exit(1) | ||
|
||
print('Compiled successfully') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.