-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caa0c01
commit c0dc819
Showing
17 changed files
with
208 additions
and
31 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ DONE: | |
run | ||
length | ||
randint | ||
TODO: | ||
to_str | ||
to_int | ||
to_int | ||
use python code | ||
TODO: | ||
make builtins easier |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# run("examples/eval") | ||
|
||
var test_1 = `input("What's your name? ")` | ||
var name = eval(test_1) | ||
print(name) | ||
|
||
var test_2 = ` | ||
print("test_2") | ||
` | ||
print("\n") | ||
eval(test_2) | ||
|
||
var test_3 = ` | ||
for i in range(10): | ||
print(f"hello, test_3! {i}") | ||
` | ||
print("\n") | ||
eval(test_3) | ||
|
||
var test_4 = ` | ||
def test_4(): | ||
print("Test 4 is wrapped in a function!") | ||
test_4() | ||
` | ||
print("\n") | ||
eval(test_4) |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# *################### | ||
# * IMPORTS | ||
# *################### | ||
|
||
from values.value_string import String | ||
from runtime_results import RTResult | ||
from errors import RTError | ||
|
||
|
||
# *################### | ||
# * PYTHON EVAL | ||
# *################### | ||
|
||
def execute_pyeval_func(self, exec_ctx): | ||
code = exec_ctx.symbol_table.get("code") | ||
try: | ||
# code = compile(code.value, "script", "exec") | ||
try: | ||
response = eval(code.value) | ||
except: | ||
response = exec(code.value) | ||
return RTResult().success(String(response)) | ||
except Exception as e: | ||
return RTResult().failure(RTError( | ||
self.pos_start, self.pos_end, | ||
f"The code could not be evaluated. \n\n{e}", | ||
exec_ctx | ||
)) |
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 @@ | ||
# *################### | ||
# * IMPORTS | ||
# *################### | ||
|
||
from values.value_string import String | ||
from values.value_number import Number | ||
from runtime_results import RTResult | ||
from errors import RTError | ||
|
||
|
||
# *################### | ||
# * TO INTEGER | ||
# *################### | ||
|
||
def execute_to_int_func(self, exec_ctx): | ||
value = exec_ctx.symbol_table.get("value") | ||
|
||
if not isinstance(value, String): | ||
return RTResult().failure(RTError( | ||
self.pos_start, self.pos_end, | ||
f"The first argument must be a string.", | ||
exec_ctx | ||
)) | ||
|
||
return RTResult().success(Number(int(value.value))) |
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,15 @@ | ||
# *################### | ||
# * IMPORTS | ||
# *################### | ||
|
||
from values.value_string import String | ||
from runtime_results import RTResult | ||
|
||
|
||
# *################### | ||
# * TO STRING | ||
# *################### | ||
|
||
def execute_to_str_func(self, exec_ctx): | ||
value = exec_ctx.symbol_table.get("value") | ||
return RTResult().success(String(str(value))) |
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import run as whython | ||
|
||
while True: | ||
text = input("whython > ") | ||
if text.strip() == "": continue | ||
result, error = whython.run("<stdin>", text) | ||
def main(): | ||
while True: | ||
text = input("whython > ") | ||
if text.strip() == "": continue | ||
result, error = whython.run("<stdin>", text) | ||
|
||
if error: print(error.as_string()) | ||
elif result: | ||
if len(result.elements) == 1: | ||
if error: print(error.as_string()) | ||
elif result: | ||
for element in result.elements: | ||
try: | ||
if element.value is not None: | ||
print(element) | ||
except AttributeError: | ||
pass | ||
else: | ||
print(repr(result)) | ||
|
||
if __name__ == "__main__": | ||
main() |
Binary file modified
BIN
+1.92 KB
(120%)
whython/values/__pycache__/value_builtinfunc.cpython-39.pyc
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