text stringlengths 0 601k |
|---|
let build fn = { fn ; transform = RTCMatrix . identity ; inverse_transform = RTCMatrix . identity } |
let rec eval texture opoint = match texture with | Solid color -> color | Pattern pattern -> let ppoint = RTCMatrix . tmult pattern . inverse_transform opoint in eval ( pattern . fn ppoint ) ppoint |
let solid ( a : RTCColor . t ) = Solid a |
let stripe ( a : texture_t ) ( b : texture_t ) = let fn ( point : RTCTuple . t ) = let disc = ( int_of_float ( floor point . x ) ) mod 2 in if disc = 0 then a else b in build fn |
let gradient ( a : texture_t ) ( b : texture_t ) = let fn ( point : RTCTuple . t ) = let ac = eval a point in let bc = eval b point in let distance = RTCColor . subtract bc ac in let fraction = point . x . - ( floor point . x ) in Solid ( RTCColor . add ac ( RTCColor . mults distance fraction ) ) in build fn |
let ring ( a : texture_t ) ( b : texture_t ) = let fn ( point : RTCTuple . t ) = let distance = floor ( sqrt ( point . x ** 2 . . + point . z ** 2 . ) ) in let disc = ( int_of_float distance ) mod 2 in if disc = 0 then a else b in build fn |
let checkers ( a : texture_t ) ( b : texture_t ) = let fn ( point : RTCTuple . t ) = let distance = ( floor point . x ) . + floor ( point . y ) . + floor ( point . z ) in let disc = ( int_of_float distance ) mod 2 in if disc = 0 then a else b in build fn |
let at_object ( pattern : t ) ( transform : RTCTuple . t -> RTCTuple . t ) ( point : RTCTuple . t ) = let opoint = transform point in eval ( Pattern pattern ) opoint |
let transform ( pattern : t ) ( m : RTCMatrix . t ) = { pattern with transform = m ; inverse_transform ( = RTCMatrix . inverse m ) } |
type test_shape_data = { mutable ray : RTCRay . t option } |
type tri_data = { p1 : RTCTuple . t ; p2 : RTCTuple . t ; p3 : RTCTuple . t ; n1 : RTCTuple . t ; n2 : RTCTuple . t ; n3 : RTCTuple . t ; smooth : bool ; e1 : RTCTuple . t ; e2 : RTCTuple . t ; normal : RTCTuple . t } |
type csg_rule_fn = bool -> bool -> bool -> bool |
type shape_t = | Sphere | Plane | Cube | Cylinder of float * float * bool | Cone of float * float * bool | Group of t list | Triangle of tri_data | Union of t * t * csg_rule_fn | Intersect of t * t * csg_rule_fn | Difference of t * t * csg_rule_fn | TestShape of test_shape_data transform : RTCMatrix . t ; inverse_trans... |
let build ( shape : shape_t ) ( isect : intersect_t ) ( normal : normal_t ) = { shape ; transform = RTCMatrix . identity ; inverse_transform = RTCMatrix . identity ; inverse_transpose_transform = RTCMatrix . identity ; material = None ; local_intersect = isect ; local_normal_at = normal ; shadow = true } |
let transform ( shape : t ) transform = let inverse_transform = RTCMatrix . inverse transform in let inverse_transpose_transform = RTCMatrix . transpose inverse_transform in { shape with transform ; inverse_transform ; inverse_transpose_transform } |
let texture ( shape : t ) material = { shape with material = Some material } |
let material ( ? trail [ ] ) = ( shape : t ) = let rec loop head tail = match head . material with | None -> ( match tail with | [ ] -> RTCMaterial . build ( ) | head ' :: tail ' -> loop head ' tail ' ) | Some m -> m in loop shape trail |
let intersect ( shape : t ) ( ? trail [ ] ) = ( ray : RTCRay . t ) = let ray2 = RTCRay . transform ray shape . inverse_transform in shape . local_intersect shape ~ trail : trail ray2 |
let world_to_object ( shape : t ) ( trail : t list ) ( wpoint : RTCTuple . t ) = let rec loop point = function | [ ] -> point | parent :: parents -> RTCMatrix . tmult parent . inverse_transform ( loop point parents ) in loop wpoint ( shape :: trail ) |
let normal_to_world ( shape : t ) ( trail : t list ) ( normal : RTCTuple . t ) = let rec loop normal = function | [ ] -> normal | shape :: shapes -> let n = RTCMatrix . tmult shape . inverse_transpose_transform normal in let n ' = RTCTuple . norm ( RTCTuple . vector n . x n . y n . z ) in loop n ' shapes in loop normal... |
let normal_at ( ? hit = None ) ( shape : t ) ( trail : t list ) ( wpoint : RTCTuple . t ) = let opoint = world_to_object shape trail wpoint in let onormal = shape . local_normal_at ~ hit : hit shape opoint in normal_to_world shape trail onormal |
let translation x y z = [ | [ | 1 . ; 0 . ; 0 . ; x ] ; | [ | 0 . ; 1 . ; 0 . ; y ] ; | [ | 0 . ; 0 . ; 1 . ; z ] ; | [ | 0 . ; 0 . ; 0 . ; 1 . ] | ] | |
let scaling x y z = [ | [ | x ; 0 . ; 0 . ; 0 . ] ; | [ | 0 . ; y ; 0 . ; 0 . ] ; | [ | 0 . ; 0 . ; z ; 0 . ] ; | [ | 0 . ; 0 . ; 0 . ; 1 . ] | ] | |
let rotation_x r = let cosr = cos ( r ) in let sinr = sin ( r ) in [ | [ | 1 . ; 0 . ; 0 . ; 0 . ] ; | [ | 0 . ; cosr ; . - sinr ; 0 . ] ; | [ | 0 . ; sinr ; cosr ; 0 . ] ; | [ | 0 . ; 0 . ; 0 . ; 1 . ] | ] | |
let rotation_y r = let cosr = cos ( r ) in let sinr = sin ( r ) in [ | [ | cosr ; 0 . ; sinr ; 0 . ] ; | [ | 0 . ; 1 . ; 0 . ; 0 . ] ; | [ | . - sinr ; 0 . ; cosr ; 0 . ] ; | [ | 0 . ; 0 . ; 0 . ; 1 . ] | ] | |
let rotation_z r = let cosr = cos ( r ) in let sinr = sin ( r ) in [ | [ | cosr ; . - sinr ; 0 . ; 0 . ] ; | [ | sinr ; cosr ; 0 . ; 0 . ] ; | [ | 0 . ; 0 . ; 1 . ; 0 . ] ; | [ | 0 . ; 0 . ; 0 . ; 1 . ] | ] | |
let shearing xy xz yx yz zx zy = [ | [ | 1 . ; xy ; xz ; 0 . ] ; | [ | yx ; 1 . ; yz ; 0 . ] ; | [ | zx ; zy ; 1 . ; 0 . ] ; | [ | 0 . ; 0 . ; 0 . ; 1 . ] | ] | |
let view from_p to_p up_v = let forward = RTCTuple . norm ( RTCTuple . subtract to_p from_p ) in let up_v ' = RTCTuple . norm up_v in let left = RTCTuple . cross forward up_v ' in let true_up = RTCTuple . cross left forward in let orientation = [ | [ | left . x ; left . y ; left . z ; 0 . ] ; | [ | true_up . x ; true_u... |
let data ( tri : RTCShape . t ) = match tri . shape with | Triangle data -> data | _ -> failwith " expected a triangle " |
let precompute p1 p2 p3 = let e1 = RTCTuple . subtract p2 p1 in let e2 = RTCTuple . subtract p3 p1 in let normal = RTCTuple . norm ( RTCTuple . cross e2 e1 ) in ( e1 , e2 , normal ) |
let local_intersect shape ( ? trail [ ] ) = ( r : RTCRay . t ) = let tri = data shape in let dir_cross_e2 = RTCTuple . cross r . direction tri . e2 in let det = RTCTuple . dot tri . e1 dir_cross_e2 in if ( abs_float det ) < RTCConst . epsilon then [ ] else let f = 1 . . / det in let p1_to_origin = RTCTuple . subtract r... |
let build p1 p2 p3 = let ( e1 , e2 , normal ) = precompute p1 p2 p3 in let data : RTCShape . tri_data = { p1 ; p2 ; p3 ; n1 = normal ; n2 = normal ; n3 = normal ; smooth = false ; e1 ; e2 ; normal } in let local_normal_at ( ? hit = None ) shape ( point : RTCTuple . t ) = normal in RTCShape . build ( Triangle data ) loc... |
let smooth p1 p2 p3 n1 n2 n3 = let ( e1 , e2 , normal ) = precompute p1 p2 p3 in let data : RTCShape . tri_data = { p1 ; p2 ; p3 ; n1 ; n2 ; n3 ; smooth = true ; e1 ; e2 ; normal } in let local_normal_at ( ? hit = None ) shape ( point : RTCTuple . t ) = let ( h : RTCShape . t RTCIntersection . t ) = match hit with | No... |
type t = { shapes : RTCShape . t list ; lights : RTCLight . point_light list } |
type x_t = RTCShape . t RTCIntersection . t |
let build ( ? shapes [ ] ) = ( ? lights [ ] ) = ( ) = { shapes ; lights } |
let intersect ( w : t ) ( r : RTCRay . t ) = let rec aux xs = function | [ ] -> xs | shape :: shapes -> let xs ' = RTCShape . intersect shape r in match xs ' with | [ ] -> aux xs shapes | _ -> aux ( List . merge ( fun ( a : x_t ) ( b : x_t ) -> compare a . t b . t ) xs xs ' ) shapes in aux [ ] w . shapes |
let is_shadowed ( w : t ) ( light : RTCLight . point_light ) ( point : RTCTuple . t ) = let v = RTCTuple . subtract light . position point in let distance = RTCTuple . mag v in let direction = RTCTuple . norm v in let r = RTCRay . build point direction in let xs = intersect w r in let allow ( x : RTCShape . t RTCInters... |
let rec shade_hit ( w : t ) ( c : RTCComps . t ) remaining = let material = RTCComps . material c in let rec collect acc = function | [ ] -> acc | light :: lights -> let shadowed = is_shadowed w light c . point in let transform = RTCShape . world_to_object c . shape c . trail in let result = RTCMaterial . lighting mate... |
type io = string -> unit |
type name = signal -> string |
type type_decl = | Input | Output | Wire | Reg | Mem of int | Constant of string |
let tab n = String . v ~ len : n ( fun _ -> ' ' ) |
let t4 = tab 4 |
let t8 = tab 8 |
let write_strings io f s = let s = Array . of_list s in let len = Array . length s in for i = 0 to len - 1 do io ( f ( i = 0 ) ( i = len - 1 ) s . ( i ) ) done |
let rec sep s l = match l with | [ ] -> " " | [ a ] -> a | a :: b -> a ^ s ^ sep s b |
let str_map f s = let l = String . length s in let x = Bytes . create l in for i = 0 to l - 1 do Bytes . set x i ( f s . [ i ] ) done ; Bytes . to_string x |
let is_alpha c = ( c >= ' a ' && c <= ' z ' ) || ( c >= ' A ' && c <= ' Z ' ) |
let is_num c = c >= ' 0 ' && c <= ' 9 ' |
let is_alpha_num c = is_alpha c || is_num c |
module type OrderedString = ( Map . OrderedType with type t = string ) |
module CaseSensitive = struct type t = string let compare a b = compare a b end |
module CaseInsensitive = struct type t = string let compare a b = compare ( String . Ascii . uppercase a ) ( String . Ascii . uppercase b ) end |
module type Mangler = sig module SM : Map . S val empty : string SM . t val lookup : string -> int SM . t -> int option val mangle : string -> int SM . t -> int SM . t * string end |
module Mangler ( Ord : OrderedString ) = struct module SM = Map . Make ( Ord ) let empty = SM . empty let lookup name map = try Some ( SM . find name map ) with Not_found -> None let rec mangle name map = match lookup name map with | Some ( x ) -> mangle ( name ^ " _ " ^ string_of_int x ) ( SM . add name ( x + 1 ) map ... |
module type SignalNaming = sig module Case : OrderedString val prefix : string val reserved : string list val legalize : string -> string end |
module VerilogNames = struct module Case = CaseSensitive let prefix = " _ " let reserved = [ " and " ; " always " ; " assign " ; " attribute " ; " begin " ; " buf " ; " bufif0 " ; " bufif1 " ; " case " ; " cmos " ; " deassign " ; " default " ; " defparam " ; " disable " ; " else " ; " endattribute " ; " end " ; " endca... |
module VhdlNames = struct module Case = CaseInsensitive let prefix = " hc_ " let reserved = [ " abs " ; " access " ; " after " ; " alias " ; " all " ; " and " ; " architecture " ; " array " ; " assert " ; " attribute " ; " begin " ; " block " ; " body " ; " buffer " ; " bus " ; " case " ; " component " ; " configuratio... |
module type SignalNameManager = sig module M : Mangler module UI : sig type t = uid * int val compare : t -> t -> int end module SMap : Map . S type mem_names = { arr : string ; typ : string ; t1 : string ; t2 : string ; } type name_map = { mangler : int M . SM . t ; signals : string SMap . t ; mem : mem_names UidMap .... |
module SignalNameManager ( S : SignalNaming ) = struct module M = Mangler ( S . Case ) module UI = struct type t = uid * int let compare = compare end module SMap = Map . Make ( UI ) let prefix = S . prefix let reserved = S . reserved type mem_names = { arr : string ; typ : string ; t1 : string ; t2 : string ; } type n... |
module Process = struct type level = Rising | Falling | High | Low type stat = | If of Signal . Types . signal * level * stat * stat | Assign of Signal . Types . signal * Signal . Types . signal | Empty let make_reg ( ? clock = true ) r s = let q = s in let d = List . hd ( deps s ) in let lev s = if s = empty || s = vd... |
module type Rtl = sig open Signal . Types module Names : SignalNameManager val comment : string -> string val header_and_ports : io -> string -> ( string * int ) list -> ( string * int ) list -> unit val signal_decl : io -> string -> signal -> unit val alias_decl : io -> string -> signal -> unit val mem_decl : io -> Na... |
module VerilogCore : Rtl = struct module Names = SignalNameManager ( VerilogNames ) let string_of_type = function | Input -> " input " | Output -> " output " | Wire -> " wire " | Reg -> " reg " | Mem ( _ ) -> " mem " | Constant ( _ ) -> " wire " let comment s = " /* " ^ s ^ " " */ let decl t n b = let decl s n b = if b... |
module VhdlCore : Rtl = struct module Names = SignalNameManager ( VhdlNames ) let conversions = let p = Names . prefix in [ " function " ^ p ^ " uns ( a : std_logic ) return unsigned is variable b : unsigned ( 0 downto 0 ) ; begin b ( 0 ) := a ; return b ; end ; " ; " function " ^ p ^ " uns ( a : std_logic_vector ) ret... |
module type Rtl_S = sig val write : ( string -> unit ) -> Circuit . t -> unit end |
module Make ( R : Rtl ) = struct let write io circ = let inputs , outputs = Circuit . inputs circ , Circuit . outputs circ in let is_internal s = not ( Circuit . is_input circ s ) && not ( Circuit . is_output circ s ) && not ( s = empty ) in let internal_signals = Circuit . filter is_internal outputs in let nm = R . Na... |
module C = struct open Circuit open Utils open Printf let array_mul os signed words_r words_a words_b bits_r bits_a bits_b r a b = let soi = string_of_int in let mem_at a = " sim -> data [ " ^ soi a ^ " ] " in let int_to_hex a = sprintf " % lx " a in let ( . ) << = Int32 . shift_left in let access a words bits i = if i... |
module Hierarchy = struct open Signal . Types let inst_name = function | Signal_inst ( _ , _ , i ) -> i . inst_name | _ -> failwith " expecting instantiation " let rec write ' ~ transforms ( seen : string list ref ) database path write_hdl circ = let name = Circuit . name circ in let fname = path ^ name ^ " . v " in le... |
type ' a t = Node of ( Envelope . t * ' a t ) list | Leaf of ( Envelope . t * ' a ) list | Empty |
let empty_node = ( Envelope . empty , Empty ) |
let enlargement_needed e e ' = Envelope . area ( Envelope . add e e ' ) . - Envelope . area e |
let rec partition_by_min_enlargement e = function | ( e ' , _ ) as n :: [ ] -> n , [ ] , enlargement_needed e e ' | ( e ' , _ ) as n :: ns -> let enlargement = enlargement_needed e e ' in let min , maxs , enlargement ' = partition_by_min_enlargement e ns in if enlargement < enlargement ' then n , min :: maxs , enlargem... |
let pairs_of_list xs = List . concat ( List . map ( fun x -> List . map ( fun y -> ( x , y ) ) xs ) xs ) |
let split_pick_seeds ns = let pairs = pairs_of_list ns in let cost ( e0 , _ ) ( e1 , _ ) = ( Envelope . area ( Envelope . add e0 e1 ) ) . - ( Envelope . area e0 ) . - ( Envelope . area e1 ) in let rec max_cost = function | ( n , n ' ) :: [ ] -> cost n n ' , ( n , n ' ) | ( n , n ' ) as pair :: ns -> let max_cost ' , pa... |
let split_pick_next e0 e1 ns = let diff ( e , _ ) = abs_float ( ( enlargement_needed e0 e ) . - ( enlargement_needed e1 e ) ) in let rec max_difference = function | n :: [ ] -> diff n , n | n :: ns -> let diff ' , n ' = max_difference ns in let diff = diff n in if diff > diff ' then diff , n else diff ' , n ' | [ ] -> ... |
let split_nodes ns = let rec partition xs xs_envelope ys ys_envelope = function | [ ] -> ( xs , xs_envelope ) , ( ys , ys_envelope ) | rest -> begin let ( e , _ ) as n = split_pick_next xs_envelope ys_envelope rest in let rest ' = List . filter ( ( ) != n ) rest in let enlargement_x = enlargement_needed e xs_envelope i... |
let envelope_of_nodes ns = Envelope . add_many ( List . map ( fun ( e , _ ) -> e ) ns ) |
let rec insert ' elem e = function | Node ns -> begin let ( _ , min ) , maxs , _ = partition_by_min_enlargement e ns in match insert ' elem e min with | min ' , ( _ , Empty ) -> let ns ' = min ' :: maxs in let e ' = envelope_of_nodes ns ' in ( e ' , Node ns ' ) , empty_node | min ' , min ' ' when ( List . length maxs +... |
let insert t elem e = match insert ' elem e t with | ( _ , a ) , ( _ , Empty ) -> a | a , b -> Node [ a ; b ] |
let filter_intersecting e = List . filter ( fun ( e ' , _ ) -> Envelope . intersects e e ' ) |
let rec find t e = match t with | Node ns -> let intersecting = filter_intersecting e ns in let found = List . map ( fun ( _ , n ) -> find n e ) intersecting in List . concat found | Leaf es -> List . map snd ( filter_intersecting e es ) | Empty -> [ ] |
let rec size = function | Node ns -> let sub_sizes = List . map ( fun ( _ , n ) -> size n ) ns in List . fold_left ( ) + 0 sub_sizes | Leaf es -> List . length es | Empty -> 0 |
type env = Pathname . t -> Pathname . t |
type builder = Pathname . t list list -> ( Pathname . t , exn ) Outcome . t list |
type action = env -> builder -> Command . t |
type digest_command = { digest : string ; command : Command . t } |
type ' a gen_rule = { name : string ; tags : Tags . t ; deps : Pathname . t list ; prods : ' a list ; stamp : ' a option ; code : env -> builder -> digest_command } |
type rule = Pathname . t gen_rule |
type rule_scheme = Resource . resource_pattern gen_rule |
let name_of_rule r = r . name |
let deps_of_rule r = r . deps |
let prods_of_rule r = r . prods |
let stamp_of_rule r = r . stamp |
type ' a rule_printer = ( Format . formatter -> ' a -> unit ) -> Format . formatter -> ' a gen_rule -> unit |
let compare _ _ = assert false |
let print_rule_name f r = pp_print_string f r . name |
let print_resource_list = List . print Resource . print |
let print_rule_contents ppelt f r = fprintf f " [ @< v2 { >@ [ @< 2 > name =@ % S ] ; @@ [ @< 2 > tags =@ % a ] ; @@ [ @< 2 > deps =@ % a ] ; @@ [ @< 2 > prods = % a ] ; @@ [ @< 2 > code = < fun ] ] >@@@ } " r . name Tags . print r . tags print_resource_list r . deps ( List . print ppelt ) r . prods |
let pretty_print ppelt f r = fprintf f " [ @< hv2 > rule @ % S @ ~ deps :% a @ ~ prods :% a @ < fun ] " >@ r . name print_resource_list r . deps ( List . print ppelt ) r . prods |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.