Selaa lähdekoodia

Modify drafts and tests

master
mtardy 4 vuotta sitten
vanhempi
commit
319f05ff1c
3 muutettua tiedostoa jossa 30 lisäystä ja 17 poistoa
  1. +12
    -10
      drafts/c.c
  2. +10
    -7
      test2.txt
  3. +8
    -0
      test3.txt

+ 12
- 10
drafts/c.c Näytä tiedosto

@ -17,25 +17,27 @@ struct jb_record
struct jb_record *jbs= 0; struct jb_record *jbs= 0;
int eval(oop ast) int eval(oop ast)
{ {
case t_call: { case t_call: {
pushJbRec();
if (0 != set_jmp(jbs->jb)) {
oop result = jbs->result;
popJbRec();
return result;
}
// run the body of the function here
result = (each statement in the func body...);
popJbRec();
return result;
pushJbRec();
if (0 != set_jmp(jbs->jb)) {
oop result = jbs->result;
popJbRec();
return result;
}
// run the body of the function here
result = (each statement in the func body...);
popJbRec();
return result;
} }
setjmp(jb); setjmp(jb);
if (n < 2) return 1; if (n < 2) return 1;
return 1 + f(n-1) + f(n-2); return 1 + f(n-1) + f(n-2);
} }
int main() int main()
{ {
printf("%zi\n", sizeof(jmp_buf)); printf("%zi\n", sizeof(jmp_buf));

+ 10
- 7
test2.txt Näytä tiedosto

@ -1,13 +1,16 @@
fun f() { fun f() {
var i = 0 var i = 0
while (i<10) {
print(i)
if (i == 5) {
return 42
}
else {
i = i + 1
for (var i= 0; i < 10; i = i + 1) {
switch (i) {
case 5: {
continue
}
case 8: {
return 66;
}
} }
print(i)
} }
24 + 2
} }
f() f()

+ 8
- 0
test3.txt Näytä tiedosto

@ -0,0 +1,8 @@
fun f(n) {
if (n < 2) {
return 1
} else {
return 1 + f(n-1) + f(n-2)
}
}
f(27)

Ladataan…
Peruuta
Tallenna