wangjicheng886的个人空间 https://blog.eetop.cn/1774723 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

skill language user guide 48--50

热度 17已有 1422 次阅读| 2023-6-24 16:41 |系统分类:芯片设计

The if Function

Use the if function to selectively evaluate two groups of one or more expressions. 

使用if函数来有选择地评估一个或多个表达式的两个组。

The  condition in an if expression evaluates to nil or non-nil.

if表达式中的条件将被评估为nil或非nil。 

The return value of the if expression is the value last computed.

if表达式的返回值是最后计算的值

if( shapeType == "rect"  

        then  

            println( "Shape is a rectangle" )  

            ++rectCount  

        else 

            println( "Shape is not a rectangle" )

           ++miscCount  

         );if

这段Cadence Skill代码是一个条件语句,根据变量shapeType的值来判断形状类型是否为矩形。如果shapeType的值为"rect",则输出"Shape is a rectangle"并将rectCount加1;否则输出"Shape is not a rectangle",并将miscCount加1。在Cadence Skill中,条件语句使用if-then-else结构表示,语句结尾需要添加分号。

这里的++miscCount是一个自增运算符,表示将变量miscCount的值加1。它等价于miscCount = miscCount + 1。


SKILL does most of its error checking during execution. 

SKILL在执行过程中会大部分进行错误检查。

Error messages involving if expressions can be obscure. 

涉及if表达式的错误信息可能会比较晦涩难懂。

Be sure to 

Be aware of the placement of the parentheses: if( … then … else … ).  

Avoid white space immediately after the if keyword.  

Use then and else when appropriate to your logic.

Consider the error message when you accidentally put white space after the if keyword.

当你在if关键字后面意外地加上空格时,请考虑错误信息。

shapeType = "rect"  

if ( shapeType == "rect"  

       then  

              println( "Shape is a rectangle" )  

              ++rectCount  

       else  

              println( "Shape is not a rectangle" )  

              ++miscCount  

       ) ;if

Message: *Error* if: too few arguments (at least 2 expected, 1 given)…


Consider the error message when you accidentally drop the then keyword, but include an  else keyword, 

and the condition returns nil

当你意外省略了then关键字,但包含了else关键字,并且条件返回nil时,请考虑错误信息

shapeType = "label"  

if( shapeType == "rect"  

              println( "Shape is a rectangle" )  

              ++rectCount  

       else  

              println( "Shape is not a rectangle" )  

              ++miscCount  

       ) ;if 

Message: *Error* if: too many arguments …


The when and unless Functions

Use the when function whenever you have only then expressions.

每当你只有then表达式时,请使用when函数。

when( shapeType == "rect"

         println( "Shape is a rectangle" )

         ++rectCount 

    ) ; when

when( shapeType == "ellipse"

         println( "Shape is an ellipse" )

         ++ellipseCount 

    ) ; when 

Use the unless function to avoid negating a condition. Some users find this less confusing.

使用unless函数来避免否定一个条件。一些用户认为这样做会更不容易混淆。


unless( shapeType == "rect" || shapeType == "line"

        println( "Shape is miscellaneous" )

        ++miscCount 

      ) ; unless

如果形状类型不是矩形或线条,则打印出“形状是杂项”并增加杂项计数器的值。

使用了unless函数来避免对条件取反,即当条件不满足时执行代码块。


The when and unless functions both return the last value evaluated within their body or  nil.


The case Function


The case function offers branching based on a numeric or string value.

case函数根据数值或字符串值提供分支选择。

case( shapeType 

      ( "rect" 

            ++rectCount 

            println( "Shape is a rectangle" ) 

            

      ( "line"

            ++lineCount 

            println( "Shape is a line" ) 

           

      ( "label" 

            ++labelCount 

            println( "Shape is a label" ) 

            

      ( t 

            ++miscCount 

            println( "Shape is miscellaneous" ) 

            

      ) ; case


这段代码是一个基于形状类型进行分支选择的代码块。它使用了case函数,根据shapeType的值进行选择。

如果shapeType的值等于"rect",则执行++rectCount(矩形计数器加1)和println("Shape is a rectangle");

如果shapeType的值等于"line",则执行++lineCount(线条计数器加1)和println("Shape is a line");

如果shapeType的值等于"label",则执行++labelCount(标签计数器加1)和println("Shape is a label");

如果shapeType的值不是上述三个值,则执行++miscCount(杂项计数器加1)和println("Shape is miscellaneous")。

最后返回case函数的返回值。

代码的目的是根据给定的shape类型执行特定的操作并进行计数跟踪,同时通过打印语句输出相应的形状信息。


The optional value t acts as a -all and should be handled last. The case function returns the  value of the last expression evaluated. In this example:  

可选值t起到了类似于"-all"的作用,应该在最后处理。case函数返回最后一个被评估的表达式的值。在这个例子中:


The value of the variable shapeType is compared against the values rect, line, and  label. If SKILL finds a match, the several expressions in that arm are evaluated.  

变量shapeType的值与"rect"、"line"和"label"进行比较。如果匹配成功,则会评估该分支中的多个表达式。

If no match is found, the final arm is evaluated.  

如果没有找到匹配项,则会评估最后一个分支。

When an arm’s target value is actually a list, SKILL searches the list for the candidate  value. If SKILL finds the candidate value, all the expressions in the arm are evaluated.

当某个分支的目标值实际上是一个列表时,SKILL会在列表中搜索候选值。如果找到候选值,则会评估该分支中的所有表达式。


case( shapeType 

           ( "rect" 

                      ++rectCount 

                      println( "Shape is a rectangle" ) 

                      ) 

           ( ( "label" "line" ) 

                      ++labelOrLineCount 

                      println( "Shape is a line or a label" ) 

                      ) 

           ( t 

                      ++miscCount 

                      println( "Shape is miscellaneous" )

                      )  

           ) ; case



3

点赞

刚表态过的朋友 (3 人)

发表评论 评论 (7 个评论)

回复 firewolf223 2023-6-25 09:13
纯纯的翻译manual?
回复 aznsj 2023-6-30 08:16
真的别学, 没用, 还不如学哥MATLAB PYTHON。 都可以做。
回复 False_promise 2023-7-5 20:38
aznsj: 真的别学, 没用, 还不如学哥MATLAB PYTHON。 都可以做。
为什么呢?cadence公司的软件可以用python?
回复 aznsj 2023-7-6 11:28
SKILL 没有市场, 只能用cadence. 不要学 浪费时间,有空多学python. 什么都可以
回复 王钰 2023-7-14 13:11
aznsj: 真的别学, 没用, 还不如学哥MATLAB PYTHON。 都可以做。
这方面的教程有没有推荐的,谢谢
回复 wangjicheng886 2023-7-21 14:38
aznsj: SKILL 没有市场, 只能用cadence. 不要学 浪费时间,有空多学python. 什么都可以
cadence 以后可能会伴我一生,只能了解一点了。
回复 wangjicheng886 2023-7-21 14:41
我不是要花很多精力去学的,纯粹业余,单纯地觉得编程很有意思

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 28

    粉丝
  • 7

    好友
  • 19

    获赞
  • 8

    评论
  • 128

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-19 05:17 , Processed in 0.020485 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部