feat: Implement input/output (ask built-in function)

This commit is contained in:
Alvin
2025-07-22 18:17:15 +02:00
parent 981147f440
commit 8e305629b8
2 changed files with 13 additions and 1 deletions

2
examples/io.fem Normal file
View File

@@ -0,0 +1,2 @@
name is ask("What's your name, femboy? ")
UwU Boy "Hello, " + name + "!"

View File

@@ -2,7 +2,12 @@ class Interpreter:
def __init__(self, ast): def __init__(self, ast):
self.ast = ast self.ast = ast
self.scope_stack = [{}] self.scope_stack = [{}]
self.functions = {} self.functions = {
"ask": self._ask_builtin
}
def _ask_builtin(self, prompt):
return input(prompt)
@property @property
def current_scope(self): def current_scope(self):
@@ -143,6 +148,11 @@ class Interpreter:
# Evaluate arguments # Evaluate arguments
evaluated_arguments = [self.visit(arg) for arg in node.arguments] evaluated_arguments = [self.visit(arg) for arg in node.arguments]
# Check if it's a built-in function
if callable(func_info):
return func_info(*evaluated_arguments)
# Existing logic for user-defined functions
# Create a new scope for the function call # Create a new scope for the function call
new_scope = {} new_scope = {}
for i, param_name in enumerate(func_info['parameters']): for i, param_name in enumerate(func_info['parameters']):