|
Revision 11549, 1.2 kB
(checked in by mokehehe, 5 years ago)
|
|
|
| Line | |
|---|
| 1 | //=============================================================================
|
|---|
| 2 | /// ��
|
|---|
| 3 | //=============================================================================
|
|---|
| 4 |
|
|---|
| 5 | #include "mlisp.h"
|
|---|
| 6 | #include "s_util.h"
|
|---|
| 7 | #include "c_compiler.h"
|
|---|
| 8 | #include "v_vm.h"
|
|---|
| 9 | #include "op.h"
|
|---|
| 10 | #include "m_basic.h"
|
|---|
| 11 | #include "inner.h"
|
|---|
| 12 |
|
|---|
| 13 | /// ��s
|
|---|
| 14 | SExp run(SExp c) {
|
|---|
| 15 | return vm(nil, c, 0, nil, 0);
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | /// �g�b�v���x���ŃR���p�C��
|
|---|
| 19 | SExp compile_ontop(SExp code) {
|
|---|
| 20 | SExp halt_code = cons(HALT, nil);
|
|---|
| 21 | return compile(code, list(1, nil), nil, halt_code);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | /// �]��
|
|---|
| 25 | SExp evaluate(SExp code) {
|
|---|
| 26 | SExp c = compile_ontop(code);
|
|---|
| 27 | //print(c);
|
|---|
| 28 | return run(c);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | // �\�[�X�̃��[�h�i�ǂݍ��݁A�R���p�C���A��s�j
|
|---|
| 33 | SExp load_eval(const char* fn) {
|
|---|
| 34 | FILE* fp = fopen(fn, "r");
|
|---|
| 35 | if (fp == NULL) {
|
|---|
| 36 | // error();
|
|---|
| 37 | return nil;
|
|---|
| 38 | } else {
|
|---|
| 39 | SExp res;
|
|---|
| 40 | for (;;) {
|
|---|
| 41 | SExp sexp = read_from_file(fp);
|
|---|
| 42 | if (nilp(sexp)) break; // @todo: EOF�̈���
|
|---|
| 43 | res = run(compile_ontop(sexp));
|
|---|
| 44 | }
|
|---|
| 45 | fclose(fp);
|
|---|
| 46 | return res;
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | void mlisp_new(const SVTable* vtbl) {
|
|---|
| 52 | sexp_new(vtbl);
|
|---|
| 53 | init_vm();
|
|---|
| 54 | init_compile();
|
|---|
| 55 | define_basic_lib();
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | void mlisp_delete(void) {
|
|---|
| 59 | sexp_delete();
|
|---|
| 60 | }
|
|---|