More Spry builtins

This commit is contained in:
Ehmry - 2019-02-08 14:29:56 +01:00
parent 3aa8a90265
commit b9733f0d19
1 changed files with 25 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import ../blobsets, ./filestores, ./httpstores
import spryvm/spryvm
import ../blobsets, ./filestores
import cbor
import std/strutils, std/tables, std/os
type BlobIdSpryNode* = ref object of Value
@ -59,12 +60,33 @@ proc addBlobSets*(spry: Interpreter) =
result = ingestBlobs(env, path)
nimFunc "newBlobStore":
let path = StringVal(evalArg(spry)).value
proc newStore(s: string): BlobStore =
if s.startsWith "http://": newHttpStore(s)
else: newFileStore(s)
let arg = StringVal(evalArg(spry)).value
BlobStoreNode(
store: newNullStore(),
store: newStore(arg),
blobs: initTable[string, tuple[id: BlobId, size: BiggestInt]](),
sets: initTable[string, BlobSet]())
nimFunc "toBlobId":
let str = StringVal(evalArg(spry)).value
BlobIdSpryNode(id: str.toBlobId)
nimFunc "cbor":
let set = BlobSetSpryNode(evalArg(spry)).set
newValue($toCbor(set))
nimFunc "commit":
let
env = BlobStoreNode(evalArgInfix(spry))
set = BlobSetSpryNode(evalArg(spry)).set
BlobSetSpryNode(set: env.store.commit(set))
nimFunc "hex":
let id = BlobIdSpryNode(evalArg(spry)).id
newValue(id.toHex)
#nimFunc "key":
# let str = StringVal(evalArg(spry)).value
# newValue(str.toKey)