Commit 5df30dad
5df30dada3baMerged
Ryan Seys <[email protected]> · 5 months ago · 6 files · +2 added · ~4 modified
Description
analyze,codegen: realize a completed curry chain to its proc's result type
A curried application stayed TY_CURRY at every step, so only puts realized it
(via a print-time special case) and p or arithmetic on a completed curry was
unsupported. Track how many arguments a curry chain has accumulated and realize
it once it reaches the proc's arity.
curry_apply_infowalks a curry chain to its base proc -- throughproc.curry, each[arg]/.call(arg)application, and any intermediate variable holding a partial curry -- and reports whether the current application reaches the proc's arity, plus the proc's return type.- At the completing application, inference yields the proc's (int) result type and
codegen realizes it with
sp_curry_to_int; earlier applications stay a curry. The runtime accumulates int arguments, so completion typing covers int-returning procs; partial applications and other return types stay TY_CURRY.
A completed curry is now a first-class int: p add.curry[5][3],
total = add.curry[10][20]; p total + 1, and add.curry[2][3] * 10 all work,
including partials held in variables (f = mul.curry[2]; g = f[3]; p g[4]).
Details
- Commit
- 5df30dada3ba
- Parent
- 370ba00705d3
src/analyze.hmodifiedView file
@@ -26,6 +26,10 @@
2626
TY_UNKNOWN when undetermined; callers default an empty `[]` to int_array. */2727
TyKind ewo_memo_elem_type(Compiler *c, int callid);2828
29+
/* For a curry-application node, whether it completes the curry (reaches the base30+
proc's arity) and the proc's return type. Returns 1 for a recognized chain. */31+
int curry_apply_info(Compiler *c, int node, int *out_complete, TyKind *out_ret);32+
2933
/* Class index when a receiverless instance_eval/exec resolves to self, else -1. */3034
int ie_implicit_self_class(Compiler *c, int id);3135
src/analyze_infer.cmodifiedView file
Loading diff…
src/analyze_pass.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…
test/proc_curry.rbaddedView file
Loading diff…
test/proc_curry.rb.expectedaddedView file
Loading diff…