add pick op, increment version
This commit is contained in:
		
							parent
							
								
									ed6cf767d0
								
							
						
					
					
						commit
						9e4eac6f12
					
				
							
								
								
									
										44
									
								
								SPEC.html
								
								
								
								
							
							
						
						
									
										44
									
								
								SPEC.html
								
								
								
								
							| 
						 | 
				
			
			@ -15,41 +15,6 @@
 | 
			
		|||
	display: none;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* From extension ms-toolsai.jupyter */
 | 
			
		||||
/* These classnames are inherited from bootstrap, but are present in most notebook renderers */
 | 
			
		||||
 | 
			
		||||
.alert {
 | 
			
		||||
    width: auto;
 | 
			
		||||
    padding: 1em;
 | 
			
		||||
    margin-top: 1em;
 | 
			
		||||
    margin-bottom: 1em;
 | 
			
		||||
}
 | 
			
		||||
.alert > *:last-child {
 | 
			
		||||
    margin-bottom: 0;
 | 
			
		||||
}
 | 
			
		||||
#preview > .alert:last-child {
 | 
			
		||||
    /* Prevent this being set to zero by the default notebook stylesheet */
 | 
			
		||||
    padding-bottom: 1em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.alert-success {
 | 
			
		||||
    /* Note there is no suitable color available, so we just copy "info" */
 | 
			
		||||
    background-color: var(--theme-info-background);
 | 
			
		||||
    color: var(--theme-info-foreground);
 | 
			
		||||
}
 | 
			
		||||
.alert-info {
 | 
			
		||||
    background-color: var(--theme-info-background);
 | 
			
		||||
    color: var(--theme-info-foreground);
 | 
			
		||||
}
 | 
			
		||||
.alert-warning {
 | 
			
		||||
    background-color: var(--theme-warning-background);
 | 
			
		||||
    color: var(--theme-warning-foreground);
 | 
			
		||||
}
 | 
			
		||||
.alert-danger {
 | 
			
		||||
    background-color: var(--theme-error-background);
 | 
			
		||||
    color: var(--theme-error-foreground);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</style>
 | 
			
		||||
        
 | 
			
		||||
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
 | 
			
		||||
| 
						 | 
				
			
			@ -408,11 +373,16 @@
 | 
			
		|||
<p>Make a copy of the second item on top of the stack.</p>
 | 
			
		||||
<p>The direct Klingon translation for <code>QI</code> is bridge, as in a bridge over a river, which works close enough.</p>
 | 
			
		||||
<p>Errors: stackUnderflow</p>
 | 
			
		||||
<h4 id="712-rotjir">7.1.2 rot/jIr</h4>
 | 
			
		||||
<h4 id="712-pickwoh">7.1.2 pick/woH</h4>
 | 
			
		||||
<p><em>N <code>woH</code> objN</em></p>
 | 
			
		||||
<p>Make a copy of the Nth item on top of the stack.</p>
 | 
			
		||||
<p>For example <em>1 <code>woH</code></em> is the same as <code>latlh</code> & <em>2 <code>woH</code></em> is the same as <code>QI</code></p>
 | 
			
		||||
<p>Errors: stackUnderflow, stackOverflow</p>
 | 
			
		||||
<h4 id="713-rotjir">7.1.3 rot/jIr</h4>
 | 
			
		||||
<p><em>obj1 obj2 obj3 <code>jIr</code> obj2 obj3 obj1</em></p>
 | 
			
		||||
<p>Rotate the third item to the top of the stack.</p>
 | 
			
		||||
<p>Errors: stackUnderflow</p>
 | 
			
		||||
<h4 id="713-depthjuv">7.1.3 depth/juv</h4>
 | 
			
		||||
<h4 id="714-depthjuv">7.1.4 depth/juv</h4>
 | 
			
		||||
<p><em>- <code>juv</code> num</em></p>
 | 
			
		||||
<p>Count the number of items on the stack and push that number to the top of the stack.</p>
 | 
			
		||||
<p>Errors: stackUnderflow</p>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										15
									
								
								SPEC.md
								
								
								
								
							
							
						
						
									
										15
									
								
								SPEC.md
								
								
								
								
							| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
_var'aq_ Specification
 | 
			
		||||
==================================
 | 
			
		||||
=================================
 | 
			
		||||
 | 
			
		||||
For better flavor text please read the [Original `var'aq` spec](https://www.oocities.org/connorbd/varaq/varaqspec.html) the following is a trimmed down version of the spec with a couple of fixes and addendums to how this implementation of the language works.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -655,8 +655,17 @@ Make a copy of the second item on top of the stack.
 | 
			
		|||
The direct Klingon translation for `QI` is bridge, as in a bridge over a river, which works close enough.
 | 
			
		||||
 | 
			
		||||
Errors: stackUnderflow
 | 
			
		||||
#### 7.1.2 pick/woH
 | 
			
		||||
 | 
			
		||||
#### 7.1.2 rot/jIr
 | 
			
		||||
_N `woH` objN_
 | 
			
		||||
 | 
			
		||||
Make a copy of the Nth item on top of the stack.
 | 
			
		||||
 | 
			
		||||
For example _1 `woH`_ is the same as `latlh` & _2 `woH`_ is the same as `QI`
 | 
			
		||||
 | 
			
		||||
Errors: stackUnderflow, stackOverflow
 | 
			
		||||
 | 
			
		||||
#### 7.1.3 rot/jIr
 | 
			
		||||
 | 
			
		||||
_obj1 obj2 obj3 `jIr` obj2 obj3 obj1_
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -664,7 +673,7 @@ Rotate the third item to the top of the stack.
 | 
			
		|||
 | 
			
		||||
Errors: stackUnderflow
 | 
			
		||||
 | 
			
		||||
#### 7.1.3 depth/juv
 | 
			
		||||
#### 7.1.4 depth/juv
 | 
			
		||||
 | 
			
		||||
_- `juv` num_
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@
 | 
			
		|||
} repeat
 | 
			
		||||
 | 
			
		||||
elves shatter depth sub1 { 
 | 
			
		||||
    over over lt? 
 | 
			
		||||
    2 pick 2 pick lt? 
 | 
			
		||||
    choose
 | 
			
		||||
    { pop exch pop true } ifyes
 | 
			
		||||
    { pop } ifno
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								main.go
								
								
								
								
							
							
						
						
									
										3
									
								
								main.go
								
								
								
								
							| 
						 | 
				
			
			@ -20,8 +20,8 @@ func main() {
 | 
			
		|||
 | 
			
		||||
func repl() {
 | 
			
		||||
	scanner := bufio.NewScanner(os.Stdin)
 | 
			
		||||
	for scanner.Scan() {
 | 
			
		||||
	fmt.Print("> ")
 | 
			
		||||
	for scanner.Scan() {
 | 
			
		||||
		line := scanner.Text()
 | 
			
		||||
		if len(line) == 0 {
 | 
			
		||||
			return
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ func repl() {
 | 
			
		|||
		if err != nil {
 | 
			
		||||
			fmt.Printf("%v\n", err)
 | 
			
		||||
		}
 | 
			
		||||
		fmt.Print("> ")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -170,6 +170,33 @@ func Interpret(code Expr, argv []string) error {
 | 
			
		|||
 | 
			
		||||
			push(stack[n-2])
 | 
			
		||||
			stack = append(stack[:n-2], stack[n-3:]...)
 | 
			
		||||
		case PICK:
 | 
			
		||||
			n := len(stack) - 1
 | 
			
		||||
			a, e := pop()
 | 
			
		||||
			if e != nil {
 | 
			
		||||
				return e
 | 
			
		||||
			}
 | 
			
		||||
			if a.Tok == IDENTIFIER {
 | 
			
		||||
				a = get(a.Value.(string))
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if a.Tok == NUMBER {
 | 
			
		||||
				idx := int(a.Value.(float64))
 | 
			
		||||
 | 
			
		||||
				if idx <= 0 {
 | 
			
		||||
					return fmt.Errorf("`pick`: index must be a positive nonzero value")
 | 
			
		||||
				}
 | 
			
		||||
				if n-idx < 0 {
 | 
			
		||||
					return fmt.Errorf("`pick`: stack underflow")
 | 
			
		||||
				}
 | 
			
		||||
				if idx > n {
 | 
			
		||||
					return fmt.Errorf("`pick`: stack overflow")
 | 
			
		||||
				}
 | 
			
		||||
				push(stack[n-idx])
 | 
			
		||||
			} else {
 | 
			
		||||
				return fmt.Errorf("cannot `pick` index is not a number @%v", idx)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		case DEPTH:
 | 
			
		||||
			push(Expr{NUMBER, nil, float64(len(stack)), 0})
 | 
			
		||||
		case CLEAR:
 | 
			
		||||
| 
						 | 
				
			
			@ -1232,7 +1259,7 @@ func Interpret(code Expr, argv []string) error {
 | 
			
		|||
 | 
			
		||||
			fmt.Println(localAddr.IP.String())
 | 
			
		||||
		case VERSION:
 | 
			
		||||
			fmt.Println("var'aq -- 0.9.0 Martoq")
 | 
			
		||||
			fmt.Println("var'aq -- 0.9.1 Martoq")
 | 
			
		||||
		case ARGV:
 | 
			
		||||
			arg := Expr{LIST, make([]Expr, 0), nil, 0}
 | 
			
		||||
			for _, v := range argv {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -181,6 +181,8 @@ var keywords = map[string]TokenType{
 | 
			
		|||
	"QI":    OVER,
 | 
			
		||||
	"depth": DEPTH,
 | 
			
		||||
	"juv":   DEPTH,
 | 
			
		||||
	"pick":  PICK,
 | 
			
		||||
	"woH":   PICK,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func isDigit(s string) bool {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -105,6 +105,7 @@ const (
 | 
			
		|||
	OVER
 | 
			
		||||
	ROT
 | 
			
		||||
	DEPTH
 | 
			
		||||
	PICK
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var tokens = [...]string{
 | 
			
		||||
| 
						 | 
				
			
			@ -209,6 +210,7 @@ var tokens = [...]string{
 | 
			
		|||
	OVER:           "OVER",
 | 
			
		||||
	ROT:            "ROT",
 | 
			
		||||
	DEPTH:          "DEPTH",
 | 
			
		||||
	PICK:           "PICK",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (me TokenType) String() string {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue