Skip to content

Commit

Permalink
range iterator
Browse files Browse the repository at this point in the history
also pointer addr is now 'write'
  • Loading branch information
borisbat committed Aug 29, 2019
1 parent 66a058c commit ff912f0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/test/hello_world.das
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
options log=true, logStack=true, logNodes=true
options printVarAccess=true

[unsafe,sideeffects]
def test_range
let rng = range(1,5)
let rit : iterator<int> = _builtin_make_range_iterator(rng);
var ikey : int
var pkey : void? = reinterpret<void?>(addr(ikey))
var loop = _builtin_iterator_first(rit,pkey)
while loop
print("rval = {ikey}\n")
loop = _builtin_iterator_next(rit,pkey)
_builtin_iterator_close(rit,pkey)

[unsafe,sideeffects]
def test_good_array
Expand Down Expand Up @@ -51,6 +64,8 @@ def test_keys_values

[export]
def test
test_range()
return true
test_fixed_array()
test_good_array()
test_keys_values()
Expand Down
1 change: 1 addition & 0 deletions include/daScript/simulate/aot_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ namespace das {

Iterator * builtin_make_good_array_iterator ( const Array & arr, int stride, Context * context );
Iterator * builtin_make_fixed_array_iterator ( void * data, int size, int stride, Context * context );
Iterator * builtin_make_range_iterator ( range rng, Context * context );
}
7 changes: 7 additions & 0 deletions src/ast/ast_unused.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ namespace das {
// at some point we should do better data trackng for this type of aliasing
if ( var->type->ref ) propagateWrite(init);
}
// addr of expression
virtual void preVisit ( ExprRef2Ptr * expr ) override {
Visitor::preVisit(expr);
// TODO:
// at some point we should do better data trackng for this type of aliasing
propagateWrite(expr);
}
// ExprField
virtual void preVisit ( ExprField * expr ) override {
Visitor::preVisit(expr);
Expand Down
9 changes: 9 additions & 0 deletions src/builtin/module_builtin_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "daScript/simulate/hash.h"
#include "daScript/simulate/bin_serializer.h"
#include "daScript/simulate/runtime_array.h"
#include "daScript/simulate/runtime_range.h"

namespace das
{
Expand Down Expand Up @@ -214,6 +215,12 @@ namespace das
return (Iterator *) iter;
}

Iterator * builtin_make_range_iterator ( range rng, Context * context ) {
char * iter = context->heap.allocate(sizeof(RangeIterator));
new (iter) RangeIterator(rng);
return (Iterator *) iter;
}

void Module_BuiltIn::addRuntime(ModuleLibrary & lib) {
// function annotations
addAnnotation(make_shared<CommentAnnotation>());
Expand All @@ -235,6 +242,8 @@ namespace das
SideEffects::modifyExternal, "builtin_make_good_array_iterator");
addExtern<DAS_BIND_FUN(builtin_make_fixed_array_iterator)>(*this, lib, "_builtin_make_fixed_array_iterator",
SideEffects::modifyExternal, "builtin_make_fixed_array_iterator");
addExtern<DAS_BIND_FUN(builtin_make_range_iterator)>(*this, lib, "_builtin_make_range_iterator",
SideEffects::modifyExternal, "builtin_make_range_iterator");
// functions
addExtern<DAS_BIND_FUN(builtin_throw)> (*this, lib, "panic", SideEffects::modifyExternal, "builtin_throw");
addExtern<DAS_BIND_FUN(builtin_print)> (*this, lib, "print", SideEffects::modifyExternal, "builtin_print");
Expand Down

0 comments on commit ff912f0

Please sign in to comment.