Skip to content

Commit 5abc72b

Browse files
committed
Better print() function
1 parent 7ed3906 commit 5abc72b

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

ZeroLang.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from operator import index
2-
3-
from jinja2.runtime import new_context
4-
from numba.typed.listobject import new_list
51
import os
62

73
TT_FLOAT = 'FLOAT'
@@ -1206,6 +1202,9 @@ def multed_by(self, other):
12061202
else:
12071203
return None, Value.illegal_operation(self, other)
12081204

1205+
def __str__(self):
1206+
return f'{",".join([str(x) for x in self.elements])}'
1207+
12091208
def __repr__(self):
12101209
return f'[{",".join([str(x) for x in self.elements])}]'
12111210

@@ -1414,7 +1413,6 @@ def populate_args(self, arg_names, args, exec_ctx):
14141413
for i in range(len(args)):
14151414
arg_name = arg_names[i]
14161415
arg_value = args[i]
1417-
# maybe newcontext?
14181416
arg_value.set_context(exec_ctx)
14191417
exec_ctx.symbol_table.set(arg_name, arg_value)
14201418

@@ -1830,19 +1828,15 @@ def visit_CallNode(self, node, context):
18301828
res = RTResult()
18311829
args = []
18321830

1833-
# 不再 copy(),保留原函数引用
18341831
value_to_call = res.register(self.visit(node.node_to_call, context))
18351832
if res.error: return res
18361833
value_to_call.set_pos(node.pos_start, node.pos_end).set_context(context)
18371834

18381835
for arg_node in node.arg_nodes:
18391836
args.append(res.register(self.visit(arg_node, context)))
18401837
if res.error: return res
1841-
18421838
return_value = res.register(value_to_call.execute(args))
18431839
if res.error: return res
1844-
1845-
# 返回值可以 copy,因为它是新创建的,不会影响上下文
18461840
return res.success(return_value.copy().set_pos(node.pos_start, node.pos_end).set_context(context))
18471841

18481842

97.8 KB
Binary file not shown.

shell.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import ZeroLang
2-
import sys
3-
4-
5-
6-
72
while True:
83

94
text = input("ZeroLang (Debug) >")

0 commit comments

Comments
 (0)