koatl 0.1.40__tar.gz → 0.1.41__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. {koatl-0.1.40 → koatl-0.1.41}/Cargo.lock +1 -1
  2. {koatl-0.1.40 → koatl-0.1.41}/PKG-INFO +1 -1
  3. {koatl-0.1.40 → koatl-0.1.41}/koatl/Cargo.toml +1 -1
  4. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/parser/src/lib.rs +3 -0
  5. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/transform.rs +66 -81
  6. {koatl-0.1.40 → koatl-0.1.41}/Cargo.toml +0 -0
  7. {koatl-0.1.40 → koatl-0.1.41}/README.md +0 -0
  8. {koatl-0.1.40 → koatl-0.1.41}/koatl/.github/workflows/CI.yml +0 -0
  9. {koatl-0.1.40 → koatl-0.1.41}/koatl/.gitignore +0 -0
  10. {koatl-0.1.40 → koatl-0.1.41}/koatl/LICENSE +0 -0
  11. {koatl-0.1.40 → koatl-0.1.41}/koatl/README.md +0 -0
  12. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/__init__.py +0 -0
  13. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/__main__.py +0 -0
  14. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/cli.py +0 -0
  15. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/notebook/__init__.py +0 -0
  16. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/notebook/magic.py +0 -0
  17. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/prelude/__init__.tl +0 -0
  18. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/runtime/__init__.py +0 -0
  19. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/runtime/meta_finder.py +0 -0
  20. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/runtime/record.py +0 -0
  21. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/runtime/vattr.py +0 -0
  22. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/alg/__init__.tl +0 -0
  23. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/alg/async.tl +0 -0
  24. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/alg/base.tl +0 -0
  25. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/alg/do.tl +0 -0
  26. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/alg/env.tl +0 -0
  27. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/alg/memo.tl +0 -0
  28. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/alg/result.tl +0 -0
  29. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/data/__init__.tl +0 -0
  30. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/data/list.tl +0 -0
  31. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/data/record.tl +0 -0
  32. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/ext.tl +0 -0
  33. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/io.tl +0 -0
  34. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/iter.tl +0 -0
  35. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/lazy_module.tl +0 -0
  36. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/re.tl +0 -0
  37. {koatl-0.1.40 → koatl-0.1.41}/koatl/python/koatl/std/trait.py +0 -0
  38. {koatl-0.1.40 → koatl-0.1.41}/koatl/requirements.txt +0 -0
  39. {koatl-0.1.40 → koatl-0.1.41}/koatl/src/emit_py.rs +0 -0
  40. {koatl-0.1.40 → koatl-0.1.41}/koatl/src/lib.rs +0 -0
  41. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/containers.tl +0 -0
  42. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/data.txt +0 -0
  43. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/decorators.tl +0 -0
  44. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/destructure-for-and-fn.tl +0 -0
  45. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/destructure.tl +0 -0
  46. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/escape_ident.tl +0 -0
  47. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/fstr.tl +0 -0
  48. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/functions.tl +0 -0
  49. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/generator.tl +0 -0
  50. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/if_expr.tl +0 -0
  51. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/loops.tl +0 -0
  52. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/match.tl +0 -0
  53. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/nary-list.tl +0 -0
  54. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/placeholder.tl +0 -0
  55. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/precedence.tl +0 -0
  56. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/scopes.tl +0 -0
  57. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/semantic_whitespace.tl +0 -0
  58. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/short_circuit.tl +0 -0
  59. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/base/with.tl +0 -0
  60. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/async.tl +0 -0
  61. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/aug_assign.tl +0 -0
  62. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/coal.tl +0 -0
  63. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/env.tl +0 -0
  64. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/imports.tl +0 -0
  65. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/iterables.tl +0 -0
  66. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/list.tl +0 -0
  67. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/memo.tl +0 -0
  68. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/record.tl +0 -0
  69. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/result.tl +0 -0
  70. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/slice.tl +0 -0
  71. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/try.tl +0 -0
  72. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/prelude/virtual.tl +0 -0
  73. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/util/__init__.py +0 -0
  74. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/util/module0.tl +0 -0
  75. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/util/module1.tl +0 -0
  76. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/e2e/util/module2.tl +0 -0
  77. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/parse/arith.tl +0 -0
  78. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/parse/assign.tl +0 -0
  79. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/parse/block-comments.tl +0 -0
  80. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/parse/deco.tl +0 -0
  81. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/parse/func.tl +0 -0
  82. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/parse/matches.tl +0 -0
  83. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/test_e2e.py +0 -0
  84. {koatl-0.1.40 → koatl-0.1.41}/koatl/tests/test_parse.py +0 -0
  85. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/Cargo.toml +0 -0
  86. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/parser/Cargo.toml +0 -0
  87. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/parser/src/ast.rs +0 -0
  88. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/parser/src/lexer.rs +0 -0
  89. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/parser/src/parser.rs +0 -0
  90. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/parser/src/util.rs +0 -0
  91. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/inference.rs +0 -0
  92. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/lib.rs +0 -0
  93. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/main.rs +0 -0
  94. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/parse_timer.rs +0 -0
  95. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/parser.rs +0 -0
  96. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/py/ast.rs +0 -0
  97. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/py/emit.rs +0 -0
  98. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/py/mod.rs +0 -0
  99. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/py/util.rs +0 -0
  100. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/resolve_scopes.rs +0 -0
  101. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/types.rs +0 -0
  102. {koatl-0.1.40 → koatl-0.1.41}/koatl-core/src/util.rs +0 -0
  103. {koatl-0.1.40 → koatl-0.1.41}/pyproject.toml +0 -0
  104. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/__init__.py +0 -0
  105. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/__main__.py +0 -0
  106. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/cli.py +0 -0
  107. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/notebook/__init__.py +0 -0
  108. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/notebook/magic.py +0 -0
  109. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/prelude/__init__.tl +0 -0
  110. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/runtime/__init__.py +0 -0
  111. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/runtime/meta_finder.py +0 -0
  112. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/runtime/record.py +0 -0
  113. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/runtime/vattr.py +0 -0
  114. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/alg/__init__.tl +0 -0
  115. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/alg/async.tl +0 -0
  116. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/alg/base.tl +0 -0
  117. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/alg/do.tl +0 -0
  118. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/alg/env.tl +0 -0
  119. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/alg/memo.tl +0 -0
  120. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/alg/result.tl +0 -0
  121. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/data/__init__.tl +0 -0
  122. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/data/list.tl +0 -0
  123. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/data/record.tl +0 -0
  124. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/ext.tl +0 -0
  125. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/io.tl +0 -0
  126. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/iter.tl +0 -0
  127. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/lazy_module.tl +0 -0
  128. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/re.tl +0 -0
  129. {koatl-0.1.40 → koatl-0.1.41}/python/koatl/std/trait.py +0 -0
@@ -99,7 +99,7 @@ checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
99
99
 
100
100
  [[package]]
101
101
  name = "koatl"
102
- version = "0.1.40"
102
+ version = "0.1.41"
103
103
  dependencies = [
104
104
  "ariadne",
105
105
  "koatl-core",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koatl
3
- Version: 0.1.40
3
+ Version: 0.1.41
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "koatl"
3
- version = "0.1.40"
3
+ version = "0.1.41"
4
4
  edition = "2021"
5
5
 
6
6
  [lib]
@@ -5,3 +5,6 @@ pub mod util;
5
5
 
6
6
  pub use lexer::{Token, TokenList, tokenize};
7
7
  pub use parser::*;
8
+
9
+ pub use chumsky::span::SimpleSpan;
10
+ pub use chumsky::span::Span;
@@ -177,14 +177,7 @@ impl<'src> PyBlock<'src> {
177
177
  }
178
178
  }
179
179
 
180
- enum PyBlockExpr<'src> {
181
- Nothing,
182
- Never,
183
- Expr(SPyExpr<'src>),
184
- }
185
-
186
180
  type SPyExprWithPre<'src> = WithPre<'src, SPyExpr<'src>>;
187
- type PyBlockExprWithPre<'src> = WithPre<'src, PyBlockExpr<'src>>;
188
181
 
189
182
  trait SPyExprWithPreExt<'src> {
190
183
  fn drop_expr<'ast>(self, ctx: &mut TlCtx<'src, 'ast>) -> PyBlock<'src>;
@@ -206,27 +199,6 @@ impl<'src> SPyExprWithPreExt<'src> for SPyExprWithPre<'src> {
206
199
  }
207
200
  }
208
201
 
