aboutsummaryrefslogtreecommitdiff
path: root/projects/Stacker/samples
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2003-11-24 02:57:25 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2003-11-24 02:57:25 +0000
commit3e4a271c891e98ace9f0833bf12fca75b03a2e8c (patch)
tree2cce74f08803942d2db31cc7bd9393851531d1ef /projects/Stacker/samples
parent866f10c493ea7c38a53af021267e3e9f76af6164 (diff)
Apply patches from PR136
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10192 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'projects/Stacker/samples')
-rw-r--r--projects/Stacker/samples/Makefile26
-rw-r--r--projects/Stacker/samples/goof.st26
-rw-r--r--projects/Stacker/samples/prime.st73
3 files changed, 110 insertions, 15 deletions
diff --git a/projects/Stacker/samples/Makefile b/projects/Stacker/samples/Makefile
index 2082d72ac1..b6b03c42bf 100644
--- a/projects/Stacker/samples/Makefile
+++ b/projects/Stacker/samples/Makefile
@@ -14,34 +14,46 @@ LEVEL = ../../..
#
DIRS =
-TESTS = fibonacci hello prime
+SAMPLES = fibonacci hello prime
-all :: $(TESTS)
+all :: $(SAMPLES)
ifdef OPTIMIZE
%.bc : %.st
- stkrc -e -o - $< | opt -stats -q -f -o $*.bc \
+ @$(ECHO) "Compiling and Optimizing $< to $*.bc"
+ $(VERB)stkrc -e -o - $< | opt -stats -q -f -o $*.bc \
-aa-eval -adce -branch-combine -cee -constmerge -constprop -dce -die -ds-aa \
-ds-opt -gcse -globaldce -indvars -inline -instcombine \
-ipconstprop -licm -loopsimplify -mem2reg -pre -sccp -simplifycfg \
-tailcallelim -verify
else
%.bc : %.st
- stkrc -e -f -o $*.bc $<
+ @$(ECHO) "Compiling $< to $*.bc"
+ $(VERB)stkrc -e -f -o $*.bc $<
endif
%.s : %.bc
- llc -f -o $*.s $<
+ @$(ECHO) "Compiling $< to $*.s"
+ $(VERB)llc -f -o $*.s $<
% : %.s
- gcc -g -L$(BUILD_OBJ_ROOT)/lib/Debug -lstkr_runtime -o $* $*.s
+ @$(ECHO) "Compiling and Linking $< to $*"
+ $(VERB)gcc -g -L$(BUILD_OBJ_ROOT)/lib/Debug -lstkr_runtime -o $* $*.s
%.ll : %.bc
- llvm-dis -f -o $*.ll $<
+ @$(ECHO) "Disassembling $< to $*.ll"
+ $(VERB)llvm-dis -f -o $*.ll $<
%.bc : $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
.PRECIOUS: %.bc %.s %.ll %.st
+
+SAMPLES_LL = $(SAMPLES:%=%.ll)
+SAMPLES_BC = $(SAMPLES:%=%.bc)
+SAMPLES_S = $(SAMPLES:%=%.s)
+
+clean ::
+ $(VERB)rm -f gmon.out $(SAMPLES_LL) $(SAMPLES_BC) $(SAMPLES_S) $(SAMPLES)
#
# Include the Master Makefile that knows how to build all.
#
diff --git a/projects/Stacker/samples/goof.st b/projects/Stacker/samples/goof.st
index 8fe9c51d92..8c1ff72ba4 100644
--- a/projects/Stacker/samples/goof.st
+++ b/projects/Stacker/samples/goof.st
@@ -1 +1,25 @@
-: defmebaby 23 0 = ;
+#
+# goof
+#
+: print_one
+ --
+ SWAP
+ >s
+ DROP
+;
+: print_it
+ WHILE
+ print_one
+ END
+;
+
+: MAIN
+ "MICKEY: I said she was f'in goofy!"
+ "MICKEY: I didn't say she was insane."
+ "JUDGE: Yet you provide no evidence of this and I do not concur."
+ "JUDGE: In your pleadings you claim that Mini Mouse is insane."
+ "MICKEY: Well, what do you mean, your honor?"
+ "JUDGE: Mr. Mouse, I find your grounds for divorce insufficient. "
+ 6
+ print_it
+;
diff --git a/projects/Stacker/samples/prime.st b/projects/Stacker/samples/prime.st
index 4e1a607a46..3b8703db18 100644
--- a/projects/Stacker/samples/prime.st
+++ b/projects/Stacker/samples/prime.st
@@ -139,7 +139,7 @@
################################################################################
: consider_prime
DUP ( save the prime number to consider )
- 10000 < IF ( check to see if we are done yet )
+ 1000000 < IF ( check to see if we are done yet )
done ( we are done, call "done" )
ENDIF
++ ( increment to next prime number )
@@ -157,6 +157,8 @@
# STACK>: empty
################################################################################
: find_primes
+ "Prime Numbers: " >s CR ( say hello )
+ DROP ( get rid of that pesky string )
1 ( stoke the fires )
print ( print the first one, we know its prime )
WHILE ( loop while the prime to consider is non zero )
@@ -165,12 +167,69 @@
;
################################################################################
-# The MAIN program just prints a banner and calls find_primes.
-# STACK<: empty
-# STACK>: empty
+#
+################################################################################
+: say_yes
+ >d ( Print the prime number )
+ " is prime." ( push string to output )
+ >s ( output it )
+ CR ( print carriage return )
+ DROP ( pop string )
+;
+
+: say_no
+ >d ( Print the prime number )
+ " is NOT prime." ( push string to put out )
+ >s ( put out the string )
+ CR ( print carriage return )
+ DROP ( pop string )
+;
+
+################################################################################
+# This definition processes a single command line argument and determines if it
+# is a prime number or not.
+# STACK<:
+# n - number of arguments
+# arg1 - the prime numbers to examine
+# STACK>:
+# n-1 - one less than number of arguments
+# arg2 - we processed one argument
+################################################################################
+: do_one_argument
+ -- ( decrement loop counter )
+ SWAP ( get the argument value )
+ is_prime IF ( determine if its prime )
+ say_yes ( uhuh )
+ ELSE
+ say_no ( nope )
+ ENDIF
+ DROP ( done with that argument )
+;
+
+################################################################################
+# The MAIN program just prints a banner and processes its arguments.
+# STACK<:
+# n - number of arguments
+# ... - the arguments
+################################################################################
+: process_arguments
+ WHILE ( while there are more arguments )
+ do_one_argument ( process one argument )
+ END
+;
+
+################################################################################
+# The MAIN program just prints a banner and processes its arguments.
+# STACK<: arguments
################################################################################
: MAIN
- "Prime Numbers: " >s CR ( say hello )
- DROP ( get rid of that pesky string )
- find_primes ( see how many we can find )
+ NIP ( get rid of the program name )
+ -- ( reduce number of arguments )
+ DUP ( save the arg counter )
+ 1 <= IF ( See if we got an argument )
+ process_arguments ( tell user if they are prime )
+ ELSE
+ find_primes ( see how many we can find )
+ ENDIF
+ 0 ( push return code )
;