some old wip shit
This commit is contained in:
parent
305642b5a4
commit
72099ccf22
@ -1,40 +1,78 @@
|
|||||||
I need to figure out how the compiler-time vs run-time execution is going to
|
# Types
|
||||||
work, and how I'm going to differentiate between the two in the language.
|
|
||||||
|
|
||||||
main := MainFunc()
|
## Axioms
|
||||||
foo := main.Int(1)
|
|
||||||
|
|
||||||
incrFunc := main.NewFunction(inType, outType)
|
The syntax described only applies within this document.
|
||||||
in := incrFunc.In()
|
|
||||||
add := incrFunc.Var("add") // should be macro?
|
|
||||||
out := incrFunc.Call(add, incrFunc.Int(1), in)
|
|
||||||
incrFunc.Return(out) // ugly
|
|
||||||
|
|
||||||
main.Return(main.Call(incrFunc, foo))
|
- All defined things below are values, all values have a type, all types have a
|
||||||
|
definition which is itself a value.
|
||||||
|
|
||||||
compiler := NewCompiler()
|
- A type definition is displayed as a value wrapped in angle brackets, like
|
||||||
compiler.Enter(main)
|
`<int>`.
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
- A type definition with no value, `<>`, is the empty type
|
||||||
|
|
||||||
type val { type, llvmVal }
|
- A type definition may have more than one type, as in `<int,string>`, to
|
||||||
|
indicate that a value with that type is actually a combination of each
|
||||||
|
type in sequence (i.e. a tuple)
|
||||||
|
|
||||||
type func { type, llvmVal }
|
- Tuples can be wrapped in parenthesis to indicate sub-groupings. I.e.
|
||||||
|
`<string,(int,int)>` is a tuple of 2 sub-types, the first being a
|
||||||
|
`<string>` and the second being a tuple of 2 `<ints>`.
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
- Any type definition can be used in place of `<any>`.
|
||||||
|
|
||||||
MACRO DISPATCHER as the thing which has a set of exposed methods. defmacro like
|
- `1` is an example of a value of type `<int>`.
|
||||||
thing can be built on top of it.
|
|
||||||
|
|
||||||
TYPED HEAP. Kind of like a typed map mixed with a set. Maybe looks like
|
- The type of value `<int>` is `<typedef,int>`.
|
||||||
|
-
|
||||||
|
- Any `lowercaseAlphaNumeric` string is an atom value, of type `<atom>`.
|
||||||
|
|
||||||
|
- `V<someType>` is a placeholder for a value of type `<someType>`. It is used
|
||||||
|
when matching a pattern.
|
||||||
|
|
||||||
|
- `(declareType, V<any>)` is understood to declare a type definition. A type
|
||||||
|
definition can then be used as `<typedef>`.
|
||||||
|
|
||||||
|
- `(declareFunction, V<atom>, <any>, <any>)` is a tuple understood to declare a
|
||||||
|
function, named after the atom, where the type definitions of the input and
|
||||||
|
output are also given.
|
||||||
|
|
||||||
|
## Type declarations.
|
||||||
|
|
||||||
```
|
```
|
||||||
h := make(heap[float64], 10)
|
(declareType, atom)
|
||||||
id := h.add(8.5)
|
(declareType, bool)
|
||||||
eightPointFive := h.get(id)
|
(declareType, int)
|
||||||
h.del(id)
|
|
||||||
```
|
|
||||||
|
|
||||||
Since the heap is a known size and each element in it is as well it can be
|
// general purpose functions for working with all types.
|
||||||
statically allocated at one spot in the stack and the pointer to it passed
|
(declareFunction, concat, <any, any>, <any>)
|
||||||
farther into the stack as needed.
|
(declareFunction, slice, <any,int,int>, <any>)
|
||||||
|
(declareFunction, len, <any>, <int>)
|
||||||
|
(declareFunction, eq, <any,any>, <bool>)
|
||||||
|
|
||||||
|
// functions for working with integers
|
||||||
|
(declareFunction, plus, <int,int>, <int>)
|
||||||
|
(declareFunction, mult, <int,int>, <int>)
|
||||||
|
(declareFunction, minus, <int,int>, <int>)
|
||||||
|
// these two may return false if divide by zero
|
||||||
|
(declareFunction, div, <int,int>, <int,bool>)
|
||||||
|
(declareFunction, mod, <int,int>, <int,bool>)
|
||||||
|
|
||||||
|
// a general iterator
|
||||||
|
(declareType, (iter,any))
|
||||||
|
(declareFunction, next, <iter,any>, <(iter,any),any,bool>)
|
||||||
|
|
||||||
|
// TODO structurally, what's the difference between `<int,int>` and
|
||||||
|
// `<iter,any>`? the latter's first element isn't a valid typedef on its own,
|
||||||
|
// but other than that there seems to be no difference?
|
||||||
|
|
||||||
|
//(declareCompound, graph, T)
|
||||||
|
//(declareFunction, addEdge, (tup,(graph,T),T,T), (tup,graph,T))
|
||||||
|
//(declareFunction, rmEdge, (tup,(graph,T),T,T), (tup,graph,T))
|
||||||
|
//// the order of elements returned by parents/children is the same as the order
|
||||||
|
//// the edges between the nodes were added.
|
||||||
|
//(declareFunction, parents, (tup,(graph,T),T), (tup,(iter,T)))
|
||||||
|
//(declareFunction, children, (tup,(graph,T),T), (tup,(iter,T)))
|
||||||
|
//(declareFunction, has, (tup,(graph,T),T), bool)
|
||||||
|
//```
|
||||||
|
Loading…
Reference in New Issue
Block a user