瀏覽代碼

Add drafts and tests

pull/5/head
mtardy 4 年之前
父節點
當前提交
309bcb1d57
共有 3 個檔案被更改,包括 57 行新增6 行删除
  1. +5
    -0
      TODO.txt
  2. +43
    -0
      drafts/c.c
  3. +9
    -6
      test2.txt

+ 5
- 0
TODO.txt 查看文件

@ -0,0 +1,5 @@
statements
switch?
return
break in switch, loops
continue in loops

+ 43
- 0
drafts/c.c 查看文件

@ -0,0 +1,43 @@
#include <stdio.h>
#include <setjmp.h>
enum jb_t {
j_function,
j_loop,
j_switch,
};
struct jb_record
{
jmp_buf jb;
enum jb_t type;
oop result;
struct jb_record next;
};
struct jb_record *jbs= 0;
int eval(oop ast)
{
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;
}
setjmp(jb);
if (n < 2) return 1;
return 1 + f(n-1) + f(n-2);
}
int main()
{
printf("%zi\n", sizeof(jmp_buf));
printf("%i\n", f(5));
}

+ 9
- 6
test2.txt 查看文件

@ -1,10 +1,13 @@
fun f() {
if (1) {
return 12
15
} else {
return 13
14
var i = 0
while (i<10) {
print(i)
if (i == 5) {
return 42
}
else {
i = i + 1
}
}
}
f()

Loading…
取消
儲存