forked from Mirror/wren
Merge branch 'master' of https://github.com/munificent/wren
This commit is contained in:
14
.gitignore
vendored
14
.gitignore
vendored
@ -17,3 +17,17 @@ scratch.wren
|
||||
|
||||
# The baseline file is machine-specific, so doesn't get checked in.
|
||||
test/benchmark/baseline.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
@ -17,7 +17,7 @@ Removes all items from the list.
|
||||
|
||||
The number of items in the list.
|
||||
|
||||
### **insert**(item, index)
|
||||
### **insert**(index, item)
|
||||
|
||||
**TODO**
|
||||
|
||||
|
||||
@ -71,10 +71,10 @@ use `add` to append a single item to the end:
|
||||
You can insert a new element at a specific position using `insert`:
|
||||
|
||||
:::dart
|
||||
hirsute.insert("soul patch", 2)
|
||||
hirsute.insert(2, "soul patch")
|
||||
|
||||
The first argument is the value to insert, and the second is the index to
|
||||
insert it at. All elements following the inserted one will be pushed down to
|
||||
The first argument is the index to insert at, and the second is the value to
|
||||
insert. All elements following the inserted one will be pushed down to
|
||||
make room for it.
|
||||
|
||||
It's valid to "insert" after the last element in the list, but only *right*
|
||||
@ -83,9 +83,9 @@ back. Doing so counts back from the size of the list *after* it's grown by one:
|
||||
|
||||
:::dart
|
||||
var letters = ["a", "b", "c"]
|
||||
letters.insert("d", 3) // OK: inserts at end.
|
||||
letters.insert(3, "d") // OK: inserts at end.
|
||||
IO.print(letters) // ["a", "b", "c", "d"]
|
||||
letters.insert("e", -2) // Counts back from size after insert.
|
||||
letters.insert(-2, "e") // Counts back from size after insert.
|
||||
IO.print(letters) // ["a", "b", "c", "e", "d"]
|
||||
|
||||
## Removing elements
|
||||
|
||||
@ -41,9 +41,11 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)..\..\src\include</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)..\..\src\include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@ -78,25 +80,25 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\src\main.c" />
|
||||
<ClCompile Include="..\..\..\src\wren_compiler.c" />
|
||||
<ClCompile Include="..\..\..\src\wren_core.c" />
|
||||
<ClCompile Include="..\..\..\src\wren_debug.c" />
|
||||
<ClCompile Include="..\..\..\src\wren_io.c" />
|
||||
<ClCompile Include="..\..\..\src\wren_utils.c" />
|
||||
<ClCompile Include="..\..\..\src\wren_value.c" />
|
||||
<ClCompile Include="..\..\..\src\wren_vm.c" />
|
||||
<ClCompile Include="..\..\..\src\cli\main.c" />
|
||||
<ClCompile Include="..\..\..\src\vm\wren_compiler.c" />
|
||||
<ClCompile Include="..\..\..\src\vm\wren_core.c" />
|
||||
<ClCompile Include="..\..\..\src\vm\wren_debug.c" />
|
||||
<ClCompile Include="..\..\..\src\vm\wren_io.c" />
|
||||
<ClCompile Include="..\..\..\src\vm\wren_utils.c" />
|
||||
<ClCompile Include="..\..\..\src\vm\wren_value.c" />
|
||||
<ClCompile Include="..\..\..\src\vm\wren_vm.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\include\wren.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_common.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_compiler.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_core.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_debug.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_io.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_utils.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_value.h" />
|
||||
<ClInclude Include="..\..\..\src\wren_vm.h" />
|
||||
<ClInclude Include="..\..\..\src\include\wren.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_common.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_compiler.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_core.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_debug.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_io.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_utils.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_value.h" />
|
||||
<ClInclude Include="..\..\..\src\vm\wren_vm.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@ -15,57 +15,57 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\src\main.c">
|
||||
<ClCompile Include="..\..\..\src\cli\main.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\wren_compiler.c">
|
||||
<ClCompile Include="..\..\..\src\vm\wren_compiler.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\wren_core.c">
|
||||
<ClCompile Include="..\..\..\src\vm\wren_core.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\wren_debug.c">
|
||||
<ClCompile Include="..\..\..\src\vm\wren_debug.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\wren_io.c">
|
||||
<ClCompile Include="..\..\..\src\vm\wren_io.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\wren_utils.c">
|
||||
<ClCompile Include="..\..\..\src\vm\wren_utils.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\wren_value.c">
|
||||
<ClCompile Include="..\..\..\src\vm\wren_value.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\wren_vm.c">
|
||||
<ClCompile Include="..\..\..\src\vm\wren_vm.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\include\wren.h">
|
||||
<ClInclude Include="..\..\..\src\include\wren.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_common.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_common.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_compiler.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_compiler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_core.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_core.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_debug.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_debug.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_io.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_io.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_utils.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_value.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_value.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\wren_vm.h">
|
||||
<ClInclude Include="..\..\..\src\vm\wren_vm.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
||||
@ -690,11 +690,11 @@ DEF_PRIMITIVE(list_insert)
|
||||
ObjList* list = AS_LIST(args[0]);
|
||||
|
||||
// count + 1 here so you can "insert" at the very end.
|
||||
int index = validateIndex(vm, args, list->count + 1, 2, "Index");
|
||||
int index = validateIndex(vm, args, list->count + 1, 1, "Index");
|
||||
if (index == -1) return PRIM_ERROR;
|
||||
|
||||
wrenListInsert(vm, list, args[1], index);
|
||||
RETURN_VAL(args[1]);
|
||||
wrenListInsert(vm, list, args[2], index);
|
||||
RETURN_VAL(args[2]);
|
||||
}
|
||||
|
||||
DEF_PRIMITIVE(list_iterate)
|
||||
|
||||
@ -1,41 +1,41 @@
|
||||
// Add to empty list.
|
||||
var a = []
|
||||
a.insert(1, 0)
|
||||
a.insert(0, 1)
|
||||
IO.print(a) // expect: [1]
|
||||
|
||||
// Normal indices.
|
||||
var b = [1, 2, 3]
|
||||
b.insert(4, 0)
|
||||
b.insert(0, 4)
|
||||
IO.print(b) // expect: [4, 1, 2, 3]
|
||||
|
||||
var c = [1, 2, 3]
|
||||
c.insert(4, 1)
|
||||
c.insert(1, 4)
|
||||
IO.print(c) // expect: [1, 4, 2, 3]
|
||||
|
||||
var d = [1, 2, 3]
|
||||
d.insert(4, 2)
|
||||
d.insert(2, 4)
|
||||
IO.print(d) // expect: [1, 2, 4, 3]
|
||||
|
||||
var e = [1, 2, 3]
|
||||
e.insert(4, 3)
|
||||
e.insert(3, 4)
|
||||
IO.print(e) // expect: [1, 2, 3, 4]
|
||||
|
||||
// Negative indices.
|
||||
var f = [1, 2, 3]
|
||||
f.insert(4, -4)
|
||||
f.insert(-4, 4)
|
||||
IO.print(f) // expect: [4, 1, 2, 3]
|
||||
|
||||
var g = [1, 2, 3]
|
||||
g.insert(4, -3)
|
||||
g.insert(-3, 4)
|
||||
IO.print(g) // expect: [1, 4, 2, 3]
|
||||
|
||||
var h = [1, 2, 3]
|
||||
h.insert(4, -2)
|
||||
h.insert(-2, 4)
|
||||
IO.print(h) // expect: [1, 2, 4, 3]
|
||||
|
||||
var i = [1, 2, 3]
|
||||
i.insert(4, -1)
|
||||
i.insert(-1, 4)
|
||||
IO.print(i) // expect: [1, 2, 3, 4]
|
||||
|
||||
// Returns.inserted value.
|
||||
IO.print([1, 2].insert(3, 0)) // expect: 3
|
||||
IO.print([1, 2].insert(0, 3)) // expect: 3
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", 1.5) // expect runtime error: Index must be an integer.
|
||||
a.insert(1.5, "value") // expect runtime error: Index must be an integer.
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", "2") // expect runtime error: Index must be a number.
|
||||
a.insert("2", "value") // expect runtime error: Index must be a number.
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", 4) // expect runtime error: Index out of bounds.
|
||||
a.insert(4, "value") // expect runtime error: Index out of bounds.
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", -5) // expect runtime error: Index out of bounds.
|
||||
a.insert(-5, "value") // expect runtime error: Index out of bounds.
|
||||
|
||||
Reference in New Issue
Block a user