-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from frugurt-lang/import-system
Import system and scope manipulation
- Loading branch information
Showing
56 changed files
with
970 additions
and
685 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/target/ | ||
Cargo.lock | ||
Cargo.lock |
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
Binary file not shown.
Binary file not shown.
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
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,3 @@ | ||
# Scope manipulation | ||
|
||
Frugurt supports explicit scope capturing and subsequent manipulation. |
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,35 @@ | ||
# Scope keyword | ||
|
||
Scope keyword can be used in three constructs: | ||
|
||
- `scope()` - captures scope in which it was evaluated | ||
- `scope s { statements... }` - run statements in specified scope | ||
- `scope s { statements... expression }` - run statements in specified scope and return result of expression | ||
|
||
Example: | ||
|
||
```frugurt | ||
let f = fn () { | ||
let a = 5; | ||
let b = 3; | ||
scope() | ||
}; | ||
let scope_object = f(); | ||
print(scope_object.a); // 5 | ||
scope scope_object { | ||
// this statement is executed in the same scope as the body of function f ran | ||
// so the variables a and b are available here | ||
print(a * b); // 15 | ||
} | ||
scope_object.a = 10; // old variables can be re-assigned | ||
scope_object.c = 20; // new variables can be declared | ||
print(scope scope_object { | ||
let r = a + c; | ||
r * b | ||
}); // 90 | ||
``` |
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 @@ | ||
# Imports | ||
|
||
Other files can be imported into your code by using the `import` expression. | ||
Import expression returns the same scope object, which was mentioned in the previous chapter. | ||
|
||
Example: | ||
|
||
`main.fru` | ||
```frugurt | ||
let foo = import "foo.fru"; | ||
print(foo.f(1, 2)); // 3 | ||
// this is as badass as extremely stupid | ||
scope foo { | ||
let wow = 5; | ||
print(omg()); // 5 | ||
} | ||
``` | ||
|
||
`foo.fru` | ||
```frugurt | ||
let f = fn(x, y) { | ||
x + y | ||
}; | ||
let omg = fn() { wow }; | ||
``` |
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,2 @@ | ||
/target/ | ||
Cargo.lock |
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,11 @@ | ||
[package] | ||
name = "macros" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
syn = "2.0.66" | ||
quote = "1.0.36" |
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,27 @@ | ||
use proc_macro::TokenStream; | ||
use std::hash::{DefaultHasher, Hash, Hasher}; | ||
|
||
use quote::quote; | ||
use syn::LitStr; | ||
|
||
#[proc_macro] | ||
pub fn static_ident(input: TokenStream) -> TokenStream { | ||
let ast: LitStr = syn::parse(input).unwrap(); | ||
|
||
let ident = ast.value(); | ||
|
||
let mut hasher = DefaultHasher::new(); | ||
ident.hash(&mut hasher); | ||
let hashed_ident = hasher.finish(); | ||
|
||
quote! { | ||
{ | ||
#[ctor::ctor] | ||
fn ident_ctor() { | ||
Identifier::new(#ident); | ||
} | ||
Identifier::new_unchecked(#hashed_ident) | ||
} | ||
} | ||
.into() | ||
} |
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 @@ | ||
/.obsidian |
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,12 @@ | ||
{ | ||
"nodes":[ | ||
{"id":"813b32f2728a4a94","type":"group","x":-800,"y":-440,"width":640,"height":820,"label":"ordinary"}, | ||
{"id":"e6b12e213f195739","type":"group","x":-1420,"y":-440,"width":520,"height":500,"label":"critical"}, | ||
{"id":"02fe9a5b84622932","type":"text","text":"`fru_clone()` horror","x":-1400,"y":-414,"width":250,"height":79}, | ||
{"id":"cd9a0d2eaf046fee","type":"text","text":"implement Display for FruValue and fix for FruObject","x":-740,"y":-409,"width":250,"height":110}, | ||
{"id":"b18a8755b912d870","type":"text","text":"remove or fix BACKWARDS_MAP in Identifier (fails testing with some probability) !! probably already fixed","x":-740,"y":-260,"width":305,"height":170}, | ||
{"id":"8b8b22b9de04c759","type":"text","text":"automate wasm module for book","x":-740,"y":-60,"width":250,"height":60}, | ||
{"id":"4cbdbc839acac840","type":"text","text":"make set expression, not statement","x":-740,"y":40,"width":250,"height":60} | ||
], | ||
"edges":[] | ||
} |
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,25 @@ | ||
{ | ||
"nodes":[ | ||
{"id":"0c274527d795ce38","type":"group","x":-80,"y":600,"width":400,"height":400,"label":"OPTIMIZATIONS"}, | ||
{"id":"0e8289b07d6ca556","type":"group","x":-600,"y":600,"width":400,"height":380,"label":"CI/CD"}, | ||
{"id":"070a7b543247f7a2","type":"text","text":"simplified syntax for read-only properties","x":-290,"y":360,"width":250,"height":60}, | ||
{"id":"5d4e5bd937436926","type":"text","text":"computed properties","x":-640,"y":360,"width":250,"height":60,"color":"4"}, | ||
{"id":"1c18b7117da43e6e","type":"text","text":"\"evil\" features","x":-460,"y":-180,"width":250,"height":67,"color":"4"}, | ||
{"id":"41499d9f6eafdeec","type":"text","text":"trait polymorphism for native types","x":-460,"y":-40,"width":250,"height":60,"color":"4"}, | ||
{"id":"4ab66adbfddd4d15","type":"text","text":"scope manipulation features","x":-80,"y":-180,"width":250,"height":60,"color":"4"}, | ||
{"id":"aa2bea5c494cbddd","type":"text","text":"add traceback for errors","x":-160,"y":252,"width":250,"height":60}, | ||
{"id":"550b9c0e5c7cd03a","type":"text","text":"derivation and implicit derivation, and make them overridable (the main reason is equality of objects)","x":620,"y":300,"width":250,"height":160}, | ||
{"id":"97a68fbd25b52ede","type":"text","text":"destructuring let statements","x":800,"y":160,"width":250,"height":60}, | ||
{"id":"feb6594a9d261a54","type":"text","text":"modules and imports\n- [ ] tests\n- [x] import as expression","x":260,"y":-180,"width":250,"height":120,"color":"3"}, | ||
{"id":"18df0d00841f02bd","type":"text","text":"collections\n- [ ] list\n- [ ] set\n- [ ] map\n- [ ] tuple?","x":-80,"y":0,"width":250,"height":182,"color":"3"}, | ||
{"id":"b9c4b54397d2bf2d","type":"text","text":"macro for computing hash of ident in compile time","x":-40,"y":660,"width":250,"height":87,"color":"4"}, | ||
{"id":"b9e932828d9a3c13","type":"text","text":"make cd for windows and linux releases","x":-580,"y":640,"width":250,"height":60} | ||
], | ||
"edges":[ | ||
{"id":"4f43eea514ca8881","fromNode":"41499d9f6eafdeec","fromSide":"right","toNode":"4ab66adbfddd4d15","toSide":"left"}, | ||
{"id":"94361d23f182cbe8","fromNode":"4ab66adbfddd4d15","fromSide":"right","toNode":"feb6594a9d261a54","toSide":"left"}, | ||
{"id":"e3e0be30be175453","fromNode":"1c18b7117da43e6e","fromSide":"right","toNode":"4ab66adbfddd4d15","toSide":"left"}, | ||
{"id":"8706d0e0442108f4","fromNode":"41499d9f6eafdeec","fromSide":"right","toNode":"18df0d00841f02bd","toSide":"left"}, | ||
{"id":"10698732105d19f9","fromNode":"5d4e5bd937436926","fromSide":"right","toNode":"070a7b543247f7a2","toSide":"left"} | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"nodes":[ | ||
{"id":"1ac37b84ff817ecc","x":-733,"y":-605,"width":473,"height":165,"type":"text","text":"Issue 1:\nIf curried function mutates one of it's arguments, should subsequent calls receive mutated value or should it be cloned on call?"}, | ||
{"id":"901340d58aa31311","type":"text","text":"introduce new wrapper extensions like `wrap_ok`, `wrap_err`, `wrap_value`","x":-720,"y":-220,"width":250,"height":130} | ||
], | ||
"edges":[] | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::rc::Rc; | ||
|
||
use crate::interpreter::{ | ||
expression::FruExpression, identifier::Identifier, statement::FruStatement, | ||
value::function::FormalParameters, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RawStaticField { | ||
pub ident: Identifier, | ||
pub value: Option<Box<FruExpression>>, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RawMethod { | ||
pub is_static: bool, | ||
pub ident: Identifier, | ||
pub parameters: FormalParameters, | ||
pub body: Rc<FruStatement>, | ||
} |
Oops, something went wrong.