|
@ -1897,6 +1897,71 @@ oop prim_String(oop scope, oop params) |
|
|
return makeString(printString(get(params, Map, elements)[0].value)); |
|
|
return makeString(printString(get(params, Map, elements)[0].value)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_Integer(oop scope, oop params) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!map_hasIntegerKey(params, 0)) return null; |
|
|
|
|
|
oop arg= get(params, Map, elements)[0].value; |
|
|
|
|
|
switch (getType(arg)) { |
|
|
|
|
|
case Undefined: { |
|
|
|
|
|
return makeInteger(0); |
|
|
|
|
|
} |
|
|
|
|
|
case Integer: { |
|
|
|
|
|
// does it make sense to copy an integer? |
|
|
|
|
|
// return arg; |
|
|
|
|
|
return makeInteger(getInteger(arg)); |
|
|
|
|
|
} |
|
|
|
|
|
case String: { |
|
|
|
|
|
return makeInteger(strtoll(get(arg, String, value), NULL, 10)); |
|
|
|
|
|
} |
|
|
|
|
|
case Symbol: { |
|
|
|
|
|
// since symbol are ident, they cannot start with a number so it's impossible that strtoll succeed |
|
|
|
|
|
return makeInteger(strtoll(get(arg, Symbol, name), NULL, 10)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_Map(oop scope, oop params) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!map_hasIntegerKey(params, 0)) return null; |
|
|
|
|
|
oop arg= get(params, Map, elements)[0].value; |
|
|
|
|
|
switch (getType(arg)) { |
|
|
|
|
|
case Undefined: { |
|
|
|
|
|
return makeMap(); |
|
|
|
|
|
} |
|
|
|
|
|
case Integer: { |
|
|
|
|
|
oop map= makeMap(); |
|
|
|
|
|
map_set(map, makeInteger(0), arg); |
|
|
|
|
|
return map; |
|
|
|
|
|
} |
|
|
|
|
|
case Function: { |
|
|
|
|
|
oop map= makeMap(); |
|
|
|
|
|
map_set(map, get(arg, Function, name), arg); |
|
|
|
|
|
return map; |
|
|
|
|
|
} |
|
|
|
|
|
case String: { |
|
|
|
|
|
oop map= makeMap(); |
|
|
|
|
|
size_t len= string_size(arg); |
|
|
|
|
|
for(size_t i=0; i<len; ++i) { |
|
|
|
|
|
map_set(map, makeInteger(i), makeInteger(get(arg, String, value)[i])); |
|
|
|
|
|
} |
|
|
|
|
|
return map; |
|
|
|
|
|
} |
|
|
|
|
|
case Symbol: { |
|
|
|
|
|
oop map= makeMap(); |
|
|
|
|
|
size_t len= strlen(get(arg, Symbol, name)); |
|
|
|
|
|
for(size_t i=0; i<len; ++i) { |
|
|
|
|
|
map_set(map, makeInteger(i), makeInteger(get(arg, Symbol, name)[i])); |
|
|
|
|
|
} |
|
|
|
|
|
return map; |
|
|
|
|
|
} |
|
|
|
|
|
case Map: { |
|
|
|
|
|
return clone(arg); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
oop prim_scope(oop scope, oop params) |
|
|
oop prim_scope(oop scope, oop params) |
|
|
{ |
|
|
{ |
|
|
return fixScope(scope); |
|
|
return fixScope(scope); |
|
@ -1931,6 +1996,8 @@ int main(int argc, char **argv) |
|
|
map_set(globals, intern("import" ), makeFunction(prim_import, intern("import" ), null, null, globals, null)); |
|
|
map_set(globals, intern("import" ), makeFunction(prim_import, intern("import" ), null, null, globals, null)); |
|
|
map_set(globals, intern("microseconds"), makeFunction(prim_microseconds, intern("microseconds"), null, null, globals, null)); |
|
|
map_set(globals, intern("microseconds"), makeFunction(prim_microseconds, intern("microseconds"), null, null, globals, null)); |
|
|
map_set(globals, intern("String" ), makeFunction(prim_String , intern("String" ), null, null, globals, null)); |
|
|
map_set(globals, intern("String" ), makeFunction(prim_String , intern("String" ), null, null, globals, null)); |
|
|
|
|
|
map_set(globals, intern("Integer" ), makeFunction(prim_Integer , intern("Integer" ), null, null, globals, null)); |
|
|
|
|
|
map_set(globals, intern("Map" ), makeFunction(prim_Map , intern("Map" ), null, null, globals, null)); |
|
|
|
|
|
|
|
|
map_set(globals, intern("scope"), makeFunction(prim_scope, intern("scope"), null, null, globals, null)); |
|
|
map_set(globals, intern("scope"), makeFunction(prim_scope, intern("scope"), null, null, globals, null)); |
|
|
|
|
|
|
|
|