Skip to content

Commit

Permalink
implement a bunch of object natives
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Aug 22, 2023
1 parent 5e70bec commit abd78dd
Show file tree
Hide file tree
Showing 16 changed files with 726 additions and 531 deletions.
18 changes: 9 additions & 9 deletions pact-core-tests/pact-tests/ops.repl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
(expect "+ decimal decimal" 7.0 (+ 1.2 5.8))
(expect "+ string string" "foobar" (+ "foo" "bar"))
(expect "+ list list" [1 2 3 4 5] (+ [1 2 3] [4 5]))
; (expect "+ object object" { "a": 2, "b": 4, "c": false}
; (+ { "a": 2 } { "b": 4, "c": false}))
; (expect "+ object object, left-biased merge" { "a": 4}
; (+ { "a": 4} {"a": true}))
(expect "+ object object" { "a": 2, "b": 4, "c": false}
(+ { "a": 2 } { "b": 4, "c": false}))
(expect "+ object object, left-biased merge" { "a": 4}
(+ { "a": 4} {"a": true}))
; (expect-failure "+ integer string" (+ 2 "hello"))
; (expect-failure "+ list string" (+ [2] "hello"))
; (expect-failure "+ object decimal" (+ {'a: 4} 1.0))
Expand Down Expand Up @@ -435,11 +435,11 @@
(expect "not != list list" false (!= [1 2 3] [1 2 3]))
(expect "!= list list" true (!= [1 3 2] [1 2 3]))

; "===== object equality"
; (expect "= object object" true (= { "a": 1 } { "a": 1 }))
; (expect "not = object object" false (= { "a": 1 } { "a": 1, "b": 2 }))
; (expect "not != object object" false (!= { "a": 1 } { "a": 1 }))
; (expect "!= object object" true (!= { "a": 1 } { "a": 1, "b": 2 }))
"===== object equality"
(expect "= object object" true (= { "a": 1 } { "a": 1 }))
(expect "not = object object" false (= { "a": 1 } { "a": 1, "b": 2 }))
(expect "not != object object" false (!= { "a": 1 } { "a": 1 }))
(expect "!= object object" true (!= { "a": 1 } { "a": 1, "b": 2 }))

; "===== keyset equality"
; (env-data { "k1": ["k1"], "k2": ["k2"] })
Expand Down
1 change: 1 addition & 0 deletions pact-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ common pact-core-common
, transformers
, text
, vector
, vector-algorithms
, megaparsec
, cryptonite
, memory
Expand Down
18 changes: 15 additions & 3 deletions pact-core/Pact/Core/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ data RawBuiltin
| RawDrop
| RawConcat
| RawReverse
| RawContains
| RawSort
| RawSortObject
| RawRemove
-- General
| RawMod
| RawMap
Expand All @@ -218,7 +222,7 @@ data RawBuiltin
| RawEnforceGuard
| RawKeysetRefGuard
-- | RawCreateUserGuard
| RawListAccess
| RawAt
| RawMakeList
| RawB64Encode
| RawB64Decode
Expand Down Expand Up @@ -273,6 +277,10 @@ rawBuiltinToText = \case
-- general
RawMap -> "map"
RawFilter -> "filter"
RawContains -> "contains"
RawSort -> "sort"
RawSortObject -> "sort-object"
RawRemove -> "remove"
-- RawIf -> "if"
RawIntToStr -> "int-to-str"
RawStrToInt -> "str-to-int"
Expand All @@ -291,7 +299,7 @@ rawBuiltinToText = \case
RawEnforceGuard -> "enforce-guard"
RawKeysetRefGuard -> "keyset-ref-guard"
-- RawCreateUserGuard -> "create-user-guard"
RawListAccess -> "at"
RawAt -> "at"
RawMakeList -> "make-list"
RawB64Encode -> "base64-encode"
RawB64Decode -> "base64-decode"
Expand Down Expand Up @@ -340,6 +348,10 @@ instance BuiltinArity RawBuiltin where
RawDrop -> 2
RawConcat -> 1
RawReverse -> 1
RawContains -> 2
RawSort -> 1
RawSortObject -> 2
RawRemove -> 2
-- General ->
RawMod -> 2
RawMap -> 2
Expand All @@ -363,7 +375,7 @@ instance BuiltinArity RawBuiltin where
RawEnforceGuard -> 1
RawKeysetRefGuard -> 1
-- RawCreateUserGuard -> 1
RawListAccess -> 2
RawAt -> 2
RawMakeList -> 2
RawB64Encode -> 1
RawB64Decode -> 1
Expand Down
5 changes: 3 additions & 2 deletions pact-core/Pact/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Pact.Core.Names
import Pact.Core.IR.Desugar
import Pact.Core.Errors
import Pact.Core.Pretty
import Pact.Core.Type
import Pact.Core.IR.Term
import Pact.Core.PactValue

Expand Down Expand Up @@ -62,7 +63,7 @@ data CompileValue b

newtype Interpreter b s m
= Interpreter {
_interpret :: HasCompileEnv b s m => Term Name b SpanInfo -> m InterpretValue
_interpret :: HasCompileEnv b s m => Term Name Type b SpanInfo -> m InterpretValue
}


Expand All @@ -88,7 +89,7 @@ interpretTopLevel
:: (HasCompileEnv b s m)
=> PactDb b SpanInfo
-> Interpreter b s m
-> DesugarOutput b SpanInfo (TopLevel Name b SpanInfo)
-> DesugarOutput b SpanInfo (TopLevel Name Type b SpanInfo)
-> m (CompileValue b)
interpretTopLevel pdb interp (DesugarOutput ds lo0 deps) = do
loaded .= lo0
Expand Down
3 changes: 1 addition & 2 deletions pact-core/Pact/Core/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module Pact.Core.Errors
import Control.Lens hiding (ix)
import Control.Exception
import Data.Text(Text)
import Data.Void
import Data.Dynamic (Typeable)

import Pact.Core.Type
Expand Down Expand Up @@ -227,7 +226,7 @@ instance Pretty DesugarError where
-- instance Exception OverloadError

data ArgTypeError
= ATEType (Type Void)
= ATEType Type
| ATEClosure
deriving (Show)

Expand Down
Loading

0 comments on commit abd78dd

Please sign in to comment.