209
- impl<'src> SPyExprWithPreExt<'src> for PyBlockExprWithPre<'src> {
210
- fn drop_expr<'ast>(self, ctx: &mut TlCtx<'src, 'ast>) -> PyBlock<'src> {
211
- if let PyBlockExpr::Expr(expr) = self.value {
212
- SPyExprWithPre {
213
- pre: self.pre,
214
- value: expr,
215
- }
216
- .drop_expr(ctx)
217
- } else {
218
- self.pre
219
- }
220
- }
221
- }
222
-
223
- trait BlockExt<'src> {
224
- fn transform<'ast>(
225
- &'ast self,
226
- ctx: &mut TlCtx<'src, 'ast>,
227
- ) -> TlResult<PyBlockExprWithPre<'src>>;
228
- }
229
-
230
202
  fn simple_err(msg: impl Into<String>, span: Span) -> TlErrs {
231
203
  TlErrBuilder::new().message(msg.into()).span(span).build()
232
204
  }
@@ -254,15 +226,26 @@ fn deduplicate<'src, 'ast>(
254
226
  Ok(SPyExprWithPre { value: expr, pre })
255
227
  }
256
228
 
229
+ trait BlockExt<'src> {
230
+ fn transform<'ast>(
231
+ &'ast self,
232
+ ctx: &mut TlCtx<'src, 'ast>,
233
+ span: &Span,
234
+ ) -> TlResult<SPyExprWithPre<'src>>;
235
+ }
236
+
257
237
  impl<'src> BlockExt<'src> for [Indirect<SStmt<'src>>] {
258
238
  fn transform<'ast>(
259
239
  &'ast self,
260
240
  ctx: &mut TlCtx<'src, 'ast>,
261
- ) -> TlResult<PyBlockExprWithPre<'src>> {
241
+ span: &Span,
242
+ ) -> TlResult<SPyExprWithPre<'src>> {
243
+ let mut value = (PyExpr::Literal(PyLiteral::None), *span).into();
244
+
262
245
  if self.is_empty() {
263
- return Ok(WithPre {
246
+ return Ok(SPyExprWithPre {
264
247
  pre: PyBlock::new(),
265
- value: PyBlockExpr::Nothing,
248
+ value,
266
249
  });
267
250
  }
268
251
 
@@ -289,22 +272,17 @@ impl<'src> BlockExt<'src> for [Indirect<SStmt<'src>>] {
289
272
  }
290
273
 
291
274
  let final_stmt = iter.next().unwrap();
292
- let mut value = PyBlockExpr::Nothing;
293
275
 
294
276
  match &final_stmt.value {
295
277
  Stmt::Expr(expr) => match expr.transform(ctx) {
296
278
  Ok(expr_with_aux) => {
297
- value = PyBlockExpr::Expr(pre.bind(expr_with_aux));
279
+ value = pre.bind(expr_with_aux);
298
280
  }
299
281
  Err(e) => {
300
282
  errs.extend(e.0);
301
283
  ok = false;
302
284
  }
303
285
  },
304
- Stmt::Raise(..) | Stmt::Return(..) | Stmt::Break | Stmt::Continue => {
305
- handle_stmt(final_stmt);
306
- value = PyBlockExpr::Never;
307
- }
308
286
  _ => {
309
287
  handle_stmt(final_stmt);
310
288
  }
@@ -1031,7 +1009,7 @@ fn make_arglist<'src, 'ast>(
1031
1009
  }
1032
1010
 
1033
1011
  struct PartialPyFnDef<'a> {
1034
- body: PyBlock<'a>,
1012
+ body: SPyExprWithPre<'a>,
1035
1013
  decorators: PyDecorators<'a>,
1036
1014
  args: Vec<PyArgDefItem<'a>>,
1037
1015
  async_: bool,
@@ -1041,7 +1019,7 @@ enum FnDef<'src, 'ast> {
1041
1019
  /**
1042
1020
  * Args, body, is_do, is_async
1043
1021
  */
1044
- PyFnDef(Vec<PyArgDefItem<'src>>, PyBlock<'src>, bool, bool),
1022
+ PyFnDef(Vec<PyArgDefItem<'src>>, SPyExprWithPre<'src>, bool, bool),
1045
1023
 
1046
1024
  // Expr::Fn, args, body
1047
1025
  TlFnDef(
@@ -1060,7 +1038,8 @@ fn prepare_py_fn<'src, 'ast>(
1060
1038
  span: &Span,
1061
1039
  ) -> TlResult<WithPre<'src, PartialPyFnDef<'src>>> {
1062
1040
  let mut pre = PyBlock::new();
1063
- let mut py_body = PyBlock::new();
1041
+ let mut py_body_pre = PyBlock::new();
1042
+ let py_body_expr: SPyExpr;
1064
1043
  let mut decorators = PyDecorators(vec![]);
1065
1044
 
1066
1045
  let a = PyAstBuilder::new(*span);
@@ -1079,7 +1058,8 @@ fn prepare_py_fn<'src, 'ast>(
1079
1058
  decorators.push(a.tl_builtin("do"));
1080
1059
  }
1081
1060
 
1082
- py_body.extend(body);
1061
+ py_body_pre.extend(body.pre);
1062
+ py_body_expr = body.value;
1083
1063
  }
1084
1064
  FnDef::TlFnDef(expr, arglist, body) => {
1085
1065
  let fn_info = ctx.fn_info(expr)?;
@@ -1093,7 +1073,7 @@ fn prepare_py_fn<'src, 'ast>(
1093
1073
  args = args_;
1094
1074
 
1095
1075
  pre.extend(arg_pre);
1096
- py_body.extend(post);
1076
+ py_body_pre.extend(post);
1097
1077
 
1098
1078
  let body = body.transform(ctx)?;
1099
1079
 
@@ -1107,16 +1087,18 @@ fn prepare_py_fn<'src, 'ast>(
1107
1087
 
1108
1088
  let (py_bindings, _, _) = py_fn_bindings(ctx, fn_info, *span)?;
1109
1089
 
1110
- py_body.extend(py_bindings);
1111
- py_body.extend(body.pre);
1112
- py_body.push(a.return_(body.value));
1090
+ py_body_pre.extend(py_bindings);
1091
+ py_body_expr = py_body_pre.bind(body);
1113
1092
  }
1114
1093
  }
1115
1094
 
1116
1095
  Ok(WithPre {
1117
1096
  pre,
1118
1097
  value: PartialPyFnDef {
1119
- body: py_body,
1098
+ body: WithPre {
1099
+ pre: py_body_pre,
1100
+ value: py_body_expr,
1101
+ },
1120
1102
  args,
1121
1103
  decorators,
1122
1104
  async_,
@@ -1138,34 +1120,34 @@ fn make_fn_exp<'src, 'ast>(
1138
1120
  } = pre.bind(prepare_py_fn(ctx, def, span)?);
1139
1121
  let a = PyAstBuilder::new(*span);
1140
1122
 
1141
- if body.0.len() == 1 && !async_ {
1123
+ if body.pre.is_empty() && !async_ {
1142
1124
  // TODO maybe refactor prepare_py_fn to return body_stmts as PyExprWithPre instead of pattern matching Return
1143
1125
 
1144
- if let PyStmt::Return(_) = &body.0[0].value {
1145
- let PyStmt::Return(expr) = body.0.into_iter().next().unwrap().value else {
1146
- return Err(simple_err(
1147
- "Internal error: Expected a single return statement in function body",
1148
- *span,
1149
- ));
1150
- };
1151
-
1152
- let mut inner = a.lambda(args, expr);
1126
+ let mut inner = a.lambda(args, body.value);
1153
1127
 
1154
- for deco in decorators.0.into_iter().rev() {
1155
- inner = a.call(deco, vec![a.call_arg(inner)]);
1156
- }
1157
-
1158
- return Ok(SPyExprWithPre { value: inner, pre });
1128
+ for deco in decorators.0.into_iter().rev() {
1129
+ inner = a.call(deco, vec![a.call_arg(inner)]);
1159
1130
  }
1131
+
1132
+ return Ok(SPyExprWithPre {
1133
+ pre: PyBlock::new(),
1134
+ value: inner,
1135
+ });
1160
1136
  }
1161
1137
 
1138
+ let body = {
1139
+ let mut block = body.pre;
1140
+ block.push(a.return_(body.value));
1141
+ block
1142
+ };
1143
+
1162
1144
  let name = ctx.create_aux_var("fnexp", span.start);
1163
1145
  pre.push(
1164
1146
  (
1165
1147
  PyStmt::FnDef(PyFnDef {
1166
1148
  name: name.clone().into(),
1167
1149
  args: args,
1168
- body,
1150
+ body: body,
1169
1151
  decorators: decorators,
1170
1152
  async_,
1171
1153
  }),
@@ -1188,6 +1170,7 @@ fn make_fn_def<'src, 'ast>(
1188
1170
  span: &Span,
1189
1171
  ) -> TlResult<PyBlock<'src>> {
1190
1172
  let mut pre = PyBlock::new();
1173
+ let a = PyAstBuilder::new(*span);
1191
1174
  let PartialPyFnDef {
1192
1175
  body,
1193
1176
  args,
@@ -1197,6 +1180,12 @@ fn make_fn_def<'src, 'ast>(
1197
1180
 
1198
1181
  decorators.0.extend(inner_decorators.0);
1199
1182
 
1183
+ let body = {
1184
+ let mut block = body.pre;
1185
+ block.push(a.return_(body.value));
1186
+ block
1187
+ };
1188
+
1200
1189
  pre.push(
1201
1190
  (
1202
1191
  PyStmt::FnDef(PyFnDef {
@@ -1385,14 +1374,12 @@ fn transform_postfix_expr<'src, 'ast>(
1385
1374
  let py_expr = make_expr(ctx, a.load_ident(arg_name.clone()))?;
1386
1375
 
1387
1376
  let fn_info = ctx.mapped_fninfo.get(&expr.into()).unwrap();
1388
- let mut fn_body = py_expr.pre;
1389
- fn_body.push(a.return_(py_expr.value));
1390
1377
 
1391
1378
  let inner_fn = pre.bind(make_fn_exp(
1392
1379
  ctx,
1393
1380
  FnDef::PyFnDef(
1394
1381
  vec![a.arg_def(arg_name, None)],
1395
- fn_body,
1382
+ py_expr,
1396
1383
  false,
1397
1384
  fn_info.is_async,
1398
1385
  ),
@@ -1946,14 +1933,7 @@ impl<'src, 'ast> SExprExt<'src, 'ast> for SExpr<'src> {
1946
1933
  else_block.as_ref().map(|x| x.as_ref()),
1947
1934
  &span,
1948
1935
  )?),
1949
- Expr::Block(block) => {
1950
- let block = pre.bind(block.transform(ctx)?);
1951
-
1952
- match block {
1953
- PyBlockExpr::Expr(expr) => expr,
1954
- PyBlockExpr::Nothing | PyBlockExpr::Never => a.none(),
1955
- }
1956
- }
1936
+ Expr::Block(block) => pre.bind(block.transform(ctx, &span)?),
1957
1937
  Expr::Match(subject, cases) => pre
1958
1938
  .bind(transform_match_expr(ctx, MatchSubject::Tl(subject), cases, true, &span)?.0),
1959
1939
  Expr::Matches(subject, pattern) => {
@@ -2088,12 +2068,19 @@ impl<'src, 'ast> SExprExt<'src, 'ast> for SExpr<'src> {
2088
2068
  }
2089
2069
 
2090
2070
  py_body.extend(py_bindings);
2091
- py_body.extend(py_expr.pre);
2092
- py_body.push(a.return_(py_expr.value));
2071
+ let py_expr = py_body.bind(py_expr);
2093
2072
 
2094
2073
  let callback = pre.bind(make_fn_exp(
2095
2074
  ctx,
2096
- FnDef::PyFnDef(vec![], py_body, memo_captures.is_do, memo_captures.is_async),
2075
+ FnDef::PyFnDef(
2076
+ vec![],
2077
+ WithPre {
2078
+ pre: py_body,
2079
+ value: py_expr,
2080
+ },
2081
+ memo_captures.is_do,
2082
+ memo_captures.is_async,
2083
+ ),
2097
2084
  &span,
2098
2085
  )?);
2099
2086
 
@@ -2257,16 +2244,14 @@ fn create_coalesce<'src, 'ast>(
2257
2244
  ) -> TlResult<SPyExprWithPre<'src>> {
2258
2245
  let a = PyAstBuilder::new(span);
2259
2246
  let mut pre = PyBlock::new();
2260
- let mut fn_body = PyBlock::new();
2261
-
2262
- let py_rhs = fn_body.bind(rhs.transform(ctx)?);
2263
- fn_body.push(a.return_(py_rhs));
2264
2247
 
2265
2248
  let fn_info = ctx.coal_fninfo.get(&rhs.into()).unwrap();
2266
2249
 
2250
+ let py_body = rhs.transform(ctx)?;
2251
+
2267
2252
  let inner_fn = pre.bind(make_fn_exp(
2268
2253
  ctx,
2269
- FnDef::PyFnDef(vec![], fn_body, false, fn_info.is_async),
2254
+ FnDef::PyFnDef(vec![], py_body, false, fn_info.is_async),
2270
2255
  &span,
2271
2256
  )?);
2272
2257
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes