duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit d2f842a492fc0a3c8742888cee253f98a7a81aeb
parent d5f2eb00454d845ccaaba80b85d2ed921edf4945
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed, 14 Sep 2022 08:27:11 -0400

cc: test that multiple return paths work

Diffstat:
Mfs/app/cos/tools/blkpack.c | 5++---
Mfs/tests/cc/cc.fs | 4++++
Mfs/tests/cc/test.c | 15++++++++++++++-
3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/fs/app/cos/tools/blkpack.c b/fs/app/cos/tools/blkpack.c @@ -1,7 +1,5 @@ // This doesn't actually work, I'm just drafting how it would look. // TODO: string scanning -// TODO: do multiple "return" paths work? -// TODO: can we "return" early in a void function? // TODO: signed arithmetics // TODO: break @@ -47,6 +45,7 @@ extern void blkpack() { int blkline; int n = 0; int cnt = strlen(line); + int i; lineno = 1; if (!cnt) { fprintf("No input\n", ConsoleOut()); @@ -85,7 +84,7 @@ extern void blkpack() { line[cnt-1] = '\0'; // remove newline puts(line); // pad line to 64 chars - for (int i=cnt-1; i<64; i++) putchar(' '); + for (i=cnt-1; i<64; i++) stdout(' '); } if (blkline == 16) { lineno++; diff --git a/fs/tests/cc/cc.fs b/fs/tests/cc/cc.fs @@ -35,6 +35,10 @@ capture helloworld S" Hello World!" #s= 42 40 50 isinrange 1 #eq 42 30 40 isinrange 0 #eq 42 5 forloop 47 #eq +1 multret 1 #eq +42 multret 32 #eq +55 capture multretvoid S" Nope" #s= +42 capture multretvoid S" Answer to the universe" #s= \ and what about inline functions? :cfunc int myinline() { return 42; } diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c @@ -136,4 +136,17 @@ extern int forloop(int a, int b) { } return a; } - +extern unsigned int multret(unsigned int x) { + if (x < 10) { + return x; + } else { + return x-10; + } +} +extern void multretvoid(unsigned int x) { + if (x == 42) { + stype("Answer to the universe"); + return; + } + stype("Nope"); +}