Skip to content

Commit

Permalink
Begin work on execution
Browse files Browse the repository at this point in the history
  • Loading branch information
rymiel committed Jun 23, 2024
1 parent fb6b116 commit fe52d77
Show file tree
Hide file tree
Showing 16 changed files with 2,628 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
_build
compile_commands.json
.cache/
12 changes: 10 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ let parse (path : string) =

let verify (name : string) =
Loader.initialize_bootstrap_loader Testclasses.test_loader;
let cls = Main.load_class name Loader.bootstrap_loader in
let cls = Loader.load_class name Loader.bootstrap_loader in
let safe = Main.classIsTypeSafe cls in
Printf.printf "Class %S is safe: %B\n" cls.name safe;
if safe then print_endline "\027[32;1mSUCCESS!!\027[0m"

let exec (name : string) =
let jvm = Exec.Jvm.create_jvm Testclasses.test_loader in
jvm#exec_main name;
jvm#free

let () =
if Array.length Sys.argv <= 2 then print_endline "usage: <action> <param>"
else
Expand All @@ -25,4 +30,7 @@ let () =
| "parse" ->
let _ = parse param in
()
| _ -> print_endline "error: Action must be verify or parse"
| "exec" ->
let _ = exec param in
()
| _ -> print_endline "error: Action must be verify, parse, or exec"
1 change: 1 addition & 0 deletions class/extern-lib
1 change: 0 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
(package
(name jvmilia)
(depends ocaml dune))

6 changes: 5 additions & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

(library
(name jvmilia)
(libraries unix))
(foreign_stubs
(language cxx)
(names native jni)
(flags -std=c++20 -fPIC))
(libraries ctypes ctypes-foreign))
32 changes: 32 additions & 0 deletions lib/exec/debug.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
let indent = 2
let depth = ref 0

type entry = string

let stack = ref []
let stack_push (v : entry) = stack := v :: !stack

let stack_pop () : entry =
match !stack with
| [] -> failwith "Debug stack is empty"
| x :: xs ->
stack := xs;
x

let push (ctx : string) (s : string) : unit =
print_string (String.make (!depth * indent) ' ');
print_string "\027[34m>>\027[0m ";
let prefix = Printf.sprintf "%s: %s" ctx s in
print_string prefix;
print_newline ();
stack_push prefix;
incr depth

let pop () : unit =
let top = stack_pop () in
decr depth;
print_string (String.make (!depth * indent) ' ');
print_string "\027[34m<<\027[0m ";
print_string top;
print_newline ();
()
2 changes: 2 additions & 0 deletions lib/exec/debug.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val push : string -> string -> unit
val pop : unit -> unit
Loading

0 comments on commit fe52d77

Please sign in to comment.