compiler/TCompilerExamples.st
changeset 13 97090c2baa33
parent 11 6d39860d0fdb
child 16 17a2d1d9f205
--- a/compiler/TCompilerExamples.st	Fri Sep 18 06:20:53 2015 +0100
+++ b/compiler/TCompilerExamples.st	Sun Sep 20 12:01:42 2015 +0100
@@ -19,6 +19,40 @@
 
 !TCompilerExamples methodsFor:'tests'!
 
+example_factorialI
+    | environment unit compiler|
+
+    environment := TEnvironment new.
+    unit := TSourceReader read:'
+nil subclass: #FactorialI
+    category: ''t-Examples''
+!!
+!!FactorialI class methodsFor:''examples''!!
+factorialI:v <tSIntegerW> <^ tSIntegerW>
+    | result <tSIntegerW> 
+      i <tSIntegerW> |
+
+    result := 0.
+    i := v.
+
+    [ i > 1 ] whileTrue:[ 
+        result := result * i.
+        i := i - 1
+    ].
+    ^ result
+!! !!
+    '.
+
+    compiler := TCompiler new.
+    compiler compile: unit in: environment.
+    self halt.
+    "
+    compiler context module
+    "
+
+    "Created: / 19-09-2015 / 18:29:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 example_if
     | environment unit compiler|