Permalink
Browse files

potion.c: Interactive mode now can run either with jit or vm.

  • Loading branch information...
1 parent 7ae9548 commit 74c8b3a26fe9b9164fd44cd66d9e2b6304c5bd48 @orangea orangea committed Dec 21, 2010
Showing with 17 additions and 15 deletions.
  1. +11 −10 core/compile.c
  2. +1 −1 core/load.c
  3. +2 −1 core/potion.c
  4. +2 −2 core/potion.h
  5. +1 −1 core/string.c
View
@@ -845,21 +845,22 @@ PN potion_source_dump(Potion *P, PN cl, PN proto) {
return pnb;
}
-PN potion_run(Potion *P, PN code) {
-#if POTION_JIT == 1
- PN cl = potion_closure_new(P, (PN_F)potion_jit_proto(P, code, POTION_JIT_TARGET), PN_NIL, 1);
- PN_CLOSURE(cl)->data[0] = code;
- return PN_PROTO(code)->jit(P, cl, P->lobby);
-#else
- return potion_vm(P, code, P->lobby, PN_NIL, 0, NULL);
-#endif
+PN potion_run(Potion *P, PN code, int jit) {
+ if (jit) {
+ if (!POTION_JIT) potion_fatal("potion not compiled with JIT");
+ PN cl = potion_closure_new(P, (PN_F)potion_jit_proto(P, code, POTION_JIT_TARGET), PN_NIL, 1);
+ PN_CLOSURE(cl)->data[0] = code;
+ return PN_PROTO(code)->jit(P, cl, P->lobby);
+ } else {
+ return potion_vm(P, code, P->lobby, PN_NIL, 0, NULL);
+ }
}
-PN potion_eval(Potion *P, PN bytes) {
+PN potion_eval(Potion *P, PN bytes, int jit) {
PN code = potion_parse(P, bytes);
if (PN_TYPE(code) != PN_TSOURCE) return code;
code = potion_send(code, PN_compile, PN_NIL, PN_NIL);
- return potion_run(P, code);
+ return potion_run(P, code, jit);
}
void potion_compiler_init(Potion *P) {
View
@@ -33,7 +33,7 @@ void potion_load_code(Potion *P, const char *filename) {
code = potion_source_load(P, PN_NIL, buf);
if (!PN_IS_PROTO(code)) {
potion_run(P, potion_send(
- potion_parse(P, buf), PN_compile, potion_str(P, filename), PN_NIL));
+ potion_parse(P, buf), PN_compile, potion_str(P, filename), PN_NIL), POTION_JIT);
}
} else {
fprintf(stderr, "** could not read entire file: %s.", filename);
View
@@ -240,6 +240,7 @@ int main(int argc, char *argv[]) {
if (!interactive) {
potion_cmd_compile(argv[argc-1], exec, verbose, sp);
} else {
+ if (!exec || verbose) potion_fatal("no filename given");
Potion *P = potion_create(sp);
potion_eval(P, potion_byte_str(P,
"loop:\n" \
@@ -252,7 +253,7 @@ int main(int argc, char *argv[]) {
" obj string print." \
" else: ('=> ', obj, \"\\n\") join print.\n" \
" .\n"
- "."));
+ "."), exec - 1);
potion_destroy(P);
}
return 0;
View
@@ -637,8 +637,8 @@ PN potion_parse(Potion *, PN);
PN potion_vm_proto(Potion *, PN, PN, ...);
PN potion_vm_class(Potion *, PN, PN);
PN potion_vm(Potion *, PN, PN, PN, PN_SIZE, PN * volatile);
-PN potion_eval(Potion *, PN);
-PN potion_run(Potion *, PN);
+PN potion_eval(Potion *, PN, int);
+PN potion_run(Potion *, PN, int);
PN_F potion_jit_proto(Potion *, PN, PN);
#endif
View
@@ -81,7 +81,7 @@ static PN potion_str_length(Potion *P, PN cl, PN self) {
}
static PN potion_str_eval(Potion *P, PN cl, PN self) {
- return potion_eval(P, self);
+ return potion_eval(P, self, POTION_JIT);
}
static PN potion_str_number(Potion *P, PN cl, PN self) {

0 comments on commit 74c8b3a

Please sign in to comment.