Permalink
Browse files

token language

  • Loading branch information...
1 parent 28d2a23 commit 9c60e382c389ec7db2f8a5225c089a485f6cf543 Jean Krivine committed May 10, 2012
Showing with 35 additions and 84 deletions.
  1. +0 −56 .paths
  2. +2 −2 OCamlMakefile
  3. +1 −0 dataStructures/mods.ml
  4. +0 −1 grammar/ast.ml
  5. +15 −14 grammar/eval.ml
  6. +2 −3 grammar/kappaParser.mly
  7. +2 −1 pattern/dynamics.ml
  8. +13 −7 simulation/external.ml
View
56 .paths
@@ -6,64 +6,8 @@ simulation
pattern
models
models/tdg
-man
-man/img
-man/bib
main
grammar
dataStructures
cflow
Error
-Error
-cflow
-dataStructures
-grammar
-main
-man
-man/bib
-man/img
-models
-models/dna
-models/nonlocal
-models/out
-pattern
-simulation
-siteGraphs
-Error
-cflow
-dataStructures
-grammar
-main
-man
-man/bib
-man/img
-models
-models/dna
-models/nonlocal
-models/out
-pattern
-simulation
-siteGraphs
-Error
-cflow
-dataStructures
-grammar
-main
-man
-man/bib
-man/img
-models
-models/dna
-models/nonlocal
-models/out
-pattern
-simulation
-siteGraphs
-models/debug
-models/stories
-models/stories
-<<<<<<< HEAD
-models/stories
-=======
->>>>>>> branch 'master' of git@github.com:jkrivine/KaSim.git
-models/token
View
@@ -386,8 +386,8 @@ export CPPFLAGS_WIN32
INCFLAGS :=
-SHELL := /bin/sh
-
+#SHELL := /bin/bash
+#PATH = /usr/bin:/usr/sbin:/opt/local/bin:/opt/local/sbin:/bin
MLDEPDIR := ._d
BCDIDIR := ._bcdi
View
@@ -13,6 +13,7 @@ module DepMap = Map.Make (struct type t = dep_type let compare = compare end)
module DepSet = Set.Make (struct type t = dep_type let compare = compare end)
let string_of_dep = function
+ | TOK i -> "TOK("^(string_of_int i)^")"
| ALG i -> "ALG("^(string_of_int i)^")"
| KAPPA i -> "KAPPA("^(string_of_int i)^")"
| EVENT -> "EVENT"
View
@@ -70,7 +70,6 @@ and modif_expr =
| UPDATE_TOK of (string * Tools.pos * alg_expr * Tools.pos) (*TODO: pause*)
| STOP of ((string * Tools.pos) option * Tools.pos)
| SNAPSHOT of ((string * Tools.pos) option * Tools.pos) (*maybe later of mixture too*)
- | RESET of (string * alg_expr * Tools.pos)
| CFLOW of (string * Tools.pos * Tools.pos)
| CFLOWOFF of (string * Tools.pos * Tools.pos)
| FLUX of (string * Tools.pos) option * Tools.pos
View
@@ -715,19 +715,6 @@ let effects_of_modif variables env ast =
let str =
Printf.sprintf "remove %s * %s" str (Mixture.to_kappa false m env)
in ((m :: variables), (Dynamics.DELETE (v, m)), str, env)
- | RESET (tk_name, alg_expr, pos) ->
- let i = try Environment.num_of_token tk_name env with
- | Not_found -> raise (ExceptionDefn.Semantics_Error (pos,"Token " ^ (tk_name ^ " is not defined")))
- in
- let (x, is_constant, _, str) = partial_eval_alg env alg_expr in
- let v =
- if is_constant
- then Dynamics.CONST (close_var x)
- else Dynamics.VAR x in
- let str =
- Printf.sprintf "set token %s to %s" tk_name str
- in
- (variables, (Dynamics.RESET (i,v)), str, env)
| UPDATE (nme, pos_rule, alg_expr, pos_pert) ->
let i,is_rule =
(try (Environment.num_of_rule nme env,true)
@@ -749,6 +736,20 @@ let effects_of_modif variables env ast =
let v_str,_ = Environment.alg_of_num i env in
Printf.sprintf "set variable '%s' to %s" v_str str
in (variables, (Dynamics.UPDATE (i, v)), str, env)
+ | UPDATE_TOK (tk_nme,tk_pos,alg_expr,instr_pos) ->
+ let tk_id =
+ try Environment.num_of_token tk_nme env with
+ | Not_found -> raise (ExceptionDefn.Semantics_Error (tk_pos,"Token " ^ (tk_nme ^ " is not defined")))
+ in
+ let (x, is_constant, dep, str) = partial_eval_alg env alg_expr in
+ let v =
+ if is_constant
+ then Dynamics.CONST (close_var x)
+ else Dynamics.VAR x
+ in
+ let str = Printf.sprintf "set token '%s' to value %s" tk_nme str
+ in
+ (variables, (Dynamics.UPDATE_TOK (tk_id, v)), str, env)
| SNAPSHOT (opt,pos) -> (*when specializing snapshots to particular mixtures, add variables below*)
let str = "snapshot state" in
let opt_name =
@@ -913,7 +914,7 @@ let pert_of_result variables env res =
dep env
in
(env,None)
- | Dynamics.UPDATE _ | Dynamics.RESET _ | Dynamics.SNAPSHOT _ | Dynamics.STOP _ | Dynamics.FLUX _ | Dynamics.FLUXOFF _ | Dynamics.CFLOWOFF _ ->
+ | Dynamics.UPDATE _ | Dynamics.UPDATE_TOK _ | Dynamics.SNAPSHOT _ | Dynamics.STOP _ | Dynamics.FLUX _ | Dynamics.FLUXOFF _ | Dynamics.CFLOWOFF _ ->
let env =
DepSet.fold
(fun dep env -> Environment.add_dependencies dep (Mods.PERT p_id) env
View
@@ -171,8 +171,6 @@ one_shot_effect:
{Ast.SNAPSHOT ($2,$1)}
| STOP fic_label
{Ast.STOP ($2,$1)}
-| ID INITIALIZE alg_expr
- {let str,pos = $1 in Ast.RESET (str,$3,pos)}
;
fic_label:
@@ -197,7 +195,8 @@ mixture token_expr {($1,$2)}
token_expr:
/*empty*/ {[]}
-| OP_BRA sum_token CL_BRA {$2}
+| PIPE sum_token {$2}
+| PIPE error {raise (ExceptionDefn.Syntax_Error "Malformed token expression, I was expecting a_0 t_0 + ... + a_n t_n, where t_i are tokens and a_i any algebraic formula")}
;
sum_token:
View
@@ -130,7 +130,7 @@ and modification =
INTRO of variable * Mixture.t
| DELETE of variable * Mixture.t
| UPDATE of int * variable
- | RESET of int * variable
+ | UPDATE_TOK of int * variable
| SNAPSHOT of string option
| STOP of string option
| CFLOW of int
@@ -144,6 +144,7 @@ let string_of_pert pert env =
| INTRO (_,mix) -> Printf.sprintf "INTRO %s" (Mixture.to_kappa false mix env)
| DELETE (_,mix) -> Printf.sprintf "DELETE %s" (Mixture.to_kappa false mix env)
| UPDATE (r_id,_) -> Printf.sprintf "UPDATE rule[%d]" r_id
+ | UPDATE_TOK (t_id,_) -> Printf.sprintf "UPDATE token %s" (Environment.token_of_num t_id env)
| SNAPSHOT opt -> (match opt with None -> "SNAPSHOT" | Some s -> "SNAPSHOT("^s^")")
| STOP opt -> (match opt with None -> "STOP" | Some s -> "STOP("^s^")")
| FLUX opt -> (match opt with None -> "FLUX" | Some s -> "FLUX("^s^")")
View
@@ -160,13 +160,19 @@ let apply_effect p_id pert state counter env =
let env,pert_ids = State.update_dep state (ALG id) IntSet.empty counter env in
(env,state,pert_ids,[])
end
- | RESET (tk_id,v) ->
- begin
- let value = State.value state ~var:v (-1) counter env in
- state.token_vector.(tk_id) <- value ;
- let env,pert_ids = State.update_dep state (TOK tk_id) IntSet.empty counter env in
- (env,state,pert_ids,[])
- end
+ | UPDATE_TOK (tk_id,v) ->
+ let _ =
+ if !Parameter.debugModeOn then
+ (Debug.tag (Printf.sprintf "Updating token '%s'" (Environment.token_of_num tk_id env)))
+ in
+ let value = State.value state ~var:v (-1) counter env in (*Change here if one wants to have address passing style of assignation*)
+ begin
+ try
+ state.State.token_vector.(tk_id) <- value ;
+ let env,pert_ids = State.update_dep state (TOK tk_id) IntSet.empty counter env in
+ (env,state,pert_ids,[])
+ with Invalid_argument _ -> failwith "External.apply_effect: invalid token id"
+ end
| SNAPSHOT opt -> (snapshot opt ; (env, state ,IntSet.empty,[]))
| CFLOW id ->
if !Parameter.debugModeOn then Debug.tag "Tracking causality" ;

0 comments on commit 9c60e38

Please sign in to comment.