mirror of https://github.com/japl-lang/japl.git
Merge pull request #13 from Productive2/master
Refactoring of object structures: create japlvalue.nim
This commit is contained in:
commit
7649cf6e3b
|
@ -15,9 +15,9 @@
|
||||||
|
|
||||||
import tables
|
import tables
|
||||||
import strutils
|
import strutils
|
||||||
import meta/valueobject
|
import meta/valuearray
|
||||||
import meta/tokenobject
|
import meta/tokenobject
|
||||||
import types/objecttype
|
import types/japlvalue
|
||||||
|
|
||||||
|
|
||||||
const FRAMES_MAX* = 400 # TODO: Inspect why the VM crashes if this exceeds 400
|
const FRAMES_MAX* = 400 # TODO: Inspect why the VM crashes if this exceeds 400
|
||||||
|
|
|
@ -12,13 +12,38 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
## Base structure for objects in JAPL, all
|
## Base structure for values and objects in JAPL, all
|
||||||
## types inherit from this simple structure
|
## types inherit from this simple structure
|
||||||
|
|
||||||
import tables
|
import tables
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
Chunk* = ref object
|
||||||
|
## A piece of bytecode.
|
||||||
|
## Consts represents (TODO newdoc)
|
||||||
|
## Code represents (TODO newdoc)
|
||||||
|
## Lines represents (TODO newdoc)
|
||||||
|
consts*: ValueArray
|
||||||
|
code*: seq[uint8]
|
||||||
|
lines*: seq[int]
|
||||||
|
|
||||||
|
ValueType* {.pure.} = enum
|
||||||
|
# All possible value types (this is the VM's notion of 'type', not the end user's)
|
||||||
|
Integer, Double, Bool, Nil, Object, Nan, Inf, Minf
|
||||||
|
Value* = object
|
||||||
|
## Represents an internal JAPL type
|
||||||
|
case kind*: ValueType
|
||||||
|
of ValueType.Integer:
|
||||||
|
intValue*: int
|
||||||
|
of ValueType.Double:
|
||||||
|
floatValue*: float
|
||||||
|
of ValueType.Bool:
|
||||||
|
boolValue*: bool
|
||||||
|
of ValueType.Nil, ValueType.Inf, ValueType.Nan, ValueType.Minf:
|
||||||
|
discard
|
||||||
|
of ValueType.Object:
|
||||||
|
obj*: ptr Obj
|
||||||
|
|
||||||
ObjectType* {.pure.} = enum
|
ObjectType* {.pure.} = enum
|
||||||
## The type of the object
|
## The type of the object
|
||||||
## (Also see meta/valueobject/ValueType)
|
## (Also see meta/valueobject/ValueType)
|
|
@ -15,8 +15,7 @@
|
||||||
## The module dedicated to the Chunk type
|
## The module dedicated to the Chunk type
|
||||||
## A chunk is a piece of bytecode.
|
## A chunk is a piece of bytecode.
|
||||||
|
|
||||||
import valueobject
|
import japlvalue
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
OpCode* {.pure.} = enum
|
OpCode* {.pure.} = enum
|
||||||
|
@ -63,14 +62,6 @@ type
|
||||||
Bnot
|
Bnot
|
||||||
|
|
||||||
|
|
||||||
Chunk* = ref object
|
|
||||||
## A piece of bytecode.
|
|
||||||
## Consts represents (TODO newdoc)
|
|
||||||
## Code represents (TODO newdoc)
|
|
||||||
## Lines represents (TODO newdoc)
|
|
||||||
consts*: ValueArray
|
|
||||||
code*: seq[uint8]
|
|
||||||
lines*: seq[int]
|
|
||||||
|
|
||||||
const simpleInstructions* = {OpCode.Return, OpCode.Add, OpCode.Multiply,
|
const simpleInstructions* = {OpCode.Return, OpCode.Add, OpCode.Multiply,
|
||||||
OpCode.Divide, OpCode.Subtract,
|
OpCode.Divide, OpCode.Subtract,
|
|
@ -19,29 +19,12 @@
|
||||||
## allocated on the heap, while the simpler ones live on the stack
|
## allocated on the heap, while the simpler ones live on the stack
|
||||||
|
|
||||||
# import ../types/functiontype
|
# import ../types/functiontype
|
||||||
import ../types/objecttype
|
import japlvalue
|
||||||
import ../types/stringtype
|
import ../types/stringtype
|
||||||
import strformat
|
import strformat
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ValueType* {.pure.} = enum
|
|
||||||
# All possible value types (this is the VM's notion of 'type', not the end user's)
|
|
||||||
Integer, Double, Bool, Nil, Object, Nan, Inf, Minf
|
|
||||||
Value* = object
|
|
||||||
## Represents an internal JAPL type
|
|
||||||
case kind*: ValueType
|
|
||||||
of ValueType.Integer:
|
|
||||||
intValue*: int
|
|
||||||
of ValueType.Double:
|
|
||||||
floatValue*: float
|
|
||||||
of ValueType.Bool:
|
|
||||||
boolValue*: bool
|
|
||||||
of ValueType.Nil, ValueType.Inf, ValueType.Nan, ValueType.Minf:
|
|
||||||
discard
|
|
||||||
of ValueType.Object:
|
|
||||||
obj*: ptr Obj
|
|
||||||
|
|
||||||
ValueArray* = ref object
|
ValueArray* = ref object
|
||||||
values*: seq[Value]
|
values*: seq[Value]
|
||||||
|
|
Loading…
Reference in New Issue