Mercurial > sos > sos
changeset 121:889c68a0036a
It's alive (again)!
so, sarpn is now oficially no longer stand-alone! :)
Wow, this feels epic.
author | Jonathan Pevarnek <pevarnj@gmail.com> |
---|---|
date | Fri, 17 Jun 2011 09:09:09 -0400 |
parents | 73deaa825710 |
children | 22990a9ff28c |
files | .hgignore Makefile include/operations.h include/prog/operations.h src/prog/dynamic.c src/prog/operations.c src/prog/rpn.c src/sarpn.c |
diffstat | 8 files changed, 72 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Jun 17 08:58:59 2011 -0400 +++ b/.hgignore Fri Jun 17 09:09:09 2011 -0400 @@ -6,7 +6,7 @@ ^hello$ ^ls$ ^echo$ -^sarpn$ +^rpn$ ^dynamic$ ^testFS$ ^loader\.bin$
--- a/Makefile Fri Jun 17 08:58:59 2011 -0400 +++ b/Makefile Fri Jun 17 09:09:09 2011 -0400 @@ -12,15 +12,15 @@ LDFLAGS=-m elf64_s390 OSBINS=shell -PROGBINS=hello ls echo dynamic +PROGBINS=hello ls echo dynamic rpn shell_OBJS=src/os/shell.o src/os/std.o src/os/fs.o src/os/string.o src/os/stdio.o src/os/scall.o src/os/heap.o src/os/memStack.o arch/arch.a hello_OBJS=src/prog/hello.o src/prog/std.o src/prog/string.o ls_OBJS=src/prog/ls.o echo_OBJS=src/prog/echo.o src/prog/std.o src/prog/string.o dynamic_OBJS=src/prog/dynamic.o src/prog/std.o src/prog/string.o src/prog/stack.o +rpn_OBJS=src/prog/rpn.o src/prog/std.o src/prog/string.o src/prog/stack.o src/prog/operations.o src/prog/math.o -sarpn_OBJS=src/sarpn.o src/std.o src/string.o src/prog/stack.o src/operations.o src/math.o arch/arch.a testFS_OBJS=src/testFS.o src/std.o src/string.o src/os/fs.o arch/arch.a ARCH_OBJS=arch/io.o arch/cons.o arch/ebcdic.o arch/fba.o arch/ioint.o \ @@ -59,9 +59,9 @@ $(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^ dynamic: $(dynamic_OBJS) $(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^ +rpn: $(rpn_OBJS) + $(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^ -sarpn: $(sarpn_OBJS) - $(LD) $(LDFLAGS) -T scripts/linker.script -o $@ $^ testFS: $(testFS_OBJS) $(LD) $(LDFLAGS) -T scripts/linker.script -o $@ $^ @@ -119,7 +119,5 @@ # DO NOT DELETE -src/sarpn.o: include/std.h include/die.h include/memHead.h include/string.h -src/sarpn.o: include/operations.h include/stack.h src/testFS.o: include/std.h include/die.h include/memHead.h include/os/fs.h src/testFS.o: include/error.h include/os/fsStructs.h
--- a/include/operations.h Fri Jun 17 08:58:59 2011 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#ifndef __OPERATIONS_H -#define __OPERATIONS_H - -#include <std.h> -#include <stack.h> - -enum Operation {PRINT, ADD, SUB, MULT, DIV, POW, DUP, DROP, LOG, EXP, SWAP, MAXOP}; -extern const char operationNames[MAXOP][10]; -extern void (*operation[MAXOP])(Stack*); - -void op_math1(Stack *stack, eltType (*mathop)(eltType)); -void op_math2(Stack *stack, eltType (*mathop)(eltType, eltType)); - -void op_print(Stack *stack); -void op_add(Stack *stack); -void op_sub(Stack *stack); -void op_mult(Stack *stack); -void op_div(Stack *stack); -void op_pow(Stack *stack); -void op_dup(Stack *stack); -void op_drop(Stack *stack); -void op_log(Stack *stack); -void op_exp(Stack *stack); -void op_swap(Stack *stack); - -#endif //__OPERATIONS_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/prog/operations.h Fri Jun 17 09:09:09 2011 -0400 @@ -0,0 +1,27 @@ +#ifndef __OPERATIONS_H +#define __OPERATIONS_H + +#include <std.h> +#include <stack.h> + +enum Operation {PRINT, ADD, SUB, MULT, DIV, POW, DUP, DROP, LOG, EXP, SWAP, QUIT, MAXOP}; +extern const char operationNames[MAXOP][10]; +extern void (*operation[MAXOP])(Stack*); + +void op_math1(Stack *stack, eltType (*mathop)(eltType)); +void op_math2(Stack *stack, eltType (*mathop)(eltType, eltType)); + +void op_print(Stack *stack); +void op_add(Stack *stack); +void op_sub(Stack *stack); +void op_mult(Stack *stack); +void op_div(Stack *stack); +void op_pow(Stack *stack); +void op_dup(Stack *stack); +void op_drop(Stack *stack); +void op_log(Stack *stack); +void op_exp(Stack *stack); +void op_swap(Stack *stack); +void op_quit(Stack *stack); + +#endif //__OPERATIONS_H
--- a/src/prog/dynamic.c Fri Jun 17 08:58:59 2011 -0400 +++ b/src/prog/dynamic.c Fri Jun 17 09:09:09 2011 -0400 @@ -46,7 +46,6 @@ void start(u64 __memsize) { - init_all(__memsize); size_t n; char *buffer; char input[30];
--- a/src/prog/operations.c Fri Jun 17 08:58:59 2011 -0400 +++ b/src/prog/operations.c Fri Jun 17 09:09:09 2011 -0400 @@ -1,12 +1,13 @@ -#include <operations.h> +#include <prog/svcCalls.h> +#include <prog/operations.h> #include <std.h> #include <string.h> #include <stack.h> #include <math.h> -const char operationNames[MAXOP][10] = {".", "+", "-", "*", "/", "**", "dup", "drop", "log", "exp", "swap"}; +const char operationNames[MAXOP][10] = {".", "+", "-", "*", "/", "**", "dup", "drop", "log", "exp", "swap", "quit"}; void (*operation[MAXOP])(Stack*) = {op_print, op_add, op_sub, op_mult, - op_div, op_pow, op_dup, op_drop, op_log, op_exp, op_swap}; + op_div, op_pow, op_dup, op_drop, op_log, op_exp, op_swap, op_quit}; static void error_unk() { @@ -112,3 +113,9 @@ } } else error_small(); } + +void op_quit(Stack *stack) +{ + stack_destroy(stack); + exit(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/prog/rpn.c Fri Jun 17 09:09:09 2011 -0400 @@ -0,0 +1,30 @@ +#include <prog/svcCalls.h> +#include <std.h> +#include <string.h> +#include <prog/operations.h> +#include <stack.h> + +int arrayLookup(char *text, const char array[][10], int last) +{ + int i; + for(i = 0; i < last; i++) + if(!strcmp(array[i], text)) return i; + return last; +} + +void start(u64 __memsize) +{ + Stack *stack = stack_init(); + while(1) { + int opVal; + char input[30]; + sPrint("Please enter an operation or value: "); + opVal = arrayLookup(sGet(input, 30), operationNames, MAXOP); + if(opVal != MAXOP) { + (*operation[opVal]) (stack); //call the function array + } else { + push(stack, atof(input)); + } + } + stack_destroy(stack); +}
--- a/src/sarpn.c Fri Jun 17 08:58:59 2011 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * This is where everything starts - */ - -#include <std.h> -#include <string.h> -#include <operations.h> -#include <stack.h> - -int arrayLookup(char *text, const char array[][10], int last) -{ - int i; - for(i = 0; i < last; i++) - if(!strcmp(array[i], text)) return i; - return last; -} - -void start(u64 __memsize) -{ - init_all(__memsize); - - Stack *stack = stack_init(); - while(1) { - int opVal; - char input[30]; - sPrint("Please enter an operation or value: "); - opVal = arrayLookup(sGet(input, 30), operationNames, MAXOP); - if(opVal != MAXOP) { - (*operation[opVal]) (stack); //call the function array - } else { - push(stack, atof(input)); - } - } - stack_destroy(stack); - - for(;;) - ; -}