mirror of https://github.com/japl-lang/japl.git
setting up conflict resolution
This commit is contained in:
commit
b3ff804296
|
@ -26,11 +26,11 @@ var a = "global";
|
|||
var b = "global1";
|
||||
{ // open a new scope
|
||||
var b = "local"; // Shadow the global variable
|
||||
print(a; // This falls back to the global scope
|
||||
print(b;
|
||||
print(a); // This falls back to the global scope
|
||||
print(b);
|
||||
}
|
||||
print(a);
|
||||
print(b)] // The outer scope isn't affected
|
||||
print(b); // The outer scope isn't affected
|
||||
|
||||
/*
|
||||
A multiline comment
|
||||
|
|
|
@ -12,8 +12,8 @@ fun factorial(n) {
|
|||
|
||||
|
||||
var start = clock();
|
||||
print "Computing factorials from 0 to 200";
|
||||
print("Computing factorials from 0 to 200");
|
||||
for (var i = 0; i < 201; i = i + 1) factorial(i);
|
||||
var result = clock() - start;
|
||||
print "Computed factorials in " + stringify(result) + " seconds";
|
||||
print("Computed factorials in " + stringify(result) + " seconds");
|
||||
|
||||
|
|
|
@ -16,7 +16,12 @@
|
|||
## types inherit from this simple structure
|
||||
|
||||
import tables
|
||||
import ../meta/chunk
|
||||
<<<<<<< HEAD
|
||||
import ../meta/japlvalue
|
||||
=======
|
||||
import ../types/objecttype
|
||||
|
||||
>>>>>>> upstream/master
|
||||
|
||||
type
|
||||
Chunk* = ref object
|
||||
|
@ -24,6 +29,7 @@ type
|
|||
## Consts represents (TODO newdoc)
|
||||
## Code represents (TODO newdoc)
|
||||
## Lines represents (TODO newdoc)
|
||||
<<<<<<< HEAD
|
||||
consts*: ValueArray
|
||||
code*: seq[uint8]
|
||||
lines*: seq[int]
|
||||
|
@ -130,8 +136,13 @@ proc bool*(obj: ptr Obj): bool =
|
|||
|
||||
|
||||
proc eq*(a: ptr Obj, b: ptr Obj): bool =
|
||||
## Compares two
|
||||
result = a.kind == b.kind
|
||||
## Compares two objects for equality
|
||||
|
||||
if obj.kind != ObjectType.BaseObject:
|
||||
var newObj = convert obj
|
||||
result = newObj.eq()
|
||||
else:
|
||||
result = a.kind == b.kind
|
||||
|
||||
|
||||
proc hash*(self: ptr Obj): uint32 =
|
||||
|
@ -191,3 +202,8 @@ proc binaryXor(self, other: ptr Obj): ptr Obj =
|
|||
## Returns the result of self ^ other
|
||||
## or nil if the operation is unsupported
|
||||
result = nil
|
||||
=======
|
||||
consts*: seq[ptr Obj]
|
||||
code*: seq[uint8]
|
||||
lines*: seq[int]
|
||||
>>>>>>> upstream/master
|
||||
|
|
|
@ -15,10 +15,14 @@
|
|||
## The module dedicated to the Chunk type
|
||||
## A chunk is a piece of bytecode.
|
||||
|
||||
<<<<<<< HEAD:meta/opcode.nim
|
||||
<<<<<<< HEAD:meta/chunk.nim
|
||||
=======
|
||||
import japlvalue
|
||||
>>>>>>> 7649cf6e3bdf4ce47c9c63bbdbe3e99a53274a8d:meta/opcode.nim
|
||||
=======
|
||||
import ../types/objecttype
|
||||
>>>>>>> upstream/master:meta/chunk.nim
|
||||
|
||||
type
|
||||
OpCode* {.pure.} = enum
|
||||
|
@ -97,7 +101,7 @@ const jumpInstructions* = {OpCode.JumpIfFalse, OpCode.Jump, OpCode.Loop}
|
|||
|
||||
proc newChunk*(): Chunk =
|
||||
## The constructor for the type Chunk
|
||||
result = Chunk(consts: ValueArray(values: @[]), code: @[], lines: @[])
|
||||
result = Chunk(consts: @[], code: @[], lines: @[])
|
||||
|
||||
|
||||
proc writeChunk*(self: Chunk, newByte: uint8, line: int) =
|
||||
|
@ -114,18 +118,18 @@ proc writeChunk*(self: Chunk, bytes: array[3, uint8], line: int) =
|
|||
|
||||
proc freeChunk*(self: Chunk) =
|
||||
## Resets a chunk to its initial value.
|
||||
self.consts = ValueArray(values: @[])
|
||||
self.consts = @[]
|
||||
self.code = @[]
|
||||
self.lines = @[]
|
||||
|
||||
|
||||
proc addConstant*(self: Chunk, constant: Value): int =
|
||||
proc addConstant*(self: Chunk, constant: ptr Obj): int =
|
||||
## Adds a constant to a chunk. Returns its index.
|
||||
self.consts.values.add(constant)
|
||||
return self.consts.values.high() # The index of the constant
|
||||
self.consts.add(constant)
|
||||
return self.consts.high() # The index of the constant
|
||||
|
||||
|
||||
proc writeConstant*(self: Chunk, constant: Value): array[3, uint8] =
|
||||
proc writeConstant*(self: Chunk, constant: ptr Obj): array[3, uint8] =
|
||||
## Writes a constant to a chunk. Returns its index casted to an array.
|
||||
## TODO newdoc
|
||||
let index = self.addConstant(constant)
|
|
@ -42,7 +42,7 @@ proc hash*(self: ptr String): uint32 =
|
|||
return result
|
||||
|
||||
|
||||
proc valuesEqual*(a: ptr String, b: ptr String): bool =
|
||||
proc eq*(a: ptr String, b: ptr String): bool =
|
||||
if a.len != b.len:
|
||||
return false
|
||||
elif a.hash != b.hash:
|
||||
|
|
Loading…
Reference in New Issue