From 40647090be982dde1ff238221a1ba9ff4f260f16 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 5 Nov 2015 00:27:47 -0800 Subject: 2366 - disallow static dispatch inside header-less recipes Not only can such recipes not have variants, their bodies too will be oblivious to multiple variants or generics. --- 057static_dispatch.cc | 1 + 1 file changed, 1 insertion(+) (limited to '057static_dispatch.cc') diff --git a/057static_dispatch.cc b/057static_dispatch.cc index 4de67aa3..3bac046e 100644 --- a/057static_dispatch.cc +++ b/057static_dispatch.cc @@ -108,6 +108,7 @@ Transform.push_back(resolve_ambiguous_calls); :(code) void resolve_ambiguous_calls(recipe_ordinal r) { + if (!Recipe[r].has_header) return; trace(9991, "transform") << "--- resolve ambiguous calls for recipe " << Recipe[r].name << end(); for (long long int index = 0; index < SIZE(Recipe[r].steps); ++index) { instruction& inst = Recipe[r].steps.at(index); -- cgit 1.4.1-2-gfad0 'switch'/> Soul of a tiny new machine. More thorough tests → More comprehensible and rewrite-friendly software → More resilient society.Kartik K. Agaram <vc@akkartik.com>
about summary refs log tree commit diff stats
path: root/generic.mu
blob: 4486e8bc4842ac5390486142767f7c853c65f196 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
; To demonstrate generic functions, we'll construct a factorial function with
; separate base and recursive clauses. Compare factorial.mu.

; factorial n = n*factorial(n-1)
(function factorial [
  (default-space:space-address <- new space:literal 30:literal)
  (n:integer <- input 0:literal)
  more-clauses
  (x:integer <- subtract n:integer 1:literal)
  (subresult:integer <- factorial x:integer)
  (result:integer <- multiply subresult:integer n:integer)
  (reply result:integer)
])

; factorial 0 = 1
(after factorial/more-clauses [
  { begin
    (zero?:boolean <- equal n:integer 0:literal)
    (break-unless zero?:boolean)
    (reply 1:literal)
  }
])

(function main [
  (1:integer <- factorial 5:literal)
  (print-primitive (("result: " literal)))
  (print-primitive 1:integer)
  (print-primitive (("\n" literal)))
])