feat: lift runtime into language, start of zelus 2024 compatibility
This commit is contained in:
parent
dc8d941b84
commit
ffc583985a
37 changed files with 1154 additions and 143 deletions
58
exm/zelus_2024/ball/ball.ml
Normal file
58
exm/zelus_2024/ball/ball.ml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
(* The Zelus compiler, version 2024-dev
|
||||
(2025-06-4-15:49) *)
|
||||
open Ztypes
|
||||
|
||||
type ('e, 'd, 'c, 'b, 'a) ball =
|
||||
{ mutable time: 'e; mutable major: 'd; mutable up: 'c;
|
||||
mutable y': 'b; mutable y: 'a }
|
||||
|
||||
let ball =
|
||||
let machine cstate =
|
||||
let alloc _ =
|
||||
cstate.cmax <- cstate.cmax + 1;
|
||||
cstate.zmax <- cstate.zmax + 1;
|
||||
{ time = -1.;
|
||||
major = false;
|
||||
up = { zin = false; zout = 1. };
|
||||
y' = -1.;
|
||||
y = { pos = -1.; der = 0. };
|
||||
} in
|
||||
let step self _ =
|
||||
let cindex = cstate.cindex in
|
||||
let cpos = ref cindex in
|
||||
let zindex = cstate.zindex in
|
||||
let zpos = ref zindex in
|
||||
cstate.cindex <- cstate.cindex + 1;
|
||||
cstate.zindex <- cstate.zindex + 1;
|
||||
self.major <- cstate.major;
|
||||
self.time <- cstate.time;
|
||||
if cstate.major then
|
||||
for i = cindex to 0 do Zls.set cstate.dvec i 0. done
|
||||
else begin
|
||||
self.y.pos <- Zls.get cstate.cvec !cpos;
|
||||
cpos := !cpos + 1
|
||||
end;
|
||||
let result =
|
||||
self.up.zout <- -. self.y.pos;
|
||||
if self.up.zin then self.y' <- -0.8 *. self.y';
|
||||
self.y.der <- self.y';
|
||||
self.y.pos, self.y', self.up.zin in
|
||||
cpos := cindex;
|
||||
if cstate.major then begin
|
||||
Zls.set cstate.cvec !cpos self.y.pos;
|
||||
cpos := !cpos + 1;
|
||||
self.up.zin <- false
|
||||
end else begin
|
||||
self.up.zin <- Zls.get_zin cstate.zinvec !zpos;
|
||||
zpos := !zpos + 1
|
||||
end;
|
||||
zpos := zindex;
|
||||
Zls.set cstate.zoutvec !zpos self.up.zout;
|
||||
zpos := !zpos + 1;
|
||||
Zls.set cstate.dvec !cpos self.y.der;
|
||||
cpos := !cpos + 1;
|
||||
result in
|
||||
let reset self =
|
||||
self.y.pos <- 50.; self.y' <- 0. in
|
||||
Node { alloc; step; reset } in
|
||||
machine
|
||||
9
exm/zelus_2024/ball/dune
Normal file
9
exm/zelus_2024/ball/dune
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(executable
|
||||
(public_name newball.exe)
|
||||
(name main)
|
||||
(libraries std))
|
||||
7
exm/zelus_2024/ball/main.ml
Normal file
7
exm/zelus_2024/ball/main.ml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
open Std
|
||||
|
||||
let input _ = ()
|
||||
let output (now, (y, _, _)) = Format.printf "%.10e\t%.10e\n" now y
|
||||
let () = Runtime.go_2024 input Ball.ball output
|
||||
|
||||
12
exm/zelus_2024/ball/ztypes.ml
Normal file
12
exm/zelus_2024/ball/ztypes.ml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
include Std
|
||||
include Ztypes
|
||||
include Solvers
|
||||
|
||||
module type IGNORE = sig end
|
||||
module Defaultsolver : IGNORE = struct end
|
||||
|
||||
module Zlsrun = struct
|
||||
module Make (S : IGNORE) = struct
|
||||
let go _ = ()
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue