diff --git a/procedures/function-procedure/Makefile b/procedures/function-procedure/Makefile new file mode 100644 index 0000000..4aa1d11 --- /dev/null +++ b/procedures/function-procedure/Makefile @@ -0,0 +1,10 @@ +VOC = /opt/voc/bin/voc + +all: + $(VOC) -m Square.Mod + +clean: + rm *.c + rm *.h + rm *.o + rm *.sym diff --git a/procedures/function-procedure/Square.Mod b/procedures/function-procedure/Square.Mod new file mode 100644 index 0000000..03172bd --- /dev/null +++ b/procedures/function-procedure/Square.Mod @@ -0,0 +1,17 @@ +MODULE square; + + +IMPORT Out; + +VAR s : INTEGER; + +PROCEDURE squared(x : INTEGER): INTEGER; +BEGIN + RETURN x * x +END squared; + +BEGIN + s := squared(7); + Out.Int(s, 0); Out.Ln; + Out.Int(squared(8), 0); Out.Ln; +END square. diff --git a/procedures/procedure/Makefile b/procedures/procedure/Makefile new file mode 100644 index 0000000..22b005a --- /dev/null +++ b/procedures/procedure/Makefile @@ -0,0 +1,10 @@ +VOC = /opt/voc/bin/voc + +all: + $(VOC) -m Procedure.Mod + +clean: + rm *.c + rm *.h + rm *.o + rm *.sym diff --git a/procedures/procedure/Procedure.Mod b/procedures/procedure/Procedure.Mod new file mode 100644 index 0000000..9991100 --- /dev/null +++ b/procedures/procedure/Procedure.Mod @@ -0,0 +1,14 @@ +MODULE proc; + + +IMPORT Out; + +PROCEDURE printSum(a, b : INTEGER); +BEGIN + Out.Int(a + b, 0); Out.Ln +END printSum; + + +BEGIN + printSum(6, 9) +END proc. diff --git a/procedures/var-parameter/Makefile b/procedures/var-parameter/Makefile new file mode 100644 index 0000000..3aa4292 --- /dev/null +++ b/procedures/var-parameter/Makefile @@ -0,0 +1,10 @@ +VOC = /opt/voc/bin/voc + +all: + $(VOC) -m VarParam.Mod + +clean: + rm *.c + rm *.h + rm *.o + rm *.sym diff --git a/procedures/var-parameter/VarParam.Mod b/procedures/var-parameter/VarParam.Mod new file mode 100644 index 0000000..d0d2546 --- /dev/null +++ b/procedures/var-parameter/VarParam.Mod @@ -0,0 +1,22 @@ +MODULE varparam; + +IMPORT Out; + +VAR + a, b : INTEGER; + +PROCEDURE swapVals(VAR x, y : INTEGER); +VAR tmp : INTEGER; +BEGIN + tmp := x; x := y; y := tmp; +END swapVals; + + +BEGIN + a := 6; b := 9; + Out.String("initial "); Out.Ln; + Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln; + swapVals(a, b); + Out.String("after swap"); Out.Ln; + Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln; +END varparam.