Hi Marco,
Some answers embedded...
marcoballins@[EMAIL PROTECTED]
wrote, on 08/27/08 09:45:
> Hi all,
>
> I use OCEAN scripts to simulate circuits. Typically I have one (or
> more) script per circuit. At the moment all the variables in my
> scripts are global.
>
> However I'd like to reduce the number of global variables, or at least
> make such that some variables that are used to simulate one circuit
> are invisible when simulating a second one.
>
> I do not want to use let(), because
>
> * I'd like to avoid to explicitly declare each variable
> * I still want to access some variables interactively from the CIW
> at the end of the script
OK. But let() is really the way to do this in SKILL...
>
> I thought something like a MATLAB workspace could do the job. I read
> about SKILL++ environments, and I thought that they work like MATLAB
> workspaces. However:
Not really. A SKILL++ environment is a lexical scope - and generally you'd
still need to use let() to define a new environment and declare the
variables
within them.
>
> * Can I use SKILL++ environment in scripts (i.e. non-
> interactively)?
yes
> * Can you use OCEAN functions directly inside SKILL++ scripts?
yes
> * Is there anything with environments functionality that can be
> used in (plain) SKILL scripts?
not really. An environment is created via a SKILL++ lexical scope - you
can access the current environment from SKILL++, but not see what's
inside it (unless you're in debug mode).
> * How are environments setup and used in a script? (simple code
> example would help here)
>
I don't think this is the right solution, although perhaps the code
I wrote below might help?
> In case I cannot use environments or they turn out to be not a good
> solution for me:
>
> * What other options do I have to share/hide variables?
> * How can I clear all the variables?
>
> Thanks for any suggestion.
>
>
> As an example of how I would like to use this functionality, consider
> the case where I want to have "workspaces", each dedicated to a
> different circuit/script. All variables used in the script
> corresponding to one circuit should be hidden when simulating a second
> one. If this is not easily possible, than at least clear all variables
> before calling a second script would help.
A simple solution would probably be just to use a table to store
variables.
However, I just wrote a bit of SKILL that might be an elegant solution
to this. See the examples at the top of the code. You have to use
the abVarSet/abVarGet macros to set and get variable values rather than
using the "=" operator, but it might suit your needs. Note that the
file containing the code MUST retain a ".ils" suffix to allow it to
be seen as SKILL++. This is in fact taking advantage of SKILL++
lexical environments to hide the data ;->
/* abWorkspace.ils
Author A.D.Beckett
Group Custom IC (UK), Cadence Design Systems Ltd.
Language SKILL
Date Aug 29, 2008
Modified
By
A simple workspace package. Use functions like this:
abWorkspace->set("first")
abVarSet(myVar 23)
abVarGet(myVar) => 23
abVarSet(myVar2 46)
abWorkspace->set("another")
abVarSet(myVar 200)
abVarGet(myVar) => 200
abWorkspace->set("first")
abVarGet(myVar) => 23
abWorkspace->delete("another")
***************************************************
SCCS Info: @[EMAIL PROTECTED]
(#) abWorkspace.ils 08/29/08.11:29:15 1.1
*/
(im****tSkillVar abWorkspace)
(setq abWorkspace
(let (currentWs (workspaces (makeTable 'workspaces nil)))
;----------------------------------------------------------------
; Sets the current workspace to either an existing
; named workspace, or creates a new one
;----------------------------------------------------------------
(defun set (wsName)
(let (ws)
(setq ws
(or (arrayref workspaces wsName)
(create wsName))
)
(setq currentWs ws)
)
)
;----------------------------------------------------------------
; Gets the current workspace. Used by the abVarSet/abVarGet
; macros
;----------------------------------------------------------------
(defun get ()
currentWs
)
;----------------------------------------------------------------
; Deletes a workspace, and zaps the current workspace if
; it is the one being deleted
;----------------------------------------------------------------
(defun delete (wsName)
(when (eq (remove wsName workspaces) currentWs)
(setq currentWs nil))
t
)
;----------------------------------------------------------------
; Create a new workspace. This is also a lexical
; environment with functions to set and get values
; from the table
;----------------------------------------------------------------
(defun create (wsName)
(let ((table (makeTable 'workspace)))
(defun set (var val)
(setarray table var val)
)
(defun get (var)
(arrayref table var)
)
(setarray workspaces wsName
(list nil 'set set 'get get))
)
)
;----------------------------------------------------------------
; The list of available functions from the package
;----------------------------------------------------------------
(list nil 'set set 'get get 'delete delete)
)
)
;------------------------------------------------------------------------
; Macros to make setting and getting variables in the current workspace
; easier. Saves having to quote the variable names.
;------------------------------------------------------------------------
(defmacro abVarSet (varName value)
`(funcall
(getq
(or
(funcall (getq abWorkspace get))
(error "No current workspace")
)
set)
(quote ,varName) ,value)
)
(defmacro abVarGet (varName)
`(funcall
(getq
(or
(funcall (getq abWorkspace get))
(error "No current workspace")
)
get)
(quote ,varName))
)


|