-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement foreign function interface
- Loading branch information
Showing
10 changed files
with
293 additions
and
93 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
false and true = [@and :with false :with true] | ||
true and true = [@and :with true :with true] | ||
true and false = [@and :with true :with false] | ||
false and false = [@and :with false :with false] | ||
|
||
false xor true = [@xor :with false :with true] | ||
true xor true = [@xor :with true :with true] | ||
true xor false = [@xor :with true :with false] | ||
false xor false = [@xor :with false :with false] | ||
|
||
[@cite :with | ||
[@strip :with | ||
|
||
autonomous AI agent | ||
look inside | ||
chatgpt prompt in a loop | ||
|
||
]] |
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 |
---|---|---|
|
@@ -14,6 +14,8 @@ expr: LB expr1 RB | |
| OPTION_KW | ||
| DEFAULT_KW | ||
| IS_KW | ||
| CALL | ||
| WITH_KW | ||
; | ||
|
||
expr1 | ||
|
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,18 @@ | ||
class Argument: | ||
def __init__(self, compute, ast): | ||
self._compute = compute | ||
self._ast = ast | ||
self._value = None | ||
self._computed = False | ||
|
||
async def compute(self): | ||
if self._computed: | ||
return self._value | ||
res = await self._compute() | ||
self._value = res | ||
self._ast = None # allow gc to collect AST | ||
self._computed = True | ||
return res | ||
|
||
async def get_ast(self): | ||
return self._ast |
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 @@ | ||
from functools import wraps | ||
import inspect | ||
|
||
|
||
def eager(fn): | ||
@wraps(fn) | ||
async def wrapper(*args, **kwargs): | ||
args_computed = [] | ||
kwargs_computed = {} | ||
for arg in args: | ||
args_computed.append(await arg.compute()) | ||
for name, arg in kwargs.items(): | ||
kwargs_computed[name] = await arg.compute() | ||
return await fn(*args_computed, **kwargs_computed) | ||
|
||
return wrapper | ||
|
||
|
||
def lazy(fn): | ||
return fn | ||
|
||
|
||
def foreign_function(eval_strategy=eager): | ||
def wrap(fn): | ||
@wraps(fn) | ||
@eval_strategy | ||
async def wrapper(*args, **kwargs): | ||
if inspect.iscoroutinefunction(fn): | ||
return await fn(*args, **kwargs) | ||
else: | ||
return fn(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return wrap |
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.