Skip to content

Instantly share code, notes, and snippets.

@kingsleyh
Last active September 26, 2019 09:00
Show Gist options
  • Save kingsleyh/104217d7519035bc77db0c33ab768f5e to your computer and use it in GitHub Desktop.
Save kingsleyh/104217d7519035bc77db0c33ab768f5e to your computer and use it in GitHub Desktop.
Taro spec

Taro Spec

For MVP initial version:

Requirements:

  1. must support basic programming logic, math, functions, variables, collections etc
  2. must support json - encoding / decoding / traversal
  3. must have http client capability
  4. must have crypto capability, openssl
  5. should support usage of C libraries for general extension of capabilities

Out of scope:

  1. does not need any disk / filesystem capability

Compiling & Execution:

  1. Should compile to LLVM IR -> native machine code
  2. Should executable via JIT and via native machine code

Language syntax and semantics:

  • Identifiers

  • Newline characters

  • Value Declarations and definitions

  • Classes and Objects

  • Expressions

  • Top level definitions

  • Collections

  • Assets

  • Equality

  • Enums

  • Packages

  • Whitespace & Comments

  • Literals

  • Assignment

  • Local variables

  • Control expression

  • Requiring files

  • Types and methods

  • Exception handling

  • Type grammar

  • Low level primitives

Examples

asset Sword {

  property attack : Int32 = 10
  property defence : Int32 = 8
  property health : Int32 = 20
  expose property name : String = "Shining Sword"

  -- special attacks
  record SpecialAttack1(name : String, description : String, value : Int32)
  record SpecialAttack2(name : String, description : String)

  immutable special_attack_1 : SpecialAttack1 = SpecialAttack1("Destroy Health", "reduces health by 10", 10)
  immutable special_attack_2 : SpecialAttack2 = SpecialAttack2("Mad Swapper", "swaps defence and health")

  -- sends a transaction to update the attack property
  expose def increase_attack(caller : Wallet, from_asset_id : Option(AssetId)) : Void {
    Asset.update(caller, Sword.asset_id, :attack, @attack += 1)
  }

  expose def decrease_attack(caller : Wallet, from_asset_id : Option(AssetId)) : Void {
    Asset.update(caller, Sword.asset_id, :attack, @attack -= 1)
  }

  -- invokes the specified asset with the function to invoke
  -- and any properties marked with expose
  expose def execute_special_attack_1(caller : Wallet, opponent_asset_id : AssetId, from_asset_id : Option(AssetId)) : Void {
    Asset.invoke(caller, opponent_asset_id, :receive_special_attack_1, Asset.encode(self))
  }

}

asset Shield {

  property health : Int32 = 30
  expose property name : String = "Golden Shield"

  expose def receive_special_attack_1(caller : Wallet, from_asset_id : AssetId, asset_data : EncodedAssetData) : Void {
    from_asset : Sword = Asset.decode(asset_data)
    name = from_asset.name
    health = @health - from_asset(:special_attack_1).value
    Asset.update(caller, Shield.asset_id, :health, health)
  }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment