Squirt
Its a tiny messy mashup of ruby and lua. Probably not useful to anyone wanting to get something productive done.
Run it
go run ./cmd/squirt
class Animal do
// Instance name attribute that is required with a default value of "dave".
// Any time it is assign nil, an argument error will be raised.
// same with the type constraint, any other type assigned will raise an argument error
attr name = "dave", {require: true, type: String}
func new(name)
self.name = name
end
end
class Tim isa Animal do
// Class attribute (capital name) with default value true
attr HasDepression = true
attr money
func new(money)
self.money = money
super("tim") // call super with argument of "tim"
end
func sayHello() // public instance method
print("hello world")
self._saymoney()
end
func _saymoney() // private instance method (prefixed with _)
if self.money < 10
print("nevermind")
elsif self.money > 10000
print("I have #{self.money}") // string interpolation
else
print("I have so much")
end
end
end
me = new(Tim, 10) // create a new Tim with 10 money
me.sayHello()
//tables can have both index and keyed values
tbl = {"one", "two", "three", four: "five", six: "seven"}
// loop though index with regular for loop
for i = 0; i < #tbl; i++ do
print(tbl[i])
end
// loop through keys with for in loop
for k, v in tbl do
print(k, v)
end
// while loop
while false do
print("this is a while loop")
end
// error handling can happen in any do/end block (for, while, if, func)
do
spill("This is spill an Error class error")
cleanup err = Error, ArgumentError do
print("caught err #{err}")
end
// func calls can be protected with a simple form
func raiseTheRoof()
spill(ArgumentError, "This is spill an ArgumentError class error")
return 43
end
val = raiseTheRoof() // This will raise an error
err, val = @raiseTheRoof() // This is a protected call and err will be the caught error
Decisions
- use lua type tables/buckets with different ways to interact with it.
- for num loop for general loop with classic form
- for in for key values
- self is always scoped in function defined on table, no special syntax, points to table
- default to local, no way to export to global other than returning
- assignment should be consistent
- if targets and values match, its 1:1
- if targets are less than values, the last value gets a bucket with the remaining values
- if targets are more than values, the remaining are left null
- this should work for spreads as well.
- Almost everything is a class except classes and func. So "string" is an Instance of String
Milestone 3
- Refinements and autocontructors
- initial value
-
const
- extracted and set refinements
-
type
error assigned an incorrect type - autocontructor
-
required
argument error in constructor if not passed -
get
,set
bool to set readonly or writeonly, func to allow custom setter/getter
- indexing
- index out of range handling
- range indexing
source[1:4]
-
and
andor
should return values other than bool. (false || x
should return the value of x) - ternary, maybe solve by having if statements return last values. (
x = if true then a else b end
)- already have lua style ternary
condval and iftrue or iffalse
- already have lua style ternary
- minimized operator interfaces
- != should just be !(==)
- OpNot should just use tobool and then !
- gt, gte, lt, lte to just a single <=> compare type operator
__compare
- require extension
- require stdlib
- caching
- directory require
- require paths LOAD_PATHS
- package management solution
- test tooling
- cli test flag
- assert tooling
- describe, test description blocks
Milestone 4
- localization. Configuration at the package level of what to translate each keyword into so that packages that use different languages still interop
- stdlib
- io
- file
- os
- http
Type annotations
- Parse time type annotation checking
- type annotations with inference
- function parameter matching
- function call parameter type and count check
- assignment type mismatch (maybe only on class attributes)
Education
- Docs!
- animate parsing with excerpts
- animate runtime with excerpts
Implement it
- function call
- assignment
- table def
- table index
- Binary operators
- unary operators
- block scope statements
- if statements (no break, return propagates)
- function def (no break, return)
- do block (no break, return propagates)
- for num loop (break, return propagates)
- for in loop (break, return propagates)
- while loop (break, return propagates)
- until loop (break, return propagates)
- break
- next
- return values
- self
- function call parameters
- named spread as last parameter
Change it
- long strings start and stop with `
- change comments from -- to //
- long comments with /* */
- default to local
- change function to func or fn
- take out
:
and always scopeself
- replace
~=
with!=
- use ! unary instead of
not
- replace
=
in table construction with:
- Name
- take out optional () in function calls
- take out goto/label
- add in
next
- add in
Second Milestone implementation
- runtime error with stacktrace and pointer to problem
- squirt naming
- parser error snippets with clear pointer to problem
- vim syntax highlighting
- string interpolation
- table ops
<<
,+
,-
-
toString()
andtoNumber()
- spread after table to unpack
- assignment
- function call values
- table constructor
- return values
- multiple return values
- assignment
- function call values
- table constructor
-
delete()
method for removing from tables - string indexing
-
require
-
eval
-
typeof()
- incr, decr
-=
,+=
,--
,++
Object Orientation
- Inheritance
- proposals
- parsing
- class definition
- class function definition
- method definition
- constructor
- super
- operator overriding
- unary
- binary
- delegate ops to classes for string, number, bool, table
- bool
- func
- nil
- number
- string
- table
- system
- call
- del
- tostring
- tobool
- index
- assignindex
- input args need to be classes
- Table keys need to be classes and they are not right now
- String index should be iindexable runtime.go:617
- inherit from std classes
- error handling
- block level catch/rescue with
clean
, (func, do, for, while, repeat) - throw errors with
spill
, will throw with string or class. - @ protect unary, first assign value will be an error or nil.
- block level catch/rescue with