mirror of
				https://github.com/Baidicoot/rpncalc-v4
				synced 2025-10-31 07:33:00 +00:00 
			
		
		
		
	buxfixes
This commit is contained in:
		| @@ -59,7 +59,7 @@ const eq = (_, args) => { | ||||
|     } | ||||
| } | ||||
|  | ||||
| const arr = (_, args) => { | ||||
| const tuple = (_, args) => { | ||||
|     return [makeFn(args[0], (_, args) => {return [{type:"array", val:args}]})]; | ||||
| } | ||||
|  | ||||
| @@ -90,7 +90,7 @@ addDefn("typeof", 1, type); | ||||
| addDefn("pair", 2, pair); | ||||
| addDefn("fst", ["pair"], fst); | ||||
| addDefn("snd", ["pair"], snd); | ||||
| addDefn("arr", ["int"], arr); | ||||
| addDefn("tuple", ["int"], tuple); | ||||
| addDefn("!!", ["int", "array"], index); | ||||
| addDefn("len", ["array"], len); | ||||
| addDefn("unsafeCoerce", 2, coerce); | ||||
| @@ -102,4 +102,4 @@ addRPNDefn("false", "(a b -> b)"); | ||||
| addRPNDefn("stop", "(-> \"stop)"); | ||||
| //addRPNDefn("id", "(a -> a)"); | ||||
| addRPNDefn("inv", "(x -> 1 x /)"); | ||||
| addRPNDefn("fold", "(x acc fn -> '(-> acc) '(-> x acc fn 'fn fold) 'x \"stop ==)"); | ||||
| addRPNDefn("fold", "(x acc fn -> 'acc '(-> x acc fn 'fn fold) 'x \"stop ==)"); | ||||
							
								
								
									
										25
									
								
								eval.mjs
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								eval.mjs
									
									
									
									
									
								
							| @@ -73,7 +73,9 @@ const makeObj = (elem) => { | ||||
| } | ||||
|  | ||||
| const cloneElem = (elem) => { | ||||
|     if (elem.type === "closure") { | ||||
|     if (Array.isArray(elem)) { | ||||
|         return elem.map(cloneElem); | ||||
|     } if (elem.type === "closure") { | ||||
|         let argsClone = []; | ||||
|         for (let i = 0; i < elem.args.length; i++) { | ||||
|             argsClone.push(cloneElem(elem.args[i])); | ||||
| @@ -86,13 +88,11 @@ const cloneElem = (elem) => { | ||||
|  | ||||
| const lookupScope = (name, scope) => { | ||||
|     let n = scope[name]; | ||||
|     console.log(n); | ||||
|     if (n) { | ||||
|         return cloneElem(n); | ||||
|     } | ||||
|     n = builtinDefn[name]; | ||||
|     if (n) { | ||||
|         console.log(name, n); | ||||
|         return cloneElem(n); | ||||
|     } else { | ||||
|         throw 'var "' + name + '" not in scope' | ||||
| @@ -136,12 +136,23 @@ const applyMany = (outstack, stack) => { | ||||
|     } | ||||
| } | ||||
|  | ||||
| const pushMany = (elems, stack) => { | ||||
|     for (let i = 0; i < elems.length; i++) { | ||||
|         pushS(elems[i], stack); | ||||
|     } | ||||
| } | ||||
|  | ||||
| const pushS = (elem, stack) => { | ||||
|     if (elem.type === "ident") { | ||||
|         let id = lookupScope(elem.val, stack.scope); | ||||
|         stack.stack.push(id); | ||||
|     if (Array.isArray(elem)) { | ||||
|         pushMany(elem, stack); | ||||
|     } else { | ||||
|         stack.stack.push(elem); | ||||
|         if (elem.type === "ident") { | ||||
|             let id = lookupScope(elem.val, stack.scope); | ||||
|             console.log(id); | ||||
|             pushS(id, stack); | ||||
|         } else { | ||||
|             stack.stack.push(elem); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Aidan K. Ewart
					Aidan K. Ewart